Added commissions system
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// © 2025 Naked People Team. All Rights Reserved.
|
||||
|
||||
|
||||
#include "LocationSubsystem.h"
|
||||
|
||||
#include "LocationData.h"
|
||||
|
||||
void ULocationSubsystem::EnterLocation(ULocationData* Location)
|
||||
{
|
||||
if (!Location)
|
||||
return;
|
||||
|
||||
int32& Count = ActiveCounts.FindOrAdd(Location);
|
||||
++Count;
|
||||
|
||||
if (Count == 1)
|
||||
{
|
||||
RebuildActiveTags();
|
||||
OnLocationEntered.Broadcast(Location);
|
||||
}
|
||||
}
|
||||
|
||||
void ULocationSubsystem::ExitLocation(ULocationData* Location)
|
||||
{
|
||||
if (!Location)
|
||||
return;
|
||||
|
||||
int32* Count = ActiveCounts.Find(Location);
|
||||
if (!Count)
|
||||
return;
|
||||
|
||||
if (--(*Count) <= 0)
|
||||
{
|
||||
ActiveCounts.Remove(Location);
|
||||
RebuildActiveTags();
|
||||
OnLocationExited.Broadcast(Location);
|
||||
}
|
||||
}
|
||||
|
||||
bool ULocationSubsystem::IsPlayerInLocation(FGameplayTag Query) const
|
||||
{
|
||||
return Query.IsValid() && ActiveTags.HasTag(Query);
|
||||
}
|
||||
|
||||
ULocationData* ULocationSubsystem::GetCurrentLocation() const
|
||||
{
|
||||
ULocationData* Best = nullptr;
|
||||
int32 BestDepth = -1;
|
||||
|
||||
for (const TPair<TObjectPtr<ULocationData>, int32>& Pair : ActiveCounts)
|
||||
{
|
||||
ULocationData* Location = Pair.Key;
|
||||
if (!Location || !Location->Tag.IsValid())
|
||||
continue;
|
||||
|
||||
// More tag segments = more specific (Location.City.Beach beats Location.City).
|
||||
const int32 Depth = Location->Tag.GetGameplayTagParents().Num();
|
||||
if (Depth > BestDepth)
|
||||
{
|
||||
BestDepth = Depth;
|
||||
Best = Location;
|
||||
}
|
||||
}
|
||||
|
||||
return Best;
|
||||
}
|
||||
|
||||
void ULocationSubsystem::RebuildActiveTags()
|
||||
{
|
||||
ActiveTags.Reset();
|
||||
for (const TPair<TObjectPtr<ULocationData>, int32>& Pair : ActiveCounts)
|
||||
{
|
||||
if (Pair.Key && Pair.Key->Tag.IsValid())
|
||||
ActiveTags.AddTag(Pair.Key->Tag);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// © 2025 Naked People Team. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameplayTagContainer.h"
|
||||
#include "Subsystems/WorldSubsystem.h"
|
||||
#include "LocationSubsystem.generated.h"
|
||||
|
||||
class ULocationData;
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnLocationChangedSignature, ULocationData*, Location);
|
||||
|
||||
/**
|
||||
* Single source of truth for which tagged locations the player currently occupies (GDD §10.4).
|
||||
* Fed by ALocationTrigger overlaps; queried + subscribed by everything else (session boundary,
|
||||
* commission location constraints, future shop entry). World-scoped and transient — nothing to save.
|
||||
*
|
||||
* Locations are identified by their ULocationData FGameplayTag, so they nest: while inside
|
||||
* Location.City.Beach the player also matches Location.City. The player can be in several at once.
|
||||
*/
|
||||
UCLASS()
|
||||
class NAKEDDESIRE_API ULocationSubsystem : public UWorldSubsystem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Reported by ALocationTrigger as the player enters / leaves a tagged volume.
|
||||
void EnterLocation(ULocationData* Location);
|
||||
void ExitLocation(ULocationData* Location);
|
||||
|
||||
// True while the player occupies a location whose tag matches (or nests under) Query.
|
||||
UFUNCTION(BlueprintPure, Category = "Location")
|
||||
bool IsPlayerInLocation(FGameplayTag Query) const;
|
||||
|
||||
UFUNCTION(BlueprintPure, Category = "Location")
|
||||
FGameplayTagContainer GetPlayerLocationTags() const { return ActiveTags; }
|
||||
|
||||
// Most-specific current location (deepest tag) — for HUD / prompts. Null when outdoors / untagged.
|
||||
UFUNCTION(BlueprintPure, Category = "Location")
|
||||
ULocationData* GetCurrentLocation() const;
|
||||
|
||||
UPROPERTY(BlueprintAssignable, Category = "Location")
|
||||
FOnLocationChangedSignature OnLocationEntered;
|
||||
|
||||
UPROPERTY(BlueprintAssignable, Category = "Location")
|
||||
FOnLocationChangedSignature OnLocationExited;
|
||||
|
||||
private:
|
||||
void RebuildActiveTags();
|
||||
|
||||
// Ref-counted: a location can be several overlapping trigger volumes, so we only fire enter on
|
||||
// 0->1 and exit on 1->0 — crossing between two boxes of the same place doesn't churn events.
|
||||
UPROPERTY()
|
||||
TMap<TObjectPtr<ULocationData>, int32> ActiveCounts;
|
||||
|
||||
FGameplayTagContainer ActiveTags;
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
// © 2025 Naked People Team. All Rights Reserved.
|
||||
// © 2025 Naked People Team. All Rights Reserved.
|
||||
|
||||
|
||||
#include "LocationTrigger.h"
|
||||
|
||||
#include "Components/BoxComponent.h"
|
||||
#include "NakedDesire/Global/SessionManagerSubsystem.h"
|
||||
#include "LocationSubsystem.h"
|
||||
#include "NakedDesire/Player/NakedDesireCharacter.h"
|
||||
|
||||
|
||||
@@ -25,11 +25,8 @@ void ALocationTrigger::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (bIsApartment)
|
||||
{
|
||||
BoxTrigger->OnComponentBeginOverlap.AddDynamic(this, &ALocationTrigger::OnTriggerBeginOverlap);
|
||||
BoxTrigger->OnComponentEndOverlap.AddDynamic(this, &ALocationTrigger::OnTriggerEndOverlap);
|
||||
}
|
||||
BoxTrigger->OnComponentBeginOverlap.AddDynamic(this, &ALocationTrigger::OnTriggerBeginOverlap);
|
||||
BoxTrigger->OnComponentEndOverlap.AddDynamic(this, &ALocationTrigger::OnTriggerEndOverlap);
|
||||
}
|
||||
|
||||
void ALocationTrigger::OnTriggerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
@@ -38,10 +35,8 @@ void ALocationTrigger::OnTriggerBeginOverlap(UPrimitiveComponent* OverlappedComp
|
||||
if (!OtherActor || !OtherActor->IsA<ANakedDesireCharacter>())
|
||||
return;
|
||||
|
||||
if (USessionManagerSubsystem* SessionManager = GetWorld()->GetSubsystem<USessionManagerSubsystem>())
|
||||
{
|
||||
SessionManager->NotifyEnteredApartment();
|
||||
}
|
||||
if (ULocationSubsystem* Locations = GetWorld()->GetSubsystem<ULocationSubsystem>())
|
||||
Locations->EnterLocation(LocationData);
|
||||
}
|
||||
|
||||
void ALocationTrigger::OnTriggerEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
@@ -50,9 +45,6 @@ void ALocationTrigger::OnTriggerEndOverlap(UPrimitiveComponent* OverlappedCompon
|
||||
if (!OtherActor || !OtherActor->IsA<ANakedDesireCharacter>())
|
||||
return;
|
||||
|
||||
if (USessionManagerSubsystem* SessionManager = GetWorld()->GetSubsystem<USessionManagerSubsystem>())
|
||||
{
|
||||
SessionManager->NotifyLeftApartment();
|
||||
}
|
||||
}
|
||||
|
||||
if (ULocationSubsystem* Locations = GetWorld()->GetSubsystem<ULocationSubsystem>())
|
||||
Locations->ExitLocation(LocationData);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// © 2025 Naked People Team. All Rights Reserved.
|
||||
// © 2025 Naked People Team. All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
class ULocationData;
|
||||
class UBoxComponent;
|
||||
|
||||
// A tagged volume. On player overlap it reports enter / leave to ULocationSubsystem, which is the
|
||||
// single authority on where the player is. Everything (session boundary, commission location
|
||||
// constraints, etc.) consumes the subsystem — the trigger itself has no consumer-specific logic.
|
||||
UCLASS()
|
||||
class NAKEDDESIRE_API ALocationTrigger : public AActor
|
||||
{
|
||||
@@ -20,12 +23,6 @@ class NAKEDDESIRE_API ALocationTrigger : public AActor
|
||||
UPROPERTY(EditAnywhere)
|
||||
ULocationData* LocationData;
|
||||
|
||||
// When set, the player crossing this trigger drives session start / end on
|
||||
// USessionManagerSubsystem (GDD §4.1 / §4.3). Exactly one trigger — the
|
||||
// apartment — should have this checked.
|
||||
UPROPERTY(EditAnywhere, Category = "Session")
|
||||
bool bIsApartment = false;
|
||||
|
||||
public:
|
||||
ALocationTrigger();
|
||||
|
||||
@@ -42,4 +39,4 @@ private:
|
||||
UFUNCTION()
|
||||
void OnTriggerEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user