/// <summary> /// Returns a valid affix for the NPC or null. /// </summary> public static Affixes.NPCs.Affix RollNewAffix(PoMNPC pomNPC, NPC npc) { if (pomNPC.FreeAffixes <= 0) { return(null); } Tuple <Affixes.NPCs.Affix, double>[] tuples = PoMDataLoader.affixesNPC .Where(a => a.AffixSpaceAvailable(pomNPC) && a.Weight > 0 && a.CanBeRolled(pomNPC, npc) && !pomNPC.affixes.Exists(ia => ia.GetType() == a.GetType())) .Select(a => new Tuple <Affixes.NPCs.Affix, double>(a, a.Weight)) .ToArray(); if (tuples.Length == 0) { return(null); } WeightedRandom <Affixes.NPCs.Affix> weightedRandom = new WeightedRandom <Affixes.NPCs.Affix>(Main.rand, tuples); Affixes.NPCs.Affix affix = weightedRandom; affix = affix.Clone(); affix.InitializeNPC(pomNPC, npc); return(affix); }
public static void ReceiveDataMaps(BinaryReader reader) { try { #region Item Affixes int length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving Item Affix Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded Item Affix Map Length: {affixItemMap.Count} "); Dictionary <Type, int> newAffixItemMap = new Dictionary <Type, int>(length); Affixes.Items.Affix[] newAffixesItem = new Affixes.Items.Affix[length]; Type type; Mod mod; for (int i = 0; i < length; i++) { string modString = reader.ReadString(); string typeString = reader.ReadString(); mod = ModLoader.GetMod(modString); type = mod.Code.GetType(typeString, true); PathOfModifiers.Instance.Logger.Debug($"ReceiveMaps: {i} / {type.FullName} from mod {mod}"); newAffixesItem[i] = affixesItem[affixItemMap[type]]; newAffixItemMap.Add(type, i); } affixItemMap = newAffixItemMap; affixesItem = newAffixesItem; #endregion #region Item Rarities length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving Item Rarity Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded Item Rarity Map Length: {rarityItemMap.Count} "); Dictionary <Type, int> newRarityMapItem = new Dictionary <Type, int>(length); RarityItem[] newRaritiesItem = new RarityItem[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newRaritiesItem[i] = raritiesItem[rarityItemMap[type]]; newRarityMapItem.Add(type, i); } rarityItemMap = newRarityMapItem; raritiesItem = newRaritiesItem; #endregion #region NPC Affixes length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving NPC Affix Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded NPC Affix Map Length: {affixNPCMap.Count} "); Dictionary <Type, int> newAffixNPCMap = new Dictionary <Type, int>(length); Affixes.NPCs.Affix[] newAffixesNPC = new Affixes.NPCs.Affix[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); PathOfModifiers.Instance.Logger.Debug($"ReceiveMaps: {i} / {type.FullName} from mod {mod}"); newAffixesNPC[i] = affixesNPC[affixNPCMap[type]]; newAffixNPCMap.Add(type, i); } affixNPCMap = newAffixNPCMap; affixesNPC = newAffixesNPC; #endregion #region NPC Rarities length = reader.ReadInt32(); PathOfModifiers.Instance.Logger.Debug($"Receiving NPC Rarity Map Length: {length} "); PathOfModifiers.Instance.Logger.Debug($"Loaded NPC Rarity Map Length: {rarityNPCMap.Count} "); Dictionary <Type, int> newRarityNPCMap = new Dictionary <Type, int>(length); RarityNPC[] newRaritiesNPC = new RarityNPC[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newRaritiesNPC[i] = raritiesNPC[rarityNPCMap[type]]; newRarityNPCMap.Add(type, i); } rarityNPCMap = newRarityNPCMap; raritiesNPC = newRaritiesNPC; #endregion #region Map Generators length = reader.ReadInt32(); Dictionary <Type, int> newGenratorMap = new Dictionary <Type, int>(length); Generator[] newGenerators = new Generator[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newGenerators[i] = generators[generatorMap[type]]; newGenratorMap.Add(type, i); } #endregion #region Maps length = reader.ReadInt32(); Dictionary <Type, int> newMapMap = new Dictionary <Type, int>(length); Map[] newMaps = new Map[length]; for (int i = 0; i < length; i++) { mod = ModLoader.GetMod(reader.ReadString()); type = mod.Code.GetType(reader.ReadString(), true); newMaps[i] = maps[mapMap[type]]; newMapMap.Add(type, i); } mapMap = newMapMap; maps = newMaps; #endregion } catch (Exception e) { PathOfModifiers.Instance.Logger.Fatal(e.ToString()); } }