public static int AddItem(Item itm) { int iid = GetInventoryID(itm.Glyph); if (iid == -1) { int index = 0; while (Inventory.ContainsKey(index)) { index++; } Inventory.Add(index, new Item(itm.Count, itm.Glyph)); DrawInventorySlots(); return(index); } else { Inventory[iid].Count += itm.Count; DrawInventorySlots(); return(iid); } }
public static Inventory LoadInventoryFromXml(XmlElement node) { int bagsize = int.Parse(node.GetAttribute("maxsize")); Inventory inv = new Inventory(bagsize); foreach (XmlNode child in node.ChildNodes) { XmlElement childElement = (XmlElement)child; string name = childElement.Name; switch(name) { case "Item": { inv.Add(LoadItemFromXml(childElement)); break; } case "Equipment": { inv.Add(LoadEquipmentFromXml(childElement)); break; } case "Weapon": { inv.Add(LoadWeaponFromXml(childElement)); break; } } } return inv; }