1818#include " Battleground.h"
1919#include " ArenaScore.h"
2020#include " BattlegroundMgr.h"
21+ #include " BattlegroundPackets.h"
2122#include " BattlegroundScore.h"
2223#include " ChatTextBuilder.h"
2324#include " Creature.h"
4243#include " WorldStatePackets.h"
4344#include < cstdarg>
4445
45- void BattlegroundScore::AppendToPacket (WorldPacket& data )
46+ void BattlegroundScore::AppendToPacket (WorldPackets::Battleground::PVPLogData_Player& playerData )
4647{
47- data << uint64 ( PlayerGuid) ;
48+ playerData. PlayerGUID = PlayerGuid;
4849
49- data << uint32 (KillingBlows);
50- data << uint32 (HonorableKills);
51- data << uint32 (Deaths);
52- data << uint32 (BonusHonor);
53- data << uint32 (DamageDone);
54- data << uint32 (HealingDone);
50+ playerData.Kills = KillingBlows;
51+ playerData.HonorOrFaction = WorldPackets::Battleground::PVPLogData_Honor
52+ {
53+ .HonorKills = HonorableKills,
54+ .Deaths = Deaths,
55+ .ContributionPoints = BonusHonor
56+ };
57+ playerData.DamageDone = DamageDone;
58+ playerData.HealingDone = HealingDone;
5559
56- BuildObjectivesBlock (data );
60+ BuildObjectivesBlock (playerData );
5761}
5862
5963template <class Do >
@@ -461,11 +465,10 @@ inline void Battleground::_ProcessJoin(uint32 diff)
461465 if (Player* player = ObjectAccessor::FindPlayer (itr->first ))
462466 {
463467 // BG Status packet
464- WorldPacket status;
465468 BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId (m_TypeID, GetBracketId (), GetArenaType ());
466- uint32 queueSlot = player-> GetBattlegroundQueueIndex (bgQueueTypeId) ;
467- sBattlegroundMgr -> BuildBattlegroundStatusPacket (&status , this , queueSlot, STATUS_IN_PROGRESS, 0 , GetStartTime (), GetArenaType (), player->GetBGTeam () );
468- player->SendDirectMessage (&status );
469+ WorldPackets::Battleground::BattlefieldStatusActive battlefieldStatus ;
470+ BattlegroundMgr::BuildBattlegroundStatusActive (&battlefieldStatus , this , player, player->GetBattlegroundQueueIndex (bgQueueTypeId), bgQueueTypeId );
471+ player->SendDirectMessage (battlefieldStatus. Write () );
469472
470473 player->RemoveAurasDueToSpell (SPELL_ARENA_PREPARATION);
471474 player->ResetAllPowers ();
@@ -716,8 +719,9 @@ void Battleground::EndBattleground(uint32 winner)
716719 // we must set it this way, because end time is sent in packet!
717720 m_EndTime = TIME_TO_AUTOREMOVE;
718721
719- WorldPacket pvpLogData;
720- BuildPvPLogDataPacket (pvpLogData);
722+ WorldPackets::Battleground::PVPMatchStatistics pvpMatchStatistics;
723+ BuildPvPLogDataPacket (pvpMatchStatistics);
724+ pvpMatchStatistics.Write ();
721725
722726 BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId (GetTypeID (), GetBracketId (), GetArenaType ());
723727
@@ -798,11 +802,12 @@ void Battleground::EndBattleground(uint32 winner)
798802
799803 BlockMovement (player);
800804
801- player->SendDirectMessage (&pvpLogData);
805+ player->SendDirectMessage (pvpMatchStatistics.GetRawPacket ());
806+
807+ WorldPackets::Battleground::BattlefieldStatusActive battlefieldStatus;
808+ BattlegroundMgr::BuildBattlegroundStatusActive (&battlefieldStatus, this , player, player->GetBattlegroundQueueIndex (bgQueueTypeId), bgQueueTypeId);
809+ player->SendDirectMessage (battlefieldStatus.Write ());
802810
803- WorldPacket data;
804- sBattlegroundMgr ->BuildBattlegroundStatusPacket (&data, this , player->GetBattlegroundQueueIndex (bgQueueTypeId), STATUS_IN_PROGRESS, TIME_TO_AUTOREMOVE, GetStartTime (), GetArenaType (), player->GetBGTeam ());
805- player->SendDirectMessage (&data);
806811 player->UpdateAchievementCriteria (ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND, player->GetMapId ());
807812 }
808813}
@@ -886,9 +891,9 @@ void Battleground::RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool Sen
886891
887892 if (SendPacket)
888893 {
889- WorldPacket data ;
890- sBattlegroundMgr -> BuildBattlegroundStatusPacket (&data, this , player->GetBattlegroundQueueIndex (bgQueueTypeId), STATUS_NONE, 0 , 0 , 0 , 0 );
891- player->SendDirectMessage (&data );
894+ WorldPackets::Battleground::BattlefieldStatusNone battlefieldStatus ;
895+ BattlegroundMgr::BuildBattlegroundStatusNone (&battlefieldStatus, player->GetBattlegroundQueueIndex (bgQueueTypeId));
896+ player->SendDirectMessage (battlefieldStatus. Write () );
892897 }
893898
894899 // this call is important, because player, when joins to battleground, this method is not called, so it must be called when leaving bg
@@ -910,9 +915,9 @@ void Battleground::RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool Sen
910915 sBattlegroundMgr ->ScheduleQueueUpdate (0 , bgQueueTypeId);
911916 }
912917 // Let others know
913- WorldPacket data ;
914- sBattlegroundMgr -> BuildPlayerLeftBattlegroundPacket (&data, guid) ;
915- SendPacketToTeam (team, &data , player, false );
918+ WorldPackets::Battleground::BattlegroundPlayerLeft playerLeft ;
919+ playerLeft. Guid = guid;
920+ SendPacketToTeam (team, playerLeft. Write () , player, false );
916921 }
917922
918923 if (player)
@@ -1001,9 +1006,9 @@ void Battleground::AddPlayer(Player* player)
10011006 if (!isInBattleground)
10021007 UpdatePlayersCountByTeam (team, false ); // +1 player
10031008
1004- WorldPacket data ;
1005- sBattlegroundMgr -> BuildPlayerJoinedBattlegroundPacket (&data, player );
1006- SendPacketToTeam (team, &data , player, false );
1009+ WorldPackets::Battleground::BattlegroundPlayerJoined playerJoined ;
1010+ playerJoined. Guid = player-> GetGUID ( );
1011+ SendPacketToTeam (team, playerJoined. Write () , player, false );
10071012
10081013 player->RemoveAurasByType (SPELL_AURA_MOUNTED);
10091014
@@ -1200,33 +1205,33 @@ bool Battleground::HasFreeSlots() const
12001205 return GetPlayersSize () < GetMaxPlayers ();
12011206}
12021207
1203- void Battleground::BuildPvPLogDataPacket (WorldPacket& data )
1208+ void Battleground::BuildPvPLogDataPacket (WorldPackets::Battleground::PVPMatchStatistics& pvpLogData )
12041209{
1205- uint8 type = (isArena () ? 1 : 0 );
1206-
1207- data.Initialize (MSG_PVP_LOG_DATA, 1 + 1 + 4 + 40 * GetPlayerScoresSize ());
1208- data << uint8 (type); // type (battleground = 0 / arena = 1)
1209-
1210- if (type) // arena
1210+ if (isArena ())
12111211 {
1212- for (uint8 i = 0 ; i < PVP_TEAMS_COUNT; ++i)
1213- _arenaTeamScores[i].BuildRatingInfoBlock (data);
1212+ WorldPackets::Battleground::PVPLogData_Arena& arena = pvpLogData.Arena .emplace ();
12141213
12151214 for (uint8 i = 0 ; i < PVP_TEAMS_COUNT; ++i)
1216- _arenaTeamScores[i].BuildTeamInfoBlock (data);
1215+ {
1216+ ArenaTeamScore const & score = _arenaTeamScores[i];
1217+
1218+ uint32 ratingLost = std::abs (std::min (score.RatingChange , 0 ));
1219+ uint32 ratingWon = std::max (score.RatingChange , 0 );
1220+
1221+ // should be old rating, new rating, and client will calculate rating change itself
1222+ arena.Ratings .Prematch [i] = ratingLost;
1223+ arena.Ratings .Postmatch [i] = ratingWon;
1224+ arena.Ratings .PrematchMMR [i] = score.MatchmakerRating ;
1225+
1226+ arena.TeamName [i] = score.TeamName ;
1227+ }
12171228 }
12181229
12191230 if (GetStatus () == STATUS_WAIT_LEAVE)
1220- {
1221- data << uint8 (1 ); // bg ended
1222- data << uint8 (GetWinner ()); // who win
1223- }
1224- else
1225- data << uint8 (0 ); // bg not ended
1231+ pvpLogData.Winner = GetWinner ();
12261232
1227- data << uint32 (GetPlayerScoresSize ());
1228- for (auto const & score : PlayerScores)
1229- score.second ->AppendToPacket (data);
1233+ for (auto const & [_, score] : PlayerScores)
1234+ score->AppendToPacket (pvpLogData.Players .emplace_back ());
12301235}
12311236
12321237bool Battleground::UpdatePlayerScore (Player* player, uint32 type, uint32 value, bool doAddHonor)
@@ -1729,16 +1734,17 @@ void Battleground::PlayerAddedToBGCheckIfBGIsRunning(Player* player)
17291734 if (GetStatus () != STATUS_WAIT_LEAVE)
17301735 return ;
17311736
1732- WorldPacket data;
17331737 BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr::BGQueueTypeId (GetTypeID (), GetBracketId (), GetArenaType ());
17341738
17351739 BlockMovement (player);
17361740
1737- BuildPvPLogDataPacket (data);
1738- player->SendDirectMessage (&data);
1741+ WorldPackets::Battleground::PVPMatchStatistics pvpMatchStatistics;
1742+ BuildPvPLogDataPacket (pvpMatchStatistics);
1743+ player->SendDirectMessage (pvpMatchStatistics.Write ());
17391744
1740- sBattlegroundMgr ->BuildBattlegroundStatusPacket (&data, this , player->GetBattlegroundQueueIndex (bgQueueTypeId), STATUS_IN_PROGRESS, GetEndTime (), GetStartTime (), GetArenaType (), player->GetBGTeam ());
1741- player->SendDirectMessage (&data);
1745+ WorldPackets::Battleground::BattlefieldStatusActive battlefieldStatus;
1746+ BattlegroundMgr::BuildBattlegroundStatusActive (&battlefieldStatus, this , player, player->GetBattlegroundQueueIndex (bgQueueTypeId), bgQueueTypeId);
1747+ player->SendDirectMessage (battlefieldStatus.Write ());
17421748}
17431749
17441750uint32 Battleground::GetAlivePlayersCountByTeam (uint32 Team) const
0 commit comments