Update AI, Character to Detect If Being Investigated

This commit is contained in:
Philip W 2024-04-18 21:26:09 +01:00
parent 6e056a94f2
commit 0b9791086e
4 changed files with 47 additions and 6 deletions

View File

@ -117,13 +117,20 @@ void AAI_EnemyController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus c
GetBlackboardComponent()->ClearValue("TargetLocation"); GetBlackboardComponent()->ClearValue("TargetLocation");
GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", false); GetBlackboardComponent()->SetValueAsBool("CanSeePlayer", false);
GetBlackboardComponent()->SetValueAsBool("SeenWithHostilities", false); GetBlackboardComponent()->SetValueAsBool("SeenWithHostilities", false);
if (!GetBlackboardComponent()->GetValueAsBool("SeenWithHostilities"))
{
PlayerCharacter->DecrementSeenHostileCount(); PlayerCharacter->DecrementSeenHostileCount();
} }
}
if (Stimulus.WasSuccessfullySensed() && Stimulus.Type == HearingConfig->GetSenseID()) if (Stimulus.WasSuccessfullySensed() && Stimulus.Type == HearingConfig->GetSenseID())
{ {
GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor); GetBlackboardComponent()->SetValueAsObject("TargetPlayer", Actor);
GetBlackboardComponent()->SetValueAsVector("InvestigationLocation", Stimulus.StimulusLocation); GetBlackboardComponent()->SetValueAsVector("InvestigationLocation", Stimulus.StimulusLocation);
if (!GetBlackboardComponent()->GetValueAsBool("IsInvestigating"))
{
PlayerCharacter->IncrementBeingInvestigatedCount();
}
GetBlackboardComponent()->SetValueAsBool("IsInvestigating", true); GetBlackboardComponent()->SetValueAsBool("IsInvestigating", true);
} }
else if (!Stimulus.WasSuccessfullySensed() && Stimulus.Type == HearingConfig->GetSenseID()) else if (!Stimulus.WasSuccessfullySensed() && Stimulus.Type == HearingConfig->GetSenseID())

View File

@ -4,6 +4,7 @@
#include "BTTask_StopInvestigating.h" #include "BTTask_StopInvestigating.h"
#include "BehaviorTree/BlackboardComponent.h" #include "BehaviorTree/BlackboardComponent.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/AI/AI_EnemyController.h" #include "EndlessVendetta/AI/AI_EnemyController.h"
#include "EndlessVendetta/AI/EnemyCharacter.h" #include "EndlessVendetta/AI/EnemyCharacter.h"
@ -17,11 +18,15 @@ EBTNodeResult::Type UBTTask_StopInvestigating::ExecuteTask(UBehaviorTreeComponen
if (AAI_EnemyController* const EnemyController = Cast<AAI_EnemyController>(OwnerComp.GetOwner())) if (AAI_EnemyController* const EnemyController = Cast<AAI_EnemyController>(OwnerComp.GetOwner()))
{ {
if (UBlackboardComponent* const BlackboardComponent = OwnerComp.GetBlackboardComponent()) if (UBlackboardComponent* const BlackboardComponent = OwnerComp.GetBlackboardComponent())
{
if (AEndlessVendettaCharacter* Player = Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{ {
BlackboardComponent->ClearValue(GetSelectedBlackboardKey()); BlackboardComponent->ClearValue(GetSelectedBlackboardKey());
Player->DecrementBeingInvestigatedCount();
FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded); FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
return EBTNodeResult::Succeeded; return EBTNodeResult::Succeeded;
} }
} }
}
return EBTNodeResult::Failed; return EBTNodeResult::Failed;
} }

View File

@ -60,8 +60,11 @@ void AEndlessVendettaCharacter::IncrementSeenHostileCount()
{ {
GetWorld()->GetTimerManager().ClearTimer(NotInCombatTimerHandle); GetWorld()->GetTimerManager().ClearTimer(NotInCombatTimerHandle);
} }
if (!bIsInCombat)
{
bIsInCombat = true; bIsInCombat = true;
} }
}
void AEndlessVendettaCharacter::DecrementSeenHostileCount() void AEndlessVendettaCharacter::DecrementSeenHostileCount()
{ {
@ -77,6 +80,24 @@ void AEndlessVendettaCharacter::DecrementSeenHostileCount()
} }
} }
void AEndlessVendettaCharacter::IncrementBeingInvestigatedCount()
{
BeingInvestigatedCount++;
if (!bIsBeingInvestigated)
{
bIsBeingInvestigated = true;
}
}
void AEndlessVendettaCharacter::DecrementBeingInvestigatedCount()
{
BeingInvestigatedCount--;
if (BeingInvestigatedCount <= 0)
{
bIsBeingInvestigated = false;
}
}
void AEndlessVendettaCharacter::ReloadAnimationComplete() void AEndlessVendettaCharacter::ReloadAnimationComplete()
{ {
if (IsValid(PrimaryWeapon)) if (IsValid(PrimaryWeapon))
@ -216,7 +237,6 @@ void AEndlessVendettaCharacter::Heal(const float Amount)
void AEndlessVendettaCharacter::NotInCombat() void AEndlessVendettaCharacter::NotInCombat()
{ {
bIsInCombat = false; bIsInCombat = false;
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Green, TEXT("Not In Combat"));
} }
void AEndlessVendettaCharacter::WeaponPickUpSystem() void AEndlessVendettaCharacter::WeaponPickUpSystem()

View File

@ -165,6 +165,9 @@ public:
bool bIsInRestrictedArea = false; bool bIsInRestrictedArea = false;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Stats") UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Stats")
bool bIsInCombat = false; bool bIsInCombat = false;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Stats")
bool bIsBeingInvestigated = false;
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void IncrementRestrictedBoundsCount(); void IncrementRestrictedBoundsCount();
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
@ -173,6 +176,10 @@ public:
void IncrementSeenHostileCount(); void IncrementSeenHostileCount();
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void DecrementSeenHostileCount(); void DecrementSeenHostileCount();
UFUNCTION(BlueprintCallable)
void IncrementBeingInvestigatedCount();
UFUNCTION(BlueprintCallable)
void DecrementBeingInvestigatedCount();
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FStartReload); DECLARE_DYNAMIC_MULTICAST_DELEGATE(FStartReload);
UPROPERTY(BlueprintAssignable, Category = "Weapon") UPROPERTY(BlueprintAssignable, Category = "Weapon")
@ -223,6 +230,8 @@ protected:
UPROPERTY() UPROPERTY()
int SeenHostileCount = 0; int SeenHostileCount = 0;
UPROPERTY() UPROPERTY()
int BeingInvestigatedCount = 0;
UPROPERTY()
FTimerHandle NotInCombatTimerHandle; FTimerHandle NotInCombatTimerHandle;
void NotInCombat(); void NotInCombat();