Core/BattlePets: Move BattlePet stuff from SpellMgr to BattlePetMgr

Port From (https://github.com/TrinityCore/TrinityCore/commit/a1f673d1ca91ceea9585f6ec7267aae94d11fca7)
This commit is contained in:
hondacrx
2022-06-14 18:12:28 -04:00
parent c989047700
commit 53619fff1d
6 changed files with 33 additions and 14 deletions
+4 -4
View File
@@ -17,16 +17,16 @@
using Framework.Constants; using Framework.Constants;
using Framework.Database; using Framework.Database;
using Framework.Dynamic; using Framework.IO;
using Game.BattlePets;
using Game.DataStorage; using Game.DataStorage;
using Game.Entities; using Game.Entities;
using Game.Mails; using Game.Mails;
using Game.Networking.Packets; using Game.Networking.Packets;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Framework.IO;
using System.Collections;
namespace Game namespace Game
{ {
@@ -926,7 +926,7 @@ namespace Game
if (player.HasSpell((uint)itemTemplate.Effects[1].SpellID)) if (player.HasSpell((uint)itemTemplate.Effects[1].SpellID))
continue; continue;
var battlePetSpecies = Global.SpellMgr.GetBattlePetSpecies((uint)itemTemplate.Effects[1].SpellID); var battlePetSpecies = BattlePetMgr.GetBattlePetSpeciesBySpell((uint)itemTemplate.Effects[1].SpellID);
if (battlePetSpecies != null) if (battlePetSpecies != null)
if (knownPetSpecies.Get((int)battlePetSpecies.Id)) if (knownPetSpecies.Get((int)battlePetSpecies.Id))
continue; continue;
@@ -46,6 +46,13 @@ namespace Game.BattlePets
if (!result.IsEmpty()) if (!result.IsEmpty())
Global.ObjectMgr.GetGenerator(HighGuid.BattlePet).Set(result.Read<ulong>(0) + 1); Global.ObjectMgr.GetGenerator(HighGuid.BattlePet).Set(result.Read<ulong>(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) foreach (var battlePetBreedState in CliDB.BattlePetBreedStateStorage.Values)
{ {
if (!BattlePetBreedStates.ContainsKey(battlePetBreedState.BattlePetBreedID)) if (!BattlePetBreedStates.ContainsKey(battlePetBreedState.BattlePetBreedID))
@@ -135,6 +142,21 @@ namespace Game.BattlePets
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} battle pet qualities.", _defaultQualityPerSpecies.Count); 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) public static ushort RollPetBreed(uint species)
{ {
var list = _availableBreedsPerSpecies.LookupByKey(species); var list = _availableBreedsPerSpecies.LookupByKey(species);
@@ -878,6 +900,8 @@ namespace Game.BattlePets
public static Dictionary<uint, Dictionary<BattlePetState, int>> BattlePetBreedStates = new(); public static Dictionary<uint, Dictionary<BattlePetState, int>> BattlePetBreedStates = new();
public static Dictionary<uint, Dictionary<BattlePetState, int>> BattlePetSpeciesStates = new(); public static Dictionary<uint, Dictionary<BattlePetState, int>> BattlePetSpeciesStates = new();
static Dictionary<uint, BattlePetSpeciesRecord> _battlePetSpeciesByCreature = new();
static Dictionary<uint, BattlePetSpeciesRecord> _battlePetSpeciesBySpell = new();
static MultiMap<uint, byte> _availableBreedsPerSpecies = new(); static MultiMap<uint, byte> _availableBreedsPerSpecies = new();
static Dictionary<uint, BattlePetBreedQuality> _defaultQualityPerSpecies = new(); static Dictionary<uint, BattlePetBreedQuality> _defaultQualityPerSpecies = new();
} }
+1 -1
View File
@@ -75,7 +75,7 @@ namespace Game.Entities
} }
bool sendSpellVisual = true; bool sendSpellVisual = true;
var speciesEntry = Global.SpellMgr.GetBattlePetSpecies(trainerSpell.SpellId); var speciesEntry = BattlePetMgr.GetBattlePetSpeciesBySpell(trainerSpell.SpellId);
if (speciesEntry != null) if (speciesEntry != null)
{ {
if (player.GetSession().GetBattlePetMgr().HasMaxPetCount(speciesEntry, player.GetGUID())) if (player.GetSession().GetBattlePetMgr().HasMaxPetCount(speciesEntry, player.GetGUID()))
+1 -1
View File
@@ -1065,7 +1065,7 @@ namespace Game
if (itemEffect.TriggerType != ItemSpelltriggerType.OnLearn) if (itemEffect.TriggerType != ItemSpelltriggerType.OnLearn)
continue; continue;
var speciesEntry = Global.SpellMgr.GetBattlePetSpecies((uint)itemEffect.SpellID); var speciesEntry = BattlePetMgr.GetBattlePetSpeciesBySpell((uint)itemEffect.SpellID);
if (speciesEntry != null) if (speciesEntry != null)
GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id)); GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id));
} }
+1 -1
View File
@@ -1752,7 +1752,7 @@ namespace Game.Spells
bool dependent = false; bool dependent = false;
var speciesEntry = Global.SpellMgr.GetBattlePetSpecies((uint)itemEffect.SpellID); var speciesEntry = BattlePetMgr.GetBattlePetSpeciesBySpell((uint)itemEffect.SpellID);
if (speciesEntry != null) if (speciesEntry != null)
{ {
player.GetSession().GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id)); player.GetSession().GetBattlePetMgr().AddPet(speciesEntry.Id, BattlePetMgr.SelectPetDisplay(speciesEntry), BattlePetMgr.RollPetBreed(speciesEntry.Id), BattlePetMgr.GetDefaultPetQuality(speciesEntry.Id));
+2 -7
View File
@@ -20,6 +20,7 @@ using Framework.Database;
using Framework.Dynamic; using Framework.Dynamic;
using Game.BattleFields; using Game.BattleFields;
using Game.BattleGrounds; using Game.BattleGrounds;
using Game.BattlePets;
using Game.DataStorage; using Game.DataStorage;
using Game.Movement; using Game.Movement;
using Game.Spells; using Game.Spells;
@@ -2162,7 +2163,7 @@ namespace Game.Entities
{ {
var battlePetSpecies = battlePetSpeciesByCreature.LookupByKey(effect.EffectMiscValue[0]); var battlePetSpecies = battlePetSpeciesByCreature.LookupByKey(effect.EffectMiscValue[0]);
if (battlePetSpecies != null) 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)); return mSpellTotemModel.LookupByKey(Tuple.Create(spellId, (byte)race));
} }
public BattlePetSpeciesRecord GetBattlePetSpecies(uint spellId)
{
return mBattlePets.LookupByKey(spellId);
}
#region Fields #region Fields
Dictionary<uint, SpellChainNode> mSpellChains = new(); Dictionary<uint, SpellChainNode> mSpellChains = new();
MultiMap<uint, uint> mSpellsReqSpell = new(); MultiMap<uint, uint> mSpellsReqSpell = new();
@@ -4760,7 +4756,6 @@ namespace Game.Entities
Dictionary<uint, PetDefaultSpellsEntry> mPetDefaultSpellsMap = new(); // only spells not listed in related mPetLevelupSpellMap entry Dictionary<uint, PetDefaultSpellsEntry> mPetDefaultSpellsMap = new(); // only spells not listed in related mPetLevelupSpellMap entry
MultiMap<uint, SpellInfo> mSpellInfoMap = new(); MultiMap<uint, SpellInfo> mSpellInfoMap = new();
Dictionary<Tuple<uint, byte>, uint> mSpellTotemModel = new(); Dictionary<Tuple<uint, byte>, uint> mSpellTotemModel = new();
Dictionary<uint, BattlePetSpeciesRecord> mBattlePets = new();
public delegate void AuraEffectHandler(AuraEffect effect, AuraApplication aurApp, AuraEffectHandleModes mode, bool apply); public delegate void AuraEffectHandler(AuraEffect effect, AuraApplication aurApp, AuraEffectHandleModes mode, bool apply);
Dictionary<AuraType, AuraEffectHandler> AuraEffectHandlers = new(); Dictionary<AuraType, AuraEffectHandler> AuraEffectHandlers = new();