public static void AddToInventory(Inventory inventory, ItemAmount itemAmount) { for (int i = 0; i < inventory.inventoryList.Count; i++) { if (inventory.inventoryList[i].itemType.typeName == itemAmount.itemType.typeName) { inventory.inventoryList[i].amount += itemAmount.amount; return; } } inventory.inventoryList.Add(itemAmount); }
public static bool RemoveFromInventory(Inventory inventory, ItemAmount itemAmount) { int index = IndexOfItemInInventory(inventory, itemAmount.itemType); if (index != 0 && inventory.inventoryList[index].amount >= itemAmount.amount) { inventory.inventoryList[index].amount -= itemAmount.amount; return(true); } else { return(false); } }
internal void Add(ItemAmount itemAmount) { if (Materials == null) { Materials = new ItemAmount[1]; Materials[0] = itemAmount; } else { for (int i = 0; i < Materials.Length; i++) { if (Materials[i].itemType.typeName == itemAmount.itemType.typeName) { Materials[i].AddAmount(itemAmount.amount); } } } }
public static bool TransferItemsBetweenInventories(Inventory from, Inventory to, ItemAmount items) { if (RemoveFromInventory(from, items)) { AddToInventory(to, items); return(true); } else { return(false); } }
void AddItemsToRecipe(ItemAmount itemAmount, int itemIndex) { ItemType itemType = allItems[itemIndex]; itemType.recipe.Add(itemAmount); }