Setup player preview for equipment panel
This commit is contained in:
@@ -2,44 +2,29 @@
|
||||
|
||||
|
||||
#include "NPCAIController.h"
|
||||
|
||||
#include "NavigationSystem.h"
|
||||
#include "NPCTargetLocation.h"
|
||||
#include "AI/NavigationSystemBase.h"
|
||||
#include "BehaviorTree/BlackboardComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Perception/AISense_Sight.h"
|
||||
#include "NakedDesire/Global/NakedDesireGameMode.h"
|
||||
#include "Perception/AISenseConfig_Sight.h"
|
||||
#include "NakedDesire/Player/NakedDesireCharacter.h"
|
||||
#include "NakedDesire/Stats/StatsManager.h"
|
||||
#include "Perception/AIPerceptionComponent.h"
|
||||
|
||||
void ANPCAIController::SetShouldReactToPlayer(const bool Value)
|
||||
ANPCAIController::ANPCAIController()
|
||||
{
|
||||
Blackboard->SetValueAsBool(FName(TEXT("ShouldReactToPlayer")), Value);
|
||||
UAIPerceptionComponent* Perception = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("PerceptionComponent"));
|
||||
SetPerceptionComponent(*Perception);
|
||||
|
||||
UAISenseConfig_Sight* SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("SightConfig"));
|
||||
SightConfig->DetectionByAffiliation.bDetectEnemies = true;
|
||||
SightConfig->DetectionByAffiliation.bDetectNeutrals = true;
|
||||
SightConfig->DetectionByAffiliation.bDetectFriendlies = true;
|
||||
Perception->ConfigureSense(*SightConfig);
|
||||
Perception->SetDominantSense(SightConfig->GetSenseImplementation());
|
||||
}
|
||||
|
||||
void ANPCAIController::OnPossess(APawn* InPawn)
|
||||
{
|
||||
Super::OnPossess(InPawn);
|
||||
|
||||
NavigationSystem = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
|
||||
GameMode = Cast<ANakedDesireGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
|
||||
|
||||
RunBehaviorTree(BehaviorTreeAsset);
|
||||
|
||||
const FVector SpawnLocation = InPawn->GetActorLocation();
|
||||
|
||||
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);
|
||||
|
||||
PlayerCharacter = Cast<ANakedDesireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||
Blackboard->SetValueAsObject("Player", PlayerCharacter);
|
||||
|
||||
PerceptionComponent->OnTargetPerceptionUpdated.AddUniqueDynamic(this, &ANPCAIController::OnTargetPerceptionUpdate);
|
||||
}
|
||||
|
||||
@@ -55,11 +40,15 @@ void ANPCAIController::OnUnPossess()
|
||||
|
||||
void ANPCAIController::OnTargetPerceptionUpdate(AActor* Actor, FAIStimulus Stimulus)
|
||||
{
|
||||
if (Actor != PlayerCharacter)
|
||||
return;
|
||||
if (Stimulus.Type != UAISense::GetSenseID<UAISense_Sight>())
|
||||
return;
|
||||
|
||||
ANakedDesireCharacter* SensedPlayer = Cast<ANakedDesireCharacter>(Actor);
|
||||
if (!SensedPlayer)
|
||||
return;
|
||||
|
||||
PlayerCharacter = SensedPlayer;
|
||||
|
||||
const bool bSensed = Stimulus.WasSuccessfullySensed();
|
||||
if (bSensed == bCurrentlyObserving)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user