public void AddItem(ObtainableItem item, int quantityToAdd) { while (quantityToAdd > 0) { if (InventoryRecords.Exists(x => (x.InventoryItem.ID == item.ID) && (x.Quantity < item.MaximumStackableQuantity))) { InventoryRecord inventoryRecord = InventoryRecords.First(x => (x.InventoryItem.ID == item.ID) && (x.Quantity < item.MaximumStackableQuantity)); int maximumQuantityYouCanAddToThisStack = (item.MaximumStackableQuantity - inventoryRecord.Quantity); int quantityToAddToStack = Math.Min(quantityToAdd, maximumQuantityYouCanAddToThisStack); inventoryRecord.AddToQuantity(quantityToAddToStack); quantityToAdd -= quantityToAddToStack; } else { if (InventoryRecords.Count < MAXIMUM_SLOTS_IN_INVENTORY) { InventoryRecords.Add(new InventoryRecord(item, 0)); } else { } } } }
public InventoryRecord(ObtainableItem item, int quantity) { InventoryItem = item; Quantity = quantity; }