diff --git a/Source/FicsitRemoteMonitoring/Private/Endpoints/World/Environment.cpp b/Source/FicsitRemoteMonitoring/Private/Endpoints/World/Environment.cpp new file mode 100644 index 00000000..ce4916db --- /dev/null +++ b/Source/FicsitRemoteMonitoring/Private/Endpoints/World/Environment.cpp @@ -0,0 +1,130 @@ +#include "Endpoints/World/Environment.h" + +#include "FGCreatureSubsystem.h" +#include "FGGasPillar.h" +#include "FGSporeFlower.h" +#include "FicsitRemoteMonitoring.h" +#include "RemoteMonitoringLibrary.h" +#include "Creature/FGCreatureSpawner.h" +#include "Kismet/GameplayStatics.h" + +void UEnvironment::getHazards(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray) { + + UClass* GasPillarClass = AFGGasPillar::StaticClass(); + TArray FoundActors; + + UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), GasPillarClass, FoundActors); + for (AActor* GasPillarActor : FoundActors) { + + AFGGasPillar* GasPillar = Cast(GasPillarActor); + + TSharedPtr JGasPillar = CreateBaseJsonObject(GasPillar); + + JGasPillar->Values.Add("ClassName", MakeShared(UKismetSystemLibrary::GetClassDisplayName(GasPillar->GetClass()))); + JGasPillar->Values.Add("location", MakeShared(getActorJSON(GasPillar))); + JGasPillar->Values.Add("features", MakeShared(getActorFeaturesJSON(GasPillar, TEXT("Gas Pillar"), TEXT("Gas Pillar")))); + + OutJsonArray.Add(MakeShared(JGasPillar)); + }; +}; + +void UEnvironment::getSpawners(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray) { + + UClass* CreatureSpawnerClass = AFGCreatureSpawner::StaticClass(); + TArray FoundActors; + + UFGGameUserSettings* UserSettings = UFGGameUserSettings::GetFGGameUserSettings(); + if (!UserSettings) + { + UE_LOG(LogFRMConfigManager, Error, TEXT("GetConfig: UserSettings is null")); + return; + } + + const bool bDisableArachnid = UserSettings->GetBoolOptionValue(TEXT("FG.GameRules.DisableArachnidCreatures")); + + UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), CreatureSpawnerClass, FoundActors); + for (AActor* CreatureSpawnerActor : FoundActors) { + + AFGCreatureSpawner* CreatureSpawner = Cast(CreatureSpawnerActor); + + TSharedPtr JCreatureSpawner = CreateBaseJsonObject(CreatureSpawner); + + AFGCreature* SpawnableCreature; + + if (bDisableArachnid) + { + SpawnableCreature = CreatureSpawner->GetCreatureClassArachnidOverride()->GetDefaultObject(); + } else + { + SpawnableCreature = CreatureSpawner->GetCreatureClass()->GetDefaultObject(); + }; + + TSharedPtr JSpawnableCreature= MakeShared(); + + if (IsValid(SpawnableCreature)) + { + FString ClassName = UKismetSystemLibrary::GetClassDisplayName(SpawnableCreature->GetClass()); + + TSharedPtr JRoaming = MakeShared(); + JRoaming->SetNumberField("MinRoaming", SpawnableCreature->GetRoamingDistance().Min); + JRoaming->SetNumberField("MaxRoaming", SpawnableCreature->GetRoamingDistance().Max); + + JSpawnableCreature->SetStringField("ClassName", ClassName); + JSpawnableCreature->SetObjectField("Roaming", JRoaming); + JSpawnableCreature->SetNumberField("SpawnDistance", SpawnableCreature->GetSpawnDistance()); + JSpawnableCreature->SetStringField("State", StaticEnum()->GetNameStringByValue((int64)SpawnableCreature->GetCurrentBehaviorState())); + } + + JCreatureSpawner->Values.Add("ClassName", MakeShared(UKismetSystemLibrary::GetClassDisplayName(CreatureSpawner->GetClass()))); + JCreatureSpawner->Values.Add("location", MakeShared(getActorJSON(CreatureSpawner))); + JCreatureSpawner->Values.Add("TotalSpawnable", MakeShared(CreatureSpawner->GetTotalNumCreatures())); + JCreatureSpawner->Values.Add("Unspawned", MakeShared(CreatureSpawner->GetNumUnspawnedCreatures())); + JCreatureSpawner->Values.Add("SpawnDistance", MakeShared(CreatureSpawner->GetSpawnDistance())); + JCreatureSpawner->Values.Add("SpawnRadius", MakeShared(CreatureSpawner->GetSpawnRadius())); + JCreatureSpawner->Values.Add("RespawnTimeInDays", MakeShared(CreatureSpawner->mRespawnTimeIndays)); + JCreatureSpawner->Values.Add("CanSpawnDay", MakeShared(CreatureSpawner->CanSpawnDuringDay())); + JCreatureSpawner->Values.Add("CanSpawnNight", MakeShared(CreatureSpawner->CanSpawnDuringNight())); + JCreatureSpawner->Values.Add("IsNearBase", MakeShared(CreatureSpawner->IsNearBase())); + JCreatureSpawner->Values.Add("IsReadyToSpawn", MakeShared(CreatureSpawner->IsReadyToSpawn())); + JCreatureSpawner->Values.Add("IsSpawnerActive", MakeShared(CreatureSpawner->IsSpawnerActive())); + JCreatureSpawner->Values.Add("IsTimeForCreature", MakeShared(CreatureSpawner->IsTimeForCreature())); + JCreatureSpawner->Values.Add("SpawnableCreature", MakeShared(JSpawnableCreature)); + JCreatureSpawner->Values.Add("features", MakeShared(getActorFeaturesJSON(CreatureSpawner, TEXT("Creature Spawner"), TEXT("Creature Spawner")))); + + OutJsonArray.Add(MakeShared(JCreatureSpawner)); + }; +}; + +void UEnvironment::getSporeFlowers(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray) { + + UClass* SporeFlowerClass = AFGSporeFlower::StaticClass(); + TArray FoundActors; + + UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), SporeFlowerClass, FoundActors); + for (AActor* SporeFlowerActor : FoundActors) { + + AFGSporeFlower* SporeFlower = Cast(SporeFlowerActor); + + TSharedPtr JSporeFlower = CreateBaseJsonObject(SporeFlower); + + AFicsitRemoteMonitoring* ModSubsystem = AFicsitRemoteMonitoring::Get(WorldContext->GetWorld()); + fgcheck(ModSubsystem); + + FString State; + FString GasState; + bool bIsSignificant; + bool bIsDead; + + ModSubsystem->SporeFlower_BIE(SporeFlower, State, GasState, bIsSignificant, bIsDead); + + JSporeFlower->Values.Add("ClassName", MakeShared(UKismetSystemLibrary::GetClassDisplayName(SporeFlower->GetClass()))); + JSporeFlower->Values.Add("location", MakeShared(getActorJSON(SporeFlower))); + JSporeFlower->Values.Add("State", MakeShared(State)); + JSporeFlower->Values.Add("GasState", MakeShared(GasState)); + JSporeFlower->Values.Add("Significant", MakeShared(bIsSignificant)); + JSporeFlower->Values.Add("Dead", MakeShared(bIsDead)); + JSporeFlower->Values.Add("features", MakeShared(getActorFeaturesJSON(SporeFlower, TEXT("Spore Flower"), TEXT("Spore Flower")))); + + OutJsonArray.Add(MakeShared(JSporeFlower)); + }; +}; \ No newline at end of file diff --git a/Source/FicsitRemoteMonitoring/Private/Endpoints/World/PlayerLibrary.cpp b/Source/FicsitRemoteMonitoring/Private/Endpoints/World/PlayerLibrary.cpp index 863c5ee8..cbb3bcbe 100644 --- a/Source/FicsitRemoteMonitoring/Private/Endpoints/World/PlayerLibrary.cpp +++ b/Source/FicsitRemoteMonitoring/Private/Endpoints/World/PlayerLibrary.cpp @@ -92,38 +92,4 @@ void UPlayerLibrary::getCreatures(UObject* WorldContext, FRequestData RequestDat OutJsonArray.Add(MakeShared(JCreature)); }; -}; - -void UPlayerLibrary::getHazards(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray) { - - UClass* SporeFlowerClass = AFGSporeFlower::StaticClass(); - TArray FoundActors; - - UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), SporeFlowerClass, FoundActors); - for (AActor* SporeFlowerActor : FoundActors) { - - AFGSporeFlower* SporeFlower = Cast(SporeFlowerActor); - - TSharedPtr JSporeFlower = CreateBaseJsonObject(SporeFlower); - - AFicsitRemoteMonitoring* ModSubsystem = AFicsitRemoteMonitoring::Get(WorldContext->GetWorld()); - fgcheck(ModSubsystem); - - FString State; - FString GasState; - bool bIsSignificant; - bool bIsDead; - - ModSubsystem->SporeFlower_BIE(SporeFlower, State, GasState, bIsSignificant, bIsDead); - - JSporeFlower->Values.Add("ClassName", MakeShared(UKismetSystemLibrary::GetClassDisplayName(SporeFlower->GetClass()))); - JSporeFlower->Values.Add("location", MakeShared(getActorJSON(SporeFlower))); - JSporeFlower->Values.Add("State", MakeShared(State)); - JSporeFlower->Values.Add("GasState", MakeShared(GasState)); - JSporeFlower->Values.Add("Significant", MakeShared(bIsSignificant)); - JSporeFlower->Values.Add("Dead", MakeShared(bIsDead)); - JSporeFlower->Values.Add("features", MakeShared(getActorFeaturesJSON(SporeFlower, TEXT("Spore Flower"), TEXT("Spore Flower")))); - - OutJsonArray.Add(MakeShared(JSporeFlower)); - }; }; \ No newline at end of file diff --git a/Source/FicsitRemoteMonitoring/Private/FicsitRemoteMonitoring.cpp b/Source/FicsitRemoteMonitoring/Private/FicsitRemoteMonitoring.cpp index 6b0350a3..7c9ba367 100644 --- a/Source/FicsitRemoteMonitoring/Private/FicsitRemoteMonitoring.cpp +++ b/Source/FicsitRemoteMonitoring/Private/FicsitRemoteMonitoring.cpp @@ -21,6 +21,7 @@ #include "Endpoints/Travel/Trains.h" #include "Endpoints/Travel/Vehicles.h" #include "Endpoints/World/Communication.h" +#include "Endpoints/World/Environment.h" #include "Endpoints/World/EventsLibrary.h" #include "Endpoints/World/Inventory.h" #include "Endpoints/World/PlayerLibrary.h" @@ -762,7 +763,7 @@ void AFicsitRemoteMonitoring::InitAPIRegistry() RegisterEndpoint(FAPIEndpoint("GET", "getFrackingActivator", &UResources::getFrackingActivator)); RegisterEndpoint(FAPIEndpoint("GET", "getFuelGenerator", &UPower::getFuelGenerator)); RegisterEndpoint(FAPIEndpoint("GET", "getGeothermalGenerator", &UPower::getGeothermalGenerator)); - RegisterEndpoint(FAPIEndpoint("GET", "getHazards", &UPlayerLibrary::getHazards).RequiresGameThread()); + RegisterEndpoint(FAPIEndpoint("GET", "getHazards", &UEnvironment::getHazards).RequiresGameThread()); RegisterEndpoint(FAPIEndpoint("GET", "getHUBTerminal", &USupport::getHubTerminal).RequiresGameThread()); RegisterEndpoint(FAPIEndpoint("GET", "getHyperEntrance", &UHypertubes::getHyperEntrance)); RegisterEndpoint(FAPIEndpoint("GET", "getHypertube", &UHypertubes::getHypertube)); @@ -791,7 +792,9 @@ void AFicsitRemoteMonitoring::InitAPIRegistry() RegisterEndpoint(FAPIEndpoint("GET", "getResourceSink", &USession::getResourceSink)); RegisterEndpoint(FAPIEndpoint("GET", "getResourceSinkBuilding", &USupport::getResourceSinkBuilding)); RegisterEndpoint(FAPIEndpoint("GET", "getResourceWell", &UResources::getResourceWell).RequiresGameThread()); + RegisterEndpoint(FAPIEndpoint("GET", "getSpawners", &UEnvironment::getSpawners).RequiresGameThread()); RegisterEndpoint(FAPIEndpoint("GET", "getSplitterMerger", &ULogistics::getSplitterMerger)); + RegisterEndpoint(FAPIEndpoint("GET", "getSporeFlowers", &UEnvironment::getSporeFlowers).RequiresGameThread()); RegisterEndpoint(FAPIEndpoint("GET", "getSessionInfo", &USession::getSessionInfo).RequiresGameThread().UseFirstObject()); RegisterEndpoint(FAPIEndpoint("GET", "getSchematics", &UResearch::getSchematics).RequiresGameThread()); RegisterEndpoint(FAPIEndpoint("GET", "getSinkList", &USession::getSinkList).RequiresGameThread()); diff --git a/Source/FicsitRemoteMonitoring/Public/Endpoints/World/Environment.h b/Source/FicsitRemoteMonitoring/Public/Endpoints/World/Environment.h new file mode 100644 index 00000000..417fa031 --- /dev/null +++ b/Source/FicsitRemoteMonitoring/Public/Endpoints/World/Environment.h @@ -0,0 +1,16 @@ +#pragma once + +#include "CoreMinimal.h" +#include "RemoteMonitoringLibrary.h" +#include "Environment.generated.h" + +UCLASS() +class FICSITREMOTEMONITORING_API UEnvironment : public URemoteMonitoringLibrary +{ + GENERATED_BODY() + +public: + static void getHazards(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray); + static void getSpawners(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray); + static void getSporeFlowers(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray); +}; diff --git a/Source/FicsitRemoteMonitoring/Public/Endpoints/World/PlayerLibrary.h b/Source/FicsitRemoteMonitoring/Public/Endpoints/World/PlayerLibrary.h index 7047bc73..ae9488e5 100644 --- a/Source/FicsitRemoteMonitoring/Public/Endpoints/World/PlayerLibrary.h +++ b/Source/FicsitRemoteMonitoring/Public/Endpoints/World/PlayerLibrary.h @@ -13,5 +13,4 @@ class FICSITREMOTEMONITORING_API UPlayerLibrary : public URemoteMonitoringLibrar static void getPlayer(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray); static void getDoggo(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray); static void getCreatures(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray); - static void getHazards(UObject* WorldContext, FRequestData RequestData, TArray>& OutJsonArray); };