Add AttackToken methods to EnemyAIController

This commit is contained in:
Louis Hobbs 2023-08-21 23:43:49 +01:00
parent ca07abb131
commit 0afcd945ce
2 changed files with 44 additions and 0 deletions

View File

@ -3,6 +3,8 @@
#include "EnemyAIController.h"
#include "Engine/EngineTypes.h"
#include "Components/CapsuleComponent.h"
#include "NakatomiGameInstance.h"
#include <Kismet/GameplayStatics.h>
AEnemyAIController::AEnemyAIController(const FObjectInitializer& object_initializer)
{
@ -135,3 +137,34 @@ void AEnemyAIController::OnPerceptionUpdated(const TArray<AActor*>& actors)
}
}
}
bool AEnemyAIController::TryObtainAttackToken()
{
if (HasAttackToken)
{
return true;
}
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
HasAttackToken = gameInstance->GetAIAttackTokenManager()->RequestToken();
}
return false;
}
void AEnemyAIController::TryReleaseAttackToken()
{
if (HasAttackToken)
{
if (auto gameInstance = Cast<UNakatomiGameInstance>(UGameplayStatics::GetGameInstance(GetWorld())))
{
HasAttackToken = gameInstance->GetAIAttackTokenManager()->ReleaseToken();
}
}
}
bool AEnemyAIController::GetHasAttackToken()
{
return HasAttackToken;
}

View File

@ -30,6 +30,8 @@ private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
UAIPerceptionComponent* AIPerception;
bool HasAttackToken = false;
public:
AEnemyAIController(const FObjectInitializer& object_initializer);
@ -49,4 +51,13 @@ public:
UFUNCTION()
void OnPerceptionUpdated(const TArray<AActor*>& actors);
UFUNCTION()
bool TryObtainAttackToken();
UFUNCTION()
void TryReleaseAttackToken();
UFUNCTION()
bool GetHasAttackToken();
};