//Fills item with mods based on its rarity, pulling from basemods, destructively modifies basemods to reflect the rollable pool for new item public static bool RollItem(ItemCraft item, IDictionary <PoEModData, int> basemods, RollOptions op = null) { if (op != null && op.ForceMods != null) { foreach (PoEModData f in op.ForceMods) { AddModAndTrim(item, basemods, f, op == null ? false : op.Sanctified); } } if (op != null && op.GlyphicCount > 0) { for (int i = 0; i < op.GlyphicCount / 100 + ((RNG.Gen.Next(100) < op.GlyphicCount % 100) ? 1 : 0); i++) { IDictionary <PoEModData, int> glyphicmods = FindGlyphicMods(item, op.ModWeightGroups, op == null ? false : op.Sanctified); if (glyphicmods.Count == 0) { break; } AddModAndTrim(item, basemods, ChooseMod(glyphicmods), op == null ? false : op.Sanctified); } } int modcount = RollModCount(item.Rarity, CraftingDatabase.AllBaseItems[item.SourceData].item_class); while (item.LiveMods.Count < modcount) { PoEModData mod = ChooseMod(basemods); if (mod == null) { break; } AddModAndTrim(item, basemods, mod, op == null ? false : op.Sanctified); } return(true); }
//Starts from basemods and checks ilvl, live tags (including influence), existing mod groups, option to ignore prefix/suffix space, checks ilvlcap and modweightgroups from RollOptions public static IDictionary <PoEModData, int> FindValidMods(ItemCraft item, IDictionary <PoEModData, int> basemods, bool ignorerarity = false, RollOptions op = null) { IDictionary <PoEModData, int> mods = new Dictionary <PoEModData, int>(); if (item == null) { return(mods); } //check for open prefix/suffix bool openprefix = item.ModCountByType(Prefix) < item.GetAffixLimit(ignorerarity); bool opensuffix = item.ModCountByType(Suffix) < item.GetAffixLimit(ignorerarity); //list existing mod groups ISet <string> groups = new HashSet <string>(); foreach (ModCraft m in item.LiveMods) { PoEModData modtemplate = CraftingDatabase.AllMods[m.SourceData]; groups.Add(modtemplate.group); } int levelcap = (op != null && op.ILvlCap > 0 && op.ILvlCap < item.ItemLevel) ? op.ILvlCap : item.ItemLevel; foreach (PoEModData mod in basemods.Keys) { //intentionally not checking against domain here to allow delve mods, shouldn't be a problem since domain was filtered before if (!openprefix && mod.generation_type == Prefix || !opensuffix && mod.generation_type == Suffix) { continue; } if (mod.required_level > levelcap || groups.Contains(mod.group)) { continue; } IList <string> catalysttags = null; if (item.QualityType != null && CatalystTags.ContainsKey(item.QualityType)) { catalysttags = CatalystTags[item.QualityType]; } int w = CalcGenWeight(mod, item.LiveTags, op?.ModWeightGroups, catalysttags, item.BaseQuality, op == null ? false : op.Sanctified); if (w > 0) { mods.Add(mod, w); } } return(mods); }