Core/BattlePets: Refactor BattlePetMgr::SendUpdates

Port From (https://github.com/TrinityCore/TrinityCore/commit/c215363e86a260e9455469ffffab9e84263fb276)
This commit is contained in:
Hondacrx
2025-08-25 22:04:07 -04:00
parent c1a6aa0752
commit 38d54703d5
+23 -26
View File
@@ -142,7 +142,7 @@ namespace Game.BattlePets
{ {
return _battlePetSpeciesBySpell.LookupByKey(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);
@@ -175,7 +175,7 @@ namespace Game.BattlePets
return 0; return 0;
} }
public void LoadFromDB(SQLResult petsResult, SQLResult slotsResult) public void LoadFromDB(SQLResult petsResult, SQLResult slotsResult)
{ {
if (!petsResult.IsEmpty()) if (!petsResult.IsEmpty())
@@ -419,8 +419,7 @@ namespace Game.BattlePets
_pets[pet.PacketInfo.Guid.GetCounter()] = pet; _pets[pet.PacketInfo.Guid.GetCounter()] = pet;
List<BattlePet> updates = new(); List<BattlePet> updates = [pet];
updates.Add(pet);
SendUpdates(updates, true); SendUpdates(updates, true);
player.UpdateCriteria(CriteriaType.UniquePetsOwned); player.UpdateCriteria(CriteriaType.UniquePetsOwned);
@@ -476,7 +475,7 @@ namespace Game.BattlePets
if (summonedBattlePet.GetBattlePetCompanionGUID() == guid) if (summonedBattlePet.GetBattlePetCompanionGUID() == guid)
summonedBattlePet.SetBattlePetCompanionNameTimestamp((uint)pet.NameTimestamp); summonedBattlePet.SetBattlePetCompanionNameTimestamp((uint)pet.NameTimestamp);
} }
bool IsPetInSlot(ObjectGuid guid) bool IsPetInSlot(ObjectGuid guid)
{ {
foreach (BattlePetSlot slot in _slots) foreach (BattlePetSlot slot in _slots)
@@ -510,7 +509,7 @@ namespace Game.BattlePets
int maxPetsPerSpecies = battlePetSpecies.HasFlag(BattlePetSpeciesFlags.LegacyAccountUnique) ? 1 : SharedConst.DefaultMaxBattlePetsPerSpecies; int maxPetsPerSpecies = battlePetSpecies.HasFlag(BattlePetSpeciesFlags.LegacyAccountUnique) ? 1 : SharedConst.DefaultMaxBattlePetsPerSpecies;
return GetPetCount(battlePetSpecies, ownerGuid) >= maxPetsPerSpecies; return GetPetCount(battlePetSpecies, ownerGuid) >= maxPetsPerSpecies;
} }
public uint GetPetUniqueSpeciesCount() public uint GetPetUniqueSpeciesCount()
{ {
HashSet<uint> speciesIds = new(); HashSet<uint> speciesIds = new();
@@ -519,7 +518,7 @@ namespace Game.BattlePets
return (uint)speciesIds.Count; return (uint)speciesIds.Count;
} }
public void UnlockSlot(BattlePetSlots slot) public void UnlockSlot(BattlePetSlots slot)
{ {
if (slot >= BattlePetSlots.Count) if (slot >= BattlePetSlots.Count)
@@ -631,8 +630,7 @@ namespace Game.BattlePets
if (pet.SaveInfo != BattlePetSaveInfo.New) if (pet.SaveInfo != BattlePetSaveInfo.New)
pet.SaveInfo = BattlePetSaveInfo.Changed; pet.SaveInfo = BattlePetSaveInfo.Changed;
List<BattlePet> updates = new(); List<BattlePet> updates = [pet];
updates.Add(pet);
SendUpdates(updates, false); SendUpdates(updates, false);
// UF::PlayerData::CurrentBattlePetBreedQuality isn't updated (Intended) // UF::PlayerData::CurrentBattlePetBreedQuality isn't updated (Intended)
@@ -653,8 +651,8 @@ namespace Game.BattlePets
var battlePetSpecies = CliDB.BattlePetSpeciesStorage.LookupByKey(pet.PacketInfo.Species); var battlePetSpecies = CliDB.BattlePetSpeciesStorage.LookupByKey(pet.PacketInfo.Species);
if (battlePetSpecies != null) if (battlePetSpecies != null)
if (battlePetSpecies.HasFlag(BattlePetSpeciesFlags.CantBattle)) if (battlePetSpecies.HasFlag(BattlePetSpeciesFlags.CantBattle))
return; return;
ushort level = pet.PacketInfo.Level; ushort level = pet.PacketInfo.Level;
if (level >= SharedConst.MaxBattlePetLevel) if (level >= SharedConst.MaxBattlePetLevel)
@@ -695,8 +693,7 @@ namespace Game.BattlePets
if (pet.SaveInfo != BattlePetSaveInfo.New) if (pet.SaveInfo != BattlePetSaveInfo.New)
pet.SaveInfo = BattlePetSaveInfo.Changed; pet.SaveInfo = BattlePetSaveInfo.Changed;
List<BattlePet> updates = new(); List<BattlePet> updates = [pet];
updates.Add(pet);
SendUpdates(updates, false); SendUpdates(updates, false);
} }
@@ -735,8 +732,7 @@ namespace Game.BattlePets
if (pet.SaveInfo != BattlePetSaveInfo.New) if (pet.SaveInfo != BattlePetSaveInfo.New)
pet.SaveInfo = BattlePetSaveInfo.Changed; pet.SaveInfo = BattlePetSaveInfo.Changed;
List<BattlePet> updates = new List<BattlePet>(); List<BattlePet> updates = [pet];
updates.Add(pet);
SendUpdates(updates, false); SendUpdates(updates, false);
} }
@@ -746,17 +742,18 @@ namespace Game.BattlePets
// regain 50 % of the damage that was taken during combat // regain 50 % of the damage that was taken during combat
List<BattlePet> updates = new(); List<BattlePet> updates = new();
foreach (var pet in _pets.Values) foreach (var (_, pet) in _pets)
{ {
if (pet.PacketInfo.Health != pet.PacketInfo.MaxHealth) if (pet.PacketInfo.Health == pet.PacketInfo.MaxHealth)
{ continue;
pet.PacketInfo.Health += MathFunctions.CalculatePct(pet.PacketInfo.MaxHealth, pct);
// don't allow Health to be greater than MaxHealth pet.PacketInfo.Health += MathFunctions.CalculatePct(pet.PacketInfo.MaxHealth, pct);
pet.PacketInfo.Health = Math.Min(pet.PacketInfo.Health, pet.PacketInfo.MaxHealth); // don't allow Health to be greater than MaxHealth
if (pet.SaveInfo != BattlePetSaveInfo.New) pet.PacketInfo.Health = Math.Min(pet.PacketInfo.Health, pet.PacketInfo.MaxHealth);
pet.SaveInfo = BattlePetSaveInfo.Changed; if (pet.SaveInfo != BattlePetSaveInfo.New)
updates.Add(pet); pet.SaveInfo = BattlePetSaveInfo.Changed;
}
updates.Add(pet);
} }
SendUpdates(updates, false); SendUpdates(updates, false);
@@ -867,7 +864,7 @@ namespace Game.BattlePets
{ {
return Global.WorldMgr.IsBattlePetJournalLockAcquired(_owner.GetBattlenetAccountGUID()); return Global.WorldMgr.IsBattlePetJournalLockAcquired(_owner.GetBattlenetAccountGUID());
} }
public BattlePetSlot GetSlot(BattlePetSlots slot) { return slot < BattlePetSlots.Count ? _slots[(byte)slot] : null; } public BattlePetSlot GetSlot(BattlePetSlots slot) { return slot < BattlePetSlots.Count ? _slots[(byte)slot] : null; }
WorldSession GetOwner() { return _owner; } WorldSession GetOwner() { return _owner; }