private void ApplyAttributeSpecifier(ItemTable definition) { foreach (var effect in definition.Attribute) { float result; if (FormulaScript.Evaluate(effect.Formula.ToArray(), this.RandomGenerator, out result)) { //Logger.Debug("Randomized value for attribute " + GameAttribute.Attributes[effect.AttributeId].Name + " is " + result); if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeF) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeF; if (effect.SNOParam != -1) { Attributes[attr, effect.SNOParam] += result; } else { Attributes[attr] += result; } } else if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeI) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeI; if (effect.SNOParam != -1) { Attributes[attr, effect.SNOParam] += (int)result; } else { Attributes[attr] += (int)result; } } } } }
public static void Generate(Item item, int affixesCount) { if (!Item.IsWeapon(item.ItemType) && !Item.IsArmor(item.ItemType) && !Item.IsOffhand(item.ItemType) && !Item.IsAccessory(item.ItemType)) { return; } var itemTypes = ItemGroup.HierarchyToHashList(item.ItemType); int itemQualityMask = 1 << item.Attributes[GameAttribute.Item_Quality_Level]; var filteredList = AffixList.Where(a => a.QualityMask.HasFlag((QualityMask)itemQualityMask) && itemTypes.ContainsAtLeastOne(a.ItemGroup) && a.AffixLevel <= item.ItemLevel); Dictionary <int, AffixTable> bestDefinitions = new Dictionary <int, AffixTable>(); foreach (var affix in filteredList) { bestDefinitions[affix.AffixFamily0] = affix; } var selectedGroups = bestDefinitions.Values.OrderBy(x => RandomHelper.Next()).Take(affixesCount); foreach (var def in selectedGroups) { if (def != null) { //Logger.Debug("Generating affix " + def.Name + " (aLvl:" + def.AffixLevel + ")"); item.AffixList.Add(new Affix(def.Hash)); foreach (var effect in def.AttributeSpecifier) { if (effect.AttributeId > 0) { float result; if (FormulaScript.Evaluate(effect.Formula.ToArray(), item.RandomGenerator, out result)) { //Logger.Debug("Randomized value for attribute " + GameAttribute.Attributes[effect.AttributeId].Name + " is " + result); var tmpAttr = GameAttribute.Attributes[effect.AttributeId]; var attrName = tmpAttr.Name; if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeF) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeF; if (effect.SNOParam != -1) { item.Attributes[attr, effect.SNOParam] += result; } else { item.Attributes[attr] += result; } } else if (GameAttribute.Attributes[effect.AttributeId] is GameAttributeI) { var attr = GameAttribute.Attributes[effect.AttributeId] as GameAttributeI; if (effect.SNOParam != -1) { item.Attributes[attr, effect.SNOParam] += (int)result; } else { item.Attributes[attr] += (int)result; } } } } } } } }