/// <summary> /// Removes the item (or at least reduce its amount). /// </summary> /// <param name="itemToRemove">Item to remove.</param> /// <param name="amount">Amount.</param> public void RemoveItem(int itemID, int amount = 1) { Item itemToRemove = database.FetchItemByID(itemID); //Dictionary<Item, int> inventory = inventoryModel.inventory; if (inventoryModel.inventory.ContainsKey(itemToRemove)) { // if the item is in the list if (amount < inventoryModel.inventory[itemToRemove]) { // if the amount to remove is lower than the amount in the inventory inventoryModel.inventory[itemToRemove] -= amount; // updates the amount of the model inventoryView.updateAmountItemView(itemToRemove, inventoryModel.inventory[itemToRemove]); // updates the view } else { // remove the item completely if (amount > inventoryModel.inventory[itemToRemove]) { Debug.LogWarning("Try to remove more item than available in the model, ain't right"); } inventoryModel.inventory.Remove(itemToRemove); // remove the item inventoryView.UpdateViewAfterRemoval(itemToRemove); // updates the view } } inventoryView.LoadInventory(); }