AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ArenaTeam Class Reference

#include "ArenaTeam.h"

Inheritance diagram for ArenaTeam:
ArenaTeamTest

Public Types

typedef std::list< ArenaTeamMember > MemberList
 

Public Member Functions

 ArenaTeam ()
 
 ~ArenaTeam ()
 
bool Create (ObjectGuid captainGuid, uint8 type, std::string const &teamName, uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor)
 
void Disband (WorldSession *session)
 
void Disband ()
 
uint32 GetId () const
 
uint32 GetType () const
 
uint8 GetSlot () const
 
ObjectGuid GetCaptain () const
 
std::string const & GetName () const
 
ArenaTeamStats const & GetStats () const
 
void SetArenaTeamStats (ArenaTeamStats &stats)
 
uint32 GetRating () const
 
uint32 GetAverageMMR (Group *group) const
 
void SetCaptain (ObjectGuid guid)
 
bool SetName (std::string const &name)
 
bool AddMember (ObjectGuid playerGuid)
 
void DelMember (ObjectGuid guid, bool cleanDb)
 
std::size_t GetMembersSize () const
 
bool Empty () const
 
MemberList::iterator m_membersBegin ()
 
MemberList::iterator m_membersEnd ()
 
MemberList & GetMembers ()
 
bool IsMember (ObjectGuid guid) const
 
ArenaTeamMember * GetMember (ObjectGuid guid)
 
ArenaTeamMember * GetMember (std::string const &name)
 
bool IsFighting () const
 
bool LoadArenaTeamFromDB (QueryResult arenaTeamDataResult)
 
bool LoadMembersFromDB (QueryResult arenaTeamMembersResult)
 
void LoadStatsFromDB (uint32 ArenaTeamId)
 
void SaveToDB (bool forceMemberSave=false)
 
void BroadcastPacket (WorldPacket *packet)
 
void BroadcastEvent (ArenaTeamEvents event, ObjectGuid guid, uint8 strCount, std::string const &str1, std::string const &str2, std::string const &str3)
 
void NotifyStatsChanged ()
 
void MassInviteToEvent (WorldSession *session)
 
void Roster (WorldSession *session)
 
void Query (WorldSession *session)
 
void SendStats (WorldSession *session)
 
void Inspect (WorldSession *session, ObjectGuid guid)
 
uint32 GetPoints (uint32 MemberRating)
 
int32 GetMatchmakerRatingMod (uint32 ownRating, uint32 opponentRating, bool won)
 
int32 GetRatingMod (uint32 ownRating, uint32 opponentRating, bool won)
 
float GetChanceAgainst (uint32 ownRating, uint32 opponentRating)
 
int32 WonAgainst (uint32 Own_MMRating, uint32 Opponent_MMRating, int32 &rating_change, Map const *bgMap)
 
void MemberWon (Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange)
 
int32 LostAgainst (uint32 Own_MMRating, uint32 Opponent_MMRating, int32 &rating_change, Map const *bgMap)
 
void MemberLost (Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange=-12)
 
void UpdateArenaPointsHelper (std::map< ObjectGuid, uint32 > &PlayerPoints)
 
bool FinishWeek ()
 
void FinishGame (int32 mod, Map const *bgMap)
 
void SetPreviousOpponents (uint32 arenaTeamId)
 
uint32 GetPreviousOpponents ()
 
void CreateTempArenaTeam (std::vector< Player * > playerList, uint8 type, std::string const &teamName)
 
void SetEmblem (uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor)
 
void SetRatingForAll (uint32 rating)
 

Static Public Member Functions

static uint8 GetSlotByType (uint32 type)
 
static uint8 GetReqPlayersForType (uint32 type)
 

Static Public Attributes

static std::unordered_map< uint32, uint8 > ArenaSlotByType
 
static std::unordered_map< uint8, uint8 > ArenaReqPlayersForType
 

Protected Attributes

uint32 TeamId
 
uint8 Type
 
std::string TeamName
 
ObjectGuid CaptainGuid
 
uint32 BackgroundColor
 
uint8 EmblemStyle
 
uint32 EmblemColor
 
uint8 BorderStyle
 
uint32 BorderColor
 
MemberList Members
 
ArenaTeamStats Stats
 
uint32 PreviousOpponents = 0
 

Detailed Description

Member Typedef Documentation

◆ MemberList

Constructor & Destructor Documentation

◆ ArenaTeam()

ArenaTeam::ArenaTeam ( )
35{
36 Stats.WeekGames = 0;
37 Stats.SeasonGames = 0;
38 Stats.Rank = 0;
39 Stats.Rating = (sArenaSeasonMgr->GetCurrentSeason() < 6)
41 : sWorld->getIntConfig(CONFIG_ARENA_START_RATING);
42 Stats.WeekWins = 0;
43 Stats.SeasonWins = 0;
44}
#define sArenaSeasonMgr
Definition ArenaSeasonMgr.h:124
Stats
Definition SharedDefines.h:245
@ CONFIG_ARENA_START_RATING
Definition WorldConfig.h:298
@ CONFIG_LEGACY_ARENA_START_RATING
Definition WorldConfig.h:299
uint32 EmblemColor
Definition ArenaTeam.h:232
uint32 BorderColor
Definition ArenaTeam.h:234
uint32 TeamId
Definition ArenaTeam.h:225
uint8 Type
Definition ArenaTeam.h:226
uint8 EmblemStyle
Definition ArenaTeam.h:231
uint8 BorderStyle
Definition ArenaTeam.h:233
std::string TeamName
Definition ArenaTeam.h:227
uint32 BackgroundColor
Definition ArenaTeam.h:230
#define sWorld
Definition World.h:318

References CONFIG_ARENA_START_RATING, CONFIG_LEGACY_ARENA_START_RATING, sArenaSeasonMgr, and sWorld.

◆ ~ArenaTeam()

ArenaTeam::~ArenaTeam ( )
47{
48}

Member Function Documentation

◆ AddMember()

bool ArenaTeam::AddMember ( ObjectGuid  playerGuid)
93{
94 std::string playerName;
95 uint8 playerClass;
96
97 // Check if arena team is full (Can't have more than type * 2 players)
98 if (GetMembersSize() >= GetType() * 2)
99 return false;
100
101 // xinef: Get player name and class from player storage or global data storage
102 Player* player = ObjectAccessor::FindConnectedPlayer(playerGuid);
103 if (player)
104 {
105 playerClass = player->getClass();
106 playerName = player->GetName();
107 }
108 else
109 {
110 CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(playerGuid);
111 if (!playerData)
112 {
113 return false;
114 }
115
116 playerName = playerData->Name;
117 playerClass = playerData->Class;
118 }
119
120 if (!sScriptMgr->CanAddMember(this, playerGuid))
121 return false;
122
123 // Check if player is already in a similar arena team
124 if ((player && player->GetArenaTeamId(GetSlot())) || sCharacterCache->GetCharacterArenaTeamIdByGuid(playerGuid, GetSlot()) != 0)
125 {
126 LOG_ERROR("bg.arena", "Arena: Player {} ({}) already has an arena team of type {}", playerName, playerGuid.ToString(), GetType());
127 return false;
128 }
129
130 // Set player's personal rating
131 uint32 personalRating = 0;
132
133 if (sWorld->getIntConfig(CONFIG_ARENA_START_PERSONAL_RATING) > 0)
134 personalRating = sWorld->getIntConfig(CONFIG_ARENA_START_PERSONAL_RATING);
135 else if (sArenaSeasonMgr->GetCurrentSeason() < 6)
136 personalRating = 1500;
137 else if (GetRating() >= 1000)
138 personalRating = 1000;
139
140 // xinef: sync query
141 // Try to get player's match maker rating from db and fall back to config setting if not found
143 stmt->SetData(0, playerGuid.GetCounter());
144 stmt->SetData(1, GetSlot());
145 PreparedQueryResult result = CharacterDatabase.Query(stmt);
146
147 uint16 matchMakerRating;
148 uint16 maxMMR;
149 if (result)
150 {
151 matchMakerRating = (*result)[0].Get<uint16>();
152 uint16 Max = (*result)[1].Get<uint16>();
153 maxMMR = std::max(Max, matchMakerRating);
154 }
155 else
156 {
157 matchMakerRating = sWorld->getIntConfig(CONFIG_ARENA_START_MATCHMAKER_RATING);
158 maxMMR = matchMakerRating;
159 }
160
161 // Remove all player signatures from other petitions
162 // This will prevent player from joining too many arena teams and corrupt arena team data integrity
164
165 // Feed data to the struct
166 ArenaTeamMember newMember;
167 newMember.Name = playerName;
168 newMember.Guid = playerGuid;
169 newMember.Class = playerClass;
170 newMember.SeasonGames = 0;
171 newMember.WeekGames = 0;
172 newMember.SeasonWins = 0;
173 newMember.WeekWins = 0;
174 newMember.PersonalRating = personalRating;
175 newMember.MatchMakerRating = matchMakerRating;
176 newMember.MaxMMR = maxMMR;
177
178 sScriptMgr->OnAddMember(this, newMember);
179
180 Members.push_back(newMember);
181 sCharacterCache->UpdateCharacterArenaTeamId(playerGuid, GetSlot(), GetId());
182
183 // Save player's arena team membership to db
184 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ARENA_TEAM_MEMBER);
185 stmt->SetData(0, TeamId);
186 stmt->SetData(1, playerGuid.GetCounter());
187 stmt->SetData(2, newMember.WeekGames);
188 stmt->SetData(3, newMember.WeekWins);
189 stmt->SetData(4, newMember.SeasonGames);
190 stmt->SetData(5, newMember.SeasonWins);
191 stmt->SetData(6, newMember.PersonalRating);
192 CharacterDatabase.Execute(stmt);
193
194 // Inform player if online
195 if (player)
196 {
197 player->SetInArenaTeam(TeamId, GetSlot(), GetType());
198 player->SetArenaTeamIdInvited(0);
199
200 // Hide promote/remove buttons
201 if (CaptainGuid != playerGuid)
203 }
204
205 return true;
206}
@ ARENA_TEAM_MEMBER
Definition ArenaTeam.h:76
#define sCharacterCache
Definition CharacterCache.h:88
@ CHAR_INS_ARENA_TEAM_MEMBER
Definition CharacterDatabase.h:226
@ CHAR_SEL_MATCH_MAKER_RATING
Definition CharacterDatabase.h:136
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::uint8_t uint8
Definition Define.h:109
std::uint32_t uint32
Definition Define.h:107
std::uint16_t uint16
Definition Define.h:108
#define LOG_ERROR(filterType__,...)
Definition Log.h:145
#define sScriptMgr
Definition ScriptMgr.h:766
TeamId
Definition SharedDefines.h:747
@ CONFIG_ARENA_START_MATCHMAKER_RATING
Definition WorldConfig.h:302
@ CONFIG_ARENA_START_PERSONAL_RATING
Definition WorldConfig.h:301
std::size_t GetMembersSize() const
Definition ArenaTeam.h:169
ObjectGuid CaptainGuid
Definition ArenaTeam.h:228
uint32 GetRating() const
Definition ArenaTeam.h:158
uint8 GetSlot() const
Definition ArenaTeam.h:150
uint32 GetType() const
Definition ArenaTeam.h:149
MemberList Members
Definition ArenaTeam.h:236
uint32 GetId() const
Definition ArenaTeam.h:148
LowType GetCounter() const
Definition ObjectGuid.h:149
std::string ToString() const
Definition ObjectGuid.cpp:48
Definition Player.h:1086
void SetArenaTeamInfoField(uint8 slot, ArenaTeamInfoType type, uint32 value)
Definition Player.cpp:16574
void SetInArenaTeam(uint32 ArenaTeamId, uint8 slot, uint8 type)
Definition Player.h:1935
uint32 GetArenaTeamId(uint8 slot) const
Definition Player.cpp:16589
static void RemovePetitionsAndSigns(ObjectGuid guid, uint32 type)
Definition Player.cpp:10283
void SetArenaTeamIdInvited(uint32 ArenaTeamId)
Definition Player.h:1945
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
uint8 getClass() const
Definition Unit.h:844
std::string const & GetName() const
Definition Object.h:535
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:281
Definition ArenaTeam.h:108
uint16 PersonalRating
Definition ArenaTeam.h:116
uint16 WeekWins
Definition ArenaTeam.h:113
uint8 Class
Definition ArenaTeam.h:111
uint16 SeasonWins
Definition ArenaTeam.h:115
std::string Name
Definition ArenaTeam.h:110
uint16 WeekGames
Definition ArenaTeam.h:112
ObjectGuid Guid
Definition ArenaTeam.h:109
uint16 MatchMakerRating
Definition ArenaTeam.h:117
uint16 SeasonGames
Definition ArenaTeam.h:114
uint16 MaxMMR
Definition ArenaTeam.h:118
Definition CharacterCache.h:28
uint8 Class
Definition CharacterCache.h:32
std::string Name
Definition CharacterCache.h:30

References ARENA_TEAM_MEMBER, CaptainGuid, CHAR_INS_ARENA_TEAM_MEMBER, CHAR_SEL_MATCH_MAKER_RATING, CharacterDatabase, ArenaTeamMember::Class, CharacterCacheEntry::Class, CONFIG_ARENA_START_MATCHMAKER_RATING, CONFIG_ARENA_START_PERSONAL_RATING, ObjectAccessor::FindConnectedPlayer(), Player::GetArenaTeamId(), Unit::getClass(), ObjectGuid::GetCounter(), GetId(), GetMembersSize(), WorldObject::GetName(), GetRating(), GetSlot(), GetType(), ArenaTeamMember::Guid, LOG_ERROR, ArenaTeamMember::MatchMakerRating, Max, ArenaTeamMember::MaxMMR, Members, ArenaTeamMember::Name, CharacterCacheEntry::Name, ArenaTeamMember::PersonalRating, Player::RemovePetitionsAndSigns(), sArenaSeasonMgr, sCharacterCache, ArenaTeamMember::SeasonGames, ArenaTeamMember::SeasonWins, Player::SetArenaTeamIdInvited(), Player::SetArenaTeamInfoField(), PreparedStatementBase::SetData(), Player::SetInArenaTeam(), sScriptMgr, sWorld, ObjectGuid::ToString(), ArenaTeamMember::WeekGames, and ArenaTeamMember::WeekWins.

Referenced by Create(), WorldSession::HandleArenaTeamAcceptOpcode(), and WorldSession::HandleTurnInPetitionOpcode().

◆ BroadcastEvent()

void ArenaTeam::BroadcastEvent ( ArenaTeamEvents  event,
ObjectGuid  guid,
uint8  strCount,
std::string const &  str1,
std::string const &  str2,
std::string const &  str3 
)
583{
584 WorldPacket data(SMSG_ARENA_TEAM_EVENT, 1 + 1 + 1);
585 data << uint8(event);
586 data << uint8(strCount);
587 switch (strCount)
588 {
589 case 0:
590 break;
591 case 1:
592 data << str1;
593 break;
594 case 2:
595 data << str1 << str2;
596 break;
597 case 3:
598 data << str1 << str2 << str3;
599 break;
600 default:
601 LOG_ERROR("bg.arena", "Unhandled strCount {} in ArenaTeam::BroadcastEvent", strCount);
602 return;
603 }
604
605 if (guid)
606 data << guid;
607
608 BroadcastPacket(&data);
609
610 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_EVENT");
611}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:157
void BroadcastPacket(WorldPacket *packet)
Definition ArenaTeam.cpp:575
Definition WorldPacket.h:26
@ SMSG_ARENA_TEAM_EVENT
Definition Opcodes.h:885

References BroadcastPacket(), LOG_DEBUG, LOG_ERROR, and SMSG_ARENA_TEAM_EVENT.

Referenced by Disband(), WorldSession::HandleArenaTeamAcceptOpcode(), WorldSession::HandleArenaTeamLeaderOpcode(), WorldSession::HandleArenaTeamLeaveOpcode(), and WorldSession::HandleArenaTeamRemoveOpcode().

◆ BroadcastPacket()

void ArenaTeam::BroadcastPacket ( WorldPacket *  packet)
576{
577 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
578 if (Player* player = ObjectAccessor::FindConnectedPlayer(itr->Guid))
579 player->SendDirectMessage(packet);
580}

References ObjectAccessor::FindConnectedPlayer(), and Members.

Referenced by BroadcastEvent().

◆ Create()

bool ArenaTeam::Create ( ObjectGuid  captainGuid,
uint8  type,
std::string const &  teamName,
uint32  backgroundColor,
uint8  emblemStyle,
uint32  emblemColor,
uint8  borderStyle,
uint32  borderColor 
)
51{
52 // Check if captain is present
54 return false;
55
56 // Check if arena team name is already taken
57 if (sArenaTeamMgr->GetArenaTeamByName(TeamName))
58 return false;
59
60 // Generate new arena team id
61 TeamId = sArenaTeamMgr->GenerateArenaTeamId();
62
63 // Assign member variables
64 CaptainGuid = captainGuid;
65 Type = type;
66 TeamName = teamName;
67 BackgroundColor = backgroundColor;
68 EmblemStyle = emblemStyle;
69 EmblemColor = emblemColor;
70 BorderStyle = borderStyle;
71 BorderColor = borderColor;
72
73 // Save arena team to db
75 stmt->SetData(0, TeamId);
76 stmt->SetData(1, TeamName);
77 stmt->SetData(2, captainGuid.GetCounter());
78 stmt->SetData(3, Type);
79 stmt->SetData(4, Stats.Rating);
80 stmt->SetData(5, BackgroundColor);
81 stmt->SetData(6, EmblemStyle);
82 stmt->SetData(7, EmblemColor);
83 stmt->SetData(8, BorderStyle);
84 stmt->SetData(9, BorderColor);
85 CharacterDatabase.Execute(stmt);
86
87 // Add captain as member
89 return true;
90}
#define sArenaTeamMgr
Definition ArenaTeamMgr.h:69
@ CHAR_INS_ARENA_TEAM
Definition CharacterDatabase.h:225
bool AddMember(ObjectGuid playerGuid)
Definition ArenaTeam.cpp:92

References AddMember(), BackgroundColor, BorderColor, BorderStyle, CaptainGuid, CHAR_INS_ARENA_TEAM, CharacterDatabase, EmblemColor, EmblemStyle, ObjectAccessor::FindConnectedPlayer(), ObjectGuid::GetCounter(), sArenaTeamMgr, PreparedStatementBase::SetData(), TeamName, and Type.

Referenced by arena_commandscript::HandleArenaCreateCommand(), and WorldSession::HandleTurnInPetitionOpcode().

◆ CreateTempArenaTeam()

void ArenaTeam::CreateTempArenaTeam ( std::vector< Player * >  playerList,
uint8  type,
std::string const &  teamName 
)
1049{
1050 auto playerCountInTeam = static_cast<uint32>(playerList.size());
1051
1052 const auto standardArenaType = { ARENA_TYPE_2v2, ARENA_TYPE_3v3, ARENA_TYPE_5v5 };
1053 bool isStandardArenaType = std::find(std::begin(standardArenaType), std::end(standardArenaType), type) != std::end(standardArenaType);
1054 if (isStandardArenaType)
1055 ASSERT(playerCountInTeam == GetReqPlayersForType(type));
1056
1057 // Generate new arena team id
1058 TeamId = sArenaTeamMgr->GenerateTempArenaTeamId();
1059
1060 // Assign member variables
1061 CaptainGuid = playerList[0]->GetGUID();
1062 Type = type;
1063 TeamName = teamName;
1064
1065 BackgroundColor = 0;
1066 EmblemStyle = 0;
1067 EmblemColor = 0;
1068 BorderStyle = 0;
1069 BorderColor = 0;
1070
1071 Stats.WeekGames = 0;
1072 Stats.SeasonGames = 0;
1073 Stats.Rating = 0;
1074 Stats.WeekWins = 0;
1075 Stats.SeasonWins = 0;
1076
1077 for (auto const& _player : playerList)
1078 {
1079 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(_player->GetArenaTeamId(GetSlotByType(type)));
1080 if (!team)
1081 continue;
1082
1083 ArenaTeamMember newMember;
1084 for (auto const& itr : Members)
1085 newMember = itr;
1086
1087 Stats.WeekGames += team->Stats.WeekGames;
1088 Stats.SeasonGames += team->Stats.SeasonGames;
1089 Stats.Rating += team->GetRating();
1090 Stats.WeekWins += team->Stats.WeekWins;
1091 Stats.SeasonWins += team->Stats.SeasonWins;
1092
1093 Members.push_back(newMember);
1094 }
1095
1096 Stats.WeekGames /= playerCountInTeam;
1097 Stats.SeasonGames /= playerCountInTeam;
1098 Stats.Rating /= playerCountInTeam;
1099 Stats.WeekWins /= playerCountInTeam;
1100 Stats.SeasonWins /= playerCountInTeam;
1101}
@ ARENA_TYPE_5v5
Definition Battleground.h:211
@ ARENA_TYPE_3v3
Definition Battleground.h:210
@ ARENA_TYPE_2v2
Definition Battleground.h:209
#define ASSERT
Definition Errors.h:68
Definition ArenaTeam.h:137
ArenaTeamStats Stats
Definition ArenaTeam.h:237
static uint8 GetReqPlayersForType(uint32 type)
Definition ArenaTeam.cpp:1036
static uint8 GetSlotByType(uint32 type)
Definition ArenaTeam.cpp:630
uint16 SeasonGames
Definition ArenaTeam.h:129
uint16 WeekGames
Definition ArenaTeam.h:127
uint16 WeekWins
Definition ArenaTeam.h:128
uint16 SeasonWins
Definition ArenaTeam.h:130

References ARENA_TYPE_2v2, ARENA_TYPE_3v3, ARENA_TYPE_5v5, ASSERT, BackgroundColor, BorderColor, BorderStyle, CaptainGuid, EmblemColor, EmblemStyle, GetRating(), GetReqPlayersForType(), GetSlotByType(), Members, sArenaTeamMgr, ArenaTeamStats::SeasonGames, ArenaTeamStats::SeasonWins, Stats, TeamName, Type, ArenaTeamMember::WeekGames, ArenaTeamStats::WeekGames, and ArenaTeamStats::WeekWins.

◆ DelMember()

void ArenaTeam::DelMember ( ObjectGuid  guid,
bool  cleanDb 
)
337{
339 Group* group = (player && player->GetGroup()) ? player->GetGroup() : nullptr;
340
341 // Remove member from team
342 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
343 {
344 // Remove queues of members
345 if (Player* playerMember = ObjectAccessor::FindConnectedPlayer(itr->Guid))
346 {
347 if (group && playerMember->GetGroup() && group->GetGUID() == playerMember->GetGroup()->GetGUID())
348 {
350 {
351 GroupQueueInfo ginfo;
352 BattlegroundQueue& queue = sBattlegroundMgr->GetBattlegroundQueue(bgQueue);
353 if (queue.GetPlayerGroupInfoData(playerMember->GetGUID(), &ginfo))
354 {
355 if (!ginfo.IsInvitedToBGInstanceGUID)
356 {
357 WorldPacket data;
358 playerMember->RemoveBattlegroundQueueId(bgQueue);
359 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, nullptr, playerMember->GetBattlegroundQueueIndex(bgQueue), STATUS_NONE, 0, 0, 0, TEAM_NEUTRAL);
360 queue.RemovePlayer(playerMember->GetGUID(), true);
361 playerMember->SendDirectMessage(&data);
362 }
363 }
364 }
365 }
366 }
367
368 if (itr->Guid == guid)
369 {
370 Members.erase(itr);
371 sCharacterCache->UpdateCharacterArenaTeamId(guid, GetSlot(), 0);
372 break;
373 }
374 }
375
376 // Inform player and remove arena team info from player data
377 if (player)
378 {
380 // delete all info regarding this team
381 for (uint32 i = 0; i < ARENA_TEAM_END; ++i)
383 }
384
385 // Only used for single member deletion, for arena team disband we use a single query for more efficiency
386 if (cleanDb)
387 {
389 stmt->SetData(0, GetId());
390 stmt->SetData(1, guid.GetCounter());
391 CharacterDatabase.Execute(stmt);
392 }
393}
@ ERR_ARENA_TEAM_QUIT_S
Definition ArenaTeam.h:34
ArenaTeamInfoType
Definition ArenaTeam.h:73
@ ARENA_TEAM_END
Definition ArenaTeam.h:81
#define sBattlegroundMgr
Definition BattlegroundMgr.h:190
@ STATUS_NONE
Definition Battleground.h:190
@ CHAR_DEL_ARENA_TEAM_MEMBER
Definition CharacterDatabase.h:230
@ BATTLEGROUND_AA
Definition SharedDefines.h:3742
BattlegroundQueueTypeId
Definition SharedDefines.h:3875
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
std::string const & GetName() const
Definition ArenaTeam.h:154
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition BattlegroundMgr.cpp:685
Definition BattlegroundQueue.h:68
bool GetPlayerGroupInfoData(ObjectGuid guid, GroupQueueInfo *ginfo)
Definition BattlegroundQueue.cpp:400
void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount)
Definition BattlegroundQueue.cpp:261
Definition Group.h:177
ObjectGuid GetGUID() const
Definition Group.cpp:2525
WorldSession * GetSession() const
Definition Player.h:2031
Group * GetGroup()
Definition Player.h:2517
void SendArenaTeamCommandResult(uint32 team_action, std::string const &team, std::string const &player, uint32 error_id=0)
Definition ArenaTeamHandler.cpp:406
Definition BattlegroundQueue.h:35
uint32 IsInvitedToBGInstanceGUID
Definition BattlegroundQueue.h:45

References ARENA_TEAM_END, BATTLEGROUND_AA, BattlegroundMgr::BGQueueTypeId(), CHAR_DEL_ARENA_TEAM_MEMBER, CharacterDatabase, ERR_ARENA_TEAM_QUIT_S, ObjectAccessor::FindConnectedPlayer(), ObjectGuid::GetCounter(), Player::GetGroup(), Group::GetGUID(), GetId(), GetName(), BattlegroundQueue::GetPlayerGroupInfoData(), Player::GetSession(), GetSlot(), GetType(), GroupQueueInfo::IsInvitedToBGInstanceGUID, Members, BattlegroundQueue::RemovePlayer(), sBattlegroundMgr, sCharacterCache, WorldSession::SendArenaTeamCommandResult(), Player::SetArenaTeamInfoField(), PreparedStatementBase::SetData(), STATUS_NONE, and TEAM_NEUTRAL.

Referenced by ArenaTeamMgr::DeleteAllArenaTeams(), Disband(), Disband(), WorldSession::HandleArenaTeamLeaveOpcode(), WorldSession::HandleArenaTeamRemoveOpcode(), Player::LeaveAllArenaTeams(), and LoadMembersFromDB().

◆ Disband() [1/2]

void ArenaTeam::Disband ( )
425{
426 // Remove all members from arena team
427 while (!Members.empty())
428 DelMember(Members.front().Guid, false);
429
430 // Update database
431 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
432
434 stmt->SetData(0, TeamId);
435 trans->Append(stmt);
436
437 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ARENA_TEAM_MEMBERS);
438 stmt->SetData(0, TeamId);
439 trans->Append(stmt);
440
441 CharacterDatabase.CommitTransaction(trans);
442
443 // Remove arena team from ObjectMgr
444 sArenaTeamMgr->RemoveArenaTeam(TeamId);
445}
@ CHAR_DEL_ARENA_TEAM_MEMBERS
Definition CharacterDatabase.h:228
@ CHAR_DEL_ARENA_TEAM
Definition CharacterDatabase.h:227
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition DatabaseEnvFwd.h:69
void DelMember(ObjectGuid guid, bool cleanDb)
Definition ArenaTeam.cpp:336

References CHAR_DEL_ARENA_TEAM, CHAR_DEL_ARENA_TEAM_MEMBERS, CharacterDatabase, DelMember(), Members, sArenaTeamMgr, and PreparedStatementBase::SetData().

◆ Disband() [2/2]

void ArenaTeam::Disband ( WorldSession *  session)
396{
397 // Remove all members from arena team
398 while (!Members.empty())
399 DelMember(Members.front().Guid, false);
400
401 // Broadcast update
402 if (session)
403 {
405 }
406
407 // Update database
408 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
409
411 stmt->SetData(0, TeamId);
412 trans->Append(stmt);
413
414 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ARENA_TEAM_MEMBERS);
415 stmt->SetData(0, TeamId);
416 trans->Append(stmt);
417
418 CharacterDatabase.CommitTransaction(trans);
419
420 // Remove arena team from ObjectMgr
421 sArenaTeamMgr->RemoveArenaTeam(TeamId);
422}
@ ERR_ARENA_TEAM_DISBANDED_S
Definition ArenaTeam.h:68
void BroadcastEvent(ArenaTeamEvents event, ObjectGuid guid, uint8 strCount, std::string const &str1, std::string const &str2, std::string const &str3)
Definition ArenaTeam.cpp:582
static ObjectGuid const Empty
Definition ObjectGuid.h:123
std::string const & GetPlayerName() const
Definition WorldSession.cpp:267

References BroadcastEvent(), CHAR_DEL_ARENA_TEAM, CHAR_DEL_ARENA_TEAM_MEMBERS, CharacterDatabase, DelMember(), ObjectGuid::Empty, ERR_ARENA_TEAM_DISBANDED_S, GetName(), WorldSession::GetPlayerName(), Members, sArenaTeamMgr, and PreparedStatementBase::SetData().

Referenced by arena_commandscript::HandleArenaDisbandCommand(), WorldSession::HandleArenaTeamLeaveOpcode(), and ArenaTeamMgr::LoadArenaTeams().

◆ Empty()

bool ArenaTeam::Empty ( ) const
inline
170{ return Members.empty(); }

References Members.

Referenced by LoadMembersFromDB().

◆ FinishGame()

void ArenaTeam::FinishGame ( int32  mod,
Map const *  bgMap 
)
788{
789 // Rating can only drop to 0
790 if (int32(Stats.Rating) + mod < 0)
791 Stats.Rating = 0;
792 else
793 {
794 Stats.Rating += mod;
795
796 // Check if rating related achivements are met
797 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
798 if (Player* member = ObjectAccessor::FindConnectedPlayer(itr->Guid))
799 if (member->FindMap() == bgMap)
800 member->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING, Stats.Rating, Type);
801 }
802
803 // Update number of games played per season or week
804 Stats.WeekGames += 1;
805 Stats.SeasonGames += 1;
806
807 // Update team's rank, start with rank 1 and increase until no team with more rating was found
808 Stats.Rank = 1;
809 ArenaTeamMgr::ArenaTeamContainer::const_iterator i = sArenaTeamMgr->GetArenaTeamMapBegin();
810 for (; i != sArenaTeamMgr->GetArenaTeamMapEnd(); ++i)
811 {
812 if (i->second->GetType() == Type && i->second->GetStats().Rating > Stats.Rating)
813 ++Stats.Rank;
814 }
815}
@ ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING
Definition DBCEnums.h:152
std::int32_t int32
Definition Define.h:103

References ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING, ObjectAccessor::FindConnectedPlayer(), Members, sArenaTeamMgr, and Type.

Referenced by Arena::EndBattleground(), LostAgainst(), and WonAgainst().

◆ FinishWeek()

bool ArenaTeam::FinishWeek ( )
993{
994 // No need to go further than this
995 if (Stats.WeekGames == 0)
996 return false;
997
998 // Reset team stats
999 Stats.WeekGames = 0;
1000 Stats.WeekWins = 0;
1001
1002 // Reset member stats
1003 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
1004 {
1005 itr->WeekGames = 0;
1006 itr->WeekWins = 0;
1007 }
1008
1009 return true;
1010}

References Members.

◆ GetAverageMMR()

uint32 ArenaTeam::GetAverageMMR ( Group *  group) const
695{
696 if (!group)
697 return 0;
698
699 uint32 matchMakerRating = 0;
700 uint32 playerDivider = 0;
701 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
702 {
703 // Skip if player is not online
705 continue;
706
707 // Skip if player is not member of group
708 if (!group->IsMember(itr->Guid))
709 continue;
710
711 matchMakerRating += itr->MatchMakerRating;
712 ++playerDivider;
713 }
714
715 // x/0 = crash
716 if (playerDivider == 0)
717 playerDivider = 1;
718
719 matchMakerRating /= playerDivider;
720
721 return matchMakerRating;
722}
bool IsMember(ObjectGuid guid) const
Definition Group.cpp:2555

References ObjectAccessor::FindConnectedPlayer(), Group::IsMember(), and Members.

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ GetCaptain()

◆ GetChanceAgainst()

float ArenaTeam::GetChanceAgainst ( uint32  ownRating,
uint32  opponentRating 
)
725{
726 // Returns the chance to win against a team with the given rating, used in the rating adjustment calculation
727 // ELO system
728 return 1.0f / (1.0f + (std::exp(std::log(10.0f) * (float)((float)opponentRating - (float)ownRating) / 650.0f)));
729}

Referenced by GetMatchmakerRatingMod(), and GetRatingMod().

◆ GetId()

◆ GetMatchmakerRatingMod()

int32 ArenaTeam::GetMatchmakerRatingMod ( uint32  ownRating,
uint32  opponentRating,
bool  won 
)
732{
733 // 'Chance' calculation - to beat the opponent
734 // This is a simulation. Not much info on how it really works
735 float chance = GetChanceAgainst(ownRating, opponentRating);
736 float won_mod = (won) ? 1.0f : 0.0f;
737 float mod = won_mod - chance;
738
739 // Work in progress:
740 /*
741 // This is a simulation, as there is not much info on how it really works
742 float confidence_mod = min(1.0f - std::fabs(mod), 0.5f);
743
744 // Apply confidence factor to the mod:
745 mod *= confidence_factor
746
747 // And only after that update the new confidence factor
748 confidence_factor -= ((confidence_factor - 1.0f) * confidence_mod) / confidence_factor;
749 */
750
751 // Real rating modification
752 mod *= sWorld->getFloatConfig(CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER);
753
754 return (int32)ceil(mod);
755}
@ CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER
Definition WorldConfig.h:166
float GetChanceAgainst(uint32 ownRating, uint32 opponentRating)
Definition ArenaTeam.cpp:724

References CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER, GetChanceAgainst(), and sWorld.

Referenced by LostAgainst(), and WonAgainst().

◆ GetMember() [1/2]

ArenaTeamMember * ArenaTeam::GetMember ( ObjectGuid  guid)
1028{
1029 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
1030 if (itr->Guid == guid)
1031 return &(*itr);
1032
1033 return nullptr;
1034}

References Members.

Referenced by Player::_LoadArenaTeamInfo(), GetMember(), WorldSession::HandleArenaTeamLeaderOpcode(), WorldSession::HandleArenaTeamRemoveOpcode(), Inspect(), and AchievementMgr::UpdateAchievementCriteria().

◆ GetMember() [2/2]

ArenaTeamMember * ArenaTeam::GetMember ( std::string const &  name)
1023{
1024 return GetMember(sCharacterCache->GetCharacterGuidByName(name));
1025}
ArenaTeamMember * GetMember(ObjectGuid guid)
Definition ArenaTeam.cpp:1027

References GetMember(), and sCharacterCache.

◆ GetMembers()

◆ GetMembersSize()

std::size_t ArenaTeam::GetMembersSize ( ) const
inline

◆ GetName()

◆ GetPoints()

uint32 ArenaTeam::GetPoints ( uint32  MemberRating)
665{
666 // Returns how many points would be awarded with this team type with this rating
667 float points;
668
669 uint32 rating = memberRating + 150 < Stats.Rating ? memberRating : Stats.Rating;
670
671 if (rating <= 1500)
672 {
673 if (sArenaSeasonMgr->GetCurrentSeason() < 6 && !sWorld->getIntConfig(CONFIG_LEGACY_ARENA_POINTS_CALC))
674 points = (float)rating * 0.22f + 14.0f;
675 else
676 points = 344;
677 }
678 else
679 points = 1511.26f / (1.0f + 1639.28f * std::exp(-0.00412f * (float)rating));
680
681 // Type penalties for teams < 5v5
682 if (Type == ARENA_TEAM_2v2)
683 points *= sWorld->getRate(RATE_ARENA_POINTS_2V2);
684 else if (Type == ARENA_TEAM_3v3)
685 points *= sWorld->getRate(RATE_ARENA_POINTS_3V3);
686
687 sScriptMgr->OnGetArenaPoints(this, points);
688
689 points *= sWorld->getRate(RATE_ARENA_POINTS);
690
691 return (uint32) points;
692}
@ ARENA_TEAM_2v2
Definition ArenaTeam.h:95
@ ARENA_TEAM_3v3
Definition ArenaTeam.h:96
@ RATE_ARENA_POINTS
Definition WorldConfig.h:487
@ RATE_ARENA_POINTS_3V3
Definition WorldConfig.h:489
@ RATE_ARENA_POINTS_2V2
Definition WorldConfig.h:488
@ CONFIG_LEGACY_ARENA_POINTS_CALC
Definition WorldConfig.h:300

References ARENA_TEAM_2v2, ARENA_TEAM_3v3, CONFIG_LEGACY_ARENA_POINTS_CALC, RATE_ARENA_POINTS, RATE_ARENA_POINTS_2V2, RATE_ARENA_POINTS_3V3, sArenaSeasonMgr, sScriptMgr, sWorld, and Type.

Referenced by UpdateArenaPointsHelper().

◆ GetPreviousOpponents()

uint32 ArenaTeam::GetPreviousOpponents ( )
inline
212{ return PreviousOpponents; }
uint32 PreviousOpponents
Definition ArenaTeam.h:239

References PreviousOpponents.

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ GetRating()

◆ GetRatingMod()

int32 ArenaTeam::GetRatingMod ( uint32  ownRating,
uint32  opponentRating,
bool  won 
)
Todo:
: Replace this hack with using the confidence factor (limiting the factor to 2.0f)
758{
759 // 'Chance' calculation - to beat the opponent
760 // This is a simulation. Not much info on how it really works
761 float chance = GetChanceAgainst(ownRating, opponentRating);
762
763 // Calculate the rating modification
764 float mod;
765
767 if (won)
768 {
769 if (ownRating < 1300)
770 {
771 float win_rating_modifier1 = sWorld->getFloatConfig(CONFIG_ARENA_WIN_RATING_MODIFIER_1);
772
773 if (ownRating < 1000)
774 mod = win_rating_modifier1 * (1.0f - chance);
775 else
776 mod = ((win_rating_modifier1 / 2.0f) + ((win_rating_modifier1 / 2.0f) * (1300.0f - float(ownRating)) / 300.0f)) * (1.0f - chance);
777 }
778 else
779 mod = sWorld->getFloatConfig(CONFIG_ARENA_WIN_RATING_MODIFIER_2) * (1.0f - chance);
780 }
781 else
782 mod = sWorld->getFloatConfig(CONFIG_ARENA_LOSE_RATING_MODIFIER) * (-chance);
783
784 return (int32)ceil(mod);
785}
@ CONFIG_ARENA_WIN_RATING_MODIFIER_1
Definition WorldConfig.h:163
@ CONFIG_ARENA_WIN_RATING_MODIFIER_2
Definition WorldConfig.h:164
@ CONFIG_ARENA_LOSE_RATING_MODIFIER
Definition WorldConfig.h:165

References CONFIG_ARENA_LOSE_RATING_MODIFIER, CONFIG_ARENA_WIN_RATING_MODIFIER_1, CONFIG_ARENA_WIN_RATING_MODIFIER_2, GetChanceAgainst(), and sWorld.

Referenced by LostAgainst(), MemberLost(), MemberWon(), and WonAgainst().

◆ GetReqPlayersForType()

uint8 ArenaTeam::GetReqPlayersForType ( uint32  type)
static
1037{
1038 auto const& itr = ArenaReqPlayersForType.find(type);
1039 if (itr == ArenaReqPlayersForType.end())
1040 {
1041 LOG_ERROR("bg.arena", "FATAL: Unknown arena type {}!", type);
1042 return 0xFF;
1043 }
1044
1045 return ArenaReqPlayersForType.at(type);
1046}
static std::unordered_map< uint8, uint8 > ArenaReqPlayersForType
Definition ArenaTeam.h:1112

References ArenaReqPlayersForType, and LOG_ERROR.

Referenced by BattlegroundMgr::CreateNewBattleground(), CreateTempArenaTeam(), and BattlegroundQueue::SendJoinMessageArenaQueue().

◆ GetSlot()

◆ GetSlotByType()

uint8 ArenaTeam::GetSlotByType ( uint32  type)
static
631{
632 uint8 slot = 0xFF;
633
634 auto const& itr = ArenaSlotByType.find(type);
635 if (itr == ArenaSlotByType.end())
636 {
637 LOG_ERROR("bg.arena", "Unknown arena team type {} for some arena team", type);
638 return slot;
639 }
640
641 slot = ArenaSlotByType.at(type);
642
643 // Get the changed slot type
644 sScriptMgr->OnGetSlotByType(type, slot);
645
646 if (slot != 0xFF)
647 {
648 return slot;
649 }
650
651 LOG_ERROR("bg.arena", "Unknown arena team type {} for some arena team", type);
652 return 0xFF;
653}
static std::unordered_map< uint32, uint8 > ArenaSlotByType
Definition ArenaTeam.h:1104

References ArenaSlotByType, LOG_ERROR, and sScriptMgr.

Referenced by CreateTempArenaTeam(), GetSlot(), WorldSession::HandleOfferPetitionOpcode(), WorldSession::HandlePetitionSignOpcode(), WorldSession::HandleTurnInPetitionOpcode(), ArenaTeamMember::ModifyPersonalRating(), and AchievementMgr::UpdateAchievementCriteria().

◆ GetStats()

◆ GetType()

◆ Inspect()

void ArenaTeam::Inspect ( WorldSession *  session,
ObjectGuid  guid 
)
526{
527 ArenaTeamMember* member = GetMember(guid);
528 if (!member || GetSlot() >= MAX_ARENA_SLOT)
529 return;
530
531 WorldPacket data(MSG_INSPECT_ARENA_TEAMS, 8 + 1 + 4 * 6);
532 data << guid; // player guid
533 data << uint8(GetSlot()); // slot (0...2)
534 data << uint32(GetId()); // arena team id
535 data << uint32(Stats.Rating); // rating
536 data << uint32(Stats.SeasonGames); // season played
537 data << uint32(Stats.SeasonWins); // season wins
538 data << uint32(member->SeasonGames); // played (count of all games, that the inspected member participated...)
539 data << uint32(member->PersonalRating); // personal rating
540 session->SendPacket(&data);
541}
#define MAX_ARENA_SLOT
Definition ArenaTeam.h:134
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition WorldSession.cpp:308
@ MSG_INSPECT_ARENA_TEAMS
Definition Opcodes.h:917

References GetId(), GetMember(), GetSlot(), MAX_ARENA_SLOT, MSG_INSPECT_ARENA_TEAMS, ArenaTeamMember::PersonalRating, ArenaTeamMember::SeasonGames, and WorldSession::SendPacket().

◆ IsFighting()

bool ArenaTeam::IsFighting ( ) const
1013{
1014 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
1015 if (Player* player = ObjectAccessor::FindPlayer(itr->Guid))
1016 if (player->GetMap()->IsBattleArena())
1017 return true;
1018
1019 return false;
1020}
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:269

References ObjectAccessor::FindPlayer(), and Members.

Referenced by arena_commandscript::HandleArenaCaptainCommand(), arena_commandscript::HandleArenaDisbandCommand(), arena_commandscript::HandleArenaRenameCommand(), WorldSession::HandleArenaTeamLeaveOpcode(), and WorldSession::HandleArenaTeamRemoveOpcode().

◆ IsMember()

bool ArenaTeam::IsMember ( ObjectGuid  guid) const
656{
657 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
658 if (itr->Guid == guid)
659 return true;
660
661 return false;
662}

References Members.

Referenced by arena_commandscript::HandleArenaCaptainCommand().

◆ LoadArenaTeamFromDB()

bool ArenaTeam::LoadArenaTeamFromDB ( QueryResult  arenaTeamDataResult)
209{
210 if (!result)
211 return false;
212
213 Field* fields = result->Fetch();
214
215 TeamId = fields[0].Get<uint32>();
216 TeamName = fields[1].Get<std::string>();
217 CaptainGuid = ObjectGuid::Create<HighGuid::Player>(fields[2].Get<uint32>());
218 Type = fields[3].Get<uint8>();
219 BackgroundColor = fields[4].Get<uint32>();
220 EmblemStyle = fields[5].Get<uint8>();
221 EmblemColor = fields[6].Get<uint32>();
222 BorderStyle = fields[7].Get<uint8>();
223 BorderColor = fields[8].Get<uint32>();
224 Stats.Rating = fields[9].Get<uint16>();
225 Stats.WeekGames = fields[10].Get<uint16>();
226 Stats.WeekWins = fields[11].Get<uint16>();
227 Stats.SeasonGames = fields[12].Get<uint16>();
228 Stats.SeasonWins = fields[13].Get<uint16>();
229 Stats.Rank = fields[14].Get<uint32>();
230
231 return true;
232}
Class used to access individual fields of database query result.
Definition Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:113

References BackgroundColor, BorderColor, BorderStyle, CaptainGuid, EmblemColor, EmblemStyle, Field::Get(), TeamName, and Type.

Referenced by ArenaTeamMgr::LoadArenaTeams().

◆ LoadMembersFromDB()

bool ArenaTeam::LoadMembersFromDB ( QueryResult  arenaTeamMembersResult)
235{
236 if (!result)
237 return false;
238
239 bool captainPresentInTeam = false;
240
241 do
242 {
243 Field* fields = result->Fetch();
244
245 // Prevent crash if db records are broken when all members in result are already processed and current team doesn't have any members
246 if (!fields)
247 break;
248
249 uint32 arenaTeamId = fields[0].Get<uint32>();
250
251 // We loaded all members for this arena_team already, break cycle
252 if (arenaTeamId > TeamId)
253 break;
254
255 ArenaTeamMember newMember;
256 newMember.Guid = ObjectGuid::Create<HighGuid::Player>(fields[1].Get<uint32>());
257 newMember.WeekGames = fields[2].Get<uint16>();
258 newMember.WeekWins = fields[3].Get<uint16>();
259 newMember.SeasonGames = fields[4].Get<uint16>();
260 newMember.SeasonWins = fields[5].Get<uint16>();
261 newMember.Name = fields[6].Get<std::string>();
262 newMember.Class = fields[7].Get<uint8>();
263 newMember.PersonalRating = fields[8].Get<uint16>();
264 newMember.MatchMakerRating = fields[9].Get<uint16>() > 0 ? fields[9].Get<uint16>() : sWorld->getIntConfig(CONFIG_ARENA_START_MATCHMAKER_RATING);
265 newMember.MaxMMR = std::max(fields[10].Get<uint16>(), newMember.MatchMakerRating);
266
267 // Delete member if character information is missing
268 if (fields[6].Get<std::string>().empty())
269 {
270 LOG_ERROR("sql.sql", "ArenaTeam {} has member with empty name - probably player {} doesn't exist, deleting him from memberlist!", arenaTeamId, newMember.Guid.ToString());
271 this->DelMember(newMember.Guid, true);
272 continue;
273 }
274
275 // Check if team team has a valid captain
276 if (newMember.Guid == GetCaptain())
277 captainPresentInTeam = true;
278
279 // Put the player in the team
280 Members.push_back(newMember);
281 sCharacterCache->UpdateCharacterArenaTeamId(newMember.Guid, GetSlot(), GetId());
282 } while (result->NextRow());
283
284 if (Empty() || !captainPresentInTeam)
285 {
286 // Arena team is empty or captain is not in team, delete from db
287 LOG_DEBUG("bg.battleground", "ArenaTeam {} does not have any members or its captain is not in team, disbanding it...", TeamId);
288 return false;
289 }
290
291 return true;
292}
bool Empty() const
Definition ArenaTeam.h:170
ObjectGuid GetCaptain() const
Definition ArenaTeam.h:153

References ArenaTeamMember::Class, CONFIG_ARENA_START_MATCHMAKER_RATING, DelMember(), Empty(), Field::Get(), GetCaptain(), GetId(), GetSlot(), ArenaTeamMember::Guid, LOG_DEBUG, LOG_ERROR, ArenaTeamMember::MatchMakerRating, ArenaTeamMember::MaxMMR, Members, ArenaTeamMember::Name, ArenaTeamMember::PersonalRating, sCharacterCache, ArenaTeamMember::SeasonGames, ArenaTeamMember::SeasonWins, sWorld, ObjectGuid::ToString(), ArenaTeamMember::WeekGames, and ArenaTeamMember::WeekWins.

Referenced by ArenaTeamMgr::LoadArenaTeams().

◆ LoadStatsFromDB()

void ArenaTeam::LoadStatsFromDB ( uint32  ArenaTeamId)

◆ LostAgainst()

int32 ArenaTeam::LostAgainst ( uint32  Own_MMRating,
uint32  Opponent_MMRating,
int32 &  rating_change,
Map const *  bgMap 
)
838{
839 // Called when the team has lost
840 // Change in Matchmaker Rating
841 int32 mod = GetMatchmakerRatingMod(Own_MMRating, Opponent_MMRating, false);
842
843 // Change in Team Rating
844 rating_change = GetRatingMod(Stats.Rating, Opponent_MMRating, false);
845
846 // Modify the team stats accordingly
847 FinishGame(rating_change, bgMap);
848
849 // return the rating change, used to display it on the results screen
850 return mod;
851}
int32 GetRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition ArenaTeam.cpp:757
int32 GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition ArenaTeam.cpp:731
void FinishGame(int32 mod, Map const *bgMap)
Definition ArenaTeam.cpp:787

References FinishGame(), GetMatchmakerRatingMod(), and GetRatingMod().

Referenced by Arena::EndBattleground().

◆ m_membersBegin()

MemberList::iterator ArenaTeam::m_membersBegin ( )
inline
171{ return Members.begin(); }

References Members.

◆ m_membersEnd()

MemberList::iterator ArenaTeam::m_membersEnd ( )
inline
172{ return Members.end(); }

References Members.

◆ MassInviteToEvent()

void ArenaTeam::MassInviteToEvent ( WorldSession *  session)
614{
615 WorldPacket data(SMSG_CALENDAR_ARENA_TEAM, (Members.size() - 1) * (4 + 8 + 1));
616 data << uint32(Members.size() - 1);
617
618 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
619 {
620 if (itr->Guid != session->GetPlayer()->GetGUID())
621 {
622 data << itr->Guid.WriteAsPacked();
623 data << uint8(0); // unk
624 }
625 }
626
627 session->SendPacket(&data);
628}
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:120
Player * GetPlayer() const
Definition WorldSession.h:503
@ SMSG_CALENDAR_ARENA_TEAM
Definition Opcodes.h:1111

References Object::GetGUID(), WorldSession::GetPlayer(), Members, WorldSession::SendPacket(), and SMSG_CALENDAR_ARENA_TEAM.

◆ MemberLost()

void ArenaTeam::MemberLost ( Player *  player,
uint32  againstMatchmakerRating,
int32  MatchmakerRatingChange = -12 
)
854{
855 // Called for each participant of a match after losing
856 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
857 {
858 if (itr->Guid == player->GetGUID())
859 {
860 // Update personal rating
861 int32 mod = GetRatingMod(itr->PersonalRating, againstMatchmakerRating, false);
862 itr->ModifyPersonalRating(player, mod, GetType());
863
864 // Update matchmaker rating
865 itr->ModifyMatchmakerRating(MatchmakerRatingChange, GetSlot());
866
867 // Update personal played stats
868 itr->WeekGames += 1;
869 itr->SeasonGames += 1;
870
871 // update the unit fields
872 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_WEEK, itr->WeekGames);
873 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_SEASON, itr->SeasonGames);
874 return;
875 }
876 }
877}
@ ARENA_TEAM_GAMES_WEEK
Definition ArenaTeam.h:77
@ ARENA_TEAM_GAMES_SEASON
Definition ArenaTeam.h:78

References ARENA_TEAM_GAMES_SEASON, ARENA_TEAM_GAMES_WEEK, Object::GetGUID(), GetRatingMod(), GetSlot(), GetType(), Members, and Player::SetArenaTeamInfoField().

Referenced by Arena::EndBattleground(), and Arena::RemovePlayerAtLeave().

◆ MemberWon()

void ArenaTeam::MemberWon ( Player *  player,
uint32  againstMatchmakerRating,
int32  MatchmakerRatingChange 
)
880{
881 // called for each participant after winning a match
882 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
883 {
884 if (itr->Guid == player->GetGUID())
885 {
886 // update personal rating
887 int32 mod = GetRatingMod(itr->PersonalRating, againstMatchmakerRating, true);
888 sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
889 itr->ModifyPersonalRating(player, mod, GetType());
890
891 // update matchmaker rating (pussywizard: but don't allow it to go over team rating)
892 if (itr->MatchMakerRating < Stats.Rating)
893 {
894 mod = std::min(MatchmakerRatingChange, Stats.Rating - itr->MatchMakerRating);
895 sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
896 itr->ModifyMatchmakerRating(mod, GetSlot());
897 }
898
899 // update personal stats
900 itr->WeekGames += 1;
901 itr->SeasonGames += 1;
902 itr->SeasonWins += 1;
903 itr->WeekWins += 1;
904 // update unit fields
905 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_WEEK, itr->WeekGames);
906 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_SEASON, itr->SeasonGames);
907 return;
908 }
909 }
910}

References ARENA_TEAM_GAMES_SEASON, ARENA_TEAM_GAMES_WEEK, Object::GetGUID(), GetRatingMod(), GetSlot(), GetType(), Members, Player::SetArenaTeamInfoField(), and sScriptMgr.

Referenced by Arena::EndBattleground().

◆ NotifyStatsChanged()

void ArenaTeam::NotifyStatsChanged ( )
517{
518 // This is called after a rated match ended
519 // Updates arena team stats for every member of the team (not only the ones who participated!)
520 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
521 if (Player* player = ObjectAccessor::FindConnectedPlayer(itr->Guid))
522 SendStats(player->GetSession());
523}
void SendStats(WorldSession *session)
Definition ArenaTeam.cpp:503

References ObjectAccessor::FindConnectedPlayer(), Members, and SendStats().

Referenced by Arena::EndBattleground().

◆ Query()

void ArenaTeam::Query ( WorldSession *  session)
489{
490 WorldPacket data(SMSG_ARENA_TEAM_QUERY_RESPONSE, 4 * 7 + GetName().size() + 1);
491 data << uint32(GetId()); // team id
492 data << GetName(); // team name
493 data << uint32(GetType()); // arena team type (2=2x2, 3=3x3 or 5=5x5)
494 data << uint32(BackgroundColor); // background color
495 data << uint32(EmblemStyle); // emblem style
496 data << uint32(EmblemColor); // emblem color
497 data << uint32(BorderStyle); // border style
498 data << uint32(BorderColor); // border color
499 session->SendPacket(&data);
500 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_QUERY_RESPONSE");
501}
@ SMSG_ARENA_TEAM_QUERY_RESPONSE
Definition Opcodes.h:874

References BackgroundColor, BorderColor, BorderStyle, EmblemColor, EmblemStyle, GetId(), GetName(), GetType(), LOG_DEBUG, WorldSession::SendPacket(), and SMSG_ARENA_TEAM_QUERY_RESPONSE.

◆ Roster()

void ArenaTeam::Roster ( WorldSession *  session)
448{
449 Player* player = nullptr;
450
451 uint8 unk308 = 0;
452 std::string tempName;
453
455 data << uint32(GetId()); // team id
456 data << uint8(unk308); // 308 unknown value but affect packet structure
457 data << uint32(GetMembersSize()); // members count
458 data << uint32(GetType()); // arena team type?
459
460 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
461 {
462 player = ObjectAccessor::FindConnectedPlayer(itr->Guid);
463
464 data << itr->Guid; // guid
465 data << uint8((player ? 1 : 0)); // online flag
466 tempName = "";
467 sCharacterCache->GetCharacterNameByGuid(itr->Guid, tempName);
468 data << tempName; // member name
469 data << uint32((itr->Guid == GetCaptain() ? 0 : 1));// captain flag 0 captain 1 member
470 data << uint8((player ? player->GetLevel() : 0)); // unknown, level?
471 data << uint8(itr->Class); // class
472 data << uint32(itr->WeekGames); // played this week
473 data << uint32(itr->WeekWins); // wins this week
474 data << uint32(itr->SeasonGames); // played this season
475 data << uint32(itr->SeasonWins); // wins this season
476 data << uint32(itr->PersonalRating); // personal rating
477 if (unk308)
478 {
479 data << float(0.0f); // 308 unk
480 data << float(0.0f); // 308 unk
481 }
482 }
483
484 session->SendPacket(&data);
485 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_ROSTER");
486}
uint8 GetLevel() const
Definition Unit.h:1109
@ SMSG_ARENA_TEAM_ROSTER
Definition Opcodes.h:876

References ObjectAccessor::FindConnectedPlayer(), GetCaptain(), GetId(), Unit::GetLevel(), GetMembersSize(), GetType(), LOG_DEBUG, Members, sCharacterCache, WorldSession::SendPacket(), and SMSG_ARENA_TEAM_ROSTER.

◆ SaveToDB()

void ArenaTeam::SaveToDB ( bool  forceMemberSave = false)
943{
944 if (!sScriptMgr->CanSaveToDB(this))
945 return;
946
947 // Save team and member stats to db
948 // Called after a match has ended or when calculating arena_points
949
950 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
951
953 stmt->SetData(0, Stats.Rating);
954 stmt->SetData(1, Stats.WeekGames);
955 stmt->SetData(2, Stats.WeekWins);
956 stmt->SetData(3, Stats.SeasonGames);
957 stmt->SetData(4, Stats.SeasonWins);
958 stmt->SetData(5, Stats.Rank);
959 stmt->SetData(6, GetId());
960 trans->Append(stmt);
961
962 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
963 {
964 // Save the effort and go
965 if (itr->WeekGames == 0 && !forceMemberSave)
966 continue;
967
968 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ARENA_TEAM_MEMBER);
969 stmt->SetData(0, itr->PersonalRating);
970 stmt->SetData(1, itr->WeekGames);
971 stmt->SetData(2, itr->WeekWins);
972 stmt->SetData(3, itr->SeasonGames);
973 stmt->SetData(4, itr->SeasonWins);
974 stmt->SetData(5, GetId());
975 stmt->SetData(6, itr->Guid.GetCounter());
976 trans->Append(stmt);
977
978 if (sScriptMgr->CanSaveArenaStatsForMember(this, itr->Guid))
979 {
980 stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHARACTER_ARENA_STATS);
981 stmt->SetData(0, itr->Guid.GetCounter());
982 stmt->SetData(1, GetSlot());
983 stmt->SetData(2, itr->MatchMakerRating);
984 stmt->SetData(3, itr->MaxMMR);
985 trans->Append(stmt);
986 }
987 }
988
989 CharacterDatabase.CommitTransaction(trans);
990}
@ CHAR_UPD_ARENA_TEAM_STATS
Definition CharacterDatabase.h:231
@ CHAR_REP_CHARACTER_ARENA_STATS
Definition CharacterDatabase.h:233
@ CHAR_UPD_ARENA_TEAM_MEMBER
Definition CharacterDatabase.h:232

References CHAR_REP_CHARACTER_ARENA_STATS, CHAR_UPD_ARENA_TEAM_MEMBER, CHAR_UPD_ARENA_TEAM_STATS, CharacterDatabase, GetId(), GetSlot(), Members, PreparedStatementBase::SetData(), and sScriptMgr.

Referenced by Arena::EndBattleground(), and SetRatingForAll().

◆ SendStats()

void ArenaTeam::SendStats ( WorldSession *  session)
504{
506 data << uint32(GetId()); // team id
507 data << uint32(Stats.Rating); // rating
508 data << uint32(Stats.WeekGames); // games this week
509 data << uint32(Stats.WeekWins); // wins this week
510 data << uint32(Stats.SeasonGames); // played this season
511 data << uint32(Stats.SeasonWins); // wins this season
512 data << uint32(Stats.Rank); // rank
513 session->SendPacket(&data);
514}
@ SMSG_ARENA_TEAM_STATS
Definition Opcodes.h:889

References GetId(), WorldSession::SendPacket(), and SMSG_ARENA_TEAM_STATS.

Referenced by NotifyStatsChanged().

◆ SetArenaTeamStats()

void ArenaTeam::SetArenaTeamStats ( ArenaTeamStats &  stats)
inline
156{ Stats = stats; }

Referenced by ArenaTeamWithRating().

◆ SetCaptain()

void ArenaTeam::SetCaptain ( ObjectGuid  guid)
308{
309 // Disable remove/promote buttons
311 if (oldCaptain)
313
314 // Set new captain
315 CaptainGuid = guid;
316
317 // Update database
319 stmt->SetData(0, guid.GetCounter());
320 stmt->SetData(1, GetId());
321 CharacterDatabase.Execute(stmt);
322
323 // Enable remove/promote buttons
324 if (Player* newCaptain = ObjectAccessor::FindConnectedPlayer(guid))
325 {
326 newCaptain->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_MEMBER, 0);
327 /*if (oldCaptain)
328 {
329 LOG_DEBUG("bg.battleground", "Player: {} [{}] promoted player: {} [{}] to leader of arena team [Id: {}] [Type: {}].",
330 oldCaptain->GetName(), oldCaptain->GetGUID().ToString(), newCaptain->GetName(),
331 newCaptain->GetGUID().ToString(), GetId(), GetType());
332 }*/
333 }
334}
@ CHAR_UPD_ARENA_TEAM_CAPTAIN
Definition CharacterDatabase.h:229

References ARENA_TEAM_MEMBER, CaptainGuid, CHAR_UPD_ARENA_TEAM_CAPTAIN, CharacterDatabase, ObjectAccessor::FindConnectedPlayer(), GetCaptain(), ObjectGuid::GetCounter(), GetId(), GetSlot(), Player::SetArenaTeamInfoField(), and PreparedStatementBase::SetData().

Referenced by arena_commandscript::HandleArenaCaptainCommand(), and WorldSession::HandleArenaTeamLeaderOpcode().

◆ SetEmblem()

void ArenaTeam::SetEmblem ( uint32  backgroundColor,
uint8  emblemStyle,
uint32  emblemColor,
uint8  borderStyle,
uint32  borderColor 
)
1121{
1122 BackgroundColor = backgroundColor;
1123 EmblemStyle = emblemStyle;
1124 EmblemColor = emblemColor;
1125 BorderStyle = borderStyle;
1126 BorderColor = borderColor;
1127
1128 if (!sScriptMgr->CanSaveToDB(this))
1129 return;
1130
1132 stmt->SetData(0, BackgroundColor);
1133 stmt->SetData(1, EmblemStyle);
1134 stmt->SetData(2, EmblemColor);
1135 stmt->SetData(3, BorderStyle);
1136 stmt->SetData(4, BorderColor);
1137 stmt->SetData(5, GetId());
1138 CharacterDatabase.Execute(stmt);
1139}
@ CHAR_UPD_ARENA_TEAM_EMBLEM
Definition CharacterDatabase.h:236

References BackgroundColor, BorderColor, BorderStyle, CHAR_UPD_ARENA_TEAM_EMBLEM, CharacterDatabase, EmblemColor, EmblemStyle, GetId(), PreparedStatementBase::SetData(), and sScriptMgr.

◆ SetName()

bool ArenaTeam::SetName ( std::string const &  name)
295{
296 if (TeamName == name || name.empty() || name.length() > 24 || !ObjectMgr::IsValidCharterName(name))
297 return false;
298
299 TeamName = name;
301 stmt->SetData(0, TeamName);
302 stmt->SetData(1, GetId());
303 CharacterDatabase.Execute(stmt);
304 return true;
305}
@ CHAR_UPD_ARENA_TEAM_NAME
Definition CharacterDatabase.h:235
static bool IsValidCharterName(std::string_view name)
Definition ObjectMgr.cpp:9319

References CHAR_UPD_ARENA_TEAM_NAME, CharacterDatabase, GetId(), ObjectMgr::IsValidCharterName(), PreparedStatementBase::SetData(), and TeamName.

Referenced by arena_commandscript::HandleArenaRenameCommand().

◆ SetPreviousOpponents()

void ArenaTeam::SetPreviousOpponents ( uint32  arenaTeamId)
inline
211{ PreviousOpponents = arenaTeamId; }

References PreviousOpponents.

Referenced by Arena::EndBattleground().

◆ SetRatingForAll()

void ArenaTeam::SetRatingForAll ( uint32  rating)
1142{
1143 Stats.Rating = rating;
1144
1145 for (ArenaTeamMember& member : Members)
1146 member.PersonalRating = rating;
1147
1148 SaveToDB(true);
1149}
void SaveToDB(bool forceMemberSave=false)
Definition ArenaTeam.cpp:942

References Members, and SaveToDB().

◆ UpdateArenaPointsHelper()

void ArenaTeam::UpdateArenaPointsHelper ( std::map< ObjectGuid, uint32 > &  PlayerPoints)
913{
914 // Called after a match has ended and the stats are already modified
915 // Helper function for arena point distribution (this way, when distributing, no actual calculation is required, just a few comparisons)
916 // 10 played games per week is a minimum
917 if (Stats.WeekGames < sWorld->getIntConfig(CONFIG_ARENA_GAMES_REQUIRED))
918 return;
919
920 // To get points, a player has to participate in at least 30% of the matches
921 uint32 requiredGames = (uint32)ceil(Stats.WeekGames * 0.3f);
922
923 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
924 {
925 // The player participated in enough games, update his points
926 uint32 pointsToAdd = 0;
927 if (itr->WeekGames >= requiredGames)
928 pointsToAdd = GetPoints(itr->PersonalRating);
929
930 std::map<ObjectGuid, uint32>::iterator plr_itr = playerPoints.find(itr->Guid);
931 if (plr_itr != playerPoints.end())
932 {
933 // Check if there is already more points
934 if (plr_itr->second < pointsToAdd)
935 playerPoints[itr->Guid] = pointsToAdd;
936 }
937 else
938 playerPoints[itr->Guid] = pointsToAdd;
939 }
940}
@ CONFIG_ARENA_GAMES_REQUIRED
Definition WorldConfig.h:297
uint32 GetPoints(uint32 MemberRating)
Definition ArenaTeam.cpp:664

References CONFIG_ARENA_GAMES_REQUIRED, GetPoints(), Members, and sWorld.

◆ WonAgainst()

int32 ArenaTeam::WonAgainst ( uint32  Own_MMRating,
uint32  Opponent_MMRating,
int32 &  rating_change,
Map const *  bgMap 
)
818{
819 // Called when the team has won
820 // Change in Matchmaker rating
821 int32 mod = GetMatchmakerRatingMod(Own_MMRating, Opponent_MMRating, true);
822
823 // Change in Team Rating
824 rating_change = GetRatingMod(Stats.Rating, Opponent_MMRating, true);
825
826 // Modify the team stats accordingly
827 FinishGame(rating_change, bgMap);
828
829 // Update number of wins per season and week
830 Stats.WeekWins += 1;
831 Stats.SeasonWins += 1;
832
833 // Return the rating change, used to display it on the results screen
834 return mod;
835}

References FinishGame(), GetMatchmakerRatingMod(), and GetRatingMod().

Referenced by Arena::EndBattleground().

Member Data Documentation

◆ ArenaReqPlayersForType

std::unordered_map< uint8, uint8 > ArenaTeam::ArenaReqPlayersForType
static
Initial value:
=
{
}
1142{
1145 ERR_ARENA_TEAM_QUIT_S = 0x03,
1147};
1148
1150{
1170};
1171
1172enum ArenaTeamEvents
1173{
1174 ERR_ARENA_TEAM_JOIN_SS = 3, // player name + arena team name
1175 ERR_ARENA_TEAM_LEAVE_SS = 4, // player name + arena team name
1176 ERR_ARENA_TEAM_REMOVE_SSS = 5, // player name + arena team name + captain name
1177 ERR_ARENA_TEAM_LEADER_IS_SS = 6, // player name + arena team name
1178 ERR_ARENA_TEAM_LEADER_CHANGED_SSS = 7, // old captain + new captain + arena team name
1179 ERR_ARENA_TEAM_DISBANDED_S = 8 // captain name + arena team name
1180};
1181
1182// PLAYER_FIELD_ARENA_TEAM_INFO_1_1 offsets
1184{
1185 ARENA_TEAM_ID = 0,
1186 ARENA_TEAM_TYPE = 1, // new in 3.2 - team type?
1187 ARENA_TEAM_MEMBER = 2, // 0 - captain, 1 - member
1192 ARENA_TEAM_END = 7
1193};
1194
1195/*
1196need info how to send these ones:
1197ERR_ARENA_TEAM_YOU_JOIN_S - client show it automatically when accept invite
1198ERR_ARENA_TEAM_TARGET_TOO_LOW_S
1199ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S
1200ERR_ARENA_TEAM_LEVEL_TOO_LOW_I
1201*/
1202
1203// EnumUtils: DESCRIBE THIS
1204enum ArenaTeamTypes
1205{
1206 ARENA_TEAM_2v2 = 2,
1207 ARENA_TEAM_3v3 = 3,
1208 ARENA_TEAM_5v5 = 5
1209};
1210
1211enum ArenaSlot
1212{
1216};
1217
1218struct ArenaTeamMember
1219{
1220 ObjectGuid Guid;
1221 std::string Name;
1222 uint8 Class;
1223 uint16 WeekGames;
1224 uint16 WeekWins;
1225 uint16 SeasonGames;
1226 uint16 SeasonWins;
1227 uint16 PersonalRating;
1228 uint16 MatchMakerRating;
1229 uint16 MaxMMR;
1230
1231 void ModifyPersonalRating(Player* player, int32 mod, uint32 type);
1232 void ModifyMatchmakerRating(int32 mod, uint32 slot);
1233};
1234
1235struct ArenaTeamStats
1236{
1237 uint16 Rating;
1238 uint16 WeekGames;
1239 uint16 WeekWins;
1240 uint16 SeasonGames;
1241 uint16 SeasonWins;
1242 uint32 Rank;
1243};
1244
1245#define MAX_ARENA_SLOT 4 // 0..2 slots
1246
1247class ArenaTeam
1248{
1249public:
1250 ArenaTeam();
1251 ~ArenaTeam();
1252
1253 bool Create(ObjectGuid captainGuid, uint8 type, std::string const& teamName, uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor);
1254 void Disband(WorldSession* session);
1255 void Disband();
1256
1257 typedef std::list<ArenaTeamMember> MemberList;
1258
1259 [[nodiscard]] uint32 GetId() const { return TeamId; }
1260 [[nodiscard]] uint32 GetType() const { return Type; }
1261 [[nodiscard]] uint8 GetSlot() const { return GetSlotByType(GetType()); }
1262 static uint8 GetSlotByType(uint32 type);
1263 static uint8 GetReqPlayersForType(uint32 type);
1264 [[nodiscard]] ObjectGuid GetCaptain() const { return CaptainGuid; }
1265 [[nodiscard]] std::string const& GetName() const { return TeamName; }
1266 [[nodiscard]] ArenaTeamStats const& GetStats() const { return Stats; }
1267 void SetArenaTeamStats(ArenaTeamStats& stats) { Stats = stats; }
1268
1269 [[nodiscard]] uint32 GetRating() const { return Stats.Rating; }
1270 uint32 GetAverageMMR(Group* group) const;
1271
1272 void SetCaptain(ObjectGuid guid);
1273 bool SetName(std::string const& name);
1274 bool AddMember(ObjectGuid playerGuid);
1275
1276 // Shouldn't be ObjectGuid, because than can reference guid from members on Disband
1277 // and this method removes given record from list. So invalid reference can happen.
1278 void DelMember(ObjectGuid guid, bool cleanDb);
1279
1280 [[nodiscard]] std::size_t GetMembersSize() const { return Members.size(); }
1281 [[nodiscard]] bool Empty() const { return Members.empty(); }
1282 MemberList::iterator m_membersBegin() { return Members.begin(); }
1283 MemberList::iterator m_membersEnd() { return Members.end(); }
1284 MemberList& GetMembers() { return Members; }
1285 [[nodiscard]] bool IsMember(ObjectGuid guid) const;
1286
1288 ArenaTeamMember* GetMember(std::string const& name);
1289
1290 [[nodiscard]] bool IsFighting() const;
1291
1292 bool LoadArenaTeamFromDB(QueryResult arenaTeamDataResult);
1293 bool LoadMembersFromDB(QueryResult arenaTeamMembersResult);
1294 void LoadStatsFromDB(uint32 ArenaTeamId);
1295 void SaveToDB(bool forceMemberSave = false);
1296
1297 void BroadcastPacket(WorldPacket* packet);
1298 void BroadcastEvent(ArenaTeamEvents event, ObjectGuid guid, uint8 strCount, std::string const& str1, std::string const& str2, std::string const& str3);
1299 void NotifyStatsChanged();
1300
1301 void MassInviteToEvent(WorldSession* session);
1302
1303 void Roster(WorldSession* session);
1304 void Query(WorldSession* session);
1305 void SendStats(WorldSession* session);
1306 void Inspect(WorldSession* session, ObjectGuid guid);
1307
1308 uint32 GetPoints(uint32 MemberRating);
1309 int32 GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won);
1310 int32 GetRatingMod(uint32 ownRating, uint32 opponentRating, bool won);
1311 float GetChanceAgainst(uint32 ownRating, uint32 opponentRating);
1312 int32 WonAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32& rating_change, Map const* bgMap);
1313 void MemberWon(Player* player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange);
1314 int32 LostAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32& rating_change, Map const* bgMap);
1315 void MemberLost(Player* player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange = -12);
1316
1317 void UpdateArenaPointsHelper(std::map<ObjectGuid, uint32>& PlayerPoints);
1318
1319 bool FinishWeek(); // returns true if arena team played this week
1320 void FinishGame(int32 mod, Map const* bgMap);
1321
1322 void SetPreviousOpponents(uint32 arenaTeamId) { PreviousOpponents = arenaTeamId; }
1324
1325 void CreateTempArenaTeam(std::vector<Player*> playerList, uint8 type, std::string const& teamName);
1326
1327 // Containers
1328 static std::unordered_map<uint32, uint8> ArenaSlotByType; // Slot -> Type
1329 static std::unordered_map<uint8, uint8> ArenaReqPlayersForType; // Type -> Players count
1330
1331 void SetEmblem(uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle,
1332 uint32 borderColor);
1333 void SetRatingForAll(uint32 rating);
1334
1335protected:
1336 uint32 TeamId;
1337 uint8 Type;
1338 std::string TeamName;
1340
1341 uint32 BackgroundColor; // ARGB format
1342 uint8 EmblemStyle; // icon id
1343 uint32 EmblemColor; // ARGB format
1344 uint8 BorderStyle; // border image id
1345 uint32 BorderColor; // ARGB format
1346
1349
1351};
1352#endif
@ ERR_ARENA_TEAM_FOUNDER_S
Definition ArenaTeam.h:35
@ ERR_ARENA_TEAM_INVITE_SS
Definition ArenaTeam.h:33
@ ERR_ARENA_TEAM_CREATE_S
Definition ArenaTeam.h:32
ArenaTeamTypes
Definition ArenaTeam.h:94
@ ARENA_TEAM_5v5
Definition ArenaTeam.h:97
@ ARENA_TEAM_TYPE
Definition ArenaTeam.h:75
@ ARENA_TEAM_ID
Definition ArenaTeam.h:74
@ ARENA_TEAM_PERSONAL_RATING
Definition ArenaTeam.h:80
@ ARENA_TEAM_WINS_SEASON
Definition ArenaTeam.h:79
ArenaTeamCommandErrors
Definition ArenaTeam.h:39
@ ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S
Definition ArenaTeam.h:56
@ ERR_ARENA_TEAM_TARGET_TOO_HIGH_S
Definition ArenaTeam.h:55
@ ERR_ARENA_TEAM_NAME_INVALID
Definition ArenaTeam.h:45
@ ERR_ALREADY_IN_ARENA_TEAM_S
Definition ArenaTeam.h:42
@ ERR_ARENA_TEAM_INTERNAL
Definition ArenaTeam.h:40
@ ERR_INVITED_TO_ARENA_TEAM
Definition ArenaTeam.h:43
@ ERR_ALREADY_IN_ARENA_TEAM
Definition ArenaTeam.h:41
@ ERR_ARENA_TEAM_IGNORING_YOU_S
Definition ArenaTeam.h:53
@ ERR_ARENA_TEAM_NOT_FOUND
Definition ArenaTeam.h:57
@ ERR_ARENA_TEAMS_LOCKED
Definition ArenaTeam.h:58
@ ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM
Definition ArenaTeam.h:49
@ ERR_ARENA_TEAM_LEADER_LEAVE_S
Definition ArenaTeam.h:47
@ ERR_ARENA_TEAM_PERMISSIONS
Definition ArenaTeam.h:48
@ ERR_ARENA_TEAM_NOT_ALLIED
Definition ArenaTeam.h:52
@ ERR_ARENA_TEAM_TARGET_TOO_LOW_S
Definition ArenaTeam.h:54
@ ERR_ARENA_TEAM_PLAYER_NOT_FOUND_S
Definition ArenaTeam.h:51
@ ERR_ALREADY_INVITED_TO_ARENA_TEAM_S
Definition ArenaTeam.h:44
@ ERR_ARENA_TEAM_NAME_EXISTS_S
Definition ArenaTeam.h:46
@ ERR_ARENA_TEAM_PLAYER_NOT_IN_TEAM_SS
Definition ArenaTeam.h:50
ArenaTeamEvents
Definition ArenaTeam.h:62
@ ERR_ARENA_TEAM_LEADER_CHANGED_SSS
Definition ArenaTeam.h:67
@ ERR_ARENA_TEAM_REMOVE_SSS
Definition ArenaTeam.h:65
@ ERR_ARENA_TEAM_LEAVE_SS
Definition ArenaTeam.h:64
@ ERR_ARENA_TEAM_JOIN_SS
Definition ArenaTeam.h:63
@ ERR_ARENA_TEAM_LEADER_IS_SS
Definition ArenaTeam.h:66
ArenaSlot
Definition ArenaTeam.h:101
@ ARENA_SLOT_2v2
Definition ArenaTeam.h:102
@ ARENA_SLOT_5v5
Definition ArenaTeam.h:104
@ ARENA_SLOT_3v3
Definition ArenaTeam.h:103
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
@ Class
Requires the player to be a specific class.
uint32 GetPreviousOpponents()
Definition ArenaTeam.h:212
MemberList::iterator m_membersBegin()
Definition ArenaTeam.h:171
void Inspect(WorldSession *session, ObjectGuid guid)
Definition ArenaTeam.cpp:525
ArenaTeamStats const & GetStats() const
Definition ArenaTeam.h:155
void Roster(WorldSession *session)
Definition ArenaTeam.cpp:447
void CreateTempArenaTeam(std::vector< Player * > playerList, uint8 type, std::string const &teamName)
Definition ArenaTeam.cpp:1048
bool LoadArenaTeamFromDB(QueryResult arenaTeamDataResult)
Definition ArenaTeam.cpp:208
ArenaTeam()
Definition ArenaTeam.cpp:32
std::list< ArenaTeamMember > MemberList
Definition ArenaTeam.h:146
void MemberLost(Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange=-12)
Definition ArenaTeam.cpp:853
bool IsMember(ObjectGuid guid) const
Definition ArenaTeam.cpp:655
MemberList & GetMembers()
Definition ArenaTeam.h:173
void SetPreviousOpponents(uint32 arenaTeamId)
Definition ArenaTeam.h:211
bool SetName(std::string const &name)
Definition ArenaTeam.cpp:294
bool FinishWeek()
Definition ArenaTeam.cpp:992
bool Create(ObjectGuid captainGuid, uint8 type, std::string const &teamName, uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor)
Definition ArenaTeam.cpp:50
void Query(WorldSession *session)
Definition ArenaTeam.cpp:488
void SetCaptain(ObjectGuid guid)
Definition ArenaTeam.cpp:307
int32 LostAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32 &rating_change, Map const *bgMap)
Definition ArenaTeam.cpp:837
void UpdateArenaPointsHelper(std::map< ObjectGuid, uint32 > &PlayerPoints)
Definition ArenaTeam.cpp:912
void NotifyStatsChanged()
Definition ArenaTeam.cpp:516
int32 WonAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32 &rating_change, Map const *bgMap)
Definition ArenaTeam.cpp:817
~ArenaTeam()
Definition ArenaTeam.cpp:46
void MassInviteToEvent(WorldSession *session)
Definition ArenaTeam.cpp:613
void SetRatingForAll(uint32 rating)
Definition ArenaTeam.cpp:1141
void Disband()
Definition ArenaTeam.cpp:424
uint32 GetAverageMMR(Group *group) const
Definition ArenaTeam.cpp:694
bool IsFighting() const
Definition ArenaTeam.cpp:1012
void LoadStatsFromDB(uint32 ArenaTeamId)
MemberList::iterator m_membersEnd()
Definition ArenaTeam.h:172
bool LoadMembersFromDB(QueryResult arenaTeamMembersResult)
Definition ArenaTeam.cpp:234
void MemberWon(Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange)
Definition ArenaTeam.cpp:879
void SetArenaTeamStats(ArenaTeamStats &stats)
Definition ArenaTeam.h:156
void SetEmblem(uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor)
Definition ArenaTeam.cpp:1119
Definition Map.h:168
Definition ObjectGuid.h:121
Player session in the World.
Definition WorldSession.h:430
Definition ArenaTeam.h:125
uint16 Rating
Definition ArenaTeam.h:126

Referenced by GetReqPlayersForType().

◆ ArenaSlotByType

std::unordered_map< uint32, uint8 > ArenaTeam::ArenaSlotByType
static
Initial value:
1134{
1137 ERR_ARENA_TEAM_QUIT_S = 0x03,
1139};
1140
1142{
1162};
1163
1164enum ArenaTeamEvents
1165{
1166 ERR_ARENA_TEAM_JOIN_SS = 3, // player name + arena team name
1167 ERR_ARENA_TEAM_LEAVE_SS = 4, // player name + arena team name
1168 ERR_ARENA_TEAM_REMOVE_SSS = 5, // player name + arena team name + captain name
1169 ERR_ARENA_TEAM_LEADER_IS_SS = 6, // player name + arena team name
1170 ERR_ARENA_TEAM_LEADER_CHANGED_SSS = 7, // old captain + new captain + arena team name
1171 ERR_ARENA_TEAM_DISBANDED_S = 8 // captain name + arena team name
1172};
1173
1174// PLAYER_FIELD_ARENA_TEAM_INFO_1_1 offsets
1176{
1177 ARENA_TEAM_ID = 0,
1178 ARENA_TEAM_TYPE = 1, // new in 3.2 - team type?
1179 ARENA_TEAM_MEMBER = 2, // 0 - captain, 1 - member
1184 ARENA_TEAM_END = 7
1185};
1186
1187/*
1188need info how to send these ones:
1189ERR_ARENA_TEAM_YOU_JOIN_S - client show it automatically when accept invite
1190ERR_ARENA_TEAM_TARGET_TOO_LOW_S
1191ERR_ARENA_TEAM_TOO_MANY_MEMBERS_S
1192ERR_ARENA_TEAM_LEVEL_TOO_LOW_I
1193*/
1194
1195// EnumUtils: DESCRIBE THIS
1196enum ArenaTeamTypes
1197{
1198 ARENA_TEAM_2v2 = 2,
1199 ARENA_TEAM_3v3 = 3,
1200 ARENA_TEAM_5v5 = 5
1201};
1202
1203enum ArenaSlot
1204{
1208};
1209
1210struct ArenaTeamMember
1211{
1212 ObjectGuid Guid;
1213 std::string Name;
1214 uint8 Class;
1215 uint16 WeekGames;
1216 uint16 WeekWins;
1217 uint16 SeasonGames;
1218 uint16 SeasonWins;
1219 uint16 PersonalRating;
1220 uint16 MatchMakerRating;
1221 uint16 MaxMMR;
1222
1223 void ModifyPersonalRating(Player* player, int32 mod, uint32 type);
1224 void ModifyMatchmakerRating(int32 mod, uint32 slot);
1225};
1226
1227struct ArenaTeamStats
1228{
1229 uint16 Rating;
1230 uint16 WeekGames;
1231 uint16 WeekWins;
1232 uint16 SeasonGames;
1233 uint16 SeasonWins;
1234 uint32 Rank;
1235};
1236
1237#define MAX_ARENA_SLOT 4 // 0..2 slots
1238
1239class ArenaTeam
1240{
1241public:
1242 ArenaTeam();
1243 ~ArenaTeam();
1244
1245 bool Create(ObjectGuid captainGuid, uint8 type, std::string const& teamName, uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle, uint32 borderColor);
1246 void Disband(WorldSession* session);
1247 void Disband();
1248
1249 typedef std::list<ArenaTeamMember> MemberList;
1250
1251 [[nodiscard]] uint32 GetId() const { return TeamId; }
1252 [[nodiscard]] uint32 GetType() const { return Type; }
1253 [[nodiscard]] uint8 GetSlot() const { return GetSlotByType(GetType()); }
1254 static uint8 GetSlotByType(uint32 type);
1255 static uint8 GetReqPlayersForType(uint32 type);
1256 [[nodiscard]] ObjectGuid GetCaptain() const { return CaptainGuid; }
1257 [[nodiscard]] std::string const& GetName() const { return TeamName; }
1258 [[nodiscard]] ArenaTeamStats const& GetStats() const { return Stats; }
1259 void SetArenaTeamStats(ArenaTeamStats& stats) { Stats = stats; }
1260
1261 [[nodiscard]] uint32 GetRating() const { return Stats.Rating; }
1262 uint32 GetAverageMMR(Group* group) const;
1263
1264 void SetCaptain(ObjectGuid guid);
1265 bool SetName(std::string const& name);
1266 bool AddMember(ObjectGuid playerGuid);
1267
1268 // Shouldn't be ObjectGuid, because than can reference guid from members on Disband
1269 // and this method removes given record from list. So invalid reference can happen.
1270 void DelMember(ObjectGuid guid, bool cleanDb);
1271
1272 [[nodiscard]] std::size_t GetMembersSize() const { return Members.size(); }
1273 [[nodiscard]] bool Empty() const { return Members.empty(); }
1274 MemberList::iterator m_membersBegin() { return Members.begin(); }
1275 MemberList::iterator m_membersEnd() { return Members.end(); }
1276 MemberList& GetMembers() { return Members; }
1277 [[nodiscard]] bool IsMember(ObjectGuid guid) const;
1278
1280 ArenaTeamMember* GetMember(std::string const& name);
1281
1282 [[nodiscard]] bool IsFighting() const;
1283
1284 bool LoadArenaTeamFromDB(QueryResult arenaTeamDataResult);
1285 bool LoadMembersFromDB(QueryResult arenaTeamMembersResult);
1286 void LoadStatsFromDB(uint32 ArenaTeamId);
1287 void SaveToDB(bool forceMemberSave = false);
1288
1289 void BroadcastPacket(WorldPacket* packet);
1290 void BroadcastEvent(ArenaTeamEvents event, ObjectGuid guid, uint8 strCount, std::string const& str1, std::string const& str2, std::string const& str3);
1291 void NotifyStatsChanged();
1292
1293 void MassInviteToEvent(WorldSession* session);
1294
1295 void Roster(WorldSession* session);
1296 void Query(WorldSession* session);
1297 void SendStats(WorldSession* session);
1298 void Inspect(WorldSession* session, ObjectGuid guid);
1299
1300 uint32 GetPoints(uint32 MemberRating);
1301 int32 GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won);
1302 int32 GetRatingMod(uint32 ownRating, uint32 opponentRating, bool won);
1303 float GetChanceAgainst(uint32 ownRating, uint32 opponentRating);
1304 int32 WonAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32& rating_change, Map const* bgMap);
1305 void MemberWon(Player* player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange);
1306 int32 LostAgainst(uint32 Own_MMRating, uint32 Opponent_MMRating, int32& rating_change, Map const* bgMap);
1307 void MemberLost(Player* player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange = -12);
1308
1309 void UpdateArenaPointsHelper(std::map<ObjectGuid, uint32>& PlayerPoints);
1310
1311 bool FinishWeek(); // returns true if arena team played this week
1312 void FinishGame(int32 mod, Map const* bgMap);
1313
1314 void SetPreviousOpponents(uint32 arenaTeamId) { PreviousOpponents = arenaTeamId; }
1316
1317 void CreateTempArenaTeam(std::vector<Player*> playerList, uint8 type, std::string const& teamName);
1318
1319 // Containers
1320 static std::unordered_map<uint32, uint8> ArenaSlotByType; // Slot -> Type
1321 static std::unordered_map<uint8, uint8> ArenaReqPlayersForType; // Type -> Players count
1322
1323 void SetEmblem(uint32 backgroundColor, uint8 emblemStyle, uint32 emblemColor, uint8 borderStyle,
1324 uint32 borderColor);
1325 void SetRatingForAll(uint32 rating);
1326
1327protected:
1328 uint32 TeamId;
1329 uint8 Type;
1330 std::string TeamName;
1332
1333 uint32 BackgroundColor; // ARGB format
1334 uint8 EmblemStyle; // icon id
1335 uint32 EmblemColor; // ARGB format
1336 uint8 BorderStyle; // border image id
1337 uint32 BorderColor; // ARGB format
1338
1341
1343};
1344#endif

Referenced by Player::_LoadArenaTeamInfo(), and GetSlotByType().

◆ BackgroundColor

uint32 ArenaTeam::BackgroundColor
protected

◆ BorderColor

uint32 ArenaTeam::BorderColor
protected

◆ BorderStyle

uint8 ArenaTeam::BorderStyle
protected

◆ CaptainGuid

ObjectGuid ArenaTeam::CaptainGuid
protected

◆ EmblemColor

uint32 ArenaTeam::EmblemColor
protected

◆ EmblemStyle

uint8 ArenaTeam::EmblemStyle
protected

◆ Members

◆ PreviousOpponents

uint32 ArenaTeam::PreviousOpponents = 0
protected

◆ Stats

ArenaTeamStats ArenaTeam::Stats
protected

Referenced by CreateTempArenaTeam(), and GetStats().

◆ TeamId

uint32 ArenaTeam::TeamId
protected

Referenced by GetId().

◆ TeamName

std::string ArenaTeam::TeamName
protected

◆ Type


The documentation for this class was generated from the following files: