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 = (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:257
@ CONFIG_ARENA_START_RATING
Definition WorldConfig.h:284
@ CONFIG_LEGACY_ARENA_START_RATING
Definition WorldConfig.h:285
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:320

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 (GetRating() >= 1000)
136 personalRating = 1000;
137
138 // xinef: sync query
139 // Try to get player's match maker rating from db and fall back to config setting if not found
141 stmt->SetData(0, playerGuid.GetCounter());
142 stmt->SetData(1, GetSlot());
143 PreparedQueryResult result = CharacterDatabase.Query(stmt);
144
145 uint16 matchMakerRating;
146 uint16 maxMMR;
147 if (result)
148 {
149 matchMakerRating = (*result)[0].Get<uint16>();
150 uint16 Max = (*result)[1].Get<uint16>();
151 maxMMR = std::max(Max, matchMakerRating);
152 }
153 else
154 {
155 matchMakerRating = sWorld->getIntConfig(CONFIG_ARENA_START_MATCHMAKER_RATING);
156 maxMMR = matchMakerRating;
157 }
158
159 // Remove all player signatures from other petitions
160 // This will prevent player from joining too many arena teams and corrupt arena team data integrity
162
163 // Feed data to the struct
164 ArenaTeamMember newMember;
165 //newMember.Name = playerName;
166 newMember.Guid = playerGuid;
167 newMember.Class = playerClass;
168 newMember.SeasonGames = 0;
169 newMember.WeekGames = 0;
170 newMember.SeasonWins = 0;
171 newMember.WeekWins = 0;
172 newMember.PersonalRating = personalRating;
173 newMember.MatchMakerRating = matchMakerRating;
174 newMember.MaxMMR = maxMMR;
175
176 Members.push_back(newMember);
177 sCharacterCache->UpdateCharacterArenaTeamId(playerGuid, GetSlot(), GetId());
178
179 // Save player's arena team membership to db
180 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ARENA_TEAM_MEMBER);
181 stmt->SetData(0, TeamId);
182 stmt->SetData(1, playerGuid.GetCounter());
183 CharacterDatabase.Execute(stmt);
184
185 // Inform player if online
186 if (player)
187 {
188 player->SetInArenaTeam(TeamId, GetSlot(), GetType());
189 player->SetArenaTeamIdInvited(0);
190
191 // Hide promote/remove buttons
192 if (CaptainGuid != playerGuid)
194 }
195
196 return true;
197}
@ 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
#define LOG_ERROR(filterType__,...)
Definition Log.h:158
#define sScriptMgr
Definition ScriptMgr.h:727
TeamId
Definition SharedDefines.h:759
@ CONFIG_ARENA_START_MATCHMAKER_RATING
Definition WorldConfig.h:288
@ CONFIG_ARENA_START_PERSONAL_RATING
Definition WorldConfig.h:287
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:1083
void SetArenaTeamInfoField(uint8 slot, ArenaTeamInfoType type, uint32 value)
Definition Player.cpp:16176
void SetInArenaTeam(uint32 ArenaTeamId, uint8 slot, uint8 type)
Definition Player.h:1920
uint32 GetArenaTeamId(uint8 slot) const
Definition Player.cpp:16191
static void RemovePetitionsAndSigns(ObjectGuid guid, uint32 type)
Definition Player.cpp:10090
void SetArenaTeamIdInvited(uint32 ArenaTeamId)
Definition Player.h:1930
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:793
std::string const & GetName() const
Definition Object.h:514
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 
)
574{
575 WorldPacket data(SMSG_ARENA_TEAM_EVENT, 1 + 1 + 1);
576 data << uint8(event);
577 data << uint8(strCount);
578 switch (strCount)
579 {
580 case 0:
581 break;
582 case 1:
583 data << str1;
584 break;
585 case 2:
586 data << str1 << str2;
587 break;
588 case 3:
589 data << str1 << str2 << str3;
590 break;
591 default:
592 LOG_ERROR("bg.arena", "Unhandled strCount {} in ArenaTeam::BroadcastEvent", strCount);
593 return;
594 }
595
596 if (guid)
597 data << guid;
598
599 BroadcastPacket(&data);
600
601 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_EVENT");
602}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
void BroadcastPacket(WorldPacket *packet)
Definition ArenaTeam.cpp:566
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)
567{
568 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
569 if (Player* player = ObjectAccessor::FindConnectedPlayer(itr->Guid))
570 player->GetSession()->SendPacket(packet);
571}

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:224
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 
)
1037{
1038 auto playerCountInTeam = static_cast<uint32>(playerList.size());
1039
1040 const auto standardArenaType = { ARENA_TYPE_2v2, ARENA_TYPE_3v3, ARENA_TYPE_5v5 };
1041 bool isStandardArenaType = std::find(std::begin(standardArenaType), std::end(standardArenaType), type) != std::end(standardArenaType);
1042 if (isStandardArenaType)
1043 ASSERT(playerCountInTeam == GetReqPlayersForType(type));
1044
1045 // Generate new arena team id
1046 TeamId = sArenaTeamMgr->GenerateTempArenaTeamId();
1047
1048 // Assign member variables
1049 CaptainGuid = playerList[0]->GetGUID();
1050 Type = type;
1051 TeamName = teamName;
1052
1053 BackgroundColor = 0;
1054 EmblemStyle = 0;
1055 EmblemColor = 0;
1056 BorderStyle = 0;
1057 BorderColor = 0;
1058
1059 Stats.WeekGames = 0;
1060 Stats.SeasonGames = 0;
1061 Stats.Rating = 0;
1062 Stats.WeekWins = 0;
1063 Stats.SeasonWins = 0;
1064
1065 for (auto const& _player : playerList)
1066 {
1067 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(_player->GetArenaTeamId(GetSlotByType(type)));
1068 if (!team)
1069 continue;
1070
1071 ArenaTeamMember newMember;
1072 for (auto const& itr : Members)
1073 newMember = itr;
1074
1075 Stats.WeekGames += team->Stats.WeekGames;
1076 Stats.SeasonGames += team->Stats.SeasonGames;
1077 Stats.Rating += team->GetRating();
1078 Stats.WeekWins += team->Stats.WeekWins;
1079 Stats.SeasonWins += team->Stats.SeasonWins;
1080
1081 Members.push_back(newMember);
1082 }
1083
1084 Stats.WeekGames /= playerCountInTeam;
1085 Stats.SeasonGames /= playerCountInTeam;
1086 Stats.Rating /= playerCountInTeam;
1087 Stats.WeekWins /= playerCountInTeam;
1088 Stats.SeasonWins /= playerCountInTeam;
1089}
@ ARENA_TYPE_5v5
Definition Battleground.h:210
@ ARENA_TYPE_3v3
Definition Battleground.h:209
@ ARENA_TYPE_2v2
Definition Battleground.h:208
#define ASSERT
Definition Errors.h:68
Definition ArenaTeam.h:137
ArenaTeamStats Stats
Definition ArenaTeam.h:233
static uint8 GetReqPlayersForType(uint32 type)
Definition ArenaTeam.cpp:1024
static uint8 GetSlotByType(uint32 type)
Definition ArenaTeam.cpp:621
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 
)
328{
330 Group* group = (player && player->GetGroup()) ? player->GetGroup() : nullptr;
331
332 // Remove member from team
333 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
334 {
335 // Remove queues of members
336 if (Player* playerMember = ObjectAccessor::FindConnectedPlayer(itr->Guid))
337 {
338 if (group && playerMember->GetGroup() && group->GetGUID() == playerMember->GetGroup()->GetGUID())
339 {
341 {
342 GroupQueueInfo ginfo;
343 BattlegroundQueue& queue = sBattlegroundMgr->GetBattlegroundQueue(bgQueue);
344 if (queue.GetPlayerGroupInfoData(playerMember->GetGUID(), &ginfo))
345 {
346 if (!ginfo.IsInvitedToBGInstanceGUID)
347 {
348 WorldPacket data;
349 playerMember->RemoveBattlegroundQueueId(bgQueue);
350 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, nullptr, playerMember->GetBattlegroundQueueIndex(bgQueue), STATUS_NONE, 0, 0, 0, TEAM_NEUTRAL);
351 queue.RemovePlayer(playerMember->GetGUID(), true);
352 playerMember->GetSession()->SendPacket(&data);
353 }
354 }
355 }
356 }
357 }
358
359 if (itr->Guid == guid)
360 {
361 Members.erase(itr);
362 sCharacterCache->UpdateCharacterArenaTeamId(guid, GetSlot(), 0);
363 break;
364 }
365 }
366
367 // Inform player and remove arena team info from player data
368 if (player)
369 {
371 // delete all info regarding this team
372 for (uint32 i = 0; i < ARENA_TEAM_END; ++i)
374 }
375
376 // Only used for single member deletion, for arena team disband we use a single query for more efficiency
377 if (cleanDb)
378 {
380 stmt->SetData(0, GetId());
381 stmt->SetData(1, guid.GetCounter());
382 CharacterDatabase.Execute(stmt);
383 }
384}
@ 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:190
@ CHAR_DEL_ARENA_TEAM_MEMBER
Definition CharacterDatabase.h:229
@ BATTLEGROUND_AA
Definition SharedDefines.h:3741
BattlegroundQueueTypeId
Definition SharedDefines.h:3874
@ 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:686
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:2305
WorldSession * GetSession() const
Definition Player.h:2016
Group * GetGroup()
Definition Player.h:2487
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 ( )
416{
417 // Remove all members from arena team
418 while (!Members.empty())
419 DelMember(Members.front().Guid, false);
420
421 // Update database
422 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
423
425 stmt->SetData(0, TeamId);
426 trans->Append(stmt);
427
428 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ARENA_TEAM_MEMBERS);
429 stmt->SetData(0, TeamId);
430 trans->Append(stmt);
431
432 CharacterDatabase.CommitTransaction(trans);
433
434 // Remove arena team from ObjectMgr
435 sArenaTeamMgr->RemoveArenaTeam(TeamId);
436}
@ 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:327

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

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

References Members.

◆ GetAverageMMR()

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

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

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ GetCaptain()

◆ GetChanceAgainst()

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

Referenced by GetMatchmakerRatingMod(), and GetRatingMod().

◆ GetId()

◆ GetMatchmakerRatingMod()

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

References CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER, GetChanceAgainst(), and sWorld.

Referenced by LostAgainst(), and WonAgainst().

◆ GetMember() [1/2]

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

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

References GetMember(), and sCharacterCache.

◆ GetMembers()

◆ GetMembersSize()

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

◆ GetName()

◆ GetPoints()

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

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

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

References ArenaReqPlayersForType, and LOG_ERROR.

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

◆ GetSlot()

◆ GetSlotByType()

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

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

References Members.

Referenced by arena_commandscript::HandleArenaCaptainCommand().

◆ LoadArenaTeamFromDB()

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

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

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

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

Referenced by Arena::EndBattleground().

◆ Query()

void ArenaTeam::Query ( WorldSession session)
480{
481 WorldPacket data(SMSG_ARENA_TEAM_QUERY_RESPONSE, 4 * 7 + GetName().size() + 1);
482 data << uint32(GetId()); // team id
483 data << GetName(); // team name
484 data << uint32(GetType()); // arena team type (2=2x2, 3=3x3 or 5=5x5)
485 data << uint32(BackgroundColor); // background color
486 data << uint32(EmblemStyle); // emblem style
487 data << uint32(EmblemColor); // emblem color
488 data << uint32(BorderStyle); // border style
489 data << uint32(BorderColor); // border color
490 session->SendPacket(&data);
491 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_QUERY_RESPONSE");
492}
@ 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)
439{
440 Player* player = nullptr;
441
442 uint8 unk308 = 0;
443 std::string tempName;
444
446 data << uint32(GetId()); // team id
447 data << uint8(unk308); // 308 unknown value but affect packet structure
448 data << uint32(GetMembersSize()); // members count
449 data << uint32(GetType()); // arena team type?
450
451 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
452 {
453 player = ObjectAccessor::FindConnectedPlayer(itr->Guid);
454
455 data << itr->Guid; // guid
456 data << uint8((player ? 1 : 0)); // online flag
457 tempName = "";
458 sCharacterCache->GetCharacterNameByGuid(itr->Guid, tempName);
459 data << tempName; // member name
460 data << uint32((itr->Guid == GetCaptain() ? 0 : 1));// captain flag 0 captain 1 member
461 data << uint8((player ? player->GetLevel() : 0)); // unknown, level?
462 data << uint8(itr->Class); // class
463 data << uint32(itr->WeekGames); // played this week
464 data << uint32(itr->WeekWins); // wins this week
465 data << uint32(itr->SeasonGames); // played this season
466 data << uint32(itr->SeasonWins); // wins this season
467 data << uint32(itr->PersonalRating); // personal rating
468 if (unk308)
469 {
470 data << float(0.0f); // 308 unk
471 data << float(0.0f); // 308 unk
472 }
473 }
474
475 session->SendPacket(&data);
476 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_ROSTER");
477}
uint8 GetLevel() const
Definition Unit.h:1026
@ 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)
934{
935 if (!sScriptMgr->CanSaveToDB(this))
936 return;
937
938 // Save team and member stats to db
939 // Called after a match has ended or when calculating arena_points
940
941 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
942
944 stmt->SetData(0, Stats.Rating);
945 stmt->SetData(1, Stats.WeekGames);
946 stmt->SetData(2, Stats.WeekWins);
947 stmt->SetData(3, Stats.SeasonGames);
948 stmt->SetData(4, Stats.SeasonWins);
949 stmt->SetData(5, Stats.Rank);
950 stmt->SetData(6, GetId());
951 trans->Append(stmt);
952
953 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
954 {
955 // Save the effort and go
956 if (itr->WeekGames == 0 && !forceMemberSave)
957 continue;
958
959 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ARENA_TEAM_MEMBER);
960 stmt->SetData(0, itr->PersonalRating);
961 stmt->SetData(1, itr->WeekGames);
962 stmt->SetData(2, itr->WeekWins);
963 stmt->SetData(3, itr->SeasonGames);
964 stmt->SetData(4, itr->SeasonWins);
965 stmt->SetData(5, GetId());
966 stmt->SetData(6, itr->Guid.GetCounter());
967 trans->Append(stmt);
968
969 stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHARACTER_ARENA_STATS);
970 stmt->SetData(0, itr->Guid.GetCounter());
971 stmt->SetData(1, GetSlot());
972 stmt->SetData(2, itr->MatchMakerRating);
973 stmt->SetData(3, itr->MaxMMR);
974 trans->Append(stmt);
975 }
976
977 CharacterDatabase.CommitTransaction(trans);
978}
@ 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)
495{
497 data << uint32(GetId()); // team id
498 data << uint32(Stats.Rating); // rating
499 data << uint32(Stats.WeekGames); // games this week
500 data << uint32(Stats.WeekWins); // wins this week
501 data << uint32(Stats.SeasonGames); // played this season
502 data << uint32(Stats.SeasonWins); // wins this season
503 data << uint32(Stats.Rank); // rank
504 session->SendPacket(&data);
505}
@ 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)
299{
300 // Disable remove/promote buttons
302 if (oldCaptain)
304
305 // Set new captain
306 CaptainGuid = guid;
307
308 // Update database
310 stmt->SetData(0, guid.GetCounter());
311 stmt->SetData(1, GetId());
312 CharacterDatabase.Execute(stmt);
313
314 // Enable remove/promote buttons
315 if (Player* newCaptain = ObjectAccessor::FindConnectedPlayer(guid))
316 {
317 newCaptain->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_MEMBER, 0);
318 /*if (oldCaptain)
319 {
320 LOG_DEBUG("bg.battleground", "Player: {} [{}] promoted player: {} [{}] to leader of arena team [Id: {}] [Type: {}].",
321 oldCaptain->GetName(), oldCaptain->GetGUID().ToString(), newCaptain->GetName(),
322 newCaptain->GetGUID().ToString(), GetId(), GetType());
323 }*/
324 }
325}
@ 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)
286{
287 if (TeamName == name || name.empty() || name.length() > 24 || !ObjectMgr::IsValidCharterName(name))
288 return false;
289
290 TeamName = name;
292 stmt->SetData(0, TeamName);
293 stmt->SetData(1, GetId());
294 CharacterDatabase.Execute(stmt);
295 return true;
296}
@ CHAR_UPD_ARENA_TEAM_NAME
Definition CharacterDatabase.h:234
static bool IsValidCharterName(std::string_view name)
Definition ObjectMgr.cpp:8680

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

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

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

Referenced by Arena::EndBattleground().

Member Data Documentation

◆ ArenaReqPlayersForType

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