Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions Source/FicsitRemoteMonitoring/Private/Endpoints/World/Environment.cpp
Original file line number Diff line number Diff line change
@@ -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<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* GasPillarClass = AFGGasPillar::StaticClass();
TArray<AActor*> FoundActors;

UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), GasPillarClass, FoundActors);
for (AActor* GasPillarActor : FoundActors) {

AFGGasPillar* GasPillar = Cast<AFGGasPillar>(GasPillarActor);

TSharedPtr<FJsonObject> JGasPillar = CreateBaseJsonObject(GasPillar);

JGasPillar->Values.Add("ClassName", MakeShared<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(GasPillar->GetClass())));
JGasPillar->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(GasPillar)));
JGasPillar->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(GasPillar, TEXT("Gas Pillar"), TEXT("Gas Pillar"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JGasPillar));
};
};

void UEnvironment::getSpawners(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* CreatureSpawnerClass = AFGCreatureSpawner::StaticClass();
TArray<AActor*> 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<AFGCreatureSpawner>(CreatureSpawnerActor);

TSharedPtr<FJsonObject> JCreatureSpawner = CreateBaseJsonObject(CreatureSpawner);

AFGCreature* SpawnableCreature;

if (bDisableArachnid)
{
SpawnableCreature = CreatureSpawner->GetCreatureClassArachnidOverride()->GetDefaultObject<AFGCreature>();
} else
{
SpawnableCreature = CreatureSpawner->GetCreatureClass()->GetDefaultObject<AFGCreature>();
};

TSharedPtr<FJsonObject> JSpawnableCreature= MakeShared<FJsonObject>();

if (IsValid(SpawnableCreature))
{
FString ClassName = UKismetSystemLibrary::GetClassDisplayName(SpawnableCreature->GetClass());

TSharedPtr<FJsonObject> JRoaming = MakeShared<FJsonObject>();
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<ECreatureState>()->GetNameStringByValue((int64)SpawnableCreature->GetCurrentBehaviorState()));
}

JCreatureSpawner->Values.Add("ClassName", MakeShared<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(CreatureSpawner->GetClass())));
JCreatureSpawner->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(CreatureSpawner)));
JCreatureSpawner->Values.Add("TotalSpawnable", MakeShared<FJsonValueNumber>(CreatureSpawner->GetTotalNumCreatures()));
JCreatureSpawner->Values.Add("Unspawned", MakeShared<FJsonValueNumber>(CreatureSpawner->GetNumUnspawnedCreatures()));
JCreatureSpawner->Values.Add("SpawnDistance", MakeShared<FJsonValueNumber>(CreatureSpawner->GetSpawnDistance()));
JCreatureSpawner->Values.Add("SpawnRadius", MakeShared<FJsonValueNumber>(CreatureSpawner->GetSpawnRadius()));
JCreatureSpawner->Values.Add("RespawnTimeInDays", MakeShared<FJsonValueNumber>(CreatureSpawner->mRespawnTimeIndays));
JCreatureSpawner->Values.Add("CanSpawnDay", MakeShared<FJsonValueBoolean>(CreatureSpawner->CanSpawnDuringDay()));
JCreatureSpawner->Values.Add("CanSpawnNight", MakeShared<FJsonValueBoolean>(CreatureSpawner->CanSpawnDuringNight()));
JCreatureSpawner->Values.Add("IsNearBase", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsNearBase()));
JCreatureSpawner->Values.Add("IsReadyToSpawn", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsReadyToSpawn()));
JCreatureSpawner->Values.Add("IsSpawnerActive", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsSpawnerActive()));
JCreatureSpawner->Values.Add("IsTimeForCreature", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsTimeForCreature()));
JCreatureSpawner->Values.Add("SpawnableCreature", MakeShared<FJsonValueObject>(JSpawnableCreature));
JCreatureSpawner->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(CreatureSpawner, TEXT("Creature Spawner"), TEXT("Creature Spawner"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JCreatureSpawner));
};
};

void UEnvironment::getSporeFlowers(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* SporeFlowerClass = AFGSporeFlower::StaticClass();
TArray<AActor*> FoundActors;

UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), SporeFlowerClass, FoundActors);
for (AActor* SporeFlowerActor : FoundActors) {

AFGSporeFlower* SporeFlower = Cast<AFGSporeFlower>(SporeFlowerActor);

TSharedPtr<FJsonObject> 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<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(SporeFlower->GetClass())));
JSporeFlower->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(SporeFlower)));
JSporeFlower->Values.Add("State", MakeShared<FJsonValueString>(State));
JSporeFlower->Values.Add("GasState", MakeShared<FJsonValueString>(GasState));
JSporeFlower->Values.Add("Significant", MakeShared<FJsonValueBoolean>(bIsSignificant));
JSporeFlower->Values.Add("Dead", MakeShared<FJsonValueBoolean>(bIsDead));
JSporeFlower->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(SporeFlower, TEXT("Spore Flower"), TEXT("Spore Flower"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JSporeFlower));
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,4 @@ void UPlayerLibrary::getCreatures(UObject* WorldContext, FRequestData RequestDat

OutJsonArray.Add(MakeShared<FJsonValueObject>(JCreature));
};
};

void UPlayerLibrary::getHazards(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* SporeFlowerClass = AFGSporeFlower::StaticClass();
TArray<AActor*> FoundActors;

UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), SporeFlowerClass, FoundActors);
for (AActor* SporeFlowerActor : FoundActors) {

AFGSporeFlower* SporeFlower = Cast<AFGSporeFlower>(SporeFlowerActor);

TSharedPtr<FJsonObject> 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<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(SporeFlower->GetClass())));
JSporeFlower->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(SporeFlower)));
JSporeFlower->Values.Add("State", MakeShared<FJsonValueString>(State));
JSporeFlower->Values.Add("GasState", MakeShared<FJsonValueString>(GasState));
JSporeFlower->Values.Add("Significant", MakeShared<FJsonValueBoolean>(bIsSignificant));
JSporeFlower->Values.Add("Dead", MakeShared<FJsonValueBoolean>(bIsDead));
JSporeFlower->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(SporeFlower, TEXT("Spore Flower"), TEXT("Spore Flower"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JSporeFlower));
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions Source/FicsitRemoteMonitoring/Public/Endpoints/World/Environment.h
Original file line number Diff line number Diff line change
@@ -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<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getSpawners(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getSporeFlowers(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ class FICSITREMOTEMONITORING_API UPlayerLibrary : public URemoteMonitoringLibrar
static void getPlayer(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getDoggo(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getCreatures(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getHazards(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
};
Loading