Exemplo n.º 1
0
        public void FinalizeDataHolder()
        {
            SpawnEntry = NPCMgr.GetSpawnEntry(SpawnId);
            if (SpawnEntry == null)
            {
                ContentMgr.OnInvalidDBData("{0} had an invalid SpawnId.", this);
            }
            else
            {
                var added = false;
                var cur   = SpawnEntry.Waypoints.First;
                while (cur != null)
                {
                    if (cur.Value.Id > Id)
                    {
                        Node  = cur.List.AddBefore(cur, this);
                        added = true;
                        break;
                    }

                    if (cur.Value.Id == Id)
                    {
                        ContentMgr.OnInvalidDBData("Found multiple Waypoints with the same Id {0} for SpawnEntry {1}", Id, SpawnEntry);
                        return;
                    }
                    cur = cur.Next;
                }

                if (!added)
                {
                    SpawnEntry.HasDefaultWaypoints = false;
                    Node = SpawnEntry.Waypoints.AddLast(this);
                }
            }
        }
Exemplo n.º 2
0
        public override VehicleEntry ConvertTo(byte[] rawData, ref int id)
        {
            id = DBCRecordConverter.GetInt32(rawData, 0);
            VehicleEntry vehicleEntry = new VehicleEntry()
            {
                Id         = DBCRecordConverter.GetUInt32(rawData, 0),
                Flags      = (VehicleFlags)DBCRecordConverter.GetUInt32(rawData, 1),
                TurnSpeed  = DBCRecordConverter.GetFloat(rawData, 2),
                PitchSpeed = DBCRecordConverter.GetFloat(rawData, 3),
                PitchMin   = DBCRecordConverter.GetFloat(rawData, 4),
                PitchMax   = DBCRecordConverter.GetFloat(rawData, 5)
            };
            int num1 = 0;
            int num2 = 0;

            for (int index = 0; index < vehicleEntry.Seats.Length; ++index)
            {
                uint uint32 = DBCRecordConverter.GetUInt32(rawData, 6 + index);
                if (uint32 > 0U)
                {
                    VehicleSeatEntry vehicleSeatEntry = NPCMgr.GetVehicleSeatEntry(uint32);
                    vehicleEntry.Seats[index] = vehicleSeatEntry;
                    ++num2;
                    num1 = index;
                }
            }

            vehicleEntry.SeatCount = num2;
            if (num1 < 7)
            {
                Array.Resize <VehicleSeatEntry>(ref vehicleEntry.Seats, num1 + 1);
            }
            vehicleEntry.PowerType = (VehiclePowerType)DBCRecordConverter.GetInt32(rawData, 37);
            return(vehicleEntry);
        }
Exemplo n.º 3
0
 public static void LoadAll(bool force = false)
 {
     if (NPCMgr.Loaded)
     {
         return;
     }
     NPCMgr.LoadNPCDefs(force);
 }
Exemplo n.º 4
0
 public static void Apply(this Action <NPCEntry> cb, params NPCId[] ids)
 {
     foreach (NPCId id in ids)
     {
         NPCEntry entry = NPCMgr.GetEntry(id);
         if (entry != null)
         {
             cb(entry);
         }
     }
 }
Exemplo n.º 5
0
 public static void Initialize()
 {
     NPCMgr.DefaultFaction = new Faction()
     {
         Id = FactionId.None
     };
     NPCMgr.DefaultFamily = new CreatureFamily()
     {
         Id = CreatureFamilyId.None
     };
     NPCMgr.InitDefault();
     NPCMgr.LoadNPCDefs(false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the NPCEntry for the given difficulty
        /// </summary>
        public NPCEntry GetEntry(uint difficultyIndex)
        {
            var id = DifficultyOverrideEntryIds.Get(difficultyIndex);

            if (id != 0)
            {
                var entry = NPCMgr.GetEntry(id);
                if (entry != null)
                {
                    return(entry);
                }
            }
            return(this);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Spawns the pool to which the NPCSpawnEntry belongs which is closest to the given location
        /// </summary>
        public static NPCSpawnPoint SpawnClosestSpawnEntry(IWorldLocation pos)
        {
            NPCSpawnEntry closestSpawnEntry = NPCMgr.GetClosestSpawnEntry(pos);

            if (closestSpawnEntry != null)
            {
                NPCSpawnPool npcSpawnPool = pos.Map.AddNPCSpawnPoolNow(closestSpawnEntry.PoolTemplate);
                if (npcSpawnPool != null)
                {
                    return(npcSpawnPool.GetSpawnPoint(closestSpawnEntry));
                }
            }

            return((NPCSpawnPoint)null);
        }
Exemplo n.º 8
0
        public override VehicleEntry ConvertTo(byte[] rawData, ref int id)
        {
            id = GetInt32(rawData, 0);
            var vehicle = new VehicleEntry {
                Id         = GetUInt32(rawData, 0),
                Flags      = (VehicleFlags)GetUInt32(rawData, 1),
                TurnSpeed  = GetFloat(rawData, 2),
                PitchSpeed = GetFloat(rawData, 3),
                PitchMin   = GetFloat(rawData, 4),
                PitchMax   = GetFloat(rawData, 5)
            };

            var lastSeatId = 0;
            var count      = 0;

            for (var i = 0; i < vehicle.Seats.Length; i++)
            {
                var seatId = GetUInt32(rawData, 6 + i);
                if (seatId <= 0)
                {
                    continue;
                }

                var seatEntry = NPCMgr.GetVehicleSeatEntry(seatId);
                vehicle.Seats[i] = seatEntry;
                count++;
                lastSeatId = i;
            }

            vehicle.SeatCount = count;
            if (lastSeatId < 7)
            {
                Array.Resize(ref vehicle.Seats, (int)lastSeatId + 1);
            }

            vehicle.PowerType = (VehiclePowerType)GetInt32(rawData, 37);

            return(vehicle);
        }
Exemplo n.º 9
0
        public void FinalizeDataHolder()
        {
            SpawnEntry = NPCMgr.GetSpawnEntry(SpawnId);
            if (SpawnEntry == null)
            {
                ContentMgr.OnInvalidDBData("{0} had an invalid SpawnId.", (object)this);
            }
            else
            {
                bool flag = false;
                for (LinkedListNode <WaypointEntry> node = SpawnEntry.Waypoints.First;
                     node != null;
                     node = node.Next)
                {
                    if (node.Value.Id > Id)
                    {
                        Node = node.List.AddBefore(node, this);
                        flag = true;
                        break;
                    }

                    if ((int)node.Value.Id == (int)Id)
                    {
                        ContentMgr.OnInvalidDBData("Found multiple Waypoints with the same Id {0} for SpawnEntry {1}",
                                                   (object)Id, (object)SpawnEntry);
                        return;
                    }
                }

                if (flag)
                {
                    return;
                }
                SpawnEntry.HasDefaultWaypoints = false;
                Node = SpawnEntry.Waypoints.AddLast(this);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Is called to initialize the object; usually after a set of other operations have been performed or if
        /// the right time has come and other required steps have been performed.
        /// </summary>
        public void FinalizeAfterLoad()
        {
            NPCId          = (NPCId)Id;
            SetFlagIndeces = Utility.GetSetIndices((uint)Flags);
            DefaultFaction = FactionMgr.Get(DefaultFactionId);

            if (AuraIds != null)
            {
                var auras = new List <Spell>(AuraIds.Length);
                foreach (var auraId in AuraIds)
                {
                    var spell = SpellHandler.Get(auraId);
                    if (spell != null)
                    {
                        auras.Add(spell);
                    }
                }
                Auras = auras.ToArray();
            }
            else
            {
                Auras = Spell.EmptyArray;
            }

            var entry = NPCMgr.GetEntry(Id);

            if (entry != null)
            {
                // set the prototype
                entry.Prototype = this;
                Entry           = entry;
            }

            InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
            SpawnTypeHandlers    = NPCMgr.GetNPCSpawnTypeHandlers(this);
        }
Exemplo n.º 11
0
 public static void LoadSpawns(bool force)
 {
     NPCMgr.Loading = true;
     try
     {
         NPCMgr.OnlyLoadSpawns(force);
         NPCMgr.LoadWaypoints(force);
         if (!ServerApp <WCell.RealmServer.RealmServer> .Instance.IsRunning)
         {
             return;
         }
         for (MapId mapId = MapId.Silaris; mapId < MapId.End; ++mapId)
         {
             Map map = WCell.RealmServer.Global.World.GetNonInstancedMap(mapId);
             if (map != null && map.NPCsSpawned)
             {
                 List <NPCSpawnPoolTemplate> poolTemplatesByMap = NPCMgr.GetSpawnPoolTemplatesByMap(mapId);
                 if (poolTemplatesByMap != null)
                 {
                     foreach (NPCSpawnPoolTemplate spawnPoolTemplate in poolTemplatesByMap)
                     {
                         if (spawnPoolTemplate.AutoSpawns)
                         {
                             NPCSpawnPoolTemplate p = spawnPoolTemplate;
                             map.ExecuteInContext((Action)(() => map.AddNPCSpawnPoolNow(p)));
                         }
                     }
                 }
             }
         }
     }
     finally
     {
         NPCMgr.Loading = false;
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Is called to initialize the object; usually after a set of other operations have been performed or if
        /// the right time has come and other required steps have been performed.
        /// </summary>
        public void FinalizeDataHolder()
        {
            if (string.IsNullOrEmpty(DefaultName))
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no name: " + this);
                return;
            }

            if (SpellGroupId != 0 && NPCMgr.PetSpells != null)
            {
                var spells = NPCMgr.PetSpells.Get(SpellGroupId) ?? Spell.EmptyArray;
                foreach (var spell in spells)
                {
                    AddSpell(spell);
                }
            }

            if (MinMana > MaxMana)
            {
                MaxMana = MinMana;
            }

            if (MaxDamage > 0)
            {
                if (MinDamage < 1)
                {
                    MinDamage = 1;
                }
                if (MaxDamage < MinDamage)
                {
                    MaxDamage = MinDamage;
                }
            }
            if (Rank == CreatureRank.WorldBoss || Rank == CreatureRank.Boss)
            {
                IsBoss = true;
            }

            NPCId = (NPCId)Id;

            DefaultDecayDelayMillis = _DefaultDecayDelayMillis;
            Family = NPCMgr.GetFamily(CreatureFamilyId.Wolf);

            if (Type == CreatureType.NotSpecified || VehicleEntry != null)
            {
                IsIdle = true;
            }

            if (Type == CreatureType.NotSpecified && UnitFlags.HasFlag((UnitFlags.Passive | UnitFlags.NotSelectable)))
            {
                IsEventTrigger = true;
                IsIdle         = false;
            }

            if (Resistances == null)
            {
                Resistances = new int[ItemConstants.MaxResCount];
            }

            SetFlagIndices = Utility.GetSetIndices((uint)NPCFlags);

            // set/fix factions
            HordeFaction    = FactionMgr.Get(HordeFactionId);
            AllianceFaction = FactionMgr.Get(AllianceFactionId);
            if (HordeFaction == null)
            {
                HordeFaction   = AllianceFaction;
                HordeFactionId = AllianceFactionId;
            }
            else if (AllianceFaction == null)
            {
                AllianceFaction   = HordeFaction;
                AllianceFactionId = HordeFactionId;
            }
            if (AllianceFaction == null)
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no valid Faction: " + this);
                HordeFaction   = AllianceFaction = NPCMgr.DefaultFaction;
                HordeFactionId = AllianceFactionId = (FactionTemplateId)HordeFaction.Template.Id;
            }

            // Add all default spells
            if (FixedSpells != null)
            {
                foreach (var spell in FixedSpells)
                {
                    AddSpell(spell);
                }
            }

            InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
            SpawnTypeHandlers    = NPCMgr.GetNPCSpawnTypeHandlers(this);


            GeneratesXp = (Type != CreatureType.Critter && Type != CreatureType.None &&
                           !ExtraFlags.HasFlag(UnitExtraFlags.NoXP));

            AtackRange = CombatReach + 0.2f;
            ModelInfo  = new UnitModelInfo {
                BoundingRadius = BoundingRadius, CombatReach = CombatReach
            };

            // add to container
            if (Id < NPCMgr.Entries.Length)
            {
                NPCMgr.Entries[Id] = this;
            }
            else
            {
                NPCMgr.CustomEntries[Id] = this;
            }
            ++NPCMgr.EntryCount;

            if (BrainCreator == null)
            {
                BrainCreator = DefaultBrainCreator;
            }

            if (NPCCreator == null)
            {
                NPCCreator = DefaultCreator;
            }

            #region calc expirience
            Expirience =
                (int)
                (((MinHealth + MaxHealth) * 2.2f + (MaxDamage + MinDamage) * 100 + Resistances.Aggregate((a, r) => a + r * 100)) /
                 2000 * Math.Pow(MinLevel, 0.3325f));
            #endregion
        }
Exemplo n.º 13
0
        /// <summary>
        /// Is called to initialize the object; usually after a set of other operations have been performed or if
        /// the right time has come and other required steps have been performed.
        /// </summary>
        public void FinalizeDataHolder()
        {
            if (string.IsNullOrEmpty(this.DefaultName))
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no name: " + (object)this);
            }
            else
            {
                if (this.SpellGroupId != 0U && NPCMgr.PetSpells != null)
                {
                    foreach (Spell spell in NPCMgr.PetSpells.Get <Spell[]>(this.SpellGroupId) ?? Spell.EmptyArray)
                    {
                        this.AddSpell(spell);
                    }
                }

                if (this.MinMana > this.MaxMana)
                {
                    this.MaxMana = this.MinMana;
                }
                if ((double)this.MaxDamage > 0.0)
                {
                    if ((double)this.MinDamage < 1.0)
                    {
                        this.MinDamage = 1f;
                    }
                    if ((double)this.MaxDamage < (double)this.MinDamage)
                    {
                        this.MaxDamage = this.MinDamage;
                    }
                }

                if (this.Rank == CreatureRank.WorldBoss || this.Rank == CreatureRank.Boss)
                {
                    this.IsBoss = true;
                }
                this.NPCId = (NPCId)this.Id;
                this.DefaultDecayDelayMillis = this._DefaultDecayDelayMillis;
                this.Family = NPCMgr.GetFamily(CreatureFamilyId.Wolf);
                if (this.Type == CreatureType.NotSpecified || this.VehicleEntry != null)
                {
                    this.IsIdle = true;
                }
                if (this.Type == CreatureType.NotSpecified &&
                    this.UnitFlags.HasFlag((Enum)(UnitFlags.Passive | UnitFlags.NotSelectable)))
                {
                    this.IsEventTrigger = true;
                    this.IsIdle         = false;
                }

                if (this.Resistances == null)
                {
                    this.Resistances = new int[7];
                }
                this.SetFlagIndices  = Utility.GetSetIndices((uint)this.NPCFlags);
                this.HordeFaction    = FactionMgr.Get(this.HordeFactionId);
                this.AllianceFaction = FactionMgr.Get(this.AllianceFactionId);
                if (this.HordeFaction == null)
                {
                    this.HordeFaction   = this.AllianceFaction;
                    this.HordeFactionId = this.AllianceFactionId;
                }
                else if (this.AllianceFaction == null)
                {
                    this.AllianceFaction   = this.HordeFaction;
                    this.AllianceFactionId = this.HordeFactionId;
                }

                if (this.AllianceFaction == null)
                {
                    ContentMgr.OnInvalidDBData("NPCEntry has no valid Faction: " + (object)this);
                    this.HordeFaction   = this.AllianceFaction = NPCMgr.DefaultFaction;
                    this.HordeFactionId = this.AllianceFactionId = (FactionTemplateId)this.HordeFaction.Template.Id;
                }

                if (this.FixedSpells != null)
                {
                    foreach (SpellId fixedSpell in this.FixedSpells)
                    {
                        this.AddSpell(fixedSpell);
                    }
                }

                this.InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
                this.SpawnTypeHandlers    = NPCMgr.GetNPCSpawnTypeHandlers(this);
                this.GeneratesXp          = this.Type != CreatureType.Critter && this.Type != CreatureType.None &&
                                            !this.ExtraFlags.HasFlag((Enum)UnitExtraFlags.NoXP);
                this.AtackRange = this.CombatReach + 0.2f;
                this.ModelInfo  = new UnitModelInfo()
                {
                    BoundingRadius = this.BoundingRadius,
                    CombatReach    = this.CombatReach
                };
                if ((long)this.Id < (long)NPCMgr.Entries.Length)
                {
                    NPCMgr.Entries[this.Id] = this;
                }
                else
                {
                    NPCMgr.CustomEntries[this.Id] = this;
                }
                ++NPCMgr.EntryCount;
                if (this.BrainCreator == null)
                {
                    this.BrainCreator = new Func <NPC, IBrain>(this.DefaultBrainCreator);
                }
                if (this.NPCCreator == null)
                {
                    this.NPCCreator = NPCEntry.DefaultCreator;
                }
                this.Expirience = (int)(((double)(this.MinHealth + this.MaxHealth) * 2.20000004768372 +
                                         ((double)this.MaxDamage + (double)this.MinDamage) * 100.0 +
                                         (double)((IEnumerable <int>) this.Resistances).Aggregate <int>(
                                             (Func <int, int, int>)((a, r) => a + r * 100))) / 2000.0 *
                                        Math.Pow((double)this.MinLevel, 0.332500010728836));
            }
        }
Exemplo n.º 14
0
        public void Dump(IndentTextWriter writer)
        {
            writer.WriteLine("{3}{0} (Id: {1}, {2})", DefaultName, Id, NPCId, Rank != 0 ? Rank + " " : "");
            if (!string.IsNullOrEmpty(DefaultTitle))
            {
                writer.WriteLine("Title: " + DefaultTitle);
            }
            if (Type != 0)
            {
                writer.WriteLine("Type: " + Type);
            }
            if (EntryFlags != 0)
            {
                writer.WriteLine("EntryFlags: " + EntryFlags);
            }
            if (Family != null)
            {
                writer.WriteLine("Family: " + Family);
            }
            if (IsLeader)
            {
                writer.WriteLine("Leader");
            }

            writer.WriteLine("DisplayIds: " + DisplayIds.ToString(", "));
            if (TrainerEntry != null)
            {
                writer.WriteLine("Trainer "
                                 //+ "for {0} {1}",
                                 //             TrainerEntry.RequiredRace != 0 ? TrainerEntry.RequiredRace.ToString() : "",
                                 //             TrainerEntry.RequiredClass != 0 ? TrainerEntry.RequiredClass.ToString() : ""
                                 );
            }

            WriteFaction(writer);
            writer.WriteLineNotDefault(IsBoss, "Boss");
            writer.WriteLine("Level: {0} - {1}", MinLevel, MaxLevel);
            writer.WriteLine("Health: {0} - {1}", MinHealth, MaxHealth);

            writer.WriteLineNotDefault(MinMana, "Mana: {0} - {1}", MinMana, MaxMana);
            writer.WriteLineNotDefault(NPCFlags, "Flags: " + NPCFlags);
            writer.WriteLineNotDefault(DynamicFlags, "DynamicFlags: " + DynamicFlags);
            writer.WriteLineNotDefault(UnitFlags, "UnitFlags: " + UnitFlags);
            writer.WriteLineNotDefault(ExtraFlags, "ExtraFlags: " + string.Format("0x{0:X}", ExtraFlags));
            writer.WriteLineNotDefault(AttackTime + OffhandAttackTime, "AttackTime: " + AttackTime, "Offhand: " + OffhandAttackTime);
            writer.WriteLineNotDefault(RangedAttackTime, "RangedAttackTime: " + RangedAttackTime);
            writer.WriteLineNotDefault(AttackPower, "AttackPower: " + AttackPower);
            writer.WriteLineNotDefault(RangedAttackPower, "RangedAttackPower: " + RangedAttackPower);
            //writer.WriteLineNotDefault(OffhandAttackPower, "OffhandAttackPower: " + OffhandAttackPower);
            writer.WriteLineNotDefault(MinDamage + MaxDamage, "Damage: {0} - {1}", MinDamage, MaxDamage);
            writer.WriteLineNotDefault(RangedMinDamage + RangedMaxDamage, "RangedDamage: {0} - {1}", RangedMinDamage,
                                       RangedMaxDamage);
            writer.WriteLineNotDefault(OffhandMinDamage + OffhandMaxDamage, "OffhandDamage: {0} - {1}", OffhandMinDamage,
                                       OffhandMaxDamage);
            var resistances = new List <string>(8);

            for (var i = 0; i < Resistances.Length; i++)
            {
                var res = Resistances[i];
                if (res > 0)
                {
                    resistances.Add(string.Format("{0}: {1}", (DamageSchool)i, res));
                }
            }
            if (Scale != 1)
            {
                writer.WriteLine("Scale: " + Scale);
            }

            var cr = GetRandomModel().CombatReach;
            var br = GetRandomModel().BoundingRadius;

            writer.WriteLine("CombatReach: " + cr);
            writer.WriteLine("BoundingRadius: " + br);
            writer.WriteLineNotDefault(resistances.Count, "Resistances: " + resistances.ToString(", "));
            writer.WriteLineNotDefault(MoneyDrop, "MoneyDrop: " + MoneyDrop);
            writer.WriteLineNotDefault(InvisibilityType, "Invisibility: " + InvisibilityType);
            writer.WriteLineNotDefault(MovementType, "MovementType: " + MovementType);
            writer.WriteLineNotDefault(WalkSpeed + RunSpeed + FlySpeed, "Speeds - Walking: {0}, Running: {1}, Flying: {2} ",
                                       WalkSpeed, RunSpeed, FlySpeed);
            writer.WriteLineNotDefault(LootId + SkinLootId + PickPocketLootId, "{0}{1}{2}",
                                       LootId != 0 ? "Lootable " : "",
                                       SkinLootId != 0 ? "Skinnable " : "",
                                       PickPocketLootId != 0 ? "Pickpocketable" : "");
            if (AddonData != null)
            {
                writer.WriteLineNotDefault(AddonData.MountModelId, "Mount: " + AddonData.MountModelId);
                writer.WriteLineNotDefault(AddonData.Auras.Count, "Auras: " + AddonData.Auras.ToString(", "));
            }
            var spells = Spells;

            if (spells != null && spells.Count > 0)
            {
                writer.WriteLine("Spells: " + Spells.ToString(", "));
            }
            if (Equipment != null)
            {
                writer.WriteLine("Equipment: {0}", Equipment.ItemIds.Where(id => id != 0).ToString(", "));
            }

            if (DifficultyOverrideEntryIds != null && DifficultyOverrideEntryIds.Any(id => id != 0))
            {
                var parts = new List <string>(4);
                for (var i = 0u; i < 3; i++)
                {
                    var id = DifficultyOverrideEntryIds[i];
                    if (id != 0)
                    {
                        var                entry = NPCMgr.GetEntry(id);
                        MapTemplate        map;
                        MapDifficultyEntry diff;
                        if (entry != null && (map = GetMapTemplate()) != null && (diff = map.GetDifficulty(i)) != null)
                        {
                            parts.Add(string.Format("{0} ({1}) = " + id + " (" + (uint)id + ")", diff.IsHeroic ? "Heroic" : "Normal", diff.MaxPlayerCount));
                        }
                        else
                        {
                            parts.Add("(unknown difficulty) = " + id + " (" + (uint)id + ")");
                        }
                    }
                }
                writer.WriteLine("DifficultyOverrides: {0}", parts.ToString("; "));
            }

            if (KillCreditIds != null && KillCreditIds.Any(id => id != 0))
            {
                var parts = new List <string>(2);
                for (var i = 0u; i < UnitConstants.MaxKillCredits; i++)
                {
                    var id = KillCreditIds[i];
                    if (id != 0)
                    {
                        var entry = NPCMgr.GetEntry(id);
                        if (entry != null)
                        {
                            parts.Add(id + " (" + (uint)id + ")");
                        }
                    }
                }
                writer.WriteLine("KillCredits: {0}", parts.ToString("; "));
            }


            //if (inclFaction)
            //{
            //    writer.WriteLineNotDefault(DefaultFactionId, "Faction: " + DefaultFactionId);
            //}
        }
Exemplo n.º 15
0
 internal static List <VendorItemEntry> GetOrCreateVendorList(NPCId npcId)
 {
     return(NPCMgr.GetOrCreateVendorList((uint)npcId));
 }
Exemplo n.º 16
0
 private static void LoadVendors(bool force)
 {
     NPCMgr.LoadItemExtendedCostEntries();
     ContentMgr.Load <VendorItemEntry>(force);
 }
Exemplo n.º 17
0
 public static void LoadNPCDefs(bool force = false)
 {
     NPCMgr.LoadEntries(force);
     NPCMgr.LoadSpawns(force);
 }
Exemplo n.º 18
0
        /// <summary>
        /// Is called to initialize the object; usually after a set of other operations have been performed or if
        /// the right time has come and other required steps have been performed.
        /// </summary>
        public void FinalizeDataHolder()
        {
            if (string.IsNullOrEmpty(DefaultName))
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no name: " + this);
                return;
            }

            if (Titles == null)
            {
                Titles = new string[(int)ClientLocale.End];
            }

            if (DefaultTitle == null)
            {
                DefaultTitle = "";
            }

            if (SpellGroupId != 0 && NPCMgr.PetSpells != null)
            {
                var spells = NPCMgr.PetSpells.Get(SpellGroupId) ?? Spell.EmptyArray;
                foreach (var spell in spells)
                {
                    AddSpell(spell);
                }
            }

            if (MinMana > MaxMana)
            {
                MaxMana = MinMana;
            }

            if (MaxDamage > 0)
            {
                if (MinDamage < 1)
                {
                    MinDamage = 1;
                }
                if (MaxDamage < MinDamage)
                {
                    MaxDamage = MinDamage;
                }
            }

            if (RangedMaxDamage > 0 && RangedMinDamage > 0)
            {
                if (RangedMaxDamage < RangedMinDamage)
                {
                    RangedMaxDamage = RangedMinDamage;
                }
                if (RangedAttackTime == 0)
                {
                    RangedAttackTime = AttackTime;
                }
            }

            AggroBaseRange = AggroBaseRangeDefault;

            NPCId = (NPCId)Id;

            DefaultDecayDelayMillis = _DefaultDecayDelayMillis;
            Family = NPCMgr.GetFamily(FamilyId);

            if (Type == CreatureType.NotSpecified || VehicleEntry != null)
            {
                IsIdle = true;
            }

            if (Type == CreatureType.NotSpecified && UnitFlags.HasFlag((UnitFlags.Passive | UnitFlags.NotSelectable)))
            {
                IsEventTrigger = true;
                IsIdle         = false;
            }

            if (Resistances == null)
            {
                Resistances = new int[ItemConstants.MaxResCount];
            }

            SetFlagIndices = Utility.GetSetIndices((uint)NPCFlags);

            // set/fix factions
            HordeFaction    = FactionMgr.Get(HordeFactionId);
            AllianceFaction = FactionMgr.Get(AllianceFactionId);
            if (HordeFaction == null)
            {
                HordeFaction   = AllianceFaction;
                HordeFactionId = AllianceFactionId;
            }
            else if (AllianceFaction == null)
            {
                AllianceFaction   = HordeFaction;
                AllianceFactionId = HordeFactionId;
            }
            if (AllianceFaction == null)
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no valid Faction: " + this);
                HordeFaction   = AllianceFaction = NPCMgr.DefaultFaction;
                HordeFactionId = AllianceFactionId = (FactionTemplateId)HordeFaction.Template.Id;
            }

            // speeds
            if (SpeedFactor < 0.01)
            {
                SpeedFactor = 1;
            }

            if (WalkSpeed == 0)
            {
                WalkSpeed = NPCMgr.DefaultNPCWalkSpeed * SpeedFactor;
            }
            if (RunSpeed == 0)
            {
                RunSpeed = NPCMgr.DefaultNPCRunSpeed * SpeedFactor;
            }
            if (FlySpeed == 0)
            {
                FlySpeed = NPCMgr.DefaultNPCFlySpeed * SpeedFactor;
            }

            // Add all default spells
            if (FixedSpells != null)
            {
                foreach (var spell in FixedSpells)
                {
                    AddSpell(spell);
                }
            }

            InstanceTypeHandlers = NPCMgr.GetNPCTypeHandlers(this);
            SpawnTypeHandlers    = NPCMgr.GetNPCSpawnTypeHandlers(this);

            //ArrayUtil.PruneVals(ref DisplayIds);

            if (EquipmentId != 0)
            {
                Equipment = NPCMgr.GetEquipment(EquipmentId);
            }

            ModelInfos = new UnitModelInfo[DisplayIds.Length];

            GeneratesXp = (Type != CreatureType.Critter && Type != CreatureType.None && !ExtraFlags.HasFlag(UnitExtraFlags.NoXP));

            var x = 0;

            for (var i = 0; i < DisplayIds.Length; i++)
            {
                var did = DisplayIds[i];
                if (did > 0)
                {
                    var model = UnitMgr.GetModelInfo(did);
                    if (model != null)
                    {
                        ModelInfos[x++] = model;
                    }
                }
            }

            if (x == 0)
            {
                ContentMgr.OnInvalidDBData("NPCEntry has no valid DisplayId: {0} ({1})", this, DisplayIds.ToString(", "));
                return;
            }

            if (TrainerTemplateId != 0)
            {
                if (!NPCMgr.TrainerSpellTemplates.ContainsKey(TrainerTemplateId))
                {
                    ContentMgr.OnInvalidDBData("NPCEntry has invalid TrainerTemplateId: {0} ({1})", this, TrainerTemplateId);
                }
                else
                {
                    if (TrainerEntry == null)
                    {
                        TrainerEntry = new TrainerEntry();
                    }
                    foreach (var trainerSpell in NPCMgr.TrainerSpellTemplates[TrainerTemplateId])
                    {
                        TrainerEntry.AddSpell(trainerSpell);
                    }
                }
            }

            if (AddonData != null)
            {
                AddonData.InitAddonData(this);
            }

            if (x < ModelInfos.Length)
            {
                Array.Resize(ref ModelInfos, x);
            }

            // add to container
            if (Id < NPCMgr.Entries.Length)
            {
                NPCMgr.Entries[Id] = this;
            }
            else
            {
                NPCMgr.CustomEntries[Id] = this;
            }
            ++NPCMgr.EntryCount;

            if (BrainCreator == null)
            {
                BrainCreator = DefaultBrainCreator;
            }

            if (NPCCreator == null)
            {
                NPCCreator = DefaultCreator;
            }
        }
Exemplo n.º 19
0
 public static void InitDefault()
 {
     NPCMgr.InitTypeHandlers();
 }
Exemplo n.º 20
0
 public static void LoadAllLater()
 {
     ServerApp <WCell.RealmServer.RealmServer> .IOQueue.AddMessage((Action)(() => NPCMgr.LoadAll(false)));
 }
Exemplo n.º 21
0
 public static NPCEntry GetEntry(NPCId id, uint difficultyIndex)
 {
     return(NPCMgr.GetEntry(id)?.GetEntry(difficultyIndex));
 }
Exemplo n.º 22
0
 public object Get(object key)
 {
     return(NPCMgr.GetPrototype((uint)key));
 }
Exemplo n.º 23
0
 internal static void GenerateId(NPC npc, HighId highId)
 {
     npc.EntityId = new EntityId(NPCMgr.GenerateUniqueLowId(), npc.EntryId, highId);
 }
Exemplo n.º 24
0
 internal static void GenerateId(NPC npc)
 {
     NPCMgr.GenerateId(npc, HighId.Unit);
 }