D1/Source/D1/AI/BehaviorTreeNodes/T_PerformAction.cpp

32 lines
1.1 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "AI/BehaviorTreeNodes/T_PerformAction.h"
#include "AIController.h"
#include "Interface/CombatInterface.h"
EBTNodeResult::Type UT_PerformAction::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->PerformAction(ActionTag, StateTag, MontageIndex, RandomIndex);
actionDuration += ActionDurationModifier;
FTimerHandle ActionTimer;
GetWorld()->GetTimerManager().SetTimer(ActionTimer, FTimerDelegate::CreateLambda([&]()
{
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
}), actionDuration, false);
return EBTNodeResult::InProgress;
}