This commit is contained in:
2023-07-21 08:58:28 +02:00
parent 8906b1a492
commit 77bb47aeb9
77 changed files with 162 additions and 162 deletions

View File

@@ -1,71 +1 @@
#include "InventoryManager.h"
// Add item to inventory
void AInventoryManager::AddToInventory(const FFireworkData& Item, const int32& Quantity, const APawn* Pawn)
{
FInventory* InventoryToUpdate = Inventory.Find(Pawn);
// If there's no inventory associated with supplied pawn, create one
if (!InventoryToUpdate)
{
InventoryToUpdate = new FInventory();
}
FFireworkEntry* ItemToUpdate = InventoryToUpdate->Items.FindByPredicate([&](const FFireworkEntry& ThisItem)
{
return ThisItem.FireworkData.Firework == Item.Firework;
});
if (ItemToUpdate == nullptr) {
UE_LOG(LogTemp, Warning, TEXT("ItemToUpdate not found - creating one"));
ItemToUpdate = new FFireworkEntry(Item, Quantity);
InventoryToUpdate->Items.Add(*ItemToUpdate);
}
else {
UE_LOG(LogTemp, Warning, TEXT("ItemToUpdate was found, updating..."));
ItemToUpdate->Quantity += 1;
}
}
// Remove item from inventory
void AInventoryManager::RemoveFromInventory(const FFireworkData& Item, const APawn* Pawn)
{
// code
}
// Remove all items of a specified player from inventory (for example if he quits match mid game)
void AInventoryManager::RemovePlayerItems(const APawn* Pawn)
{
// code
}
// Get joint inventory of all players
FInventory AInventoryManager::GetInventory()
{
FInventory Joint;
TArray<APawn*> Pawns;
Inventory.GetKeys(Pawns);
for (int32 i = 0; i < Pawns.Num(); i++)
{
FInventory* ThisInventory = Inventory.Find(Pawns[i]);
for (int32 f = 0; f < ThisInventory->Items.Num(); f++)
{
// Check if items of this category already exist in joint inventory
FFireworkEntry* ItemToUpdate = Joint.Items.FindByPredicate([&](const FFireworkEntry& ThisItem) {
return ThisItem.FireworkData.Firework == ThisInventory->Items[i].FireworkData.Firework;
});
if (ItemToUpdate == nullptr) {
ItemToUpdate = &ThisInventory->Items[i];
}
else {
ItemToUpdate->Quantity += ThisInventory->Items[i].Quantity;
}
Joint.Items.Add(*ItemToUpdate);
}
}
return Joint;
}