public static WeaponEnchantment GetWeaponEnchantment(string enchantName) { WeaponEnchantment wEnchant = null; XElement wEnchantData = null; // load all the enchantments XElement root = XElement.Load("res/data/WeaponEnchantTypes.xml"); IEnumerable <XElement> enchants = from el in root.Elements("enchantment") select el; // choose the right enchantment foreach (XElement e in enchants) { if (ReadAttribute(e.Attribute("name")).Equals(enchantName)) { wEnchantData = e; } } if (wEnchantData == null) { return(null); } string name = enchantName; List <XElement> partNames = wEnchantData.Element("part_names").Elements().ToList(); string partName = ReadAttribute(partNames[Program.RNG.Next(0, partNames.Count)].FirstAttribute); Enum.TryParse(ReadAttribute(wEnchantData.Attribute("damage_type")), out DamageType damageType); Effect appliedEffect = GetEffect(ReadAttribute(wEnchantData.Attribute("applied_effect"))); int victimDamage = Program.RNG.Next(System.Convert.ToInt32(ReadAttribute(wEnchantData.Element("victim_damage").FirstAttribute)), System.Convert.ToInt32(ReadAttribute(wEnchantData.Element("victim_damage").LastAttribute))); wEnchant = new WeaponEnchantment(name, partName, damageType, victimDamage, appliedEffect); return(wEnchant); }
public void DetermineEnchantments() { // the amount of enchantments you will find scales with the level you are at in the dungeon int rand = Program.RNG.Next(0, 101); if (rand <= 66) // 66% chance { maxEnchantments = 0; } else if (rand <= 81) // 15% chance { maxEnchantments = 1; } else if (rand <= 90) // 9% chance { maxEnchantments = 2; } else if (rand <= 96) // 6% chance { maxEnchantments = 3; } else // 4% chance { maxEnchantments = 4; } int enchantCount = 0; rand = Program.RNG.Next(0, 101); if (rand <= 78 && maxEnchantments >= 0) // 78% chance { enchantCount = 0; } else if (rand <= 90 && maxEnchantments >= 1) // 12% chance { enchantCount = 1; } else if (rand <= 96 && maxEnchantments >= 2) // 6% chance { enchantCount = 2; } else if (rand <= 99 && maxEnchantments >= 3) // 3% chance { enchantCount = 3; } else // 1% chance { enchantCount = maxEnchantments; } int i = 0; while (i < enchantCount && i < maxEnchantments) { WeaponEnchantment enchantment = DataReader.GetNextWeaponEnchantment(); if (enchantments.Find(e => e.Name == enchantment.Name) == null) { enchantments.Add(enchantment); i++; } } }