diff --git a/Source/Game/AuctionHouse/AuctionManager.cs b/Source/Game/AuctionHouse/AuctionManager.cs index 27d3cf6ef..952a19664 100644 --- a/Source/Game/AuctionHouse/AuctionManager.cs +++ b/Source/Game/AuctionHouse/AuctionManager.cs @@ -17,16 +17,16 @@ using Framework.Constants; using Framework.Database; -using Framework.Dynamic; +using Framework.IO; +using Game.BattlePets; using Game.DataStorage; using Game.Entities; using Game.Mails; using Game.Networking.Packets; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; -using Framework.IO; -using System.Collections; namespace Game { @@ -926,7 +926,7 @@ namespace Game if (player.HasSpell((uint)itemTemplate.Effects[1].SpellID)) continue; - var battlePetSpecies = Global.SpellMgr.GetBattlePetSpecies((uint)itemTemplate.Effects[1].SpellID); + var battlePetSpecies = BattlePetMgr.GetBattlePetSpeciesBySpell((uint)itemTemplate.Effects[1].SpellID); if (battlePetSpecies != null) if (knownPetSpecies.Get((int)battlePetSpecies.Id)) continue; diff --git a/Source/Game/BattlePets/BattlePetManager.cs b/Source/Game/BattlePets/BattlePetManager.cs index 43451ead5..1f1c6994d 100644 --- a/Source/Game/BattlePets/BattlePetManager.cs +++ b/Source/Game/BattlePets/BattlePetManager.cs @@ -46,6 +46,13 @@ namespace Game.BattlePets if (!result.IsEmpty()) Global.ObjectMgr.GetGenerator(HighGuid.BattlePet).Set(result.Read(0) + 1); + foreach (var battlePetSpecies in CliDB.BattlePetSpeciesStorage.Values) + { + uint creatureId = battlePetSpecies.CreatureID; + if (creatureId != 0) + _battlePetSpeciesByCreature[creatureId] = battlePetSpecies; + } + foreach (var battlePetBreedState in CliDB.BattlePetBreedStateStorage.Values) { if (!BattlePetBreedStates.ContainsKey(battlePetBreedState.BattlePetBreedID)) @@ -135,6 +142,21 @@ namespace Game.BattlePets Log.outInfo(LogFilter.ServerLoading, "Loaded {0} battle pet qualities.", _defaultQualityPerSpecies.Count); } + public static void AddBattlePetSpeciesBySpell(uint spellId, BattlePetSpeciesRecord speciesEntry) + { + _battlePetSpeciesBySpell[spellId] = speciesEntry; + } + + public static BattlePetSpeciesRecord GetBattlePetSpeciesByCreature(uint creatureId) + { + return _battlePetSpeciesByCreature.LookupByKey(creatureId); + } + + public static BattlePetSpeciesRecord GetBattlePetSpeciesBySpell(uint spellId) + { + return _battlePetSpeciesBySpell.LookupByKey(spellId); + } + public static ushort RollPetBreed(uint species) { var list = _availableBreedsPerSpecies.LookupByKey(species); @@ -878,6 +900,8 @@ namespace Game.BattlePets public static Dictionary> BattlePetBreedStates = new(); public static Dictionary> BattlePetSpeciesStates = new(); + static Dictionary _battlePetSpeciesByCreature = new(); + static Dictionary _battlePetSpeciesBySpell = new(); static MultiMap _availableBreedsPerSpecies = new(); static Dictionary _defaultQualityPerSpecies = new(); } diff --git a/Source/Game/Entities/Creature/Trainer.cs b/Source/Game/Entities/Creature/Trainer.cs index 95b8c6ec4..1e4c7276e 100644 --- a/Source/Game/Entities/Creature/Trainer.cs +++ b/Source/Game/Entities/Creature/Trainer.cs @@ -75,7 +75,7 @@ namespace Game.Entities } bool sendSpellVisual = true; - var speciesEntry = Global.SpellMgr.GetBattlePetSpecies(trainerSpell.SpellId); + var speciesEntry = BattlePetMgr.GetBattlePetSpeciesBySpell(trainerSpell.SpellId); if (speciesEntry != null) { if (player.GetSession().GetBattlePetMgr().HasMaxPetCount(speciesEntry, player.GetGUID())) diff --git a/Source/Game/Handlers/ItemHandler.cs b/Source/Game/Handlers/ItemHandler.cs index 2d6e6e491..2f2f674d6 100644 --- a/Source/Game/Handlers/ItemHandler.cs +++ b/Source/Game/Handlers/ItemHandler.cs @@ -1065,7 +1065,7 @@ namespace Game if (itemEffect.TriggerType != ItemSpelltriggerType.OnLearn) continue; - var speciesEntry = Global.SpellMgr.GetBattlePetSpecies((uint)itemEffect.SpellID); + var speciesEntry = BattlePetMgr.GetBattlePetSpeciesBySpell((uint)itemEffect.SpellID); if (speciesEntry != null) GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id)); } diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index b48af05f4..42f6ce47f 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -1752,7 +1752,7 @@ namespace Game.Spells bool dependent = false; - var speciesEntry = Global.SpellMgr.GetBattlePetSpecies((uint)itemEffect.SpellID); + var speciesEntry = BattlePetMgr.GetBattlePetSpeciesBySpell((uint)itemEffect.SpellID); if (speciesEntry != null) { player.GetSession().GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id)); diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index f1f7a4953..7a8ebea63 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -20,6 +20,7 @@ using Framework.Database; using Framework.Dynamic; using Game.BattleFields; using Game.BattleGrounds; +using Game.BattlePets; using Game.DataStorage; using Game.Movement; using Game.Spells; @@ -2162,7 +2163,7 @@ namespace Game.Entities { var battlePetSpecies = battlePetSpeciesByCreature.LookupByKey(effect.EffectMiscValue[0]); if (battlePetSpecies != null) - mBattlePets[effect.SpellID] = battlePetSpecies; + BattlePetMgr.AddBattlePetSpeciesBySpell(effect.SpellID, battlePetSpecies); } } } @@ -4728,11 +4729,6 @@ namespace Game.Entities return mSpellTotemModel.LookupByKey(Tuple.Create(spellId, (byte)race)); } - public BattlePetSpeciesRecord GetBattlePetSpecies(uint spellId) - { - return mBattlePets.LookupByKey(spellId); - } - #region Fields Dictionary mSpellChains = new(); MultiMap mSpellsReqSpell = new(); @@ -4760,7 +4756,6 @@ namespace Game.Entities Dictionary mPetDefaultSpellsMap = new(); // only spells not listed in related mPetLevelupSpellMap entry MultiMap mSpellInfoMap = new(); Dictionary, uint> mSpellTotemModel = new(); - Dictionary mBattlePets = new(); public delegate void AuraEffectHandler(AuraEffect effect, AuraApplication aurApp, AuraEffectHandleModes mode, bool apply); Dictionary AuraEffectHandlers = new();