// Fill out your copyright notice in the Description page of Project Settings.


#include "BTTask_SetLocalAlertLevel.h"
#include "EndlessVendetta/AI/AI_EnemyController.h"
#include "EndlessVendetta/AI/EnemyCharacter.h"

UBTTask_SetLocalAlertLevel::UBTTask_SetLocalAlertLevel()
{
	NodeName = "Set Local Alert Level";
}

EBTNodeResult::Type UBTTask_SetLocalAlertLevel::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	if (const AAI_EnemyController* const AIEnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
	{
		if (const AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIEnemyController->GetPawn()))
		{
			EnemyCharacter->SetLocalAlertLevel(AlertLevel);

			FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
			return EBTNodeResult::Succeeded;
		}
	}
	return EBTNodeResult::Failed;
}
