Most inventory cap types implemented
This commit is contained in:
@@ -41,6 +41,7 @@ void UAC_PlayerInventory::InitializePlayerInventory()
|
||||
for (const FStartingItems& Item : StartingItems)
|
||||
{
|
||||
FString ContextString = TEXT("Initialize Player Inventory");
|
||||
InventoryCurrentCapacity = PlayerInventory.Num();
|
||||
|
||||
// For each of the quantities defined
|
||||
for (int32 i = 0; i < Item.QuantityOfItem; i++)
|
||||
@@ -55,12 +56,14 @@ void UAC_PlayerInventory::InitializePlayerInventory()
|
||||
{
|
||||
// Add item to player inventory array
|
||||
PlayerInventory.Add(*LocItemInfo);
|
||||
//Update Carry Capacity
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
InventoryCurrentCapacity = PlayerInventory.Num();
|
||||
}
|
||||
|
||||
TArray<FBaseItemInfo> UAC_PlayerInventory::GetPlayerInventory()
|
||||
@@ -80,7 +83,29 @@ void UAC_PlayerInventory::RequestAddItem(FBaseItemInfo InItemInfo, int32 InItemQ
|
||||
for (int32 i = 0; i < InItemQuantity; i++)
|
||||
{
|
||||
PlayerInventory.Add(InItemInfo);
|
||||
InventoryCurrentCapacity++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TArray<FBaseItemInfo> UAC_PlayerInventory::GetAllInventoryItemsInCategory(EItemType InItemType)
|
||||
{
|
||||
TArray<FBaseItemInfo> LocItemsInCategory;
|
||||
|
||||
for (const FBaseItemInfo& Item : PlayerInventory)
|
||||
{
|
||||
|
||||
if (Item.ItemType == InItemType)
|
||||
{
|
||||
LocItemsInCategory.Add(Item);
|
||||
}
|
||||
|
||||
}
|
||||
return LocItemsInCategory;
|
||||
}
|
||||
|
||||
EInventoryCapType UAC_PlayerInventory::GetInventoryCapType()
|
||||
{
|
||||
return this->InventoryCapType;
|
||||
}
|
||||
|
||||
|
@@ -21,11 +21,11 @@ void UAC_PlayerStats::InitializePlayerStats()
|
||||
CurrentHealth = MaxHealth;
|
||||
CurrentStamina = MaxStamina;
|
||||
CurrentMana = MaxMana;
|
||||
UpdateCurrentCarryWeight(CurrentCarryWeight);
|
||||
UpdateCurrentCarryWeight();
|
||||
|
||||
}
|
||||
|
||||
float UAC_PlayerStats::UpdateCurrentCarryWeight(float& InCurrentCarryWeight)
|
||||
void UAC_PlayerStats::UpdateCurrentCarryWeight()
|
||||
{
|
||||
APawn* PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
|
||||
float LocCarryWeight = 0.f;
|
||||
@@ -38,10 +38,9 @@ float UAC_PlayerStats::UpdateCurrentCarryWeight(float& InCurrentCarryWeight)
|
||||
{
|
||||
LocCarryWeight += InventoryItem.ItemWeight;
|
||||
}
|
||||
InCurrentCarryWeight = LocCarryWeight;
|
||||
CurrentCarryWeight = LocCarryWeight;
|
||||
}
|
||||
|
||||
return InCurrentCarryWeight;
|
||||
}
|
||||
|
||||
// Called when the game starts
|
||||
|
@@ -4,6 +4,9 @@
|
||||
#include "BPFL_EpicInventory.h"
|
||||
#include "AC_PlayerInventory.h"
|
||||
#include "AC_InventoryItem.h"
|
||||
#include "AC_PlayerStats.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "GameFramework/Character.h"
|
||||
|
||||
|
||||
//Returns the player's Inventory Component
|
||||
@@ -32,30 +35,163 @@ void UBPFL_EpicInventory::RequestInteraction(AActor* InteractingActor)
|
||||
UAC_PlayerInventory* PlayerInventoryComponent = GetPlayerInventoryComponent(InteractingActor);
|
||||
UAC_InventoryItem* ObjectInventoryItem = InteractingActor->FindComponentByClass<UAC_InventoryItem>();
|
||||
TArray<FStartingItems> ObjectItemInfoArray = ObjectInventoryItem->ItemInformation;
|
||||
|
||||
UAC_PlayerStats* PlayerStatsComponent = GetPlayerStatsComponent(InteractingActor);
|
||||
APawn* PlayerPawn = InteractingActor->GetWorld()->GetFirstPlayerController()->GetPawn();
|
||||
ACharacter* PlayerCharacter = Cast<ACharacter>(PlayerPawn);
|
||||
EInventoryCapType PlayerCapType = PlayerInventoryComponent->GetInventoryCapType();
|
||||
if (PlayerInventoryComponent)
|
||||
{
|
||||
if (PlayerInventoryComponent->bUseInventoryCap)
|
||||
{
|
||||
//Check type of cap and if there is room then add item
|
||||
UE_LOG(LogTemp, Warning, TEXT("Implement cap check"))
|
||||
UE_LOG(LogTemp, Warning, TEXT("Implement cap check"));
|
||||
switch (PlayerCapType)
|
||||
{
|
||||
case EInventoryCapType::None:
|
||||
for (const FStartingItems& DTRow : ObjectItemInfoArray)
|
||||
{
|
||||
FBaseItemInfo* LocItemInfo = DTRow.ItemDataTableAndRow.DataTable->FindRow<FBaseItemInfo>(DTRow.ItemDataTableAndRow.RowName, FString("Interaction Request"));
|
||||
int32 LocItemQuantity = DTRow.QuantityOfItem;
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
|
||||
InteractingActor->Destroy();
|
||||
|
||||
}
|
||||
break;
|
||||
case EInventoryCapType::Weight:
|
||||
for (int32 i = 0; i < ObjectItemInfoArray.Num(); i++)
|
||||
{
|
||||
FBaseItemInfo* LocItemInfo = ObjectItemInfoArray[i].ItemDataTableAndRow.DataTable->FindRow<FBaseItemInfo>(ObjectItemInfoArray[i].ItemDataTableAndRow.RowName, FString("Interaction Request"));
|
||||
int32 LocItemQuantity = ObjectItemInfoArray[i].QuantityOfItem;
|
||||
float LocItemWeight = LocItemInfo->ItemWeight;
|
||||
float LocMaxCarryWeight = PlayerStatsComponent->MaxCarryWeight;
|
||||
float LocCurrentCarryWeight = PlayerStatsComponent->CurrentCarryWeight;
|
||||
|
||||
if ((LocItemWeight + LocCurrentCarryWeight) >= LocMaxCarryWeight)
|
||||
{
|
||||
//Item will encumber player so trigger encumberance as well
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
PlayerStatsComponent->UpdateCurrentCarryWeight();
|
||||
UCharacterMovementComponent* MovementComponent = PlayerCharacter->GetCharacterMovement();
|
||||
MovementComponent->MaxWalkSpeed = 75.0f;
|
||||
InteractingActor->Destroy();
|
||||
UE_LOG(LogTemp, Warning, TEXT("Weight method used"));
|
||||
|
||||
}
|
||||
else if ((LocItemWeight + LocCurrentCarryWeight) < LocMaxCarryWeight)
|
||||
{
|
||||
//Item will not encumber player so only add item and update weight
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
PlayerStatsComponent->UpdateCurrentCarryWeight();
|
||||
InteractingActor->Destroy();
|
||||
UE_LOG(LogTemp, Warning, TEXT("Weight method used"));
|
||||
|
||||
}
|
||||
else {
|
||||
//Item will neither encumber or not encumber player somehow so add item and update weight
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
PlayerStatsComponent->UpdateCurrentCarryWeight();
|
||||
InteractingActor->Destroy();
|
||||
UE_LOG(LogTemp, Warning, TEXT("Weight method used"));
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case EInventoryCapType::TotalItems:
|
||||
for (int32 i = 0; i < ObjectItemInfoArray.Num(); i++)
|
||||
{
|
||||
FBaseItemInfo* LocItemInfo = ObjectItemInfoArray[i].ItemDataTableAndRow.DataTable->FindRow<FBaseItemInfo>(ObjectItemInfoArray[i].ItemDataTableAndRow.RowName, FString("Interaction Request"));
|
||||
int32 LocItemQuantity = ObjectItemInfoArray[i].QuantityOfItem;
|
||||
int32 LocMaxItemCapacity = PlayerInventoryComponent->InventoryMaxCapacity;
|
||||
int32 LocCurrentItemCapacity = PlayerInventoryComponent->InventoryCurrentCapacity;
|
||||
|
||||
if ((LocItemQuantity + LocCurrentItemCapacity) > LocMaxItemCapacity)
|
||||
{
|
||||
//Would make capacity over max so do not add
|
||||
UE_LOG(LogTemp, Warning, TEXT("Thought it was too much"));
|
||||
}
|
||||
else if ((LocItemQuantity + LocCurrentItemCapacity) <= LocMaxItemCapacity)
|
||||
{
|
||||
//Would not go over max capacity so add item
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
|
||||
InteractingActor->Destroy();
|
||||
}
|
||||
else {
|
||||
//Some weird edgcase where it would not exeed or be less than
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
|
||||
InteractingActor->Destroy();
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EInventoryCapType::TotalItemsPerCategory:
|
||||
for (int32 i = 0; i < ObjectItemInfoArray.Num(); i++)
|
||||
{
|
||||
FBaseItemInfo* LocItemInfo = ObjectItemInfoArray[i].ItemDataTableAndRow.DataTable->FindRow<FBaseItemInfo>(ObjectItemInfoArray[i].ItemDataTableAndRow.RowName, FString("Interaction Request"));
|
||||
int32 LocItemQuantity = ObjectItemInfoArray[i].QuantityOfItem;
|
||||
TMap<EItemType, int32> LocInventoryCapacityMap = PlayerInventoryComponent->InventoryCapacityPerCategory;
|
||||
EItemType LocItemType = LocItemInfo->ItemType;
|
||||
int32* LocCategoryMaxCapacity = LocInventoryCapacityMap.Find(LocItemType);
|
||||
int32 LocCategoryCurrentCapacity = PlayerInventoryComponent->GetAllInventoryItemsInCategory(LocItemType).Num();
|
||||
if ((LocItemQuantity + LocCategoryCurrentCapacity) > *LocCategoryMaxCapacity)
|
||||
{
|
||||
//Item would exceed category max so do not add
|
||||
}
|
||||
else if ((LocItemQuantity + LocCategoryCurrentCapacity) <= *LocCategoryMaxCapacity)
|
||||
{
|
||||
//Item would not exceed category max so add and update capacity
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
InteractingActor->Destroy();
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
UE_LOG(LogTemp, Warning, TEXT("Default Case Entered"));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
UE_LOG(LogTemp, Warning, TEXT("Implement AddItem"));
|
||||
// Add item for each item defined in the item array on the component
|
||||
for (const FStartingItems& DTRow : ObjectItemInfoArray)
|
||||
{
|
||||
FBaseItemInfo* LocItemInfo = DTRow.ItemDataTableAndRow.DataTable->FindRow<FBaseItemInfo>(DTRow.ItemDataTableAndRow.RowName, FString("Interaction Request"));
|
||||
int32 LocItemQuantity = DTRow.QuantityOfItem;
|
||||
PlayerInventoryComponent->RequestAddItem(*LocItemInfo, LocItemQuantity);
|
||||
UE_LOG(LogTemp, Warning, TEXT("Attempted Add"));
|
||||
InteractingActor->Destroy();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
InteractingActor->Destroy();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
UAC_PlayerStats* UBPFL_EpicInventory::GetPlayerStatsComponent(UObject* WorldContextObject)
|
||||
{
|
||||
UAC_PlayerStats* PlayerStatsComponent(nullptr);
|
||||
|
||||
APawn* PlayerPawn = WorldContextObject->GetWorld()->GetFirstPlayerController()->GetPawn();
|
||||
if (PlayerPawn)
|
||||
{
|
||||
PlayerStatsComponent = PlayerPawn->FindComponentByClass<UAC_PlayerStats>();
|
||||
if (PlayerStatsComponent)
|
||||
{
|
||||
return PlayerStatsComponent;
|
||||
}
|
||||
else {
|
||||
return PlayerStatsComponent;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return PlayerStatsComponent;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,9 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::TotalItems", EditConditionHides))
|
||||
int32 InventoryMaxCapacity = 100;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
int32 InventoryCurrentCapacity = 0;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inventory Configuration", meta = (EditCondition = "InventoryCapType == EInventoryCapType::PerCat", EditConditionHides))
|
||||
TMap<EItemType, int32> InventoryCapacityPerCategory;
|
||||
|
||||
@@ -49,6 +52,12 @@ public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void RequestAddItem(FBaseItemInfo InItemInfo, int32 InItemQuantity);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
TArray<FBaseItemInfo> GetAllInventoryItemsInCategory(EItemType InItemType);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
EInventoryCapType GetInventoryCapType();
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
@@ -44,7 +44,7 @@ public:
|
||||
void InitializePlayerStats();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
float UpdateCurrentCarryWeight(float& InCurrentCarryWeight);
|
||||
void UpdateCurrentCarryWeight();
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
|
@@ -9,7 +9,7 @@
|
||||
//Forward Declarations
|
||||
class UAC_PlayerInventory;
|
||||
class UAC_InventoryItem;
|
||||
|
||||
class UAC_PlayerStats;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -27,5 +27,9 @@ public:
|
||||
//Request interaction with the player quest component
|
||||
UFUNCTION(BlueprintCallable, Category = "Inventory Interaction")
|
||||
static void RequestInteraction(AActor* InteractingActor);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Player Stat Getters")
|
||||
static UAC_PlayerStats* GetPlayerStatsComponent(UObject* WorldContextObject);
|
||||
|
||||
|
||||
};
|
||||
|
@@ -90,8 +90,8 @@ enum class EInventoryCapType : uint8
|
||||
{
|
||||
None UMETA(DisplayName = "None"),
|
||||
Weight UMETA(DisplayName = "Weight"),
|
||||
TotalItems UMETA(DisplayName = "Total Items"),
|
||||
PerCat UMETA(DisplayName = "Total Items per Category")
|
||||
TotalItems UMETA(DisplayName = "TotalItems"),
|
||||
TotalItemsPerCategory UMETA(DisplayName = "TotalItemsPerCategory")
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user