Beispiel #1
0
 private void CollectItems(List <IItem> items)
 {
     foreach (IItem item in items)
     {
         bool added = false;
         for (int i = 0; i < _items.Count; i++)
         {
             if (_items[i].ID.Equals(item.ID))
             {
                 InventoryRecord ir = _items[i];
                 ir.Count++;
                 _items[i] = ir;
                 added     = true;
                 break;
             }
         }
         if (!added)
         {
             InventoryRecord ir = new InventoryRecord();
             ir.Item  = item;
             ir.Count = 1;
             _items.Add(ir);
         }
     }
 }
Beispiel #2
0
 private void TakeEverything()
 {
     for (int i = 0; i < _hoard.Count; i++)
     {
         InventoryRecord take = _hoard[i];
         _hoard[i] = new InventoryRecord();
         _taken.Add(take);
     }
     _takeEverything = true;
     _option         = 6;
 }
Beispiel #3
0
        private void TakeItem()
        {
            if (_option > _hoard.Count)
            {
                return;
            }
            InventoryRecord take = _hoard[_option - 1];

            if (take.ID == "")
            {
                return;
            }
            _hoard[_option - 1] = new InventoryRecord();
            _taken.Add(take);
        }
Beispiel #4
0
        public static void Init()
        {
            _inventory = new InventoryRecord[INVENTORY_SIZE];

            XmlDocument savegame = Globals.SaveGame;

            foreach (XmlNode node in savegame.SelectSingleNode("//inventory").ChildNodes)
            {
                if (node.NodeType == XmlNodeType.Comment)
                {
                    continue;
                }

                XmlDocument xml = new XmlDocument();
                xml.Load(new MemoryStream(Encoding.UTF8.GetBytes(node.OuterXml)));

                XmlNode itemNode = xml.DocumentElement;

                string type  = itemNode.Name;
                string id    = itemNode.Attributes["id"].Value;
                int    count = Int32.Parse(itemNode.Attributes["count"].Value);
                int    slot  = Int32.Parse(itemNode.Attributes["slot"].Value);

                _inventory[slot]       = new InventoryRecord(slot);
                _inventory[slot].Count = count;
                _inventory[slot].Item  = Item.GetItem(id, type);
            }

            for (int i = 0; i < INVENTORY_SIZE; i++)
            {
                if (_inventory[i].Item == null)
                {
                    _inventory[i] = new InventoryRecord(i);
                }
            }
        }