public static Affixes.Items.Affix RollNewSuffix(AffixItemItem pomItem, Item item) { if (pomItem.FreeSuffixes <= 0) { return(null); } Tuple <Affixes.Items.Affix, double>[] tuples = PoMDataLoader.affixesItem .Where(a => a.AffixSpaceAvailable(pomItem) && a.Weight > 0 && a.CanBeRolled(pomItem, item) && a is Affixes.ISuffix && !pomItem.affixes.Exists(ia => ia.GetType() == a.GetType())) .Select(a => new Tuple <Affixes.Items.Affix, double>(a, a.Weight)) .ToArray(); if (tuples.Length == 0) { return(null); } WeightedRandom <Affixes.Items.Affix> weightedRandom = new WeightedRandom <Affixes.Items.Affix>(Main.rand, tuples); Affixes.Items.Affix suffix = weightedRandom; suffix = suffix.Clone(); suffix.InitializeItem(pomItem); return(suffix); }
/// <summary> /// Returns a new instance of the affix based on class name /// </summary> public static Affixes.Items.Affix GetAffix(AffixItemItem pomItem, string name, bool isPrefix) { string namespaceQualifiedTypeName; if (isPrefix) { namespaceQualifiedTypeName = typeof(Affixes.Items.Prefixes.AccessoryConsumeAmmo).Namespace; } else { namespaceQualifiedTypeName = typeof(Affixes.Items.Suffixes.WeaponAssistance).Namespace; } namespaceQualifiedTypeName = $"{ namespaceQualifiedTypeName }.{ name }"; Type affixType = Type.GetType(namespaceQualifiedTypeName); Affixes.Items.Affix affix = PoMDataLoader.affixesItem[PoMDataLoader.affixItemMap[affixType]]; affix = affix.Clone(); affix.InitializeItem(pomItem); return(affix); }