diff --git a/Source/Framework/Constants/SharedConst.cs b/Source/Framework/Constants/SharedConst.cs index 0422de6c6..6913c2bf5 100644 --- a/Source/Framework/Constants/SharedConst.cs +++ b/Source/Framework/Constants/SharedConst.cs @@ -47,6 +47,7 @@ namespace Framework.Constants /// /// BattlePets Const /// + public const int MaxBattlePetSpeciesId = 2873; public const int MaxPetBattleSlots = 3; public const int MaxBattlePetsPerSpecies = 3; public const int BattlePetCageItemId = 82800; diff --git a/Source/Game/Handlers/ItemHandler.cs b/Source/Game/Handlers/ItemHandler.cs index 3e58f971d..e191bf6bc 100644 --- a/Source/Game/Handlers/ItemHandler.cs +++ b/Source/Game/Handlers/ItemHandler.cs @@ -1056,14 +1056,12 @@ namespace Game return; uint spellToLearn = (uint)item.GetTemplate().Effects[1].SpellID; - foreach (BattlePetSpeciesRecord entry in CliDB.BattlePetSpeciesStorage.Values) + + var entry = Global.SpellMgr.GetBattlePetSpecies(spellToLearn); + if (entry != null) { - if (entry.SummonSpellID == spellToLearn) - { - GetBattlePetMgr().AddPet(entry.Id, entry.CreatureID, BattlePetMgr.RollPetBreed(entry.Id), BattlePetMgr.GetDefaultPetQuality(entry.Id)); - _player.UpdateCriteria(CriteriaTypes.OwnBattlePetCount); - break; - } + GetBattlePetMgr().AddPet(entry.Id, entry.CreatureID, BattlePetMgr.RollPetBreed(entry.Id), BattlePetMgr.GetDefaultPetQuality(entry.Id)); + _player.UpdateCriteria(CriteriaTypes.OwnBattlePetCount); } GetPlayer().DestroyItem(item.GetBagSlot(), item.GetSlot(), true); diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index e68651699..ce524cbf7 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -1971,6 +1971,12 @@ namespace Game.Entities mSpellInfoMap.Clear(); Dictionary loadData = new Dictionary(); + Dictionary battlePetSpeciesByCreature = new Dictionary(); + Dictionary battlePetSpeciesBySpellId = new Dictionary(); + foreach (var battlePetSpecies in CliDB.BattlePetSpeciesStorage.Values) + if (battlePetSpecies.CreatureID != 0) + battlePetSpeciesByCreature[battlePetSpecies.CreatureID] = battlePetSpecies; + Dictionary> effectsBySpell = new Dictionary>(); Dictionary> visualsBySpell = new Dictionary>(); foreach (var effect in CliDB.SpellEffectStorage.Values) @@ -1988,6 +1994,20 @@ namespace Game.Entities effectsBySpell[effect.SpellID][effect.DifficultyID] = new SpellEffectRecord[SpellConst.MaxEffects]; effectsBySpell[effect.SpellID][effect.DifficultyID][effect.EffectIndex] = effect; + + if (effect.Effect == (int)SpellEffectName.Summon) + { + var summonProperties = CliDB.SummonPropertiesStorage.LookupByKey(effect.EffectMiscValue[1]); + if (summonProperties != null) + { + if (summonProperties.Slot == (int)SummonSlot.MiniPet && summonProperties.Flags.HasAnyFlag(SummonPropFlags.Companion)) + { + var battlePetSpecies = battlePetSpeciesByCreature.LookupByKey(effect.EffectMiscValue[0]); + if (battlePetSpecies != null) + mBattlePets[effect.SpellID] = battlePetSpecies; + } + } + } } SpellInfoLoadHelper GetSpellInfoLoadHelper(uint spellId) @@ -3359,8 +3379,12 @@ namespace Game.Entities return mSpellTotemModel.LookupByKey(Tuple.Create(spellId, (byte)race)); } + public BattlePetSpeciesRecord GetBattlePetSpecies(uint spellId) + { + return mBattlePets.LookupByKey(spellId); + } + #region Fields - //private: Dictionary mSpellChains = new Dictionary(); MultiMap mSpellsReqSpell = new MultiMap(); MultiMap mSpellReq = new MultiMap(); @@ -3387,6 +3411,7 @@ namespace Game.Entities Dictionary mPetDefaultSpellsMap = new Dictionary(); // only spells not listed in related mPetLevelupSpellMap entry Dictionary mSpellInfoMap = new Dictionary(); Dictionary, uint> mSpellTotemModel = new Dictionary, uint>(); + Dictionary mBattlePets = new Dictionary(); public delegate void AuraEffectHandler(AuraEffect effect, AuraApplication aurApp, AuraEffectHandleModes mode, bool apply); Dictionary AuraEffectHandlers = new Dictionary();