// Fill out your copyright notice in the Description page of PrBTTask_LowerWeapon.h"

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

UBTTask_LowerWeapon::UBTTask_LowerWeapon()
{
	NodeName = "Lower Weapon";
}

EBTNodeResult::Type UBTTask_LowerWeapon::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	if (const AAI_EnemyController* const AIEnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
	{
		if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIEnemyController->GetPawn()))
		{
			if (!EnemyCharacter->WeaponRaised)
			{
				FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
				return EBTNodeResult::Succeeded;
			}
			EnemyCharacter->DeEquipWeapon();
			EnemyCharacter->WeaponRaised = false;

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

	return EBTNodeResult::Failed;
}
