Fix embarrassment gain/decay not tied to NPC observation state
This commit is contained in:
@@ -8,8 +8,10 @@
|
||||
#include "AI/NavigationSystemBase.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Perception/AISense_Sight.h"
|
||||
#include "NakedDesire/Global/NakedDesireGameMode.h"
|
||||
#include "NakedDesire/Player/NakedDesireCharacter.h"
|
||||
#include "NakedDesire/Stats/StatsManager.h"
|
||||
|
||||
void ANPCAIController::SetShouldReactToPlayer(const bool Value)
|
||||
{
|
||||
@@ -19,7 +21,7 @@ void ANPCAIController::SetShouldReactToPlayer(const bool Value)
|
||||
void ANPCAIController::OnPossess(APawn* InPawn)
|
||||
{
|
||||
Super::OnPossess(InPawn);
|
||||
|
||||
|
||||
NavigationSystem = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
|
||||
GameMode = Cast<ANakedDesireGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
|
||||
|
||||
@@ -29,7 +31,7 @@ void ANPCAIController::OnPossess(APawn* InPawn)
|
||||
|
||||
TArray<AActor*> TargetActors;
|
||||
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ANPCTargetLocation::StaticClass(), TargetActors);
|
||||
|
||||
|
||||
const int RandomIndex = FMath::RandRange(0, TargetActors.Num() - 1);
|
||||
Blackboard->SetValueAsVector("TargetLocation", TargetActors[RandomIndex]->GetActorLocation());
|
||||
Blackboard->SetValueAsVector("SpawnLocation", SpawnLocation);
|
||||
@@ -37,3 +39,30 @@ void ANPCAIController::OnPossess(APawn* InPawn)
|
||||
PlayerCharacter = Cast<ANakedDesireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||
Blackboard->SetValueAsObject("Player", PlayerCharacter);
|
||||
}
|
||||
|
||||
void ANPCAIController::OnUnpossess()
|
||||
{
|
||||
if (bCurrentlyObserving && PlayerCharacter)
|
||||
{
|
||||
PlayerCharacter->StatsManager->SetObserved(false);
|
||||
bCurrentlyObserving = false;
|
||||
}
|
||||
Super::OnUnpossess();
|
||||
}
|
||||
|
||||
void ANPCAIController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus Stimulus)
|
||||
{
|
||||
Super::OnTargetPerceptionUpdated(Actor, Stimulus);
|
||||
|
||||
if (Actor != PlayerCharacter)
|
||||
return;
|
||||
if (Stimulus.Type != UAISense::GetSenseID<UAISense_Sight>())
|
||||
return;
|
||||
|
||||
const bool bSensed = Stimulus.WasSuccessfullySensed();
|
||||
if (bSensed == bCurrentlyObserving)
|
||||
return;
|
||||
|
||||
bCurrentlyObserving = bSensed;
|
||||
PlayerCharacter->StatsManager->SetObserved(bSensed);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "DetourCrowdAIController.h"
|
||||
#include "Perception/AIPerceptionTypes.h"
|
||||
#include "NPCAIController.generated.h"
|
||||
|
||||
class ANakedDesireGameMode;
|
||||
class UNavigationSystemV1;
|
||||
class ANakedDesireCharacter;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
UCLASS()
|
||||
class NAKEDDESIRE_API ANPCAIController : public ADetourCrowdAIController
|
||||
{
|
||||
@@ -19,7 +18,7 @@ class NAKEDDESIRE_API ANPCAIController : public ADetourCrowdAIController
|
||||
|
||||
UPROPERTY()
|
||||
ANakedDesireCharacter* PlayerCharacter = nullptr;
|
||||
|
||||
|
||||
UPROPERTY()
|
||||
const UNavigationSystemV1* NavigationSystem = nullptr;
|
||||
|
||||
@@ -29,10 +28,14 @@ class NAKEDDESIRE_API ANPCAIController : public ADetourCrowdAIController
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
UBehaviorTree* BehaviorTreeAsset = nullptr;
|
||||
|
||||
bool bCurrentlyObserving = false;
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SetShouldReactToPlayer(bool Value);
|
||||
|
||||
protected:
|
||||
virtual void OnPossess(APawn* InPawn) override;
|
||||
virtual void OnUnpossess() override;
|
||||
virtual void OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus Stimulus) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user