#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 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; }