public void AddCell(InventoryCell cell, int atIndex = -1, int quantity = 1) { for (var i = 0; i < container.Length; ++i) { if (container[i] == null || container[i].item == null) { container[i] = cell; break; } } }
public void AddItem(ItemObject item, int atIndex = -1, int quantity = 1) { var firstFreeCellIdx = atIndex == -1 ? FindFreeCellToAdd(item) : atIndex; if (container[firstFreeCellIdx].item != null && container[firstFreeCellIdx].item.ItemType == item.ItemType) { container[firstFreeCellIdx].AddAmount(quantity); } else { container[firstFreeCellIdx] = new InventoryCell(item, quantity); } }
public void RemoveItem(InventoryCell item, int quantity = 1) { var containedItemIndex = Array.FindIndex(container, cell => cell.item != null && cell == item); if (containedItemIndex == -1) { return; } var amount = container[containedItemIndex].amount; if (amount > 1 && quantity < amount) { container[containedItemIndex].ReduceAmount(quantity); } else { container[containedItemIndex] = new InventoryCell(null, 0); } }