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


#include "BTService_ChangeSpeed.h"

#include "EndlessVendetta/AI/AI_EnemyController.h"
#include "EndlessVendetta/AI/EnemyCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"

UBTService_ChangeSpeed::UBTService_ChangeSpeed()
{
	bNotifyBecomeRelevant = true;
	NodeName = TEXT("Change Speed");
}

void UBTService_ChangeSpeed::OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	Super::OnBecomeRelevant(OwnerComp, NodeMemory);
	if (const AAI_EnemyController* const EnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
	{
		if (const AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(EnemyController->GetPawn()))
		{
			EnemyCharacter->GetCharacterMovement()->MaxWalkSpeed = Speed;
		}
	}
}
