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

#include "ArenaTeamMgr.h"

Public Types

typedef std::unordered_map< uint32, ArenaTeam * > ArenaTeamContainer
 

Public Member Functions

ArenaTeamGetArenaTeamById (uint32 arenaTeamId) const
 
ArenaTeamGetArenaTeamByName (std::string const &arenaTeamName) const
 
ArenaTeamGetArenaTeamByCaptain (ObjectGuid guid) const
 
ArenaTeamGetArenaTeamByName (std::string const &arenaTeamName, const uint32 type) const
 
ArenaTeamGetArenaTeamByCaptain (ObjectGuid guid, const uint32 type) const
 
void LoadArenaTeams ()
 
void AddArenaTeam (ArenaTeam *arenaTeam)
 
void RemoveArenaTeam (uint32 Id)
 
ArenaTeamContainer::iterator GetArenaTeamMapBegin ()
 
ArenaTeamContainer::iterator GetArenaTeamMapEnd ()
 
ArenaTeamContainerGetArenaTeams ()
 
void DistributeArenaPoints ()
 
uint32 GenerateArenaTeamId ()
 
void SetNextArenaTeamId (uint32 Id)
 
uint32 GetNextArenaLogId ()
 
void SetLastArenaLogId (uint32 id)
 
uint32 GenerateTempArenaTeamId ()
 

Static Public Member Functions

static ArenaTeamMgrinstance ()
 

Protected Attributes

uint32 NextArenaTeamId
 
uint32 NextTempArenaTeamId
 
ArenaTeamContainer ArenaTeamStore
 
uint32 LastArenaLogId
 

Private Member Functions

 ArenaTeamMgr ()
 
 ~ArenaTeamMgr ()
 

Detailed Description

Member Typedef Documentation

◆ ArenaTeamContainer

typedef std::unordered_map<uint32, ArenaTeam*> ArenaTeamMgr::ArenaTeamContainer

Constructor & Destructor Documentation

◆ ArenaTeamMgr()

ArenaTeamMgr::ArenaTeamMgr ( )
private
30{
33 NextTempArenaTeamId = 0xFFF00000;
34}
uint32 NextArenaTeamId
Definition: ArenaTeamMgr.h:61
uint32 NextTempArenaTeamId
Definition: ArenaTeamMgr.h:62
uint32 LastArenaLogId
Definition: ArenaTeamMgr.h:64

References LastArenaLogId, NextArenaTeamId, and NextTempArenaTeamId.

◆ ~ArenaTeamMgr()

ArenaTeamMgr::~ArenaTeamMgr ( )
private
37{
38 for (ArenaTeamContainer::iterator itr = ArenaTeamStore.begin(); itr != ArenaTeamStore.end(); ++itr)
39 delete itr->second;
40}
ArenaTeamContainer ArenaTeamStore
Definition: ArenaTeamMgr.h:63

References ArenaTeamStore.

Member Function Documentation

◆ AddArenaTeam()

void ArenaTeamMgr::AddArenaTeam ( ArenaTeam arenaTeam)
119{
120 ArenaTeamStore[arenaTeam->GetId()] = arenaTeam;
121}
uint32 GetId() const
Definition: ArenaTeam.h:148

References ArenaTeamStore, and ArenaTeam::GetId().

Referenced by LoadArenaTeams().

◆ DistributeArenaPoints()

void ArenaTeamMgr::DistributeArenaPoints ( )
196{
197 // Used to distribute arena points based on last week's stats
199
201
202 // Temporary structure for storing maximum points to add values for all players
203 std::map<ObjectGuid, uint32> PlayerPoints;
204
205 // At first update all points for all team members
206 for (ArenaTeamContainer::iterator teamItr = GetArenaTeamMapBegin(); teamItr != GetArenaTeamMapEnd(); ++teamItr)
207 if (ArenaTeam* at = teamItr->second)
208 {
209 at->UpdateArenaPointsHelper(PlayerPoints);
210 sScriptMgr->OnBeforeUpdateArenaPoints(at, PlayerPoints);
211 }
212
213 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
214
216
217 // Cycle that gives points to all players
218 for (std::map<ObjectGuid, uint32>::iterator playerItr = PlayerPoints.begin(); playerItr != PlayerPoints.end(); ++playerItr)
219 {
220 // Add points to player if online
221 if (Player* player = ObjectAccessor::FindPlayer(playerItr->first))
222 player->ModifyArenaPoints(playerItr->second, trans);
223 else // Update database
224 {
225 stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_ARENA_POINTS);
226 stmt->SetData(0, playerItr->second);
227 stmt->SetData(1, playerItr->first.GetCounter());
228 trans->Append(stmt);
229 }
230 }
231
232 CharacterDatabase.CommitTransaction(trans);
233
234 PlayerPoints.clear();
235
237
239 for (ArenaTeamContainer::iterator titr = GetArenaTeamMapBegin(); titr != GetArenaTeamMapEnd(); ++titr)
240 {
241 if (ArenaTeam* at = titr->second)
242 {
243 if (at->FinishWeek())
244 at->SaveToDB(true);
245
246 at->NotifyStatsChanged();
247 }
248 }
249
251
253}
@ LANG_DIST_ARENA_POINTS_TEAM_START
Definition: Language.h:715
@ LANG_DIST_ARENA_POINTS_ONLINE_START
Definition: Language.h:713
@ LANG_DIST_ARENA_POINTS_START
Definition: Language.h:712
@ LANG_DIST_ARENA_POINTS_TEAM_END
Definition: Language.h:716
@ LANG_DIST_ARENA_POINTS_END
Definition: Language.h:717
@ LANG_DIST_ARENA_POINTS_ONLINE_END
Definition: Language.h:714
#define sScriptMgr
Definition: ScriptMgr.h:709
@ CHAR_UPD_CHAR_ARENA_POINTS
Definition: CharacterDatabase.h:373
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:69
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Player * FindPlayer(ObjectGuid const guid)
Definition: ObjectAccessor.cpp:245
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77
Definition: ArenaTeam.h:137
ArenaTeamContainer::iterator GetArenaTeamMapBegin()
Definition: ArenaTeamMgr.h:46
ArenaTeamContainer::iterator GetArenaTeamMapEnd()
Definition: ArenaTeamMgr.h:47
Definition: Chat.h:37
void SendWorldText(std::string_view str)
Definition: Chat.cpp:130
Definition: Player.h:1081

References CHAR_UPD_CHAR_ARENA_POINTS, CharacterDatabase, ObjectAccessor::FindPlayer(), GetArenaTeamMapBegin(), GetArenaTeamMapEnd(), LANG_DIST_ARENA_POINTS_END, LANG_DIST_ARENA_POINTS_ONLINE_END, LANG_DIST_ARENA_POINTS_ONLINE_START, LANG_DIST_ARENA_POINTS_START, LANG_DIST_ARENA_POINTS_TEAM_END, LANG_DIST_ARENA_POINTS_TEAM_START, ChatHandler::SendWorldText(), PreparedStatementBase::SetData(), and sScriptMgr.

◆ GenerateArenaTeamId()

uint32 ArenaTeamMgr::GenerateArenaTeamId ( )
129{
131 {
132 LOG_ERROR("bg.arena", "Arena team ids overflow!! Can't continue, shutting down server. ");
134 }
135
136 return NextArenaTeamId++;
137}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
constexpr uint32 MAX_ARENA_TEAM_ID
Definition: ArenaTeamMgr.h:23
@ ERROR_EXIT_CODE
Definition: World.h:54
static void StopNow(uint8 exitcode)
Definition: World.h:253

References ERROR_EXIT_CODE, LOG_ERROR, MAX_ARENA_TEAM_ID, NextArenaTeamId, and World::StopNow().

◆ GenerateTempArenaTeamId()

uint32 ArenaTeamMgr::GenerateTempArenaTeamId ( )
140{
143
144 return NextTempArenaTeamId++;
145}
constexpr uint32 MAX_TEMP_ARENA_TEAM_ID
Definition: ArenaTeamMgr.h:24

References MAX_ARENA_TEAM_ID, MAX_TEMP_ARENA_TEAM_ID, and NextTempArenaTeamId.

◆ GetArenaTeamByCaptain() [1/2]

ArenaTeam * ArenaTeamMgr::GetArenaTeamByCaptain ( ObjectGuid  guid) const
95{
96 for (ArenaTeamContainer::const_iterator itr = ArenaTeamStore.begin(); itr != ArenaTeamStore.end(); ++itr)
97 {
98 if (itr->second->GetCaptain() == guid)
99 {
100 return itr->second;
101 }
102 }
103 return nullptr;
104}

References ArenaTeamStore.

◆ GetArenaTeamByCaptain() [2/2]

ArenaTeam * ArenaTeamMgr::GetArenaTeamByCaptain ( ObjectGuid  guid,
const uint32  type 
) const
107{
108 for (ArenaTeamContainer::const_iterator itr = ArenaTeamStore.begin(); itr != ArenaTeamStore.end(); ++itr)
109 {
110 if (itr->second->GetCaptain() == guid && itr->second->GetType() == type)
111 {
112 return itr->second;
113 }
114 }
115 return nullptr;
116}

References ArenaTeamStore.

◆ GetArenaTeamById()

ArenaTeam * ArenaTeamMgr::GetArenaTeamById ( uint32  arenaTeamId) const
50{
51 ArenaTeamContainer::const_iterator itr = ArenaTeamStore.find(arenaTeamId);
52 if (itr != ArenaTeamStore.end())
53 return itr->second;
54
55 return nullptr;
56}

References ArenaTeamStore.

◆ GetArenaTeamByName() [1/2]

ArenaTeam * ArenaTeamMgr::GetArenaTeamByName ( std::string const &  arenaTeamName) const
59{
60 std::string search = arenaTeamName;
61 std::transform(search.begin(), search.end(), search.begin(), ::toupper);
62 for (ArenaTeamContainer::const_iterator itr = ArenaTeamStore.begin(); itr != ArenaTeamStore.end(); ++itr)
63 {
64 std::string teamName = itr->second->GetName();
65 std::transform(teamName.begin(), teamName.end(), teamName.begin(), ::toupper);
66 if (search == teamName)
67 {
68 return itr->second;
69 }
70 }
71 return nullptr;
72}

References ArenaTeamStore.

◆ GetArenaTeamByName() [2/2]

ArenaTeam * ArenaTeamMgr::GetArenaTeamByName ( std::string const &  arenaTeamName,
const uint32  type 
) const
75{
76 std::string search = arenaTeamName;
77 std::transform(search.begin(), search.end(), search.begin(), ::toupper);
78 for (auto itr = ArenaTeamStore.begin(); itr != ArenaTeamStore.end(); ++itr)
79 {
80 if (itr->second->GetType() != type)
81 {
82 continue;
83 }
84 std::string teamName = itr->second->GetName();
85 std::transform(teamName.begin(), teamName.end(), teamName.begin(), ::toupper);
86 if (search == teamName)
87 {
88 return itr->second;
89 }
90 }
91 return nullptr;
92}

References ArenaTeamStore.

◆ GetArenaTeamMapBegin()

ArenaTeamContainer::iterator ArenaTeamMgr::GetArenaTeamMapBegin ( )
inline
46{ return ArenaTeamStore.begin(); }

References ArenaTeamStore.

Referenced by DistributeArenaPoints().

◆ GetArenaTeamMapEnd()

ArenaTeamContainer::iterator ArenaTeamMgr::GetArenaTeamMapEnd ( )
inline
47{ return ArenaTeamStore.end(); }

References ArenaTeamStore.

Referenced by DistributeArenaPoints().

◆ GetArenaTeams()

ArenaTeamContainer & ArenaTeamMgr::GetArenaTeams ( )
inline
48{ return ArenaTeamStore; }

References ArenaTeamStore.

◆ GetNextArenaLogId()

uint32 ArenaTeamMgr::GetNextArenaLogId ( )
inline
55{ return ++LastArenaLogId; }

References LastArenaLogId.

◆ instance()

ArenaTeamMgr * ArenaTeamMgr::instance ( )
static
43{
45 return &instance;
46}
Definition: ArenaTeamMgr.h:27
static ArenaTeamMgr * instance()
Definition: ArenaTeamMgr.cpp:42

References instance().

Referenced by instance().

◆ LoadArenaTeams()

void ArenaTeamMgr::LoadArenaTeams ( )
148{
149 uint32 oldMSTime = getMSTime();
150
151 // Clean out the trash before loading anything
152 CharacterDatabase.Execute("DELETE FROM arena_team_member WHERE arenaTeamId NOT IN (SELECT arenaTeamId FROM arena_team)"); // One-time query
153
154 // 0 1 2 3 4 5 6 7 8
155 QueryResult result = CharacterDatabase.Query("SELECT arenaTeamId, name, captainGuid, type, backgroundColor, emblemStyle, emblemColor, borderStyle, borderColor, "
156 // 9 10 11 12 13 14
157 "rating, weekGames, weekWins, seasonGames, seasonWins, `rank` FROM arena_team ORDER BY arenaTeamId ASC");
158
159 if (!result)
160 {
161 LOG_WARN("server.loading", ">> Loaded 0 arena teams. DB table `arena_team` is empty!");
162 LOG_INFO("server.loading", " ");
163 return;
164 }
165
166 QueryResult result2 = CharacterDatabase.Query(
167 // 0 1 2 3 4 5 6 7 8 9 10
168 "SELECT arenaTeamId, atm.guid, atm.weekGames, atm.weekWins, atm.seasonGames, atm.seasonWins, c.name, class, personalRating, matchMakerRating, maxMMR FROM arena_team_member atm"
169 " INNER JOIN arena_team ate USING (arenaTeamId)"
170 " LEFT JOIN characters AS c ON atm.guid = c.guid"
171 " LEFT JOIN character_arena_stats AS cas ON c.guid = cas.guid AND (cas.slot = 0 AND ate.type = 2 OR cas.slot = 1 AND ate.type = 3 OR cas.slot = 2 AND ate.type = 5)"
172 " ORDER BY atm.arenateamid ASC");
173
174 uint32 count = 0;
175 do
176 {
177 ArenaTeam* newArenaTeam = new ArenaTeam;
178
179 if (!newArenaTeam->LoadArenaTeamFromDB(result) || !newArenaTeam->LoadMembersFromDB(result2))
180 {
181 newArenaTeam->Disband(nullptr);
182 delete newArenaTeam;
183 continue;
184 }
185
186 AddArenaTeam(newArenaTeam);
187
188 ++count;
189 } while (result->NextRow());
190
191 LOG_INFO("server.loading", ">> Loaded {} arena teams in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
192 LOG_INFO("server.loading", " ");
193}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::uint32_t uint32
Definition: Define.h:107
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
void Disband(WorldSession *session)
Definition: ArenaTeam.cpp:383
bool LoadArenaTeamFromDB(QueryResult arenaTeamDataResult)
Definition: ArenaTeam.cpp:196
bool LoadMembersFromDB(QueryResult arenaTeamMembersResult)
Definition: ArenaTeam.cpp:222
void AddArenaTeam(ArenaTeam *arenaTeam)
Definition: ArenaTeamMgr.cpp:118

References AddArenaTeam(), CharacterDatabase, ArenaTeam::Disband(), getMSTime(), GetMSTimeDiffToNow(), ArenaTeam::LoadArenaTeamFromDB(), ArenaTeam::LoadMembersFromDB(), LOG_INFO, and LOG_WARN.

◆ RemoveArenaTeam()

void ArenaTeamMgr::RemoveArenaTeam ( uint32  Id)
124{
125 ArenaTeamStore.erase(arenaTeamId);
126}

References ArenaTeamStore.

◆ SetLastArenaLogId()

void ArenaTeamMgr::SetLastArenaLogId ( uint32  id)
inline
56{ LastArenaLogId = id; }

References LastArenaLogId.

◆ SetNextArenaTeamId()

void ArenaTeamMgr::SetNextArenaTeamId ( uint32  Id)
inline
53{ NextArenaTeamId = Id; }

References NextArenaTeamId.

Member Data Documentation

◆ ArenaTeamStore

◆ LastArenaLogId

uint32 ArenaTeamMgr::LastArenaLogId
protected

◆ NextArenaTeamId

uint32 ArenaTeamMgr::NextArenaTeamId
protected

◆ NextTempArenaTeamId

uint32 ArenaTeamMgr::NextTempArenaTeamId
protected