diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-08-19 18:02:42 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-08-19 18:02:42 +0200 |
commit | c215363e86a260e9455469ffffab9e84263fb276 (patch) | |
tree | bb8d34b03ca521536d40a1537d105f5cddc0a7f3 /src/server/game/BattlePets/BattlePetMgr.cpp | |
parent | 55be2976b0951a96a188cc343143b3c1476a701d (diff) |
Core/BattlePets: Refactor BattlePetMgr::SendUpdates to use std::span argument
Diffstat (limited to 'src/server/game/BattlePets/BattlePetMgr.cpp')
-rw-r--r-- | src/server/game/BattlePets/BattlePetMgr.cpp | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/src/server/game/BattlePets/BattlePetMgr.cpp b/src/server/game/BattlePets/BattlePetMgr.cpp index 05e7939097f..b1a0acad7e0 100644 --- a/src/server/game/BattlePets/BattlePetMgr.cpp +++ b/src/server/game/BattlePets/BattlePetMgr.cpp @@ -479,9 +479,8 @@ void BattlePetMgr::AddPet(uint32 species, uint32 display, uint16 breed, BattlePe _pets[pet.PacketInfo.Guid.GetCounter()] = std::move(pet); - std::vector<std::reference_wrapper<BattlePet>> updates; - updates.push_back(std::ref(pet)); - SendUpdates(std::move(updates), true); + std::array<std::reference_wrapper<BattlePet const>, 1> updates = { pet }; + SendUpdates(updates, true); player->UpdateCriteria(CriteriaType::UniquePetsOwned); player->UpdateCriteria(CriteriaType::LearnedNewPet, species); @@ -687,9 +686,8 @@ void BattlePetMgr::ChangeBattlePetQuality(ObjectGuid guid, BattlePetBreedQuality if (pet->SaveInfo != BATTLE_PET_NEW) pet->SaveInfo = BATTLE_PET_CHANGED; - std::vector<std::reference_wrapper<BattlePet>> updates; - updates.push_back(std::ref(*pet)); - SendUpdates(std::move(updates), false); + std::array<std::reference_wrapper<BattlePet const>, 1> updates = { *pet }; + SendUpdates(updates, false); // UF::PlayerData::CurrentBattlePetBreedQuality isn't updated (Intended) // _owner->GetPlayer()->SetCurrentBattlePetBreedQuality(qualityValue); @@ -750,9 +748,8 @@ void BattlePetMgr::GrantBattlePetExperience(ObjectGuid guid, uint16 xp, BattlePe if (pet->SaveInfo != BATTLE_PET_NEW) pet->SaveInfo = BATTLE_PET_CHANGED; - std::vector<std::reference_wrapper<BattlePet>> updates; - updates.push_back(std::ref(*pet)); - SendUpdates(std::move(updates), false); + std::array<std::reference_wrapper<BattlePet const>, 1> updates = { *pet }; + SendUpdates(updates, false); } void BattlePetMgr::GrantBattlePetLevel(ObjectGuid guid, uint16 grantedLevels) @@ -789,29 +786,31 @@ void BattlePetMgr::GrantBattlePetLevel(ObjectGuid guid, uint16 grantedLevels) if (pet->SaveInfo != BATTLE_PET_NEW) pet->SaveInfo = BATTLE_PET_CHANGED; - std::vector<std::reference_wrapper<BattlePet>> updates; - updates.push_back(std::ref(*pet)); - SendUpdates(std::move(updates), false); + std::array<std::reference_wrapper<BattlePet const>, 1> updates = { *pet }; + SendUpdates(updates, false); } void BattlePetMgr::HealBattlePetsPct(uint8 pct) { // TODO: After each Pet Battle, any injured companion will automatically // regain 50 % of the damage that was taken during combat - std::vector<std::reference_wrapper<BattlePet>> updates; + std::vector<std::reference_wrapper<BattlePet const>> updates; - for (auto& pet : _pets) - if (pet.second.PacketInfo.Health != pet.second.PacketInfo.MaxHealth) - { - pet.second.PacketInfo.Health += CalculatePct(pet.second.PacketInfo.MaxHealth, pct); - // don't allow Health to be greater than MaxHealth - pet.second.PacketInfo.Health = std::min(pet.second.PacketInfo.Health, pet.second.PacketInfo.MaxHealth); - if (pet.second.SaveInfo != BATTLE_PET_NEW) - pet.second.SaveInfo = BATTLE_PET_CHANGED; - updates.push_back(std::ref(pet.second)); - } + for (auto& [_, pet] : _pets) + { + if (pet.PacketInfo.Health == pet.PacketInfo.MaxHealth) + continue; - SendUpdates(std::move(updates), false); + pet.PacketInfo.Health += CalculatePct(pet.PacketInfo.MaxHealth, pct); + // don't allow Health to be greater than MaxHealth + pet.PacketInfo.Health = std::min(pet.PacketInfo.Health, pet.PacketInfo.MaxHealth); + if (pet.SaveInfo != BATTLE_PET_NEW) + pet.SaveInfo = BATTLE_PET_CHANGED; + + updates.push_back(pet); + } + + SendUpdates(updates, false); } void BattlePetMgr::UpdateBattlePetData(ObjectGuid guid) @@ -885,12 +884,10 @@ void BattlePetMgr::SendJournal() _owner->SendPacket(battlePetJournal.Write()); } -void BattlePetMgr::SendUpdates(std::vector<std::reference_wrapper<BattlePet>> pets, bool petAdded) +void BattlePetMgr::SendUpdates(std::span<std::reference_wrapper<BattlePet const> const> pets, bool petAdded) { WorldPackets::BattlePet::BattlePetUpdates updates; - for (BattlePet& pet : pets) - updates.Pets.push_back(std::ref(pet.PacketInfo)); - + std::ranges::transform(pets, std::back_inserter(updates.Pets), &BattlePet::PacketInfo); updates.PetAdded = petAdded; _owner->SendPacket(updates.Write()); } |