From 0c186f35bb031269f53c267cb4b04c91bae5f729 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 9 May 2022 12:30:19 -0400 Subject: [PATCH] Core/BattlePets: Implemented CMSG_BATTLE_PET_UPDATE_NOTIFY Port From (https://github.com/TrinityCore/TrinityCore/commit/966430dc449f6ac259262cb996051dfd04a6e5fb) --- Source/Game/BattlePets/BattlePetManager.cs | 46 +++++++++---------- Source/Game/Handlers/BattlePetHandler.cs | 6 +++ .../Networking/Packets/BattlePetPackets.cs | 11 +++++ 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/Source/Game/BattlePets/BattlePetManager.cs b/Source/Game/BattlePets/BattlePetManager.cs index f7ea08268..43451ead5 100644 --- a/Source/Game/BattlePets/BattlePetManager.cs +++ b/Source/Game/BattlePets/BattlePetManager.cs @@ -689,17 +689,6 @@ namespace Game.BattlePets List updates = new(); updates.Add(pet); SendUpdates(updates, false); - - // Update battle pet related update fields - Creature summonedBattlePet = player.GetSummonedBattlePet(); - if (summonedBattlePet != null) - { - if (summonedBattlePet.GetBattlePetCompanionGUID() == guid) - { - summonedBattlePet.SetWildBattlePetLevel(pet.PacketInfo.Level); - player.SetBattlePetData(pet); - } - } } public void GrantBattlePetLevel(ObjectGuid guid, ushort grantedLevels) @@ -720,14 +709,12 @@ namespace Game.BattlePets if (level >= SharedConst.MaxBattlePetLevel) return; - Player player = _owner.GetPlayer(); - while (grantedLevels > 0 && level < SharedConst.MaxBattlePetLevel) { ++level; --grantedLevels; - player.UpdateCriteria(CriteriaType.BattlePetReachLevel, pet.PacketInfo.Species, level); + _owner.GetPlayer().UpdateCriteria(CriteriaType.BattlePetReachLevel, pet.PacketInfo.Species, level); } pet.PacketInfo.Level = level; @@ -742,17 +729,6 @@ namespace Game.BattlePets List updates = new List(); updates.Add(pet); SendUpdates(updates, false); - - // Update battle pet related update fields - Creature summonedBattlePet = player.GetSummonedBattlePet(); - if (summonedBattlePet != null) - { - if (summonedBattlePet.GetBattlePetCompanionGUID() == guid) - { - summonedBattlePet.SetWildBattlePetLevel(pet.PacketInfo.Level); - player.SetBattlePetData(pet); - } - } } public void HealBattlePetsPct(byte pct) @@ -777,6 +753,26 @@ namespace Game.BattlePets SendUpdates(updates, false); } + public void UpdateBattlePetData(ObjectGuid guid) + { + BattlePet pet = GetPet(guid); + if (pet == null) + return; + + Player player = _owner.GetPlayer(); + + // Update battle pet related update fields + Creature summonedBattlePet = player.GetSummonedBattlePet(); + if (summonedBattlePet != null) + { + if (summonedBattlePet.GetBattlePetCompanionGUID() == guid) + { + summonedBattlePet.SetWildBattlePetLevel(pet.PacketInfo.Level); + player.SetBattlePetData(pet); + } + } + } + public void SummonPet(ObjectGuid guid) { BattlePet pet = GetPet(guid); diff --git a/Source/Game/Handlers/BattlePetHandler.cs b/Source/Game/Handlers/BattlePetHandler.cs index c2a75ba30..f38ce37c2 100644 --- a/Source/Game/Handlers/BattlePetHandler.cs +++ b/Source/Game/Handlers/BattlePetHandler.cs @@ -146,5 +146,11 @@ namespace Game else GetBattlePetMgr().DismissPet(); } + + [WorldPacketHandler(ClientOpcodes.BattlePetUpdateNotify)] + void HandleBattlePetUpdateNotify(BattlePetUpdateNotify battlePetUpdateNotify) + { + GetBattlePetMgr().UpdateBattlePetData(battlePetUpdateNotify.PetGuid); + } } } diff --git a/Source/Game/Networking/Packets/BattlePetPackets.cs b/Source/Game/Networking/Packets/BattlePetPackets.cs index a72bbc435..93f49cc9b 100644 --- a/Source/Game/Networking/Packets/BattlePetPackets.cs +++ b/Source/Game/Networking/Packets/BattlePetPackets.cs @@ -301,7 +301,18 @@ namespace Game.Networking.Packets public ObjectGuid PetGuid; } + class BattlePetUpdateNotify : ClientPacket + { + public ObjectGuid PetGuid; + public BattlePetUpdateNotify(WorldPacket packet) : base(packet) { } + + public override void Read() + { + PetGuid = _worldPacket.ReadPackedGuid(); + } + } + //Structs public struct BattlePetStruct {