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

#include "ArenaTeam.h"

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 ( )
34{
35 Stats.WeekGames = 0;
36 Stats.SeasonGames = 0;
37 Stats.Rank = 0;
38 Stats.Rating = sWorld->getIntConfig(CONFIG_ARENA_START_RATING);
39 Stats.WeekWins = 0;
40 Stats.SeasonWins = 0;
41}
@ CONFIG_ARENA_START_RATING
Definition: IWorld.h:332
Stats
Definition: SharedDefines.h:257
#define sWorld
Definition: World.h:444
uint32 EmblemColor
Definition: ArenaTeam.h:229
uint32 BorderColor
Definition: ArenaTeam.h:231
uint32 TeamId
Definition: ArenaTeam.h:222
uint8 Type
Definition: ArenaTeam.h:223
uint8 EmblemStyle
Definition: ArenaTeam.h:228
uint8 BorderStyle
Definition: ArenaTeam.h:230
std::string TeamName
Definition: ArenaTeam.h:224
uint32 BackgroundColor
Definition: ArenaTeam.h:227

References CONFIG_ARENA_START_RATING, and sWorld.

◆ ~ArenaTeam()

ArenaTeam::~ArenaTeam ( )
44{
45}

Member Function Documentation

◆ AddMember()

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

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 
)
571{
572 WorldPacket data(SMSG_ARENA_TEAM_EVENT, 1 + 1 + 1);
573 data << uint8(event);
574 data << uint8(strCount);
575 switch (strCount)
576 {
577 case 0:
578 break;
579 case 1:
580 data << str1;
581 break;
582 case 2:
583 data << str1 << str2;
584 break;
585 case 3:
586 data << str1 << str2 << str3;
587 break;
588 default:
589 LOG_ERROR("bg.arena", "Unhandled strCount {} in ArenaTeam::BroadcastEvent", strCount);
590 return;
591 }
592
593 if (guid)
594 data << guid;
595
596 BroadcastPacket(&data);
597
598 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_EVENT");
599}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:168
@ SMSG_ARENA_TEAM_EVENT
Definition: Opcodes.h:885
void BroadcastPacket(WorldPacket *packet)
Definition: ArenaTeam.cpp:563
Definition: WorldPacket.h:27

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)
564{
565 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
566 if (Player* player = ObjectAccessor::FindConnectedPlayer(itr->Guid))
567 player->GetSession()->SendPacket(packet);
568}

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

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 
)
1034{
1035 auto playerCountInTeam = static_cast<uint32>(playerList.size());
1036
1037 const auto standardArenaType = { ARENA_TYPE_2v2, ARENA_TYPE_3v3, ARENA_TYPE_5v5 };
1038 bool isStandardArenaType = std::find(std::begin(standardArenaType), std::end(standardArenaType), type) != std::end(standardArenaType);
1039 if (isStandardArenaType)
1040 ASSERT(playerCountInTeam == GetReqPlayersForType(type));
1041
1042 // Generate new arena team id
1043 TeamId = sArenaTeamMgr->GenerateTempArenaTeamId();
1044
1045 // Assign member variables
1046 CaptainGuid = playerList[0]->GetGUID();
1047 Type = type;
1048 TeamName = teamName;
1049
1050 BackgroundColor = 0;
1051 EmblemStyle = 0;
1052 EmblemColor = 0;
1053 BorderStyle = 0;
1054 BorderColor = 0;
1055
1056 Stats.WeekGames = 0;
1057 Stats.SeasonGames = 0;
1058 Stats.Rating = 0;
1059 Stats.WeekWins = 0;
1060 Stats.SeasonWins = 0;
1061
1062 for (auto const& _player : playerList)
1063 {
1064 ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(_player->GetArenaTeamId(GetSlotByType(type)));
1065 if (!team)
1066 continue;
1067
1068 ArenaTeamMember newMember;
1069 for (auto const& itr : Members)
1070 newMember = itr;
1071
1072 Stats.WeekGames += team->Stats.WeekGames;
1073 Stats.SeasonGames += team->Stats.SeasonGames;
1074 Stats.Rating += team->GetRating();
1075 Stats.WeekWins += team->Stats.WeekWins;
1076 Stats.SeasonWins += team->Stats.SeasonWins;
1077
1078 Members.push_back(newMember);
1079 }
1080
1081 Stats.WeekGames /= playerCountInTeam;
1082 Stats.SeasonGames /= playerCountInTeam;
1083 Stats.Rating /= playerCountInTeam;
1084 Stats.WeekWins /= playerCountInTeam;
1085 Stats.SeasonWins /= playerCountInTeam;
1086}
#define ASSERT
Definition: Errors.h:68
@ ARENA_TYPE_5v5
Definition: Battleground.h:214
@ ARENA_TYPE_3v3
Definition: Battleground.h:213
@ ARENA_TYPE_2v2
Definition: Battleground.h:212
uint16 SeasonGames
Definition: ArenaTeam.h:130
uint16 WeekGames
Definition: ArenaTeam.h:128
uint16 WeekWins
Definition: ArenaTeam.h:129
uint16 SeasonWins
Definition: ArenaTeam.h:131
Definition: ArenaTeam.h:138
ArenaTeamStats Stats
Definition: ArenaTeam.h:234
static uint8 GetReqPlayersForType(uint32 type)
Definition: ArenaTeam.cpp:1021
static uint8 GetSlotByType(uint32 type)
Definition: ArenaTeam.cpp:618

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 
)
325{
327 Group* group = (player && player->GetGroup()) ? player->GetGroup() : nullptr;
328
329 // Remove member from team
330 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
331 {
332 // Remove queues of members
333 if (Player* playerMember = ObjectAccessor::FindConnectedPlayer(itr->Guid))
334 {
335 if (group && playerMember->GetGroup() && group->GetGUID() == playerMember->GetGroup()->GetGUID())
336 {
338 {
339 GroupQueueInfo ginfo;
340 BattlegroundQueue& queue = sBattlegroundMgr->GetBattlegroundQueue(bgQueue);
341 if (queue.GetPlayerGroupInfoData(playerMember->GetGUID(), &ginfo))
342 {
343 if (!ginfo.IsInvitedToBGInstanceGUID)
344 {
345 WorldPacket data;
346 playerMember->RemoveBattlegroundQueueId(bgQueue);
347 sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, nullptr, playerMember->GetBattlegroundQueueIndex(bgQueue), STATUS_NONE, 0, 0, 0, TEAM_NEUTRAL);
348 queue.RemovePlayer(playerMember->GetGUID(), true);
349 playerMember->GetSession()->SendPacket(&data);
350 }
351 }
352 }
353 }
354 }
355
356 if (itr->Guid == guid)
357 {
358 Members.erase(itr);
359 sCharacterCache->UpdateCharacterArenaTeamId(guid, GetSlot(), 0);
360 break;
361 }
362 }
363
364 // Inform player and remove arena team info from player data
365 if (player)
366 {
368 // delete all info regarding this team
369 for (uint32 i = 0; i < ARENA_TEAM_END; ++i)
371 }
372
373 // Only used for single member deletion, for arena team disband we use a single query for more efficiency
374 if (cleanDb)
375 {
377 stmt->SetData(0, GetId());
378 stmt->SetData(1, guid.GetCounter());
379 CharacterDatabase.Execute(stmt);
380 }
381}
@ ERR_ARENA_TEAM_QUIT_S
Definition: ArenaTeam.h:35
ArenaTeamInfoType
Definition: ArenaTeam.h:74
@ ARENA_TEAM_END
Definition: ArenaTeam.h:82
@ STATUS_NONE
Definition: Battleground.h:194
#define sBattlegroundMgr
Definition: BattlegroundMgr.h:188
@ CHAR_DEL_ARENA_TEAM_MEMBER
Definition: CharacterDatabase.h:227
@ BATTLEGROUND_AA
Definition: SharedDefines.h:3486
BattlegroundQueueTypeId
Definition: SharedDefines.h:3619
@ TEAM_NEUTRAL
Definition: SharedDefines.h:762
std::string const & GetName() const
Definition: ArenaTeam.h:155
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
Definition: BattlegroundMgr.cpp:672
Definition: BattlegroundQueue.h:31
uint32 IsInvitedToBGInstanceGUID
Definition: BattlegroundQueue.h:41
Definition: BattlegroundQueue.h:64
bool GetPlayerGroupInfoData(ObjectGuid guid, GroupQueueInfo *ginfo)
Definition: BattlegroundQueue.cpp:383
void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount)
Definition: BattlegroundQueue.cpp:259
WorldSession * GetSession() const
Definition: Player.h:1978
Group * GetGroup()
Definition: Player.h:2448
Definition: Group.h:169
ObjectGuid GetGUID() const
Definition: Group.cpp:2306
void SendArenaTeamCommandResult(uint32 team_action, std::string const &team, std::string const &player, uint32 error_id=0)
Definition: ArenaTeamHandler.cpp:406

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 Disband(), WorldSession::HandleArenaTeamLeaveOpcode(), WorldSession::HandleArenaTeamRemoveOpcode(), Player::LeaveAllArenaTeams(), and LoadMembersFromDB().

◆ Disband() [1/2]

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

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)
384{
385 // Remove all members from arena team
386 while (!Members.empty())
387 DelMember(Members.front().Guid, false);
388
389 // Broadcast update
390 if (session)
391 {
393 }
394
395 // Update database
396 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
397
399 stmt->SetData(0, TeamId);
400 trans->Append(stmt);
401
402 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ARENA_TEAM_MEMBERS);
403 stmt->SetData(0, TeamId);
404 trans->Append(stmt);
405
406 CharacterDatabase.CommitTransaction(trans);
407
408 // Remove arena team from ObjectMgr
409 sArenaTeamMgr->RemoveArenaTeam(TeamId);
410}
@ ERR_ARENA_TEAM_DISBANDED_S
Definition: ArenaTeam.h:69
void BroadcastEvent(ArenaTeamEvents event, ObjectGuid guid, uint8 strCount, std::string const &str1, std::string const &str2, std::string const &str3)
Definition: ArenaTeam.cpp:570
static ObjectGuid const Empty
Definition: ObjectGuid.h:120
std::string const & GetPlayerName() const
Definition: WorldSession.cpp:186

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
171{ return Members.empty(); }

References Members.

Referenced by LoadMembersFromDB().

◆ FinishGame()

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

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

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

◆ FinishWeek()

bool ArenaTeam::FinishWeek ( )
978{
979 // No need to go further than this
980 if (Stats.WeekGames == 0)
981 return false;
982
983 // Reset team stats
984 Stats.WeekGames = 0;
985 Stats.WeekWins = 0;
986
987 // Reset member stats
988 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
989 {
990 itr->WeekGames = 0;
991 itr->WeekWins = 0;
992 }
993
994 return true;
995}

References Members.

◆ GetAverageMMR()

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

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

Referenced by WorldSession::HandleBattlemasterJoinArena().

◆ GetCaptain()

◆ GetChanceAgainst()

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

Referenced by GetMatchmakerRatingMod(), and GetRatingMod().

◆ GetId()

◆ GetMatchmakerRatingMod()

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

References CONFIG_ARENA_MATCHMAKER_RATING_MODIFIER, GetChanceAgainst(), and sWorld.

Referenced by LostAgainst(), and WonAgainst().

◆ GetMember() [1/2]

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

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

References GetMember(), and sCharacterCache.

◆ GetMembers()

MemberList & ArenaTeam::GetMembers ( )
inline

◆ GetMembersSize()

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

◆ GetName()

◆ GetPoints()

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

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

Referenced by UpdateArenaPointsHelper().

◆ GetPreviousOpponents()

uint32 ArenaTeam::GetPreviousOpponents ( )
inline
213{ return PreviousOpponents; }
uint32 PreviousOpponents
Definition: ArenaTeam.h:236

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

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

References ArenaReqPlayersForType, and LOG_ERROR.

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

◆ GetSlot()

◆ GetSlotByType()

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

References ArenaSlotByType, LOG_ERROR, and sScriptMgr.

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

◆ GetStats()

const ArenaTeamStats & ArenaTeam::GetStats ( ) const
inline
156{ return Stats; }

References Stats.

Referenced by AchievementMgr::UpdateAchievementCriteria().

◆ GetType()

◆ Inspect()

void ArenaTeam::Inspect ( WorldSession session,
ObjectGuid  guid 
)
514{
515 ArenaTeamMember* member = GetMember(guid);
516 if (!member || GetSlot() >= MAX_ARENA_SLOT)
517 return;
518
519 WorldPacket data(MSG_INSPECT_ARENA_TEAMS, 8 + 1 + 4 * 6);
520 data << guid; // player guid
521 data << uint8(GetSlot()); // slot (0...2)
522 data << uint32(GetId()); // arena team id
523 data << uint32(Stats.Rating); // rating
524 data << uint32(Stats.SeasonGames); // season played
525 data << uint32(Stats.SeasonWins); // season wins
526 data << uint32(member->SeasonGames); // played (count of all games, that the inspected member participated...)
527 data << uint32(member->PersonalRating); // personal rating
528 session->SendPacket(&data);
529}
#define MAX_ARENA_SLOT
Definition: ArenaTeam.h:135
@ MSG_INSPECT_ARENA_TEAMS
Definition: Opcodes.h:917
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214

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

◆ IsFighting()

bool ArenaTeam::IsFighting ( ) const
998{
999 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
1000 if (Player* player = ObjectAccessor::FindPlayer(itr->Guid))
1001 if (player->GetMap()->IsBattleArena())
1002 return true;
1003
1004 return false;
1005}
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:248

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

References Members.

Referenced by arena_commandscript::HandleArenaCaptainCommand().

◆ LoadArenaTeamFromDB()

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

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

Referenced by ArenaTeamMgr::LoadArenaTeams().

◆ LoadMembersFromDB()

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

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 
)
826{
827 // Called when the team has lost
828 // Change in Matchmaker Rating
829 int32 mod = GetMatchmakerRatingMod(Own_MMRating, Opponent_MMRating, false);
830
831 // Change in Team Rating
832 rating_change = GetRatingMod(Stats.Rating, Opponent_MMRating, false);
833
834 // Modify the team stats accordingly
835 FinishGame(rating_change, bgMap);
836
837 // return the rating change, used to display it on the results screen
838 return mod;
839}
int32 GetRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition: ArenaTeam.cpp:745
int32 GetMatchmakerRatingMod(uint32 ownRating, uint32 opponentRating, bool won)
Definition: ArenaTeam.cpp:719
void FinishGame(int32 mod, const Map *bgMap)
Definition: ArenaTeam.cpp:775

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

Referenced by Arena::EndBattleground().

◆ m_membersBegin()

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

References Members.

◆ m_membersEnd()

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

References Members.

◆ MassInviteToEvent()

void ArenaTeam::MassInviteToEvent ( WorldSession session)
602{
603 WorldPacket data(SMSG_CALENDAR_ARENA_TEAM, (Members.size() - 1) * (4 + 8 + 1));
604 data << uint32(Members.size() - 1);
605
606 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
607 {
608 if (itr->Guid != session->GetPlayer()->GetGUID())
609 {
610 data << itr->Guid.WriteAsPacked();
611 data << uint8(0); // unk
612 }
613 }
614
615 session->SendPacket(&data);
616}
@ SMSG_CALENDAR_ARENA_TEAM
Definition: Opcodes.h:1111
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
Player * GetPlayer() const
Definition: WorldSession.h:362

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

◆ MemberLost()

void ArenaTeam::MemberLost ( Player player,
uint32  againstMatchmakerRating,
int32  MatchmakerRatingChange = -12 
)
842{
843 // Called for each participant of a match after losing
844 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
845 {
846 if (itr->Guid == player->GetGUID())
847 {
848 // Update personal rating
849 int32 mod = GetRatingMod(itr->PersonalRating, againstMatchmakerRating, false);
850 itr->ModifyPersonalRating(player, mod, GetType());
851
852 // Update matchmaker rating
853 itr->ModifyMatchmakerRating(MatchmakerRatingChange, GetSlot());
854
855 // Update personal played stats
856 itr->WeekGames += 1;
857 itr->SeasonGames += 1;
858
859 // update the unit fields
860 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_WEEK, itr->WeekGames);
861 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_SEASON, itr->SeasonGames);
862 return;
863 }
864 }
865}
@ ARENA_TEAM_GAMES_WEEK
Definition: ArenaTeam.h:78
@ ARENA_TEAM_GAMES_SEASON
Definition: ArenaTeam.h:79

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 
)
868{
869 // called for each participant after winning a match
870 for (MemberList::iterator itr = Members.begin(); itr != Members.end(); ++itr)
871 {
872 if (itr->Guid == player->GetGUID())
873 {
874 // update personal rating
875 int32 mod = GetRatingMod(itr->PersonalRating, againstMatchmakerRating, true);
876 sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
877 itr->ModifyPersonalRating(player, mod, GetType());
878
879 // update matchmaker rating (pussywizard: but don't allow it to go over team rating)
880 if (itr->MatchMakerRating < Stats.Rating)
881 {
882 mod = std::min(MatchmakerRatingChange, Stats.Rating - itr->MatchMakerRating);
883 sScriptMgr->OnBeforeUpdatingPersonalRating(mod, GetType());
884 itr->ModifyMatchmakerRating(mod, GetSlot());
885 }
886
887 // update personal stats
888 itr->WeekGames += 1;
889 itr->SeasonGames += 1;
890 itr->SeasonWins += 1;
891 itr->WeekWins += 1;
892 // update unit fields
893 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_WEEK, itr->WeekGames);
894 player->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_GAMES_SEASON, itr->SeasonGames);
895 return;
896 }
897 }
898}

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

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

Referenced by Arena::EndBattleground().

◆ Query()

void ArenaTeam::Query ( WorldSession session)
477{
478 WorldPacket data(SMSG_ARENA_TEAM_QUERY_RESPONSE, 4 * 7 + GetName().size() + 1);
479 data << uint32(GetId()); // team id
480 data << GetName(); // team name
481 data << uint32(GetType()); // arena team type (2=2x2, 3=3x3 or 5=5x5)
482 data << uint32(BackgroundColor); // background color
483 data << uint32(EmblemStyle); // emblem style
484 data << uint32(EmblemColor); // emblem color
485 data << uint32(BorderStyle); // border style
486 data << uint32(BorderColor); // border color
487 session->SendPacket(&data);
488 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_QUERY_RESPONSE");
489}
@ 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)
436{
437 Player* player = nullptr;
438
439 uint8 unk308 = 0;
440 std::string tempName;
441
443 data << uint32(GetId()); // team id
444 data << uint8(unk308); // 308 unknown value but affect packet structure
445 data << uint32(GetMembersSize()); // members count
446 data << uint32(GetType()); // arena team type?
447
448 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
449 {
450 player = ObjectAccessor::FindConnectedPlayer(itr->Guid);
451
452 data << itr->Guid; // guid
453 data << uint8((player ? 1 : 0)); // online flag
454 tempName = "";
455 sCharacterCache->GetCharacterNameByGuid(itr->Guid, tempName);
456 data << tempName; // member name
457 data << uint32((itr->Guid == GetCaptain() ? 0 : 1));// captain flag 0 captain 1 member
458 data << uint8((player ? player->GetLevel() : 0)); // unknown, level?
459 data << uint8(itr->Class); // class
460 data << uint32(itr->WeekGames); // played this week
461 data << uint32(itr->WeekWins); // wins this week
462 data << uint32(itr->SeasonGames); // played this season
463 data << uint32(itr->SeasonWins); // wins this season
464 data << uint32(itr->PersonalRating); // personal rating
465 if (unk308)
466 {
467 data << float(0.0f); // 308 unk
468 data << float(0.0f); // 308 unk
469 }
470 }
471
472 session->SendPacket(&data);
473 LOG_DEBUG("network", "WORLD: Sent SMSG_ARENA_TEAM_ROSTER");
474}
@ SMSG_ARENA_TEAM_ROSTER
Definition: Opcodes.h:876
uint8 GetLevel() const
Definition: Unit.h:855

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)
931{
932 if (!sScriptMgr->CanSaveToDB(this))
933 return;
934
935 // Save team and member stats to db
936 // Called after a match has ended or when calculating arena_points
937
938 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
939
941 stmt->SetData(0, Stats.Rating);
942 stmt->SetData(1, Stats.WeekGames);
943 stmt->SetData(2, Stats.WeekWins);
944 stmt->SetData(3, Stats.SeasonGames);
945 stmt->SetData(4, Stats.SeasonWins);
946 stmt->SetData(5, Stats.Rank);
947 stmt->SetData(6, GetId());
948 trans->Append(stmt);
949
950 for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr)
951 {
952 // Save the effort and go
953 if (itr->WeekGames == 0 && !forceMemberSave)
954 continue;
955
956 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_ARENA_TEAM_MEMBER);
957 stmt->SetData(0, itr->PersonalRating);
958 stmt->SetData(1, itr->WeekGames);
959 stmt->SetData(2, itr->WeekWins);
960 stmt->SetData(3, itr->SeasonGames);
961 stmt->SetData(4, itr->SeasonWins);
962 stmt->SetData(5, GetId());
963 stmt->SetData(6, itr->Guid.GetCounter());
964 trans->Append(stmt);
965
966 stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CHARACTER_ARENA_STATS);
967 stmt->SetData(0, itr->Guid.GetCounter());
968 stmt->SetData(1, GetSlot());
969 stmt->SetData(2, itr->MatchMakerRating);
970 stmt->SetData(3, itr->MaxMMR);
971 trans->Append(stmt);
972 }
973
974 CharacterDatabase.CommitTransaction(trans);
975}
@ CHAR_UPD_ARENA_TEAM_STATS
Definition: CharacterDatabase.h:228
@ CHAR_REP_CHARACTER_ARENA_STATS
Definition: CharacterDatabase.h:230
@ CHAR_UPD_ARENA_TEAM_MEMBER
Definition: CharacterDatabase.h:229

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)
492{
494 data << uint32(GetId()); // team id
495 data << uint32(Stats.Rating); // rating
496 data << uint32(Stats.WeekGames); // games this week
497 data << uint32(Stats.WeekWins); // wins this week
498 data << uint32(Stats.SeasonGames); // played this season
499 data << uint32(Stats.SeasonWins); // wins this season
500 data << uint32(Stats.Rank); // rank
501 session->SendPacket(&data);
502}
@ 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
157{ Stats = stats; }

◆ SetCaptain()

void ArenaTeam::SetCaptain ( ObjectGuid  guid)
296{
297 // Disable remove/promote buttons
299 if (oldCaptain)
301
302 // Set new captain
303 CaptainGuid = guid;
304
305 // Update database
307 stmt->SetData(0, guid.GetCounter());
308 stmt->SetData(1, GetId());
309 CharacterDatabase.Execute(stmt);
310
311 // Enable remove/promote buttons
312 if (Player* newCaptain = ObjectAccessor::FindConnectedPlayer(guid))
313 {
314 newCaptain->SetArenaTeamInfoField(GetSlot(), ARENA_TEAM_MEMBER, 0);
315 /*if (oldCaptain)
316 {
317 LOG_DEBUG("bg.battleground", "Player: {} [{}] promoted player: {} [{}] to leader of arena team [Id: {}] [Type: {}].",
318 oldCaptain->GetName(), oldCaptain->GetGUID().ToString(), newCaptain->GetName(),
319 newCaptain->GetGUID().ToString(), GetId(), GetType());
320 }*/
321 }
322}
@ CHAR_UPD_ARENA_TEAM_CAPTAIN
Definition: CharacterDatabase.h:226

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)
283{
284 if (TeamName == name || name.empty() || name.length() > 24 || !ObjectMgr::IsValidCharterName(name))
285 return false;
286
287 TeamName = name;
289 stmt->SetData(0, TeamName);
290 stmt->SetData(1, GetId());
291 CharacterDatabase.Execute(stmt);
292 return true;
293}
@ CHAR_UPD_ARENA_TEAM_NAME
Definition: CharacterDatabase.h:232
static bool IsValidCharterName(std::string_view name)
Definition: ObjectMgr.cpp:8413

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
212{ PreviousOpponents = arenaTeamId; }

References PreviousOpponents.

Referenced by Arena::EndBattleground().

◆ UpdateArenaPointsHelper()

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

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

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

Referenced by Arena::EndBattleground().

Member Data Documentation

◆ ArenaReqPlayersForType

std::unordered_map< uint8, uint8 > ArenaTeam::ArenaReqPlayersForType
static
Initial value:
=
{
}

Referenced by GetReqPlayersForType().

◆ ArenaSlotByType

std::unordered_map< uint32, uint8 > ArenaTeam::ArenaSlotByType
static
Initial value:
=
{
}
@ ARENA_TEAM_5v5
Definition: ArenaTeam.h:98
@ ARENA_SLOT_2v2
Definition: ArenaTeam.h:103
@ ARENA_SLOT_5v5
Definition: ArenaTeam.h:105
@ ARENA_SLOT_3v3
Definition: ArenaTeam.h:104

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

uint8 ArenaTeam::Type
protected