You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

9 months ago
// Copyright Zelle Games
#include "BTTask_Attack.h"
#include "AIController.h"
#include "PlayMontageCallbackProxy.h"
#include "Unit.h"
#include "BehaviorTree/BlackboardComponent.h"
EBTNodeResult::Type UBTTask_Attack::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
OwnerComponent = &OwnerComp;
const AUnit* Target = Cast<AUnit>(OwnerComp.GetBlackboardComponent()->GetValueAsObject(BlackboardKey.SelectedKeyName));
AUnit* ThisUnit = Cast<AUnit>(OwnerComp.GetAIOwner()->GetPawn());
if(!Target || !ThisUnit || Target->IsDead())
{
return EBTNodeResult::Failed;
}
if(FVector::Distance(ThisUnit->GetActorLocation(), Target->GetActorLocation()) >= ThisUnit->Range + 500)
{
return EBTNodeResult::Failed;
}
if(ThisUnit->CooldownTimer < ThisUnit->Cooldown)
{
return EBTNodeResult::Failed;
}
MontageCallbackProxy = UPlayMontageCallbackProxy::CreateProxyObjectForPlayMontage(
ThisUnit->GetMesh(),
ThisUnit->MeleeMontage[FMath::RandRange(0, ThisUnit->MeleeMontage.Num() -1)]);
if(ThisUnit->AttachedWeaponMesh && ThisUnit->AttachedWeaponMontage)
{
UPlayMontageCallbackProxy::CreateProxyObjectForPlayMontage(
ThisUnit->AttachedWeaponMesh,
ThisUnit->AttachedWeaponMontage);
}
9 months ago
ThisUnit->CooldownTimer = 0;
return EBTNodeResult::Succeeded;
}