public bool TakeItem(ref Room.ItemGenerator.Item item, int quantity) { if (Room.ItemGenerator.IsWeapon(item.Type)) { Logger.WriteLine("Player {0} : Take weapon {1}", Id, item.ID); Inventory.Add(item.ID, item); } else { foreach (var i in Inventory) { if (i.Value.Type == item.Type) { Logger.WriteLine("Player {0} : Take item {1} and stack into {2}", Id, item.ID, i.Key); item.Quantity -= quantity; i.Value.Quantity += quantity; if (item.Quantity <= 0) { return(true); } return(false); } } Logger.WriteLine("Player {0} : Take item {1} and added in his inventory", Id, item.ID); Inventory.Add(item.ID, item); } return(true); }
public Room.ItemGenerator.Item DropItem(int itemID, int quantity) { var item = Inventory[itemID]; if (item.Quantity == quantity) { Inventory.Remove(itemID); } else { item.Quantity -= quantity; item = new Room.ItemGenerator.Item(item, quantity); } return(item); }
public void SwitchCurrentItem(int itemID) { CurrentItem = Inventory[itemID]; }