TrinityCore
BattlegroundScore.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "BattlegroundScore.h"
19#include "BattlegroundMgr.h"
20#include "Errors.h"
21#include "Log.h"
22#include "ObjectAccessor.h"
23#include "Player.h"
24#include "SharedDefines.h"
25
26#include <sstream>
27
28BattlegroundScore::BattlegroundScore(ObjectGuid playerGuid, uint32 team, std::unordered_set<uint32> const* pvpStatIds) : PlayerGuid(playerGuid), TeamId(team == ALLIANCE ? PVP_TEAM_ALLIANCE : PVP_TEAM_HORDE),
29 KillingBlows(0), Deaths(0), HonorableKills(0), BonusHonor(0), DamageDone(0), HealingDone(0),
30 PreMatchRating(0), PreMatchMMR(0), PostMatchRating(0), PostMatchMMR(0), _validPvpStatIds(pvpStatIds)
31{
33 for (uint32 pvpStatId : *_validPvpStatIds)
34 PvpStats[pvpStatId] = 0;
35}
36
38
40{
41 switch (type)
42 {
43 case SCORE_KILLING_BLOWS: // Killing blows
44 KillingBlows += value;
45 break;
46 case SCORE_DEATHS: // Deaths
47 Deaths += value;
48 break;
49 case SCORE_HONORABLE_KILLS: // Honorable kills
50 HonorableKills += value;
51 break;
52 case SCORE_BONUS_HONOR: // Honor bonus
53 BonusHonor += value;
54 break;
55 case SCORE_DAMAGE_DONE: // Damage Done
56 DamageDone += value;
57 break;
58 case SCORE_HEALING_DONE: // Healing Done
59 HealingDone += value;
60 break;
61 default:
62 ABORT_MSG("Not implemented Battleground score type %u!", type);
63 break;
64 }
65}
66
68{
70 return;
71
72 if (!_validPvpStatIds->contains(pvpStatID))
73 {
74 TC_LOG_WARN("bg.scores", "Tried updating PvpStat {} but this stat is not allowed on this map", pvpStatID);
75 return;
76 }
77
78 PvpStats[pvpStatID] += value;
80 player->UpdateCriteria(CriteriaType::TrackedWorldStateUIModified, pvpStatID);
81}
82
84{
85 auto const& itr = std::next(PvpStats.begin(), index);
86 if (itr == PvpStats.end())
87 return 0;
88
89 return itr->second;
90}
91
93{
94 playerData.PlayerGUID = PlayerGuid;
95 playerData.Kills = KillingBlows;
96 playerData.Faction = TeamId;
98 {
99 playerData.Honor.emplace();
100 playerData.Honor->HonorKills = HonorableKills;
101 playerData.Honor->Deaths = Deaths;
102 playerData.Honor->ContributionPoints = BonusHonor;
103 }
104
105 playerData.DamageDone = DamageDone;
106 playerData.HealingDone = HealingDone;
107
108 if (PreMatchRating)
109 playerData.PreMatchRating = PreMatchRating;
110
113
114 if (PreMatchMMR)
115 playerData.PreMatchMMR = PreMatchMMR;
116
118 playerData.MmrChange = int32(PostMatchMMR) - PreMatchMMR;
119
120 for (const auto& [pvpStatID, value] : PvpStats)
121 playerData.Stats.emplace_back(pvpStatID, value);
122}
123
125{
126 std::ostringstream stream;
127 stream << "Damage done: " << DamageDone << ", Healing done: " << HealingDone << ", Killing blows: " << KillingBlows
128 << ", PreMatchRating: " << PreMatchRating << ", PreMatchMMR: " << PreMatchMMR
129 << ", PostMatchRating: " << PostMatchRating << ", PostMatchMMR: " << PostMatchMMR;
130 return stream.str();
131}
@ SCORE_KILLING_BLOWS
@ SCORE_BONUS_HONOR
@ SCORE_DEATHS
@ SCORE_DAMAGE_DONE
@ SCORE_HEALING_DONE
@ SCORE_HONORABLE_KILLS
@ TrackedWorldStateUIModified
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
#define ABORT_MSG
Definition: Errors.h:75
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:162
TeamId
@ ALLIANCE
@ PVP_TEAM_HORDE
@ PVP_TEAM_ALLIANCE
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
virtual ~BattlegroundScore()
BattlegroundScore(ObjectGuid playerGuid, uint32 team, std::unordered_set< uint32 > const *pvpStatIds)
void BuildPvPLogPlayerDataPacket(WorldPackets::Battleground::PVPMatchStatistics::PVPMatchPlayerStatistics &playerData) const
void UpdateScore(uint32 type, uint32 value)
std::string ToString() const
std::unordered_set< uint32 > const * _validPvpStatIds
void UpdatePvpStat(uint32 pvpStatID, uint32 value)
std::map< uint32, uint32 > PvpStats
uint32 GetAttr(uint8 index) const