Add item drop command
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "AgrarianGamePlayerController.h"
|
||||
#include "AgrarianGameCharacter.h"
|
||||
#include "AgrarianInventoryComponent.h"
|
||||
#include "AgrarianItemPickup.h"
|
||||
#include "AgrarianPersistenceSubsystem.h"
|
||||
#include "AgrarianShelterActor.h"
|
||||
#include "AgrarianSurvivalComponent.h"
|
||||
@@ -127,6 +128,17 @@ void AAgrarianGamePlayerController::AgrarianHeal()
|
||||
ServerAgrarianHeal();
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianDropItem(FName ItemId, int32 Quantity)
|
||||
{
|
||||
if (ItemId == NAME_None || Quantity <= 0)
|
||||
{
|
||||
ClientMessage(TEXT("Usage: AgrarianDropItem <ItemId> <Quantity>"));
|
||||
return;
|
||||
}
|
||||
|
||||
ServerAgrarianDropItem(ItemId, Quantity);
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::AgrarianTravel(float X, float Y, float Z)
|
||||
{
|
||||
ServerAgrarianTravel(FVector(X, Y, Z));
|
||||
@@ -214,6 +226,48 @@ void AAgrarianGamePlayerController::ServerAgrarianHeal_Implementation()
|
||||
ClientMessage(TEXT("Agrarian survival restored."));
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::ServerAgrarianDropItem_Implementation(FName ItemId, int32 Quantity)
|
||||
{
|
||||
AAgrarianGameCharacter* AgrarianCharacter = GetPawn<AAgrarianGameCharacter>();
|
||||
UAgrarianInventoryComponent* InventoryComponent = AgrarianCharacter ? AgrarianCharacter->GetInventoryComponent() : nullptr;
|
||||
if (!AgrarianCharacter || !InventoryComponent)
|
||||
{
|
||||
ClientMessage(TEXT("No Agrarian inventory component found."));
|
||||
return;
|
||||
}
|
||||
|
||||
FAgrarianItemStack DroppedStack;
|
||||
if (!InventoryComponent->ExtractItem(ItemId, Quantity, DroppedStack))
|
||||
{
|
||||
ClientMessage(FString::Printf(TEXT("Could not drop %d x %s."), Quantity, *ItemId.ToString()));
|
||||
return;
|
||||
}
|
||||
|
||||
const FVector DropLocation = AgrarianCharacter->GetActorLocation()
|
||||
+ AgrarianCharacter->GetActorForwardVector() * 150.0f
|
||||
+ FVector(0.0f, 0.0f, 40.0f);
|
||||
const FRotator DropRotation(0.0f, AgrarianCharacter->GetActorRotation().Yaw, 0.0f);
|
||||
|
||||
FActorSpawnParameters SpawnParameters;
|
||||
SpawnParameters.Owner = AgrarianCharacter;
|
||||
SpawnParameters.Instigator = AgrarianCharacter;
|
||||
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
|
||||
|
||||
AAgrarianItemPickup* Pickup = GetWorld()
|
||||
? GetWorld()->SpawnActor<AAgrarianItemPickup>(AAgrarianItemPickup::StaticClass(), DropLocation, DropRotation, SpawnParameters)
|
||||
: nullptr;
|
||||
if (!Pickup)
|
||||
{
|
||||
InventoryComponent->AddItem(DroppedStack);
|
||||
ClientMessage(FString::Printf(TEXT("Failed to spawn dropped %s; item restored."), *ItemId.ToString()));
|
||||
return;
|
||||
}
|
||||
|
||||
Pickup->PickupStack = DroppedStack;
|
||||
Pickup->Quantity = DroppedStack.Quantity;
|
||||
ClientMessage(FString::Printf(TEXT("Dropped %d x %s."), DroppedStack.Quantity, *ItemId.ToString()));
|
||||
}
|
||||
|
||||
void AAgrarianGamePlayerController::ServerAgrarianTravel_Implementation(FVector Destination)
|
||||
{
|
||||
APawn* ControlledPawn = GetPawn();
|
||||
|
||||
Reference in New Issue
Block a user