/// <summary> /// Add 'quantity' of 'itemToAdd' to inventory, or increase existing quantity /// </summary> /// <param name="itemToAdd">Item to be added to inventory (can already be in inventory)</param> /// <param name="quantity">Amount of item to be added (Default = 1)</param> public void AddItemToInventory(Item itemToAdd, int quantity = 1) { InventoryItem item = Inventory.SingleOrDefault( ii => ii.Details.ID == itemToAdd.ID); if (item == null) { // They didn't have the item, so add it to their inventory // If there are none of this type of item, and it has a "CurrentItem" // property, then set this to it, so indexing will work right // NOTE: The UI code will follow-thru with the updates, based on // RaiseInventoryChangedEvent and Player.PropertyChanged event if (itemToAdd is Weapon && !Weapons.Any()) { CurrentWeapon = (Weapon)itemToAdd; } if (itemToAdd is HealingPotion && !Potions.Any()) { CurrentPotion = (HealingPotion)itemToAdd; } Inventory.Add(new InventoryItem(itemToAdd, quantity)); } else { // They already have the item in inventory, so just increase quantity item.Quantity += quantity; } // An inventory quantity was changed, raise an event RaiseInventoryChangedEvent(itemToAdd); }
public bool HasPotions() { return(Potions.Any()); }