TrinityCore
BattlegroundMgr.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "BattlegroundMgr.h"
19#include "BattlegroundAB.h"
20#include "BattlegroundAV.h"
21#include "BattlegroundBE.h"
22#include "BattlegroundBFG.h"
23#include "BattlegroundDS.h"
24#include "BattlegroundEY.h"
25#include "BattlegroundIC.h"
26#include "BattlegroundNA.h"
27#include "BattlegroundPackets.h"
28#include "BattlegroundRL.h"
29#include "BattlegroundRV.h"
30#include "BattlegroundSA.h"
31#include "BattlegroundTP.h"
32#include "BattlegroundWS.h"
33#include "Containers.h"
34#include "DatabaseEnv.h"
35#include "DB2Stores.h"
36#include "DisableMgr.h"
37#include "GameEventMgr.h"
38#include "Language.h"
39#include "Log.h"
40#include "MapManager.h"
41#include "ObjectMgr.h"
42#include "Player.h"
43#include "SharedDefines.h"
44#include "World.h"
45
47{
49}
50
52{
54}
55
57{
59}
60
62{
64}
65
67{
69}
70
71/*********************************************************/
72/*** BATTLEGROUND MANAGER ***/
73/*********************************************************/
74
76 m_NextRatedArenaUpdate(sWorld->getIntConfig(CONFIG_ARENA_RATED_UPDATE_TIMER)),
77 m_UpdateTimer(0), m_ArenaTesting(false), m_Testing(false)
78{ }
79
81{
83}
84
86{
87 bgDataStore.clear();
88 m_BGFreeSlotQueue.clear();
89}
90
92{
94 return &instance;
95}
96
97// used to update running battlegrounds, and delete finished ones
99{
100 m_UpdateTimer += diff;
102 {
103 for (BattlegroundDataContainer::iterator itr1 = bgDataStore.begin(); itr1 != bgDataStore.end(); ++itr1)
104 {
105 BattlegroundContainer& bgs = itr1->second.m_Battlegrounds;
106 BattlegroundContainer::iterator itrDelete = bgs.begin();
107 for (BattlegroundContainer::iterator itr = itrDelete; itr != bgs.end();)
108 {
109 itrDelete = itr++;
110 Battleground* bg = itrDelete->second.get();
111
113 if (bg->ToBeDeleted())
114 {
115 BattlegroundClientIdsContainer& clients = itr1->second.m_ClientBattlegroundIds[bg->GetBracketId()];
116 if (!clients.empty())
117 clients.erase(bg->GetClientInstanceID());
118
119 // move out unique_ptr to delete after erasing
120 Trinity::unique_trackable_ptr<Battleground> bgPtr = std::move(itrDelete->second);
121
122 bgs.erase(itrDelete);
123 }
124 }
125 }
126
127 m_UpdateTimer = 0;
128 }
129
130 // update events timer
131 for (std::pair<BattlegroundQueueTypeId const, BattlegroundQueue>& pair : m_BattlegroundQueues)
132 pair.second.UpdateEvents(diff);
133
134 // update scheduled queues
135 if (!m_QueueUpdateScheduler.empty())
136 {
137 std::vector<ScheduledQueueUpdate> scheduled;
138 std::swap(scheduled, m_QueueUpdateScheduler);
139
140 for (uint8 i = 0; i < scheduled.size(); i++)
141 {
142 uint32 arenaMMRating = scheduled[i].ArenaMatchmakerRating;
143 BattlegroundQueueTypeId bgQueueTypeId = scheduled[i].QueueId;
144 BattlegroundBracketId bracket_id = scheduled[i].BracketId;
145 GetBattlegroundQueue(bgQueueTypeId).BattlegroundQueueUpdate(diff, bracket_id, arenaMMRating);
146 }
147 }
148
149 // if rating difference counts, maybe force-update queues
151 {
152 // it's time to force update
153 if (m_NextRatedArenaUpdate < diff)
154 {
155 // forced update for rated arenas (scan all, but skipped non rated)
156 TC_LOG_TRACE("bg.arena", "BattlegroundMgr: UPDATING ARENA QUEUES");
158 {
160 for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
161 GetBattlegroundQueue(ratedArenaQueueId).BattlegroundQueueUpdate(diff, BattlegroundBracketId(bracket), 0);
162 }
163
165 }
166 else
168 }
169}
170
172{
173 header->Ticket.RequesterGuid = player->GetGUID();
174 header->Ticket.Id = ticketId;
176 header->Ticket.Time = joinTime;
177 header->QueueID.push_back(queueId.GetPacked());
178 header->RangeMin = 0; // seems to always be 0
179 header->RangeMax = DEFAULT_MAX_LEVEL; // alwyas max level of current expansion. Might be limited to account
180 header->TeamSize = queueId.TeamSize;
181 header->InstanceID = 0; // seems to always be 0
182 header->RegisteredMatch = queueId.Rated;
183 header->TournamentRules = false;
184}
185
187{
188 battlefieldStatus->Ticket.RequesterGuid = player->GetGUID();
189 battlefieldStatus->Ticket.Id = ticketId;
191 battlefieldStatus->Ticket.Time = joinTime;
192}
193
195{
196 BuildBattlegroundStatusHeader(&battlefieldStatus->Hdr, player, ticketId, joinTime, queueId);
197 battlefieldStatus->Mapid = bg->GetMapId();
198 battlefieldStatus->Timeout = timeout;
199 battlefieldStatus->Role = 0;
200}
201
203{
204 BuildBattlegroundStatusHeader(&battlefieldStatus->Hdr, player, ticketId, joinTime, queueId);
205 battlefieldStatus->ShutdownTimer = bg->GetRemainingTime();
206 battlefieldStatus->ArenaFaction = player->GetBGTeam() == HORDE ? PVP_TEAM_HORDE : PVP_TEAM_ALLIANCE;
207 battlefieldStatus->LeftEarly = false;
208 battlefieldStatus->StartTimer = bg->GetElapsedTime();
209 battlefieldStatus->Mapid = bg->GetMapId();
210}
211
213{
214 BuildBattlegroundStatusHeader(&battlefieldStatus->Hdr, player, ticketId, joinTime, queueId);
215 battlefieldStatus->AverageWaitTime = avgWaitTime;
216 battlefieldStatus->AsGroup = asGroup;
217 battlefieldStatus->SuspendedQueue = false;
218 battlefieldStatus->EligibleForMatchmaking = true;
219 battlefieldStatus->WaitTime = GetMSTimeDiffToNow(joinTime);
220}
221
223{
224 battlefieldStatus->Ticket.RequesterGuid = pPlayer->GetGUID();
225 battlefieldStatus->Ticket.Id = ticketId;
227 battlefieldStatus->Ticket.Time = pPlayer->GetBattlegroundQueueJoinTime(queueId);
228 battlefieldStatus->QueueID = queueId.GetPacked();
229 battlefieldStatus->Reason = result;
230 if (errorGuid && (result == ERR_BATTLEGROUND_NOT_IN_BATTLEGROUND || result == ERR_BATTLEGROUND_JOIN_TIMED_OUT))
231 battlefieldStatus->ClientID = *errorGuid;
232}
233
235{
236 if (!instanceId)
237 return nullptr;
238
239 BattlegroundDataContainer::const_iterator begin, end;
240
241 if (bgTypeId == BATTLEGROUND_TYPE_NONE || IsRandomBattleground(bgTypeId))
242 {
243 begin = bgDataStore.begin();
244 end = bgDataStore.end();
245 }
246 else
247 {
248 end = bgDataStore.find(bgTypeId);
249 if (end == bgDataStore.end())
250 return nullptr;
251 begin = end++;
252 }
253
254 for (BattlegroundDataContainer::const_iterator it = begin; it != end; ++it)
255 {
256 BattlegroundContainer const& bgs = it->second.m_Battlegrounds;
257 BattlegroundContainer::const_iterator itr = bgs.find(instanceId);
258 if (itr != bgs.end())
259 return itr->second.get();
260 }
261
262 return nullptr;
263}
264
266{
267 if (IsArenaType(bgTypeId))
268 return 0; //arenas don't have client-instanceids
269
270 // we create here an instanceid, which is just for
271 // displaying this to the client and without any other use..
272 // the client-instanceIds are unique for each battleground-type
273 // the instance-id just needs to be as low as possible, beginning with 1
274 // the following works, because std::set is default ordered with "<"
275 // the optimalization would be to use as bitmask std::vector<uint32> - but that would only make code unreadable
276
277 BattlegroundClientIdsContainer& clientIds = bgDataStore[bgTypeId].m_ClientBattlegroundIds[bracket_id];
278 uint32 lastId = 0;
279 for (BattlegroundClientIdsContainer::const_iterator itr = clientIds.begin(); itr != clientIds.end();)
280 {
281 if ((++lastId) != *itr) //if there is a gap between the ids, we will break..
282 break;
283 lastId = *itr;
284 }
285
286 clientIds.insert(++lastId);
287 return lastId;
288}
289
290// create a new battleground that will really be used to play
292{
294
295 // get the template BG
296 BattlegroundTemplate const* bg_template = GetBattlegroundTemplateByTypeId(bgTypeId);
297
298 if (!bg_template)
299 {
300 TC_LOG_ERROR("bg.battleground", "Battleground: CreateNewBattleground - bg template not found for {}", bgTypeId);
301 return nullptr;
302 }
303
304 PVPDifficultyEntry const* bracketEntry = DB2Manager::GetBattlegroundBracketById(bg_template->BattlemasterEntry->MapID[0], bracketId);
305 if (!bracketEntry)
306 {
307 TC_LOG_ERROR("bg.battleground", "Battleground: CreateNewBattleground: bg bracket entry not found for map {} bracket id {}", bg_template->BattlemasterEntry->MapID[0], bracketId);
308 return nullptr;
309 }
310
311 Battleground* bg = nullptr;
312 // create a copy of the BG template
313 switch (bgTypeId)
314 {
315 case BATTLEGROUND_AV:
316 bg = new BattlegroundAV(bg_template);
317 break;
318 case BATTLEGROUND_WS:
320 bg = new BattlegroundWS(bg_template);
321 break;
322 case BATTLEGROUND_AB:
324 bg = new BattlegroundAB(bg_template);
325 break;
326 case BATTLEGROUND_NA:
327 bg = new BattlegroundNA(bg_template);
328 break;
329 case BATTLEGROUND_BE:
330 bg = new BattlegroundBE(bg_template);
331 break;
332 case BATTLEGROUND_EY:
333 bg = new BattlegroundEY(bg_template);
334 break;
335 case BATTLEGROUND_RL:
336 bg = new BattlegroundRL(bg_template);
337 break;
338 case BATTLEGROUND_SA:
339 bg = new BattlegroundSA(bg_template);
340 break;
341 case BATTLEGROUND_DS:
342 bg = new BattlegroundDS(bg_template);
343 break;
344 case BATTLEGROUND_RV:
345 bg = new BattlegroundRV(bg_template);
346 break;
347 case BATTLEGROUND_IC:
348 bg = new BattlegroundIC(bg_template);
349 break;
350 case BATTLEGROUND_TP:
351 bg = new BattlegroundTP(bg_template);
352 break;
353 case BATTLEGROUND_BFG:
354 bg = new BattlegroundBFG(bg_template);
355 break;
356 case BATTLEGROUND_RB:
357 case BATTLEGROUND_AA:
359 default:
360 return nullptr;
361 }
362
363 bg->SetBracket(bracketEntry);
364 bg->SetInstanceID(sMapMgr->GenerateInstanceId());
366 // reset the new bg (set status to status_wait_queue from status_none)
367 // this shouldn't be needed anymore as a new Battleground instance is created each time. But some bg sub classes still depend on it.
368 bg->Reset();
369 bg->SetStatus(STATUS_WAIT_JOIN); // start the joining of the bg
370 bg->SetArenaType(queueId.TeamSize);
371 bg->SetRated(queueId.Rated);
372
373 return bg;
374}
375
377{
378 uint32 oldMSTime = getMSTime();
379
380 // 0 1 2 3 4 5
381 QueryResult result = WorldDatabase.Query("SELECT ID, AllianceStartLoc, HordeStartLoc, StartMaxDist, Weight, ScriptName FROM battleground_template");
382 if (!result)
383 {
384 TC_LOG_INFO("server.loading", ">> Loaded 0 battlegrounds. DB table `battleground_template` is empty.");
385 return;
386 }
387
388 uint32 count = 0;
389
390 do
391 {
392 Field* fields = result->Fetch();
393
394 BattlegroundTypeId bgTypeId = BattlegroundTypeId(fields[0].GetUInt32());
395
397 continue;
398
399 // can be overwrite by values from DB
400 BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId);
401 if (!bl)
402 {
403 TC_LOG_ERROR("bg.battleground", "Battleground ID {} could not be found in BattlemasterList.dbc. The battleground was not created.", bgTypeId);
404 continue;
405 }
406
407 BattlegroundTemplate& bgTemplate = _battlegroundTemplates[bgTypeId];
408 bgTemplate.Id = bgTypeId;
409 float dist = fields[3].GetFloat();
410 bgTemplate.MaxStartDistSq = dist * dist;
411 bgTemplate.Weight = fields[4].GetUInt8();
412 bgTemplate.ScriptId = sObjectMgr->GetScriptId(fields[5].GetString());
413 bgTemplate.BattlemasterEntry = bl;
414
415 if (bgTemplate.Id != BATTLEGROUND_AA && !IsRandomBattleground(bgTemplate.Id))
416 {
417 uint32 startId = fields[1].GetUInt32();
418 if (WorldSafeLocsEntry const* start = sObjectMgr->GetWorldSafeLoc(startId))
419 bgTemplate.StartLocation[TEAM_ALLIANCE] = start;
420 else if (bgTemplate.StartLocation[TEAM_ALLIANCE]) // reload case
421 TC_LOG_ERROR("sql.sql", "Table `battleground_template` for id {} contains a non-existing WorldSafeLocs.dbc id {} in field `AllianceStartLoc`. Ignoring.", bgTemplate.Id, startId);
422 else
423 {
424 TC_LOG_ERROR("sql.sql", "Table `battleground_template` for id {} contains a non-existing WorldSafeLocs.dbc id {} in field `AllianceStartLoc`. BG not created.", bgTemplate.Id, startId);
425 _battlegroundTemplates.erase(bgTypeId);
426 continue;
427 }
428
429 startId = fields[2].GetUInt32();
430 if (WorldSafeLocsEntry const* start = sObjectMgr->GetWorldSafeLoc(startId))
431 bgTemplate.StartLocation[TEAM_HORDE] = start;
432 else if (bgTemplate.StartLocation[TEAM_HORDE]) // reload case
433 TC_LOG_ERROR("sql.sql", "Table `battleground_template` for id {} contains a non-existing WorldSafeLocs.dbc id {} in field `HordeStartLoc`. Ignoring.", bgTemplate.Id, startId);
434 else
435 {
436 TC_LOG_ERROR("sql.sql", "Table `battleground_template` for id {} contains a non-existing WorldSafeLocs.dbc id {} in field `HordeStartLoc`. BG not created.", bgTemplate.Id, startId);
437 _battlegroundTemplates.erase(bgTypeId);
438 continue;
439 }
440 }
441
442 if (bgTemplate.BattlemasterEntry->MapID[1] == -1) // in this case we have only one mapId
444
445 ++count;
446 }
447 while (result->NextRow());
448
449 TC_LOG_INFO("server.loading", ">> Loaded {} battlegrounds in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
450}
451
453{
454 BattlegroundTemplate const* bgTemplate = GetBattlegroundTemplateByTypeId(bgTypeId);
455 if (!bgTemplate)
456 return;
457
459 battlefieldList.BattlemasterGuid = guid;
460 battlefieldList.BattlemasterListID = bgTypeId;
461 battlefieldList.MinLevel = bgTemplate->GetMinLevel();
462 battlefieldList.MaxLevel = bgTemplate->GetMaxLevel();
463 battlefieldList.PvpAnywhere = guid.IsEmpty();
464 battlefieldList.HasRandomWinToday = player->GetRandomWinner();
465 player->SendDirectMessage(battlefieldList.Write());
466}
467
469{
470 if (Battleground* bg = GetBattleground(instanceId, bgTypeId))
471 {
472 uint32 mapid = bg->GetMapId();
473 Team team = player->GetBGTeam();
474
475 WorldSafeLocsEntry const* pos = bg->GetTeamStartPosition(Battleground::GetTeamIndexByTeamId(team));
476 TC_LOG_DEBUG("bg.battleground", "BattlegroundMgr::SendToBattleground: Sending {} to map {}, {} (bgType {})", player->GetName(), mapid, pos->Loc.ToString(), bgTypeId);
477 player->TeleportTo(pos->Loc);
478 }
479 else
480 TC_LOG_ERROR("bg.battleground", "BattlegroundMgr::SendToBattleground: Instance {} (bgType {}) not found while trying to teleport player {}", instanceId, bgTypeId, player->GetName());
481}
482
484{
485 return bgTypeId == BATTLEGROUND_AA
486 || bgTypeId == BATTLEGROUND_BE
487 || bgTypeId == BATTLEGROUND_NA
488 || bgTypeId == BATTLEGROUND_DS
489 || bgTypeId == BATTLEGROUND_RV
490 || bgTypeId == BATTLEGROUND_RL;
491}
492
494{
495 return battlemasterListId == BATTLEGROUND_RB || battlemasterListId == BATTLEGROUND_RANDOM_EPIC;
496}
497
499{
500 return { battlemasterListId, AsUnderlyingType(type), rated, teamSize };
501}
502
504{
507}
508
510{
513}
514
516{
517 BattlemasterListEntry const* battlemasterList = sBattlemasterListStore.LookupEntry(bgQueueTypeId.BattlemasterListId);
518 if (!battlemasterList)
519 return false;
520
521 switch (BattlegroundQueueIdType(bgQueueTypeId.Type))
522 {
524 if (battlemasterList->InstanceType != MAP_BATTLEGROUND)
525 return false;
526 if (bgQueueTypeId.TeamSize)
527 return false;
528 break;
530 if (battlemasterList->InstanceType != MAP_ARENA)
531 return false;
532 if (!bgQueueTypeId.Rated)
533 return false;
534 if (!bgQueueTypeId.TeamSize)
535 return false;
536 break;
538 if (bgQueueTypeId.Rated)
539 return false;
540 break;
542 if (battlemasterList->InstanceType != MAP_ARENA)
543 return false;
544 if (!bgQueueTypeId.Rated)
545 return false;
546 if (bgQueueTypeId.TeamSize != ARENA_TYPE_3v3)
547 return false;
548 break;
549 default:
550 return false;
551 }
552
553 return true;
554}
555
557{
558 //This method must be atomic, @todo add mutex
559 //we will use only 1 number created of bgTypeId and bracket_id
560 ScheduledQueueUpdate scheduleId{ arenaMatchmakerRating, bgQueueTypeId, bracket_id };
561 if (std::find(m_QueueUpdateScheduler.begin(), m_QueueUpdateScheduler.end(), scheduleId) == m_QueueUpdateScheduler.end())
562 m_QueueUpdateScheduler.push_back(scheduleId);
563}
564
566{
567 // this is for stupid people who can't use brain and set max rating difference to 0
569 if (diff == 0)
570 diff = 5000;
571 return diff;
572}
573
575{
576 return sWorld->getIntConfig(CONFIG_ARENA_RATING_DISCARD_TIMER);
577}
578
580{
582}
583
585{
586 uint32 oldMSTime = getMSTime();
587
588 mBattleMastersMap.clear(); // need for reload case
589
590 QueryResult result = WorldDatabase.Query("SELECT entry, bg_template FROM battlemaster_entry");
591
592 if (!result)
593 {
594 TC_LOG_INFO("server.loading", ">> Loaded 0 battlemaster entries. DB table `battlemaster_entry` is empty!");
595 return;
596 }
597
598 uint32 count = 0;
599
600 do
601 {
602 ++count;
603
604 Field* fields = result->Fetch();
605
606 uint32 entry = fields[0].GetUInt32();
607 if (CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(entry))
608 {
609 if ((cInfo->npcflag & UNIT_NPC_FLAG_BATTLEMASTER) == 0)
610 TC_LOG_ERROR("sql.sql", "Creature (Entry: {}) listed in `battlemaster_entry` is not a battlemaster.", entry);
611 }
612 else
613 {
614 TC_LOG_ERROR("sql.sql", "Creature (Entry: {}) listed in `battlemaster_entry` does not exist.", entry);
615 continue;
616 }
617
618 uint32 bgTypeId = fields[1].GetUInt32();
619 if (!sBattlemasterListStore.LookupEntry(bgTypeId))
620 {
621 TC_LOG_ERROR("sql.sql", "Table `battlemaster_entry` contains entry {} for a non-existing battleground type {}, ignored.", entry, bgTypeId);
622 continue;
623 }
624
625 mBattleMastersMap[entry] = BattlegroundTypeId(bgTypeId);
626 }
627 while (result->NextRow());
628
630
631 TC_LOG_INFO("server.loading", ">> Loaded {} battlemaster entries in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
632}
633
635{
636 CreatureTemplateContainer const& ctc = sObjectMgr->GetCreatureTemplates();
637 for (auto const& creatureTemplatePair : ctc)
638 {
639 if ((creatureTemplatePair.second.npcflag & UNIT_NPC_FLAG_BATTLEMASTER) && !mBattleMastersMap.count(creatureTemplatePair.first))
640 {
641 TC_LOG_ERROR("sql.sql", "Creature_Template Entry: {} has UNIT_NPC_FLAG_BATTLEMASTER, but no data in the `battlemaster_entry` table. Removing flag.", creatureTemplatePair.first);
642 const_cast<CreatureTemplate&>(creatureTemplatePair.second).npcflag &= ~UNIT_NPC_FLAG_BATTLEMASTER;
643 }
644 }
645}
646
648{
649 switch (bgTypeId)
650 {
659 default: return HOLIDAY_NONE;
660 }
661}
662
664{
665 switch (holiday)
666 {
675 default: return BATTLEGROUND_TYPE_NONE;
676 }
677}
678
680{
682}
683
685{
686 if (BattlegroundTemplate const* bgTemplate = GetBattlegroundTemplateByTypeId(bgTypeId))
687 {
688 std::vector<BattlegroundTypeId> ids;
689 ids.reserve(16);
690 std::vector<double> weights;
691 weights.reserve(16);
692 for (int32 mapId : bgTemplate->BattlemasterEntry->MapID)
693 {
694 if (mapId == -1)
695 break;
696
698 {
699 ids.push_back(bg->Id);
700 weights.push_back(bg->Weight);
701 }
702 }
703
704 return *Trinity::Containers::SelectRandomWeightedContainerElement(ids, std::span(weights));
705 }
706
708}
709
711{
712 return m_BGFreeSlotQueue[mapId];
713}
714
716{
717 m_BGFreeSlotQueue[bg->GetMapId()].push_front(bg);
718}
719
721{
723 for (BGFreeSlotQueueContainer::iterator itr = queues.begin(); itr != queues.end(); ++itr)
724 if ((*itr)->GetInstanceID() == instanceId)
725 {
726 queues.erase(itr);
727 return;
728 }
729}
730
732{
733 if (bg)
734 {
736 ptr.reset(bg);
737 bg->SetWeakPtr(ptr);
738 }
739}
@ BATTLEGROUND_OBJECTIVE_UPDATE_INTERVAL
std::set< uint32 > BattlegroundClientIdsContainer
std::map< uint32, Trinity::unique_trackable_ptr< Battleground > > BattlegroundContainer
std::list< Battleground * > BGFreeSlotQueueContainer
@ ARENA_TYPE_5v5
Definition: Battleground.h:192
@ ARENA_TYPE_3v3
Definition: Battleground.h:191
@ ARENA_TYPE_2v2
Definition: Battleground.h:190
BattlegroundQueueIdType
Definition: Battleground.h:231
@ STATUS_WAIT_JOIN
Definition: Battleground.h:166
DB2Storage< BattlemasterListEntry > sBattlemasterListStore("BattlemasterList.db2", &BattlemasterListLoadInfo::Instance)
@ DEFAULT_MAX_LEVEL
Definition: DBCEnums.h:47
@ MAP_BATTLEGROUND
Definition: DBCEnums.h:1231
@ MAP_ARENA
Definition: DBCEnums.h:1232
BattlegroundBracketId
Definition: DBCEnums.h:59
@ BG_BRACKET_ID_FIRST
Definition: DBCEnums.h:60
@ MAX_BATTLEGROUND_BRACKETS
Definition: DBCEnums.h:64
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
@ DISABLE_TYPE_BATTLEGROUND
Definition: DisableMgr.h:30
bool IsHolidayActive(HolidayIds id)
@ LANG_DEBUG_BG_OFF
Definition: Language.h:730
@ LANG_DEBUG_ARENA_OFF
Definition: Language.h:728
@ LANG_DEBUG_BG_ON
Definition: Language.h:729
@ LANG_DEBUG_ARENA_ON
Definition: Language.h:727
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:153
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:165
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:159
#define sMapMgr
Definition: MapManager.h:184
#define sObjectMgr
Definition: ObjectMgr.h:1946
std::unordered_map< uint32, CreatureTemplate > CreatureTemplateContainer
Definition: ObjectMgr.h:495
GroupJoinBattlegroundResult
@ TEAM_ALLIANCE
@ TEAM_HORDE
@ ERR_BATTLEGROUND_JOIN_TIMED_OUT
@ ERR_BATTLEGROUND_NOT_IN_BATTLEGROUND
Team
@ HORDE
BattlegroundTypeId
@ BATTLEGROUND_BFG
@ BATTLEGROUND_IC
@ BATTLEGROUND_AA
@ BATTLEGROUND_WS
@ BATTLEGROUND_DOM_AB
@ BATTLEGROUND_EY
@ BATTLEGROUND_AV
@ BATTLEGROUND_BE
@ BATTLEGROUND_WG_CTF
@ BATTLEGROUND_TP
@ BATTLEGROUND_RV
@ BATTLEGROUND_TYPE_NONE
@ BATTLEGROUND_NA
@ BATTLEGROUND_RANDOM_EPIC
@ BATTLEGROUND_DS
@ BATTLEGROUND_SA
@ BATTLEGROUND_AB
@ BATTLEGROUND_RL
@ BATTLEGROUND_RB
HolidayIds
@ HOLIDAY_NONE
@ HOLIDAY_CALL_TO_ARMS_AB
@ HOLIDAY_CALL_TO_ARMS_ES
@ HOLIDAY_CALL_TO_ARMS_SA
@ HOLIDAY_CALL_TO_ARMS_IC
@ HOLIDAY_CALL_TO_ARMS_BG
@ HOLIDAY_CALL_TO_ARMS_AV
@ HOLIDAY_CALL_TO_ARMS_WG
@ HOLIDAY_CALL_TO_ARMS_TP
@ PVP_TEAM_HORDE
@ PVP_TEAM_ALLIANCE
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:57
uint32 getMSTime()
Definition: Timer.h:33
@ UNIT_NPC_FLAG_BATTLEMASTER
Definition: UnitDefines.h:317
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:491
BattlegroundMapTemplateContainer _battlegroundMapTemplates
void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone *battlefieldStatus, Player *player, uint32 ticketId, uint32 joinTime)
std::map< BattlegroundQueueTypeId, BattlegroundQueue > m_BattlegroundQueues
BattlegroundTemplate const * GetBattlegroundTemplateByMapId(uint32 mapId)
void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive *battlefieldStatus, Battleground *bg, Player *player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId)
std::vector< ScheduledQueueUpdate > m_QueueUpdateScheduler
void DeleteAllBattlegrounds()
Battleground * GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId)
BattlegroundTemplateMap _battlegroundTemplates
static BattlegroundQueueTypeId BGQueueTypeId(uint16 battlemasterListId, BattlegroundQueueIdType type, bool rated, uint8 teamSize)
uint32 GetMaxRatingDifference() const
static BattlegroundMgr * instance()
BGFreeSlotQueueContainer & GetBGFreeSlotQueueStore(uint32 mapId)
static bool IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId)
BattlegroundTypeId GetRandomBG(BattlegroundTypeId id)
static bool IsArenaType(BattlegroundTypeId bgTypeId)
BattlegroundQueue & GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId)
void AddBattleground(Battleground *bg)
void AddToBGFreeSlotQueue(Battleground *bg)
BattleMastersMap mBattleMastersMap
std::map< uint32, BGFreeSlotQueueContainer > m_BGFreeSlotQueue
static bool IsRandomBattleground(uint32 battlemasterListId)
void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundBracketId bracket_id)
void SendBattlegroundList(Player *player, ObjectGuid const &guid, BattlegroundTypeId bgTypeId)
BattlegroundTemplate const * GetBattlegroundTemplateByTypeId(BattlegroundTypeId id)
Battleground * CreateNewBattleground(BattlegroundQueueTypeId queueId, BattlegroundBracketId bracketId)
void SendToBattleground(Player *player, uint32 InstanceID, BattlegroundTypeId bgTypeId)
void BuildBattlegroundStatusHeader(WorldPackets::Battleground::BattlefieldStatusHeader *battlefieldStatus, Player *player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId)
void RemoveFromBGFreeSlotQueue(uint32 mapId, uint32 instanceId)
uint32 GetRatingDiscardTimer() const
static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday)
void BuildBattlegroundStatusNeedConfirmation(WorldPackets::Battleground::BattlefieldStatusNeedConfirmation *battlefieldStatus, Battleground *bg, Player *player, uint32 ticketId, uint32 joinTime, uint32 timeout, BattlegroundQueueTypeId queueId)
static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId)
uint32 GetPrematureFinishTime() const
uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
void Update(uint32 diff)
uint32 m_NextRatedArenaUpdate
void BuildBattlegroundStatusFailed(WorldPackets::Battleground::BattlefieldStatusFailed *battlefieldStatus, BattlegroundQueueTypeId queueId, Player *pPlayer, uint32 ticketId, GroupJoinBattlegroundResult result, ObjectGuid const *errorGuid=nullptr)
static bool IsBGWeekend(BattlegroundTypeId bgTypeId)
void BuildBattlegroundStatusQueued(WorldPackets::Battleground::BattlefieldStatusQueued *battlefieldStatus, Player *player, uint32 ticketId, uint32 joinTime, BattlegroundQueueTypeId queueId, uint32 avgWaitTime, bool asGroup)
BattlegroundDataContainer bgDataStore
void LoadBattlegroundTemplates()
void BattlegroundQueueUpdate(uint32 diff, BattlegroundBracketId bracket_id, uint32 minRating=0)
Class for manage Strand of Ancient battleground.
void SetInstanceID(uint32 InstanceID)
Definition: Battleground.h:306
uint32 GetMapId() const
bool ToBeDeleted() const
Definition: Battleground.h:468
virtual void Reset()
void SetRated(bool state)
Definition: Battleground.h:311
uint32 GetRemainingTime() const
Definition: Battleground.h:287
BattlegroundTypeId GetTypeID() const
void Update(uint32 diff)
uint32 GetInstanceID() const
Definition: Battleground.h:283
uint32 GetClientInstanceID() const
Definition: Battleground.h:285
void SetClientInstanceID(uint32 InstanceID)
Definition: Battleground.h:308
static TeamId GetTeamIndexByTeamId(Team team)
Definition: Battleground.h:392
void SetStatus(BattlegroundStatus Status)
Definition: Battleground.h:307
void SetArenaType(uint8 type)
Definition: Battleground.h:312
BattlegroundBracketId GetBracketId() const
uint32 GetElapsedTime() const
Definition: Battleground.h:286
void SetBracket(PVPDifficultyEntry const *bracketEntry)
void SetWeakPtr(Trinity::unique_weak_ptr< Battleground > weakRef)
Definition: Battleground.h:502
static PVPDifficultyEntry const * GetBattlegroundBracketById(uint32 mapid, BattlegroundBracketId id)
Definition: DB2Stores.cpp:2789
Class used to access individual fields of database query result.
Definition: Field.h:90
uint8 GetUInt8() const
Definition: Field.cpp:30
float GetFloat() const
Definition: Field.cpp:94
uint32 GetUInt32() const
Definition: Field.cpp:62
bool IsEmpty() const
Definition: ObjectGuid.h:319
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
void SendDirectMessage(WorldPacket const *data) const
Definition: Player.cpp:6324
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, TeleportToOptions options=TELE_TO_NONE, Optional< uint32 > instanceId={})
Definition: Player.cpp:1250
uint32 GetBattlegroundQueueJoinTime(BattlegroundQueueTypeId bgQueueTypeId) const
Definition: Player.cpp:24984
bool GetRandomWinner() const
Definition: Player.h:2434
Team GetBGTeam() const
Definition: Player.cpp:23609
std::string const & GetName() const
Definition: Object.h:555
#define sWorld
Definition: World.h:931
@ CONFIG_ARENA_MAX_RATING_DIFFERENCE
Definition: World.h:344
@ CONFIG_ARENA_RATED_UPDATE_TIMER
Definition: World.h:346
@ CONFIG_ARENA_RATING_DISCARD_TIMER
Definition: World.h:345
@ CONFIG_BATTLEGROUND_PREMATURE_FINISH_TIMER
Definition: World.h:341
bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const *ref, uint8 flags)
Definition: DisableMgr.cpp:285
auto SelectRandomWeightedContainerElement(C const &container, std::span< double > const &weights) -> decltype(std::begin(container))
Definition: Containers.h:126
Definition: Session.h:36
constexpr uint64 GetPacked() const
BattlegroundTypeId Id
uint8 GetMinLevel() const
BattlemasterListEntry const * BattlemasterEntry
uint16 GetMaxPlayersPerTeam() const
WorldSafeLocsEntry const * StartLocation[PVP_TEAMS_COUNT]
uint16 GetMinPlayersPerTeam() const
uint8 GetMaxLevel() const
std::array< int16, 16 > MapID
Definition: DB2Structure.h:517
BattlegroundBracketId GetBracketId() const
std::string ToString() const
Definition: Position.cpp:128
WorldLocation Loc
Definition: ObjectMgr.h:835