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.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;
@@ -46,6 +46,13 @@ namespace Game.BattlePets
if (!result.IsEmpty())
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)
{
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<uint, Dictionary<BattlePetState, int>> BattlePetBreedStates = 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 Dictionary<uint, BattlePetBreedQuality> _defaultQualityPerSpecies = new();
}
+1 -1
View File
@@ -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()))
+1 -1
View File
@@ -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));
}
+1 -1
View File
@@ -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));
+2 -7
View File
@@ -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<uint, SpellChainNode> mSpellChains = 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
MultiMap<uint, SpellInfo> mSpellInfoMap = 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);
Dictionary<AuraType, AuraEffectHandler> AuraEffectHandlers = new();