D1/Source/D1/AI/T_PerformAttack.cpp

32 lines
1.1 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "AI/T_PerformAttack.h"
#include "AIController.h"
#include "Interface/CombatInterface.h"
EBTNodeResult::Type UT_PerformAttack::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
EBTNodeResult::Type result = Super::ExecuteTask(OwnerComp, NodeMemory);
if(result == EBTNodeResult::Failed)
return EBTNodeResult::Failed;
APawn* ControllingPawn = OwnerComp.GetAIOwner()->GetPawn();
if(ControllingPawn == nullptr)
return EBTNodeResult::Failed;
ICombatInterface* CombatInterface = Cast<ICombatInterface>(ControllingPawn);
if(!CombatInterface)
return EBTNodeResult::Failed;
float actionDuration = CombatInterface->PerformCombatAttack(AttackTypeTag, AttackIndex, RandomIndex);
actionDuration += ActionDurationModifier;
FTimerHandle ActionTimer;
GetWorld()->GetTimerManager().SetTimer(ActionTimer, FTimerDelegate::CreateLambda([&]()
{
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
}), actionDuration, false);
return EBTNodeResult::InProgress;
}