Added NPC logic

This commit is contained in:
2026-06-01 22:04:31 +03:00
parent 89c2e93369
commit 0e9832719d
37 changed files with 156 additions and 41 deletions
+22 -4
View File
@@ -2,8 +2,12 @@
#include "NPC.h"
#include "BrainComponent.h"
#include "NPCTypeDefinition.h"
#include "NPCAIController.h"
#include "NPCTargetLocation.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
@@ -58,15 +62,26 @@ void ANPC::ActivateFromPool(const FVector& Location, const FRotator& Rotation)
Move->SetComponentTickEnabled(true);
Move->SetMovementMode(MOVE_Walking);
}
OnActivatedFromPool();
if (ANPCAIController* NPCController = Cast<ANPCAIController>(GetController()))
{
NPCController->RunCustomBehaviorTree();
NPCController->GetBlackboardComponent()->SetValueAsBool(TEXT("bHasReacted"), false);
}
}
void ANPC::DeactivateToPool()
{
// Drop any active observation so a pooled-out NPC stops contributing to the player's embarrassment.
if (ANPCAIController* NPCController = Cast<ANPCAIController>(GetController()))
{
NPCController->ClearObservation();
if (UBrainComponent* Brain = NPCController->GetBrainComponent())
{
Brain->StopLogic(TEXT("Moved to pool"));
}
NPCController->ClearFocus(EAIFocusPriority::Default);
}
if (UCharacterMovementComponent* Move = GetCharacterMovement())
{
@@ -74,9 +89,12 @@ void ANPC::DeactivateToPool()
Move->DisableMovement();
Move->SetComponentTickEnabled(false);
}
if (TargetLocationActor)
{
TargetLocationActor->Release(this);
}
SetActorHiddenInGame(true);
SetActorEnableCollision(false);
OnDeactivatedToPool();
}