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


#include "BTTask_StopInvestigating.h"

#include "BehaviorTree/BlackboardComponent.h"
#include "EndlessVendetta/AI/AI_EnemyController.h"
#include "EndlessVendetta/AI/EnemyCharacter.h"

UBTTask_StopInvestigating::UBTTask_StopInvestigating()
{
	NodeName = TEXT("Stop Investigating");
}

EBTNodeResult::Type UBTTask_StopInvestigating::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	if (AAI_EnemyController* const EnemyController = Cast<AAI_EnemyController>(OwnerComp.GetOwner()))
	{
		if (UBlackboardComponent* const BlackboardComponent = OwnerComp.GetBlackboardComponent())
		{
			BlackboardComponent->ClearValue(GetSelectedBlackboardKey());
			FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
			return EBTNodeResult::Succeeded;
		}
	}
	return EBTNodeResult::Failed;
}
