Esempio n. 1
0
 /// <summary>
 /// Completely rerolls rarity and affixes.
 /// </summary>
 public void RollNPC(NPC npc)
 {
     ClearAffixes(npc);
     rarity = PoMAffixController.RollRarity(npc);
     RollAffixes(npc);
     UpdateName(npc);
 }
Esempio n. 2
0
        /// <summary>
        /// Returns a valid rarity for the NPC.
        /// </summary>
        public static RarityNPC RollRarity(NPC npc)
        {
            Tuple <RarityNPC, double>[] tuples = PoMDataLoader.raritiesNPC
                                                 .Where(r => r.Weight > 0 && r.CanBeRolled(npc))
                                                 .Select(r => new Tuple <RarityNPC, double>(r, r.Weight))
                                                 .ToArray();
            WeightedRandom <RarityNPC> weightedRandom = new WeightedRandom <RarityNPC>(Main.rand, tuples);
            RarityNPC rarity = (RarityNPC)weightedRandom ?? new NPCNone();

            return(rarity);
        }
Esempio n. 3
0
        public void NetReceiveAffixes(BinaryReader reader, NPC npc)
        {
            try
            {
                int rarityIndex = reader.ReadInt32();
                rarity = PoMDataLoader.raritiesNPC[rarityIndex];

                int   affixCount = reader.ReadByte();
                Affix affix;
                for (int i = 0; i < affixCount; i++)
                {
                    affix = PoMDataLoader.affixesNPC[reader.ReadInt32()].Clone();
                    affix.NetReceive(reader);
                    AddAffix(affix, npc);
                }
                UpdateName(npc);
            }
            catch (Exception e)
            {
                mod.Logger.Error(e.ToString());
            }
        }
Esempio n. 4
0
        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());
            }
        }
Esempio n. 5
0
 public PoMNPC()
 {
     rarity  = ((PoMDataLoader.raritiesNPC?.Length ?? 0) == 0) ? new NPCNone() : PoMDataLoader.raritiesNPC[PoMDataLoader.rarityNPCMap[typeof(NPCNone)]];
     affixes = new List <Affix>();
 }