Exemplo n.º 1
0
 public Item(string name, ItemAttributes attributes, int id)
 {
     this.name = name;
     this.itemAttr = attributes;
     this.inventorySlot = -1;    //default value -1 for not in inventory.
     this.id = id;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Universal Item constructor.
        /// </summary>
        /// <param name="attributes">An object of type ItemAttributes.</param>
        public Item(string name, ItemAttributes attributes)
        {
            this.name = name;
            this.itemAttr = attributes;
            this.inventorySlot = -1;    //default value -1 for not in inventory.

            int id = Database.SearchItemDB(this.name);
            if (id == -1)
                this.id = ++lastItemID;
            else
                this.id = id;

            itemsGenerated.Add(this);
        }
Exemplo n.º 3
0
        private static List<Item> LoadItems()
        {
            XDocument itemXML = XDocument.Load(SaveLoadTools.ITEMS_SAVE_FILE);
            List<Item> itemsList = new List<Item>();
            var items = itemXML.Element("items").Elements("item");

            foreach (var item in items)
            {
                int id = int.Parse(item.Element("id").Value);

                XElement attr = item.Element("attr");
                string name = attr.Attribute("name").Value;
                int str = int.Parse(attr.Attribute("str").Value);
                int dex = int.Parse(attr.Attribute("dex").Value);
                int con = int.Parse(attr.Attribute("con").Value);
                int wis = int.Parse(attr.Attribute("wis").Value);
                int spi = int.Parse(attr.Attribute("spi").Value);
                int luck = int.Parse(attr.Attribute("luck").Value);
                float weight = float.Parse(attr.Attribute("weight").Value);

                XElement itemType = item.Element("itemtype");
                int equipSlot = int.Parse(itemType.Attribute("equipslot").Value);
                int baseType = int.Parse(itemType.Attribute("basetype").Value);
                int subType = int.Parse(itemType.Attribute("subtype").Value);

                ItemType currItemType = new ItemType((BaseType)baseType, subType, (EquipSlot)equipSlot);
                if (currItemType.BaseType == BaseType.Weapon)
                {
                    XElement wepAttr = item.Element("weapon_attr");
                    int baseDmg = int.Parse(wepAttr.Attribute("base_dmg").Value);
                    int speed = int.Parse(wepAttr.Attribute("speed").Value);
                    int accuracy = int.Parse(wepAttr.Attribute("accuracy").Value);
                    string randomEle = wepAttr.Attribute("random_ele").Value;
                    //create weapon, add to list
                    ItemAttributes weaponAttr = new ItemAttributes(currItemType, weight, baseDmg, randomEle, speed, accuracy, str, dex, con, wis, spi, luck);
                    itemsList.Add(new Item(name, weaponAttr, id));
                }
                //else create item, add to list!
                else
                {
                    ItemAttributes itemAttr = new ItemAttributes(currItemType, weight, str, dex, con, wis, spi, luck);
                    itemsList.Add(new Item(name, itemAttr, id));
                }
            }
            return itemsList;
        }