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:245
@ CONFIG_ARENA_START_RATING
Definition WorldConfig.h:291
@ CONFIG_LEGACY_ARENA_START_RATING
Definition WorldConfig.h:292
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:316

References CONFIG_ARENA_START_RATING, CONFIG_LEGACY_ARENA_START_RATING, sArenaSeasonMgr, and sWorld.

◆ ~ArenaTeam()

ArenaTeam::~ArenaTeam ( )
47{
48}

Member Function Documentation

◆ AddMember()

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

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

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

◆ BroadcastEvent()

void ArenaTeam::BroadcastEvent ( ArenaTeamEvents  event,
ObjectGuid  guid,
uint8  strCount,
std::string const &  str1,
std::string const &  str2,
std::string const &  str3 
)
577{
578 WorldPacket data(SMSG_ARENA_TEAM_EVENT, 1 + 1 + 1);
579 data << uint8(event);
580 data << uint8(strCount);
581 switch (strCount)
582 {
583 case 0:
584 break;
585 case 1:
586 data << str1;
587 break;
588 case 2:
589 data << str1 << str2;
590 break;
591 case 3:
592 data << str1 << str2 << str3;
593 break;
594 default:
595 LOG_ERROR("bg.arena", "Unhandled strCount {} in ArenaTeam::BroadcastEvent", strCount);
596 return;
597 }
598
599 if (guid)
600 data << guid;
601
602 BroadcastPacket(&data);
603
604 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_EVENT");
605}
#define LOG_DEBUG(filterType__,...)
Definition Log.h:170
void BroadcastPacket(WorldPacket *packet)
Definition ArenaTeam.cpp:569
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)
570{
571 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
572 if (Player* player = ObjectAccessor::FindConnectedPlayer(itr->Guid))
573 player->SendDirectMessage(packet);
574}

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 
)
1043{
1044 auto playerCountInTeam = static_cast<uint32>(playerList.size());
1045
1046 const auto standardArenaType = { ARENA_TYPE_2v2, ARENA_TYPE_3v3, ARENA_TYPE_5v5 };
1047 bool isStandardArenaType = std::find(std::begin(standardArenaType), std::end(standardArenaType), type) != std::end(standardArenaType);
1048 if (isStandardArenaType)
1049 ASSERT(playerCountInTeam == GetReqPlayersForType(type));
1050
1051 // Generate new arena team id
1052 TeamId = sArenaTeamMgr->GenerateTempArenaTeamId();
1053
1054 // Assign member variables
1055 CaptainGuid = playerList[0]->GetGUID();
1056 Type = type;
1057 TeamName = teamName;
1058
1059 BackgroundColor = 0;
1060 EmblemStyle = 0;
1061 EmblemColor = 0;
1062 BorderStyle = 0;
1063 BorderColor = 0;
1064
1065 Stats.WeekGames = 0;
1066 Stats.SeasonGames = 0;
1067 Stats.Rating = 0;
1068 Stats.WeekWins = 0;
1069 Stats.SeasonWins = 0;
1070
1071 for (auto const& _player : playerList)
1072 {
1073 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(_player->GetArenaTeamId(GetSlotByType(type)));
1074 if (!team)
1075 continue;
1076
1077 ArenaTeamMember newMember;
1078 for (auto const& itr : Members)
1079 newMember = itr;
1080
1081 Stats.WeekGames += team->Stats.WeekGames;
1082 Stats.SeasonGames += team->Stats.SeasonGames;
1083 Stats.Rating += team->GetRating();
1084 Stats.WeekWins += team->Stats.WeekWins;
1085 Stats.SeasonWins += team->Stats.SeasonWins;
1086
1087 Members.push_back(newMember);
1088 }
1089
1090 Stats.WeekGames /= playerCountInTeam;
1091 Stats.SeasonGames /= playerCountInTeam;
1092 Stats.Rating /= playerCountInTeam;
1093 Stats.WeekWins /= playerCountInTeam;
1094 Stats.SeasonWins /= playerCountInTeam;
1095}
@ 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:1030
static uint8 GetSlotByType(uint32 type)
Definition ArenaTeam.cpp:624
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 
)
331{
333 Group* group = (player && player->GetGroup()) ? player->GetGroup() : nullptr;
334
335 // Remove member from team
336 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
337 {
338 // Remove queues of members
339 if (Player* playerMember = ObjectAccessor::FindConnectedPlayer(itr->Guid))
340 {
341 if (group && playerMember->GetGroup() && group->GetGUID() == playerMember->GetGroup()->GetGUID())
342 {
344 {
345 GroupQueueInfo ginfo;
346 BattlegroundQueue& queue = sBattlegroundMgr->GetBattlegroundQueue(bgQueue);
347 if (queue.GetPlayerGroupInfoData(playerMember->GetGUID(), &ginfo))
348 {
349 if (!ginfo.IsInvitedToBGInstanceGUID)
350 {
351 WorldPacket data;
352 playerMember->RemoveBattlegroundQueueId(bgQueue);
353 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, nullptr, playerMember->GetBattlegroundQueueIndex(bgQueue), STATUS_NONE, 0, 0, 0, TEAM_NEUTRAL);
354 queue.RemovePlayer(playerMember->GetGUID(), true);
355 playerMember->SendDirectMessage(&data);
356 }
357 }
358 }
359 }
360 }
361
362 if (itr->Guid == guid)
363 {
364 Members.erase(itr);
365 sCharacterCache->UpdateCharacterArenaTeamId(guid, GetSlot(), 0);
366 break;
367 }
368 }
369
370 // Inform player and remove arena team info from player data
371 if (player)
372 {
374 // delete all info regarding this team
375 for (uint32 i = 0; i < ARENA_TEAM_END; ++i)
377 }
378
379 // Only used for single member deletion, for arena team disband we use a single query for more efficiency
380 if (cleanDb)
381 {
383 stmt->SetData(0, GetId());
384 stmt->SetData(1, guid.GetCounter());
385 CharacterDatabase.Execute(stmt);
386 }
387}
@ 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:3744
BattlegroundQueueTypeId
Definition SharedDefines.h:3877
@ TEAM_NEUTRAL
Definition SharedDefines.h:750
std::string const & GetName() const
Definition ArenaTeam.h:154
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition BattlegroundMgr.cpp: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:2316
WorldSession * GetSession() const
Definition Player.h:2019
Group * GetGroup()
Definition Player.h:2504
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 ( )
419{
420 // Remove all members from arena team
421 while (!Members.empty())
422 DelMember(Members.front().Guid, false);
423
424 // Update database
425 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
426
428 stmt->SetData(0, TeamId);
429 trans->Append(stmt);
430
431 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ARENA_TEAM_MEMBERS);
432 stmt->SetData(0, TeamId);
433 trans->Append(stmt);
434
435 CharacterDatabase.CommitTransaction(trans);
436
437 // Remove arena team from ObjectMgr
438 sArenaTeamMgr->RemoveArenaTeam(TeamId);
439}
@ 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:330

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

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

References Members.

◆ GetAverageMMR()

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

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

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ GetCaptain()

◆ GetChanceAgainst()

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

Referenced by GetMatchmakerRatingMod(), and GetRatingMod().

◆ GetId()

◆ GetMatchmakerRatingMod()

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

References CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER, GetChanceAgainst(), and sWorld.

Referenced by LostAgainst(), and WonAgainst().

◆ GetMember() [1/2]

ArenaTeamMember * ArenaTeam::GetMember ( ObjectGuid  guid)
1022{
1023 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
1024 if (itr->Guid == guid)
1025 return &(*itr);
1026
1027 return nullptr;
1028}

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)
1017{
1018 return GetMember(sCharacterCache->GetCharacterGuidByName(name));
1019}
ArenaTeamMember * GetMember(ObjectGuid guid)
Definition ArenaTeam.cpp:1021

References GetMember(), and sCharacterCache.

◆ GetMembers()

◆ GetMembersSize()

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

◆ GetName()

◆ GetPoints()

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

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

Referenced by UpdateArenaPointsHelper().

◆ GetPreviousOpponents()

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

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
1031{
1032 auto const& itr = ArenaReqPlayersForType.find(type);
1033 if (itr == ArenaReqPlayersForType.end())
1034 {
1035 LOG_ERROR("bg.arena", "FATAL: Unknown arena type {}!", type);
1036 return 0xFF;
1037 }
1038
1039 return ArenaReqPlayersForType.at(type);
1040}
static std::unordered_map< uint8, uint8 > ArenaReqPlayersForType
Definition ArenaTeam.h:1106

References ArenaReqPlayersForType, and LOG_ERROR.

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

◆ GetSlot()

◆ GetSlotByType()

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

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

References Members.

Referenced by arena_commandscript::HandleArenaCaptainCommand().

◆ LoadArenaTeamFromDB()

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

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

Referenced by ArenaTeamMgr::LoadArenaTeams().

◆ LoadStatsFromDB()

void ArenaTeam::LoadStatsFromDB ( uint32  ArenaTeamId)

◆ LostAgainst()

int32 ArenaTeam::LostAgainst ( uint32  Own_MMRating,
uint32  Opponent_MMRating,
int32 rating_change,
const Map bgMap 
)
832{
833 // Called when the team has lost
834 // Change in Matchmaker Rating
835 int32 mod = GetMatchmakerRatingMod(Own_MMRating, Opponent_MMRating, false);
836
837 // Change in Team Rating
838 rating_change = GetRatingMod(Stats.Rating, Opponent_MMRating, false);
839
840 // Modify the team stats accordingly
841 FinishGame(rating_change, bgMap);
842
843 // return the rating change, used to display it on the results screen
844 return mod;
845}
int32 GetRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition ArenaTeam.cpp:751
int32 GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition ArenaTeam.cpp:725
void FinishGame(int32 mod, const Map *bgMap)
Definition ArenaTeam.cpp:781

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

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

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

Referenced by Arena::EndBattleground().

◆ Query()

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

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

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

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

Referenced by Arena::EndBattleground().

Member Data Documentation

◆ ArenaReqPlayersForType

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

Referenced by GetReqPlayersForType().

◆ ArenaSlotByType

std::unordered_map< uint32, uint8 > ArenaTeam::ArenaSlotByType
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

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: