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< ArenaTeamMemberMemberList
 

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
 
const ArenaTeamStatsGetStats () 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 ()
 
MemberListGetMembers ()
 
bool IsMember (ObjectGuid guid) const
 
ArenaTeamMemberGetMember (ObjectGuid guid)
 
ArenaTeamMemberGetMember (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, const Map *bgMap)
 
void MemberWon (Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange)
 
int32 LostAgainst (uint32 Own_MMRating, uint32 Opponent_MMRating, int32 &rating_change, const Map *bgMap)
 
void MemberLost (Player *player, uint32 againstMatchmakerRating, int32 MatchmakerRatingChange=-12)
 
void UpdateArenaPointsHelper (std::map< ObjectGuid, uint32 > &PlayerPoints)
 
bool FinishWeek ()
 
void FinishGame (int32 mod, const Map *bgMap)
 
void SetPreviousOpponents (uint32 arenaTeamId)
 
uint32 GetPreviousOpponents ()
 
void CreateTempArenaTeam (std::vector< Player * > playerList, uint8 type, std::string const &teamName)
 

Static Public Member Functions

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

Static Public Attributes

static std::unordered_map< uint32, uint8ArenaSlotByType
 
static std::unordered_map< uint8, uint8ArenaReqPlayersForType
 

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 = sWorld->getIntConfig(CONFIG_ARENA_START_RATING);
40 Stats.WeekWins = 0;
41 Stats.SeasonWins = 0;
42}
@ CONFIG_ARENA_START_RATING
Definition IWorld.h:332
Stats
Definition SharedDefines.h:257
uint32 EmblemColor
Definition ArenaTeam.h:228
uint32 BorderColor
Definition ArenaTeam.h:230
uint32 TeamId
Definition ArenaTeam.h:221
uint8 Type
Definition ArenaTeam.h:222
uint8 EmblemStyle
Definition ArenaTeam.h:227
uint8 BorderStyle
Definition ArenaTeam.h:229
std::string TeamName
Definition ArenaTeam.h:223
uint32 BackgroundColor
Definition ArenaTeam.h:226
#define sWorld
Definition World.h:363

References CONFIG_ARENA_START_RATING, and sWorld.

◆ ~ArenaTeam()

ArenaTeam::~ArenaTeam ( )
45{
46}

Member Function Documentation

◆ AddMember()

bool ArenaTeam::AddMember ( ObjectGuid  playerGuid)
91{
92 std::string playerName;
93 uint8 playerClass;
94
95 // Check if arena team is full (Can't have more than type * 2 players)
96 if (GetMembersSize() >= GetType() * 2)
97 return false;
98
99 // xinef: Get player name and class from player storage or global data storage
100 Player* player = ObjectAccessor::FindConnectedPlayer(playerGuid);
101 if (player)
102 {
103 playerClass = player->getClass();
104 playerName = player->GetName();
105 }
106 else
107 {
108 CharacterCacheEntry const* playerData = sCharacterCache->GetCharacterCacheByGuid(playerGuid);
109 if (!playerData)
110 {
111 return false;
112 }
113
114 playerName = playerData->Name;
115 playerClass = playerData->Class;
116 }
117
118 if (!sScriptMgr->CanAddMember(this, playerGuid))
119 return false;
120
121 // Check if player is already in a similar arena team
122 if ((player && player->GetArenaTeamId(GetSlot())) || sCharacterCache->GetCharacterArenaTeamIdByGuid(playerGuid, GetSlot()) != 0)
123 {
124 LOG_ERROR("bg.arena", "Arena: Player {} ({}) already has an arena team of type {}", playerName, playerGuid.ToString(), GetType());
125 return false;
126 }
127
128 // Set player's personal rating
129 uint32 personalRating = 0;
130
131 if (sWorld->getIntConfig(CONFIG_ARENA_START_PERSONAL_RATING) > 0)
132 personalRating = sWorld->getIntConfig(CONFIG_ARENA_START_PERSONAL_RATING);
133 else if (GetRating() >= 1000)
134 personalRating = 1000;
135
136 // xinef: sync query
137 // Try to get player's match maker rating from db and fall back to config setting if not found
139 stmt->SetData(0, playerGuid.GetCounter());
140 stmt->SetData(1, GetSlot());
141 PreparedQueryResult result = CharacterDatabase.Query(stmt);
142
143 uint16 matchMakerRating;
144 uint16 maxMMR;
145 if (result)
146 {
147 matchMakerRating = (*result)[0].Get<uint16>();
148 uint16 Max = (*result)[1].Get<uint16>();
149 maxMMR = std::max(Max, matchMakerRating);
150 }
151 else
152 {
153 matchMakerRating = sWorld->getIntConfig(CONFIG_ARENA_START_MATCHMAKER_RATING);
154 maxMMR = matchMakerRating;
155 }
156
157 // Remove all player signatures from other petitions
158 // This will prevent player from joining too many arena teams and corrupt arena team data integrity
160
161 // Feed data to the struct
162 ArenaTeamMember newMember;
163 //newMember.Name = playerName;
164 newMember.Guid = playerGuid;
165 newMember.Class = playerClass;
166 newMember.SeasonGames = 0;
167 newMember.WeekGames = 0;
168 newMember.SeasonWins = 0;
169 newMember.WeekWins = 0;
170 newMember.PersonalRating = personalRating;
171 newMember.MatchMakerRating = matchMakerRating;
172 newMember.MaxMMR = maxMMR;
173
174 Members.push_back(newMember);
175 sCharacterCache->UpdateCharacterArenaTeamId(playerGuid, GetSlot(), GetId());
176
177 // Save player's arena team membership to db
178 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ARENA_TEAM_MEMBER);
179 stmt->SetData(0, TeamId);
180 stmt->SetData(1, playerGuid.GetCounter());
181 CharacterDatabase.Execute(stmt);
182
183 // Inform player if online
184 if (player)
185 {
186 player->SetInArenaTeam(TeamId, GetSlot(), GetType());
187 player->SetArenaTeamIdInvited(0);
188
189 // Hide promote/remove buttons
190 if (CaptainGuid != playerGuid)
192 }
193
194 return true;
195}
@ ARENA_TEAM_MEMBER
Definition ArenaTeam.h:76
#define sCharacterCache
Definition CharacterCache.h:83
@ CHAR_INS_ARENA_TEAM_MEMBER
Definition CharacterDatabase.h:225
@ CHAR_SEL_MATCH_MAKER_RATING
Definition CharacterDatabase.h:135
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
@ CONFIG_ARENA_START_MATCHMAKER_RATING
Definition IWorld.h:335
@ CONFIG_ARENA_START_PERSONAL_RATING
Definition IWorld.h:334
#define LOG_ERROR(filterType__,...)
Definition Log.h:157
#define sScriptMgr
Definition ScriptMgr.h:727
TeamId
Definition SharedDefines.h:759
std::size_t GetMembersSize() const
Definition ArenaTeam.h:169
ObjectGuid CaptainGuid
Definition ArenaTeam.h:224
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:232
uint32 GetId() const
Definition ArenaTeam.h:148
LowType GetCounter() const
Definition ObjectGuid.h:145
std::string ToString() const
Definition ObjectGuid.cpp:47
Definition Player.h:1081
void SetArenaTeamInfoField(uint8 slot, ArenaTeamInfoType type, uint32 value)
Definition Player.cpp:16250
void SetInArenaTeam(uint32 ArenaTeamId, uint8 slot, uint8 type)
Definition Player.h:1914
uint32 GetArenaTeamId(uint8 slot) const
Definition Player.cpp:16265
static void RemovePetitionsAndSigns(ObjectGuid guid, uint32 type)
Definition Player.cpp:10169
void SetArenaTeamIdInvited(uint32 ArenaTeamId)
Definition Player.h:1924
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:809
std::string const & GetName() const
Definition Object.h:463
Player * FindConnectedPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:257
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
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, CharacterCacheEntry::Name, ArenaTeamMember::PersonalRating, Player::RemovePetitionsAndSigns(), 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 
)
572{
573 WorldPacket data(SMSG_ARENA_TEAM_EVENT, 1 + 1 + 1);
574 data << uint8(event);
575 data << uint8(strCount);
576 switch (strCount)
577 {
578 case 0:
579 break;
580 case 1:
581 data << str1;
582 break;
583 case 2:
584 data << str1 << str2;
585 break;
586 case 3:
587 data << str1 << str2 << str3;
588 break;
589 default:
590 LOG_ERROR("bg.arena", "Unhandled strCount {} in ArenaTeam::BroadcastEvent", strCount);
591 return;
592 }
593
594 if (guid)
595 data << guid;
596
597 BroadcastPacket(&data);
598
599 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_EVENT");
600}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:169
void BroadcastPacket(WorldPacket *packet)
Definition ArenaTeam.cpp:564
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)
565{
566 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
567 if (Player* player = ObjectAccessor::FindConnectedPlayer(itr->Guid))
568 player->GetSession()->SendPacket(packet);
569}

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

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 
)
1035{
1036 auto playerCountInTeam = static_cast<uint32>(playerList.size());
1037
1038 const auto standardArenaType = { ARENA_TYPE_2v2, ARENA_TYPE_3v3, ARENA_TYPE_5v5 };
1039 bool isStandardArenaType = std::find(std::begin(standardArenaType), std::end(standardArenaType), type) != std::end(standardArenaType);
1040 if (isStandardArenaType)
1041 ASSERT(playerCountInTeam == GetReqPlayersForType(type));
1042
1043 // Generate new arena team id
1044 TeamId = sArenaTeamMgr->GenerateTempArenaTeamId();
1045
1046 // Assign member variables
1047 CaptainGuid = playerList[0]->GetGUID();
1048 Type = type;
1049 TeamName = teamName;
1050
1051 BackgroundColor = 0;
1052 EmblemStyle = 0;
1053 EmblemColor = 0;
1054 BorderStyle = 0;
1055 BorderColor = 0;
1056
1057 Stats.WeekGames = 0;
1058 Stats.SeasonGames = 0;
1059 Stats.Rating = 0;
1060 Stats.WeekWins = 0;
1061 Stats.SeasonWins = 0;
1062
1063 for (auto const& _player : playerList)
1064 {
1065 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(_player->GetArenaTeamId(GetSlotByType(type)));
1066 if (!team)
1067 continue;
1068
1069 ArenaTeamMember newMember;
1070 for (auto const& itr : Members)
1071 newMember = itr;
1072
1073 Stats.WeekGames += team->Stats.WeekGames;
1074 Stats.SeasonGames += team->Stats.SeasonGames;
1075 Stats.Rating += team->GetRating();
1076 Stats.WeekWins += team->Stats.WeekWins;
1077 Stats.SeasonWins += team->Stats.SeasonWins;
1078
1079 Members.push_back(newMember);
1080 }
1081
1082 Stats.WeekGames /= playerCountInTeam;
1083 Stats.SeasonGames /= playerCountInTeam;
1084 Stats.Rating /= playerCountInTeam;
1085 Stats.WeekWins /= playerCountInTeam;
1086 Stats.SeasonWins /= playerCountInTeam;
1087}
@ ARENA_TYPE_5v5
Definition Battleground.h:220
@ ARENA_TYPE_3v3
Definition Battleground.h:219
@ ARENA_TYPE_2v2
Definition Battleground.h:218
#define ASSERT
Definition Errors.h:68
Definition ArenaTeam.h:137
ArenaTeamStats Stats
Definition ArenaTeam.h:233
static uint8 GetReqPlayersForType(uint32 type)
Definition ArenaTeam.cpp:1022
static uint8 GetSlotByType(uint32 type)
Definition ArenaTeam.cpp:619
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 
)
326{
328 Group* group = (player && player->GetGroup()) ? player->GetGroup() : nullptr;
329
330 // Remove member from team
331 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
332 {
333 // Remove queues of members
334 if (Player* playerMember = ObjectAccessor::FindConnectedPlayer(itr->Guid))
335 {
336 if (group && playerMember->GetGroup() && group->GetGUID() == playerMember->GetGroup()->GetGUID())
337 {
339 {
340 GroupQueueInfo ginfo;
341 BattlegroundQueue& queue = sBattlegroundMgr->GetBattlegroundQueue(bgQueue);
342 if (queue.GetPlayerGroupInfoData(playerMember->GetGUID(), &ginfo))
343 {
344 if (!ginfo.IsInvitedToBGInstanceGUID)
345 {
346 WorldPacket data;
347 playerMember->RemoveBattlegroundQueueId(bgQueue);
348 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, nullptr, playerMember->GetBattlegroundQueueIndex(bgQueue), STATUS_NONE, 0, 0, 0, TEAM_NEUTRAL);
349 queue.RemovePlayer(playerMember->GetGUID(), true);
350 playerMember->GetSession()->SendPacket(&data);
351 }
352 }
353 }
354 }
355 }
356
357 if (itr->Guid == guid)
358 {
359 Members.erase(itr);
360 sCharacterCache->UpdateCharacterArenaTeamId(guid, GetSlot(), 0);
361 break;
362 }
363 }
364
365 // Inform player and remove arena team info from player data
366 if (player)
367 {
369 // delete all info regarding this team
370 for (uint32 i = 0; i < ARENA_TEAM_END; ++i)
372 }
373
374 // Only used for single member deletion, for arena team disband we use a single query for more efficiency
375 if (cleanDb)
376 {
378 stmt->SetData(0, GetId());
379 stmt->SetData(1, guid.GetCounter());
380 CharacterDatabase.Execute(stmt);
381 }
382}
@ 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:187
@ STATUS_NONE
Definition Battleground.h:200
@ CHAR_DEL_ARENA_TEAM_MEMBER
Definition CharacterDatabase.h:229
@ BATTLEGROUND_AA
Definition SharedDefines.h:3486
BattlegroundQueueTypeId
Definition SharedDefines.h:3619
@ TEAM_NEUTRAL
Definition SharedDefines.h:762
std::string const & GetName() const
Definition ArenaTeam.h:154
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition BattlegroundMgr.cpp:685
Definition BattlegroundQueue.h:64
bool GetPlayerGroupInfoData(ObjectGuid guid, GroupQueueInfo *ginfo)
Definition BattlegroundQueue.cpp:385
void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount)
Definition BattlegroundQueue.cpp:261
Definition Group.h:169
ObjectGuid GetGUID() const
Definition Group.cpp:2304
WorldSession * GetSession() const
Definition Player.h:2005
Group * GetGroup()
Definition Player.h:2476
void SendArenaTeamCommandResult(uint32 team_action, std::string const &team, std::string const &player, uint32 error_id=0)
Definition ArenaTeamHandler.cpp:406
Definition BattlegroundQueue.h:31
uint32 IsInvitedToBGInstanceGUID
Definition BattlegroundQueue.h:41

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 ( )
414{
415 // Remove all members from arena team
416 while (!Members.empty())
417 DelMember(Members.front().Guid, false);
418
419 // Update database
420 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
421
423 stmt->SetData(0, TeamId);
424 trans->Append(stmt);
425
426 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ARENA_TEAM_MEMBERS);
427 stmt->SetData(0, TeamId);
428 trans->Append(stmt);
429
430 CharacterDatabase.CommitTransaction(trans);
431
432 // Remove arena team from ObjectMgr
433 sArenaTeamMgr->RemoveArenaTeam(TeamId);
434}
@ CHAR_DEL_ARENA_TEAM_MEMBERS
Definition CharacterDatabase.h:227
@ CHAR_DEL_ARENA_TEAM
Definition CharacterDatabase.h:226
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition DatabaseEnvFwd.h:69
void DelMember(ObjectGuid guid, bool cleanDb)
Definition ArenaTeam.cpp:325

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)
385{
386 // Remove all members from arena team
387 while (!Members.empty())
388 DelMember(Members.front().Guid, false);
389
390 // Broadcast update
391 if (session)
392 {
394 }
395
396 // Update database
397 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
398
400 stmt->SetData(0, TeamId);
401 trans->Append(stmt);
402
403 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ARENA_TEAM_MEMBERS);
404 stmt->SetData(0, TeamId);
405 trans->Append(stmt);
406
407 CharacterDatabase.CommitTransaction(trans);
408
409 // Remove arena team from ObjectMgr
410 sArenaTeamMgr->RemoveArenaTeam(TeamId);
411}
@ 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:571
static ObjectGuid const Empty
Definition ObjectGuid.h:120
std::string const & GetPlayerName() const
Definition WorldSession.cpp:185

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,
const Map bgMap 
)
777{
778 // Rating can only drop to 0
779 if (int32(Stats.Rating) + mod < 0)
780 Stats.Rating = 0;
781 else
782 {
783 Stats.Rating += mod;
784
785 // Check if rating related achivements are met
786 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
787 if (Player* member = ObjectAccessor::FindConnectedPlayer(itr->Guid))
788 if (member->FindMap() == bgMap)
789 member->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING, Stats.Rating, Type);
790 }
791
792 // Update number of games played per season or week
793 Stats.WeekGames += 1;
794 Stats.SeasonGames += 1;
795
796 // Update team's rank, start with rank 1 and increase until no team with more rating was found
797 Stats.Rank = 1;
798 ArenaTeamMgr::ArenaTeamContainer::const_iterator i = sArenaTeamMgr->GetArenaTeamMapBegin();
799 for (; i != sArenaTeamMgr->GetArenaTeamMapEnd(); ++i)
800 {
801 if (i->second->GetType() == Type && i->second->GetStats().Rating > Stats.Rating)
802 ++Stats.Rank;
803 }
804}
@ 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 ( )
979{
980 // No need to go further than this
981 if (Stats.WeekGames == 0)
982 return false;
983
984 // Reset team stats
985 Stats.WeekGames = 0;
986 Stats.WeekWins = 0;
987
988 // Reset member stats
989 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
990 {
991 itr->WeekGames = 0;
992 itr->WeekWins = 0;
993 }
994
995 return true;
996}

References Members.

◆ GetAverageMMR()

uint32 ArenaTeam::GetAverageMMR ( Group group) const
684{
685 if (!group)
686 return 0;
687
688 uint32 matchMakerRating = 0;
689 uint32 playerDivider = 0;
690 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
691 {
692 // Skip if player is not online
694 continue;
695
696 // Skip if player is not member of group
697 if (!group->IsMember(itr->Guid))
698 continue;
699
700 matchMakerRating += itr->MatchMakerRating;
701 ++playerDivider;
702 }
703
704 // x/0 = crash
705 if (playerDivider == 0)
706 playerDivider = 1;
707
708 matchMakerRating /= playerDivider;
709
710 return matchMakerRating;
711}
bool IsMember(ObjectGuid guid) const
Definition Group.cpp:2334

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

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ GetCaptain()

◆ GetChanceAgainst()

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

Referenced by GetMatchmakerRatingMod(), and GetRatingMod().

◆ GetId()

◆ GetMatchmakerRatingMod()

int32 ArenaTeam::GetMatchmakerRatingMod ( uint32  ownRating,
uint32  opponentRating,
bool  won 
)
721{
722 // 'Chance' calculation - to beat the opponent
723 // This is a simulation. Not much info on how it really works
724 float chance = GetChanceAgainst(ownRating, opponentRating);
725 float won_mod = (won) ? 1.0f : 0.0f;
726 float mod = won_mod - chance;
727
728 // Work in progress:
729 /*
730 // This is a simulation, as there is not much info on how it really works
731 float confidence_mod = min(1.0f - std::fabs(mod), 0.5f);
732
733 // Apply confidence factor to the mod:
734 mod *= confidence_factor
735
736 // And only after that update the new confidence factor
737 confidence_factor -= ((confidence_factor - 1.0f) * confidence_mod) / confidence_factor;
738 */
739
740 // Real rating modification
741 mod *= sWorld->getFloatConfig(CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER);
742
743 return (int32)ceil(mod);
744}
@ CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER
Definition IWorld.h:201
float GetChanceAgainst(uint32 ownRating, uint32 opponentRating)
Definition ArenaTeam.cpp:713

References CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER, GetChanceAgainst(), and sWorld.

Referenced by LostAgainst(), and WonAgainst().

◆ GetMember() [1/2]

ArenaTeamMember * ArenaTeam::GetMember ( ObjectGuid  guid)
1014{
1015 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
1016 if (itr->Guid == guid)
1017 return &(*itr);
1018
1019 return nullptr;
1020}

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)
1009{
1010 return GetMember(sCharacterCache->GetCharacterGuidByName(name));
1011}
ArenaTeamMember * GetMember(ObjectGuid guid)
Definition ArenaTeam.cpp:1013

References GetMember(), and sCharacterCache.

◆ GetMembers()

◆ GetMembersSize()

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

◆ GetName()

◆ GetPoints()

uint32 ArenaTeam::GetPoints ( uint32  MemberRating)
654{
655 // Returns how many points would be awarded with this team type with this rating
656 float points;
657
658 uint32 rating = memberRating + 150 < Stats.Rating ? memberRating : Stats.Rating;
659
660 if (rating <= 1500)
661 {
662 if (sArenaSeasonMgr->GetCurrentSeason() < 6 && !sWorld->getIntConfig(CONFIG_LEGACY_ARENA_POINTS_CALC))
663 points = (float)rating * 0.22f + 14.0f;
664 else
665 points = 344;
666 }
667 else
668 points = 1511.26f / (1.0f + 1639.28f * std::exp(-0.00412f * (float)rating));
669
670 // Type penalties for teams < 5v5
671 if (Type == ARENA_TEAM_2v2)
672 points *= 0.76f;
673 else if (Type == ARENA_TEAM_3v3)
674 points *= 0.88f;
675
676 sScriptMgr->OnGetArenaPoints(this, points);
677
678 points *= sWorld->getRate(RATE_ARENA_POINTS);
679
680 return (uint32) points;
681}
#define sArenaSeasonMgr
Definition ArenaSeasonMgr.h:124
@ ARENA_TEAM_2v2
Definition ArenaTeam.h:95
@ ARENA_TEAM_3v3
Definition ArenaTeam.h:96
@ CONFIG_LEGACY_ARENA_POINTS_CALC
Definition IWorld.h:333
@ RATE_ARENA_POINTS
Definition IWorld.h:515

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

Referenced by UpdateArenaPointsHelper().

◆ GetPreviousOpponents()

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

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)
747{
748 // 'Chance' calculation - to beat the opponent
749 // This is a simulation. Not much info on how it really works
750 float chance = GetChanceAgainst(ownRating, opponentRating);
751
752 // Calculate the rating modification
753 float mod;
754
756 if (won)
757 {
758 if (ownRating < 1300)
759 {
760 float win_rating_modifier1 = sWorld->getFloatConfig(CONFIG_ARENA_WIN_RATING_MODIFIER_1);
761
762 if (ownRating < 1000)
763 mod = win_rating_modifier1 * (1.0f - chance);
764 else
765 mod = ((win_rating_modifier1 / 2.0f) + ((win_rating_modifier1 / 2.0f) * (1300.0f - float(ownRating)) / 300.0f)) * (1.0f - chance);
766 }
767 else
768 mod = sWorld->getFloatConfig(CONFIG_ARENA_WIN_RATING_MODIFIER_2) * (1.0f - chance);
769 }
770 else
771 mod = sWorld->getFloatConfig(CONFIG_ARENA_LOSE_RATING_MODIFIER) * (-chance);
772
773 return (int32)ceil(mod);
774}
@ CONFIG_ARENA_WIN_RATING_MODIFIER_1
Definition IWorld.h:198
@ CONFIG_ARENA_WIN_RATING_MODIFIER_2
Definition IWorld.h:199
@ CONFIG_ARENA_LOSE_RATING_MODIFIER
Definition IWorld.h:200

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
1023{
1024 auto const& itr = ArenaReqPlayersForType.find(type);
1025 if (itr == ArenaReqPlayersForType.end())
1026 {
1027 LOG_ERROR("bg.arena", "FATAL: Unknown arena type {}!", type);
1028 return 0xFF;
1029 }
1030
1031 return ArenaReqPlayersForType.at(type);
1032}
static std::unordered_map< uint8, uint8 > ArenaReqPlayersForType
Definition ArenaTeam.h:1098

References ArenaReqPlayersForType, and LOG_ERROR.

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

◆ GetSlot()

◆ GetSlotByType()

uint8 ArenaTeam::GetSlotByType ( uint32  type)
static
620{
621 uint8 slot = 0xFF;
622
623 auto const& itr = ArenaSlotByType.find(type);
624 if (itr == ArenaSlotByType.end())
625 {
626 LOG_ERROR("bg.arena", "Unknown arena team type {} for some arena team", type);
627 return slot;
628 }
629
630 slot = ArenaSlotByType.at(type);
631
632 // Get the changed slot type
633 sScriptMgr->OnGetSlotByType(type, slot);
634
635 if (slot != 0xFF)
636 {
637 return slot;
638 }
639
640 LOG_ERROR("bg.arena", "Unknown arena team type {} for some arena team", type);
641 return 0xFF;
642}
static std::unordered_map< uint32, uint8 > ArenaSlotByType
Definition ArenaTeam.h:1090

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 
)
515{
516 ArenaTeamMember* member = GetMember(guid);
517 if (!member || GetSlot() >= MAX_ARENA_SLOT)
518 return;
519
520 WorldPacket data(MSG_INSPECT_ARENA_TEAMS, 8 + 1 + 4 * 6);
521 data << guid; // player guid
522 data << uint8(GetSlot()); // slot (0...2)
523 data << uint32(GetId()); // arena team id
524 data << uint32(Stats.Rating); // rating
525 data << uint32(Stats.SeasonGames); // season played
526 data << uint32(Stats.SeasonWins); // season wins
527 data << uint32(member->SeasonGames); // played (count of all games, that the inspected member participated...)
528 data << uint32(member->PersonalRating); // personal rating
529 session->SendPacket(&data);
530}
#define MAX_ARENA_SLOT
Definition ArenaTeam.h:134
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition WorldSession.cpp:226
@ 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
999{
1000 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
1001 if (Player* player = ObjectAccessor::FindPlayer(itr->Guid))
1002 if (player->GetMap()->IsBattleArena())
1003 return true;
1004
1005 return false;
1006}
Player * FindPlayer(ObjectGuid const guid)
Definition ObjectAccessor.cpp:245

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
645{
646 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
647 if (itr->Guid == guid)
648 return true;
649
650 return false;
651}

References Members.

Referenced by arena_commandscript::HandleArenaCaptainCommand().

◆ LoadArenaTeamFromDB()

bool ArenaTeam::LoadArenaTeamFromDB ( QueryResult  arenaTeamDataResult)
198{
199 if (!result)
200 return false;
201
202 Field* fields = result->Fetch();
203
204 TeamId = fields[0].Get<uint32>();
205 TeamName = fields[1].Get<std::string>();
206 CaptainGuid = ObjectGuid::Create<HighGuid::Player>(fields[2].Get<uint32>());
207 Type = fields[3].Get<uint8>();
208 BackgroundColor = fields[4].Get<uint32>();
209 EmblemStyle = fields[5].Get<uint8>();
210 EmblemColor = fields[6].Get<uint32>();
211 BorderStyle = fields[7].Get<uint8>();
212 BorderColor = fields[8].Get<uint32>();
213 Stats.Rating = fields[9].Get<uint16>();
214 Stats.WeekGames = fields[10].Get<uint16>();
215 Stats.WeekWins = fields[11].Get<uint16>();
216 Stats.SeasonGames = fields[12].Get<uint16>();
217 Stats.SeasonWins = fields[13].Get<uint16>();
218 Stats.Rank = fields[14].Get<uint32>();
219
220 return true;
221}
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112

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

Referenced by ArenaTeamMgr::LoadArenaTeams().

◆ LoadMembersFromDB()

bool ArenaTeam::LoadMembersFromDB ( QueryResult  arenaTeamMembersResult)
224{
225 if (!result)
226 return false;
227
228 bool captainPresentInTeam = false;
229
230 do
231 {
232 Field* fields = result->Fetch();
233
234 // Prevent crash if db records are broken when all members in result are already processed and current team doesn't have any members
235 if (!fields)
236 break;
237
238 uint32 arenaTeamId = fields[0].Get<uint32>();
239
240 // We loaded all members for this arena_team already, break cycle
241 if (arenaTeamId > TeamId)
242 break;
243
244 ArenaTeamMember newMember;
245 newMember.Guid = ObjectGuid::Create<HighGuid::Player>(fields[1].Get<uint32>());
246 newMember.WeekGames = fields[2].Get<uint16>();
247 newMember.WeekWins = fields[3].Get<uint16>();
248 newMember.SeasonGames = fields[4].Get<uint16>();
249 newMember.SeasonWins = fields[5].Get<uint16>();
250 //newMember.Name = fields[6].Get<std::string>();
251 newMember.Class = fields[7].Get<uint8>();
252 newMember.PersonalRating = fields[8].Get<uint16>();
253 newMember.MatchMakerRating = fields[9].Get<uint16>() > 0 ? fields[9].Get<uint16>() : sWorld->getIntConfig(CONFIG_ARENA_START_MATCHMAKER_RATING);
254 newMember.MaxMMR = std::max(fields[10].Get<uint16>(), newMember.MatchMakerRating);
255
256 // Delete member if character information is missing
257 if (fields[6].Get<std::string>().empty())
258 {
259 LOG_ERROR("sql.sql", "ArenaTeam {} has member with empty name - probably player {} doesn't exist, deleting him from memberlist!", arenaTeamId, newMember.Guid.ToString());
260 this->DelMember(newMember.Guid, true);
261 continue;
262 }
263
264 // Check if team team has a valid captain
265 if (newMember.Guid == GetCaptain())
266 captainPresentInTeam = true;
267
268 // Put the player in the team
269 Members.push_back(newMember);
270 sCharacterCache->UpdateCharacterArenaTeamId(newMember.Guid, GetSlot(), GetId());
271 } while (result->NextRow());
272
273 if (Empty() || !captainPresentInTeam)
274 {
275 // Arena team is empty or captain is not in team, delete from db
276 LOG_DEBUG("bg.battleground", "ArenaTeam {} does not have any members or its captain is not in team, disbanding it...", TeamId);
277 return false;
278 }
279
280 return true;
281}
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::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,
const Map bgMap 
)
827{
828 // Called when the team has lost
829 // Change in Matchmaker Rating
830 int32 mod = GetMatchmakerRatingMod(Own_MMRating, Opponent_MMRating, false);
831
832 // Change in Team Rating
833 rating_change = GetRatingMod(Stats.Rating, Opponent_MMRating, false);
834
835 // Modify the team stats accordingly
836 FinishGame(rating_change, bgMap);
837
838 // return the rating change, used to display it on the results screen
839 return mod;
840}
int32 GetRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition ArenaTeam.cpp:746
int32 GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition ArenaTeam.cpp:720
void FinishGame(int32 mod, const Map *bgMap)
Definition ArenaTeam.cpp:776

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)
603{
604 WorldPacket data(SMSG_CALENDAR_ARENA_TEAM, (Members.size() - 1) * (4 + 8 + 1));
605 data << uint32(Members.size() - 1);
606
607 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
608 {
609 if (itr->Guid != session->GetPlayer()->GetGUID())
610 {
611 data << itr->Guid.WriteAsPacked();
612 data << uint8(0); // unk
613 }
614 }
615
616 session->SendPacket(&data);
617}
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:112
Player * GetPlayer() const
Definition WorldSession.h:376
@ 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 
)
843{
844 // Called for each participant of a match after losing
845 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
846 {
847 if (itr->Guid == player->GetGUID())
848 {
849 // Update personal rating
850 int32 mod = GetRatingMod(itr->PersonalRating, againstMatchmakerRating, false);
851 itr->ModifyPersonalRating(player, mod, GetType());
852
853 // Update matchmaker rating
854 itr->ModifyMatchmakerRating(MatchmakerRatingChange, GetSlot());
855
856 // Update personal played stats
857 itr->WeekGames += 1;
858 itr->SeasonGames += 1;
859
860 // update the unit fields
861 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_WEEK, itr->WeekGames);
862 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_SEASON, itr->SeasonGames);
863 return;
864 }
865 }
866}
@ 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 
)
869{
870 // called for each participant after winning a match
871 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
872 {
873 if (itr->Guid == player->GetGUID())
874 {
875 // update personal rating
876 int32 mod = GetRatingMod(itr->PersonalRating, againstMatchmakerRating, true);
877 sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
878 itr->ModifyPersonalRating(player, mod, GetType());
879
880 // update matchmaker rating (pussywizard: but don't allow it to go over team rating)
881 if (itr->MatchMakerRating < Stats.Rating)
882 {
883 mod = std::min(MatchmakerRatingChange, Stats.Rating - itr->MatchMakerRating);
884 sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
885 itr->ModifyMatchmakerRating(mod, GetSlot());
886 }
887
888 // update personal stats
889 itr->WeekGames += 1;
890 itr->SeasonGames += 1;
891 itr->SeasonWins += 1;
892 itr->WeekWins += 1;
893 // update unit fields
894 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_WEEK, itr->WeekGames);
895 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_SEASON, itr->SeasonGames);
896 return;
897 }
898 }
899}

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 ( )
506{
507 // This is called after a rated match ended
508 // Updates arena team stats for every member of the team (not only the ones who participated!)
509 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
510 if (Player* player = ObjectAccessor::FindConnectedPlayer(itr->Guid))
511 SendStats(player->GetSession());
512}
void SendStats(WorldSession *session)
Definition ArenaTeam.cpp:492

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

Referenced by Arena::EndBattleground().

◆ Query()

void ArenaTeam::Query ( WorldSession session)
478{
479 WorldPacket data(SMSG_ARENA_TEAM_QUERY_RESPONSE, 4 * 7 + GetName().size() + 1);
480 data << uint32(GetId()); // team id
481 data << GetName(); // team name
482 data << uint32(GetType()); // arena team type (2=2x2, 3=3x3 or 5=5x5)
483 data << uint32(BackgroundColor); // background color
484 data << uint32(EmblemStyle); // emblem style
485 data << uint32(EmblemColor); // emblem color
486 data << uint32(BorderStyle); // border style
487 data << uint32(BorderColor); // border color
488 session->SendPacket(&data);
489 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_QUERY_RESPONSE");
490}
@ 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)
437{
438 Player* player = nullptr;
439
440 uint8 unk308 = 0;
441 std::string tempName;
442
444 data << uint32(GetId()); // team id
445 data << uint8(unk308); // 308 unknown value but affect packet structure
446 data << uint32(GetMembersSize()); // members count
447 data << uint32(GetType()); // arena team type?
448
449 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
450 {
451 player = ObjectAccessor::FindConnectedPlayer(itr->Guid);
452
453 data << itr->Guid; // guid
454 data << uint8((player ? 1 : 0)); // online flag
455 tempName = "";
456 sCharacterCache->GetCharacterNameByGuid(itr->Guid, tempName);
457 data << tempName; // member name
458 data << uint32((itr->Guid == GetCaptain() ? 0 : 1));// captain flag 0 captain 1 member
459 data << uint8((player ? player->GetLevel() : 0)); // unknown, level?
460 data << uint8(itr->Class); // class
461 data << uint32(itr->WeekGames); // played this week
462 data << uint32(itr->WeekWins); // wins this week
463 data << uint32(itr->SeasonGames); // played this season
464 data << uint32(itr->SeasonWins); // wins this season
465 data << uint32(itr->PersonalRating); // personal rating
466 if (unk308)
467 {
468 data << float(0.0f); // 308 unk
469 data << float(0.0f); // 308 unk
470 }
471 }
472
473 session->SendPacket(&data);
474 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_ROSTER");
475}
uint8 GetLevel() const
Definition Unit.h:1033
@ 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)
932{
933 if (!sScriptMgr->CanSaveToDB(this))
934 return;
935
936 // Save team and member stats to db
937 // Called after a match has ended or when calculating arena_points
938
939 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
940
942 stmt->SetData(0, Stats.Rating);
943 stmt->SetData(1, Stats.WeekGames);
944 stmt->SetData(2, Stats.WeekWins);
945 stmt->SetData(3, Stats.SeasonGames);
946 stmt->SetData(4, Stats.SeasonWins);
947 stmt->SetData(5, Stats.Rank);
948 stmt->SetData(6, GetId());
949 trans->Append(stmt);
950
951 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
952 {
953 // Save the effort and go
954 if (itr->WeekGames == 0 && !forceMemberSave)
955 continue;
956
957 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ARENA_TEAM_MEMBER);
958 stmt->SetData(0, itr->PersonalRating);
959 stmt->SetData(1, itr->WeekGames);
960 stmt->SetData(2, itr->WeekWins);
961 stmt->SetData(3, itr->SeasonGames);
962 stmt->SetData(4, itr->SeasonWins);
963 stmt->SetData(5, GetId());
964 stmt->SetData(6, itr->Guid.GetCounter());
965 trans->Append(stmt);
966
967 stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHARACTER_ARENA_STATS);
968 stmt->SetData(0, itr->Guid.GetCounter());
969 stmt->SetData(1, GetSlot());
970 stmt->SetData(2, itr->MatchMakerRating);
971 stmt->SetData(3, itr->MaxMMR);
972 trans->Append(stmt);
973 }
974
975 CharacterDatabase.CommitTransaction(trans);
976}
@ CHAR_UPD_ARENA_TEAM_STATS
Definition CharacterDatabase.h:230
@ CHAR_REP_CHARACTER_ARENA_STATS
Definition CharacterDatabase.h:232
@ CHAR_UPD_ARENA_TEAM_MEMBER
Definition CharacterDatabase.h:231

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().

◆ SendStats()

void ArenaTeam::SendStats ( WorldSession session)
493{
495 data << uint32(GetId()); // team id
496 data << uint32(Stats.Rating); // rating
497 data << uint32(Stats.WeekGames); // games this week
498 data << uint32(Stats.WeekWins); // wins this week
499 data << uint32(Stats.SeasonGames); // played this season
500 data << uint32(Stats.SeasonWins); // wins this season
501 data << uint32(Stats.Rank); // rank
502 session->SendPacket(&data);
503}
@ 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)
297{
298 // Disable remove/promote buttons
300 if (oldCaptain)
302
303 // Set new captain
304 CaptainGuid = guid;
305
306 // Update database
308 stmt->SetData(0, guid.GetCounter());
309 stmt->SetData(1, GetId());
310 CharacterDatabase.Execute(stmt);
311
312 // Enable remove/promote buttons
313 if (Player* newCaptain = ObjectAccessor::FindConnectedPlayer(guid))
314 {
315 newCaptain->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_MEMBER, 0);
316 /*if (oldCaptain)
317 {
318 LOG_DEBUG("bg.battleground", "Player: {} [{}] promoted player: {} [{}] to leader of arena team [Id: {}] [Type: {}].",
319 oldCaptain->GetName(), oldCaptain->GetGUID().ToString(), newCaptain->GetName(),
320 newCaptain->GetGUID().ToString(), GetId(), GetType());
321 }*/
322 }
323}
@ CHAR_UPD_ARENA_TEAM_CAPTAIN
Definition CharacterDatabase.h:228

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().

◆ SetName()

bool ArenaTeam::SetName ( std::string const &  name)
284{
285 if (TeamName == name || name.empty() || name.length() > 24 || !ObjectMgr::IsValidCharterName(name))
286 return false;
287
288 TeamName = name;
290 stmt->SetData(0, TeamName);
291 stmt->SetData(1, GetId());
292 CharacterDatabase.Execute(stmt);
293 return true;
294}
@ CHAR_UPD_ARENA_TEAM_NAME
Definition CharacterDatabase.h:234
static bool IsValidCharterName(std::string_view name)
Definition ObjectMgr.cpp:8511

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().

◆ UpdateArenaPointsHelper()

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

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

◆ WonAgainst()

int32 ArenaTeam::WonAgainst ( uint32  Own_MMRating,
uint32  Opponent_MMRating,
int32 rating_change,
const Map bgMap 
)
807{
808 // Called when the team has won
809 // Change in Matchmaker rating
810 int32 mod = GetMatchmakerRatingMod(Own_MMRating, Opponent_MMRating, true);
811
812 // Change in Team Rating
813 rating_change = GetRatingMod(Stats.Rating, Opponent_MMRating, true);
814
815 // Modify the team stats accordingly
816 FinishGame(rating_change, bgMap);
817
818 // Update number of wins per season and week
819 Stats.WeekWins += 1;
820 Stats.SeasonWins += 1;
821
822 // Return the rating change, used to display it on the results screen
823 return mod;
824}

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

Referenced by Arena::EndBattleground().

Member Data Documentation

◆ ArenaReqPlayersForType

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

Referenced by GetReqPlayersForType().

◆ ArenaSlotByType

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