본문 바로가기
개발일지

08-26~08-27 Boss 패턴 2 및 Boss Tree변경, Enemy AOE, Projectile

by ksw8596 2024. 8. 28.

BT_Boss

 

 

 

 

Pattern
BaseAttack

 

TempProjectile

 

EnemyAOE.cpp

#include "Enemy/FEnemyAOE.h"
#include "Components/SphereComponent.h"
#include "FGameFunctionLibrary.h"

// Sets default values
AFEnemyAOE::AFEnemyAOE()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("SphereComponent"));
	SetRootComponent(SphereComp);

	SphereComp->OnComponentBeginOverlap.AddDynamic(this, &AFEnemyAOE::OnComponentBeginOverlap);
	SphereComp->OnComponentEndOverlap.AddDynamic(this, &AFEnemyAOE::OnComponentEndOverlap);
}

// Called when the game starts or when spawned
void AFEnemyAOE::BeginPlay()
{
	Super::BeginPlay();

	FTimerHandle TimerHandle;
	GetWorldTimerManager().SetTimer(TimerHandle, this, &AFEnemyAOE::TickDamage, 0.5f, true);
	SetLifeSpan(5.0f);
}

// Called every frame
void AFEnemyAOE::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

void AFEnemyAOE::OnComponentBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (OtherActor->ActorHasTag(TEXT("Player")))
	{
		bPlayerCome = true;
		TargetActor = OtherActor;
	}
}

void AFEnemyAOE::OnComponentEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	if (OtherActor->ActorHasTag(TEXT("Player")))
	{
		bPlayerCome = false;
	}
}

void AFEnemyAOE::TickDamage()
{
	if (bPlayerCome)
	{
		TArray<TSubclassOf<class UFBuff>> BuffClassesToApply;
		UFGameFunctionLibrary::ApplyDamage(this, TargetActor, 2.0f, BuffClassesToApply);
	}
}