🎮 IWeaponInterface.h
class BOSSFIGHT_API IWeaponInterface { GENERATED_BODY() // Add interface functions to this class. This is the class that will be inherited to implement this interface. public: virtual void AttackTrace() = 0; virtual void OnHitActor(AActor* HitActor) = 0; virtual void AttackEnd() = 0; virtual void AttackStart() = 0; };위와 같이 IWeaponInterface에 공격 시작을 알리는 AttackStart() 순수 가상함수를 작성 하였다.
🎮 AWeaponBase.cpp
void AWeaponBase::AttackEnd() { HitedActor = nullptr; WeaponCollision->SetCollisionEnabled(ECollisionEnabled::NoCollision); } void AWeaponBase::AttackStart() { WeaponCollision->SetCollisionEnabled(ECollisionEnabled::QueryOnly); }이후 AWeaponBase Class에서 위와 같이 SetCollisionEnabled()함수를 통해 Collision을 활성화 및 비활성화 하고 있다.
🎮 APlayerWeapon.h
UCLASS() class BOSSFIGHT_API APlayerWeapon : public AWeaponBase { GENERATED_BODY() //중략 UFUNCTION() void OnWeaponParryOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); protected: APlayerWeapon(); //중략 };🎮 APlayerWeapon.cpp
APlayerWeapon::APlayerWeapon() { WeaponCollision->OnComponentBeginOverlap.AddDynamic(this, &APlayerWeapon::OnWeaponParryOverlap); } void APlayerWeapon::OnWeaponParryOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { UBFFunctionLibrary::AddGameplayTagToActorIfNone(GetOwner(), BFGameplayTag::Player_Status_ParrySuccess) ; }우선은 간단하게 Tag를 부착하고, 해당 Tag가 있으면 데미지를 받지 않도록 구현 해보자.
void AEnemyWeapon::OnHitActor(AActor* HitActor) { if (HitedActor == HitActor) { return; } HitedActor = HitActor; if (UBFFunctionLibrary::NativeDoseActorHaveTag(HitedActor, BFGameplayTag::Player_Status_Avoiding)) { return; } if (UBFFunctionLibrary::NativeDoseActorHaveTag(HitedActor, BFGameplayTag::Player_Status_ParrySuccess)) { return; } FGameplayEventData Data; Data.Instigator = GetOwner(); Data.Target = HitActor; UAbilitySystemBlueprintLibrary::SendGameplayEventToActor(GetOwner(), BFGameplayTag::Shared_Event_OnDamaged, Data); if (UBFFunctionLibrary::NativeDoseActorHaveTag(GetOwner(), BFGameplayTag::Enemy_Status_Attack_Normal)) { UAbilitySystemBlueprintLibrary::SendGameplayEventToActor(HitedActor, BFGameplayTag::Player_Event_OnHit_Normal, FGameplayEventData()); } else if (UBFFunctionLibrary::NativeDoseActorHaveTag(GetOwner(), BFGameplayTag::Enemy_Status_Attack_Power)) { UAbilitySystemBlueprintLibrary::SendGameplayEventToActor(HitedActor, BFGameplayTag::Player_Event_OnHit_Power, FGameplayEventData()); } }
🎮 UPawnCombetComponent.cpp
void UPawnCombetComponent::AttackStart(EBFEquipType Type) { UPawnEquipmentComponent* EquipmentComponent = Cast<IPawnEquipmentInterface>(GetOwner())->GetPawnEquipmentComponent(); IWeaponInterface* WeaponInterface = Cast<IWeaponInterface>(EquipmentComponent->GetCurrentWeapon(Type)); WeaponInterface->AttackStart(); }위의 함수는 BlueprintCallable로 구현 하였다.
