Add Agrarian dev console commands
This commit is contained in:
@@ -2,6 +2,11 @@
|
||||
|
||||
|
||||
#include "AgrarianGamePlayerController.h"
|
||||
#include "AgrarianGameCharacter.h"
|
||||
#include "AgrarianInventoryComponent.h"
|
||||
#include "AgrarianPersistenceSubsystem.h"
|
||||
#include "AgrarianShelterActor.h"
|
||||
#include "AgrarianSurvivalComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "Engine/LocalPlayer.h"
|
||||
#include "InputMappingContext.h"
|
||||
@@ -65,3 +70,120 @@ bool AAgrarianGamePlayerController::ShouldUseTouchControls() const
|
||||
// are we on a mobile platform? Should we force touch?
|
||||
return SVirtualJoystick::ShouldDisplayTouchInterface() || bForceTouchControls;
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianGrantItem(FName ItemId, int32 Quantity)
|
||||
{
|
||||
if (ItemId == NAME_None || Quantity <= 0)
|
||||
{
|
||||
ClientMessage(TEXT("Usage: AgrarianGrantItem <ItemId> <Quantity>"));
|
||||
return;
|
||||
}
|
||||
|
||||
ServerAgrarianGrantItem(ItemId, Quantity);
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianSaveWorld()
|
||||
{
|
||||
ServerAgrarianSaveWorld();
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianLoadWorld()
|
||||
{
|
||||
ServerAgrarianLoadWorld();
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianSurvival()
|
||||
{
|
||||
const AAgrarianGameCharacter* AgrarianCharacter = GetPawn<AAgrarianGameCharacter>();
|
||||
const UAgrarianSurvivalComponent* SurvivalComponent = AgrarianCharacter ? AgrarianCharacter->GetSurvivalComponent() : nullptr;
|
||||
if (!SurvivalComponent)
|
||||
{
|
||||
ClientMessage(TEXT("No Agrarian survival component found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const FAgrarianSurvivalSnapshot& Survival = SurvivalComponent->Survival;
|
||||
ClientMessage(FString::Printf(
|
||||
TEXT("Health %.1f | Stamina %.1f | Hunger %.1f | Thirst %.1f | Temp %.1fC | Injury %.1f"),
|
||||
Survival.Health,
|
||||
Survival.Stamina,
|
||||
Survival.Hunger,
|
||||
Survival.Thirst,
|
||||
Survival.BodyTemperature,
|
||||
Survival.InjurySeverity));
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianHeal()
|
||||
{
|
||||
ServerAgrarianHeal();
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::ServerAgrarianGrantItem_Implementation(FName ItemId, int32 Quantity)
|
||||
{
|
||||
AAgrarianGameCharacter* AgrarianCharacter = GetPawn<AAgrarianGameCharacter>();
|
||||
UAgrarianInventoryComponent* InventoryComponent = AgrarianCharacter ? AgrarianCharacter->GetInventoryComponent() : nullptr;
|
||||
if (!InventoryComponent)
|
||||
{
|
||||
ClientMessage(TEXT("No Agrarian inventory component found."));
|
||||
return;
|
||||
}
|
||||
|
||||
FAgrarianItemStack Stack;
|
||||
Stack.ItemId = ItemId;
|
||||
Stack.DisplayName = FText::FromName(ItemId);
|
||||
Stack.Quantity = Quantity;
|
||||
|
||||
if (InventoryComponent->AddItem(Stack))
|
||||
{
|
||||
ClientMessage(FString::Printf(TEXT("Granted %d x %s."), Quantity, *ItemId.ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
ClientMessage(FString::Printf(TEXT("Failed to grant %d x %s."), Quantity, *ItemId.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::ServerAgrarianSaveWorld_Implementation()
|
||||
{
|
||||
UAgrarianPersistenceSubsystem* Persistence = GetGameInstance() ? GetGameInstance()->GetSubsystem<UAgrarianPersistenceSubsystem>() : nullptr;
|
||||
if (!Persistence)
|
||||
{
|
||||
ClientMessage(TEXT("No Agrarian persistence subsystem found."));
|
||||
return;
|
||||
}
|
||||
|
||||
const bool bSaved = Persistence->SaveCurrentWorld();
|
||||
ClientMessage(bSaved ? TEXT("Agrarian world saved.") : TEXT("Agrarian world save failed."));
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::ServerAgrarianLoadWorld_Implementation()
|
||||
{
|
||||
UAgrarianPersistenceSubsystem* Persistence = GetGameInstance() ? GetGameInstance()->GetSubsystem<UAgrarianPersistenceSubsystem>() : nullptr;
|
||||
if (!Persistence)
|
||||
{
|
||||
ClientMessage(TEXT("No Agrarian persistence subsystem found."));
|
||||
return;
|
||||
}
|
||||
|
||||
Persistence->RegisterWorldActorClass(TEXT("primitive_shelter"), AAgrarianShelterActor::StaticClass());
|
||||
const UAgrarianSaveGame* SaveGame = Persistence->LoadOrCreateSave();
|
||||
const int32 RestoredCount = Persistence->RestoreWorldActors(SaveGame);
|
||||
ClientMessage(FString::Printf(TEXT("Agrarian world loaded. Restored actors: %d."), RestoredCount));
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::ServerAgrarianHeal_Implementation()
|
||||
{
|
||||
AAgrarianGameCharacter* AgrarianCharacter = GetPawn<AAgrarianGameCharacter>();
|
||||
UAgrarianSurvivalComponent* SurvivalComponent = AgrarianCharacter ? AgrarianCharacter->GetSurvivalComponent() : nullptr;
|
||||
if (!SurvivalComponent)
|
||||
{
|
||||
ClientMessage(TEXT("No Agrarian survival component found."));
|
||||
return;
|
||||
}
|
||||
|
||||
SurvivalComponent->RestoreHealth(100.0f);
|
||||
SurvivalComponent->AddFood(100.0f);
|
||||
SurvivalComponent->AddWater(100.0f);
|
||||
SurvivalComponent->AddWarmth(37.0f - SurvivalComponent->Survival.BodyTemperature);
|
||||
ClientMessage(TEXT("Agrarian survival restored."));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
class UInputMappingContext;
|
||||
class UUserWidget;
|
||||
class AAgrarianShelterActor;
|
||||
|
||||
/**
|
||||
* Basic PlayerController class for a third person game
|
||||
@@ -49,4 +50,32 @@ protected:
|
||||
/** Returns true if the player should use UMG touch controls */
|
||||
bool ShouldUseTouchControls() const;
|
||||
|
||||
public:
|
||||
UFUNCTION(Exec)
|
||||
void AgrarianGrantItem(FName ItemId, int32 Quantity);
|
||||
|
||||
UFUNCTION(Exec)
|
||||
void AgrarianSaveWorld();
|
||||
|
||||
UFUNCTION(Exec)
|
||||
void AgrarianLoadWorld();
|
||||
|
||||
UFUNCTION(Exec)
|
||||
void AgrarianSurvival();
|
||||
|
||||
UFUNCTION(Exec)
|
||||
void AgrarianHeal();
|
||||
|
||||
protected:
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerAgrarianGrantItem(FName ItemId, int32 Quantity);
|
||||
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerAgrarianSaveWorld();
|
||||
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerAgrarianLoadWorld();
|
||||
|
||||
UFUNCTION(Server, Reliable)
|
||||
void ServerAgrarianHeal();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user