public static void ItemTest(Unit unit) { var amuletType = new ItemType(JewelleryType.Amulet, EquipSlot.AmuletA); var anotherAmulet = new ItemType(JewelleryType.Amulet, EquipSlot.AmuletA); var chestArmorType = new ItemType(ArmorType.Leather, EquipSlot.Chest); var hoodArmorType = new ItemType(ArmorType.Leather, EquipSlot.Head); var swordType = new ItemType(WeaponType.OneHandedSwords, EquipSlot.MainHand); Item[] itemArr = new Item[] { new Item("Lucky Charm", new ItemAttributes(amuletType, 0.2f, 1, 1, 1, 1, 1, 5)), new Item("Undead's Claw", new ItemAttributes(anotherAmulet, 0.2f, str: 2, wis: 4, luck: -1)), new Item("Rugged L.Chest", new ItemAttributes(chestArmorType, 2.2f, str: 2, con: 3)), new Item("Assassins Hood", new ItemAttributes(hoodArmorType, 1f, dex:5, luck:1)), new Item("Dark Sword", new ItemAttributes(swordType, 3.5f, 30, "2d5", 30, 24, str: 5, con: 3)) }; GameEngine.GameField[unit.X, unit.Y].ItemList.AddRange(itemArr); }
/// <summary> /// ItemAttribute constructor for weapons. /// </summary> public ItemAttributes(ItemType itemType, float weight, int baseDamage, string randomElement, int speed, int accuracy, int str = 0, int dex = 0, int con = 0, int wis = 0, int spi = 0, int luck = 0) : base(str, dex, con, wis, spi, luck) { if (itemType.BaseType == BaseType.Weapon) { this.itemType = itemType; this.itemWeight = weight; this.baseDamage = baseDamage; this.randomElement = randomElement; this.speed = speed; this.accuracy = accuracy; } else throw new ArgumentException("Used constructor is for items of BaseType Weapon only!"); }
private string randomElement; //in format 2d5, 1d3, 3d12, etc. /// <summary> /// ItemAttribute constructor for armor and jewellery items. /// </summary> public ItemAttributes(ItemType itemType, float weight, int str = 0, int dex = 0, int con = 0, int wis = 0, int spi = 0, int luck = 0) : base(str, dex, con, wis, spi, luck) { if (itemType.BaseType == BaseType.Armor || itemType.BaseType == BaseType.Jewellery) { this.itemType = itemType; this.itemWeight = weight; } else throw new ArgumentException("Used constructor is for items of BaseType Armor and Jewellery only!"); }
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; }