62 m_NextAutoDistributionTime(0),
63 m_AutoDistributionTimeChecker(0), m_UpdateTimer(0), m_ArenaTesting(false), m_Testing(false)
75 battleground->RemoveFromBGFreeSlotQueueOnShutdown();
95 BattlegroundContainer::iterator itrDelete = bgs.begin();
97 for (BattlegroundContainer::iterator itr = ++itrDelete; itr != bgs.end();)
106 if (!clients.empty())
112 bgs.erase(itrDelete);
122 pair.second.UpdateEvents(diff);
127 std::vector<ScheduledQueueUpdate> scheduled;
130 for (
auto& [arenaMMRating, bgQueueTypeId] : scheduled)
141 TC_LOG_TRACE(
"bg.arena",
"BattlegroundMgr: UPDATING ARENA QUEUES");
148 arenaQueue->BattlegroundQueueUpdate(diff,
true, 0);
189 battlefieldStatus->
QueueSlot = queueSlot;
196 battlefieldStatus->
Timeout = timeout;
212 .BracketId =
uint8(realBracket->GetBracketId()),
227 battlefieldStatus->
Reason = result;
229 battlefieldStatus->
ClientID = *errorGuid;
234 groupJoinedBattleground->
Reason = bgTypeId;
248 BattlegroundDataContainer::const_iterator it =
bgDataStore.find(bgTypeId);
252 for (BattlegroundContainer::const_iterator itr = it->second.m_Battlegrounds.begin(); itr != it->second.m_Battlegrounds.end(); ++itr)
254 if (itr->second->GetClientInstanceID() == instanceId)
255 return itr->second.get();
266 BattlegroundDataContainer::const_iterator begin, end;
281 for (BattlegroundDataContainer::const_iterator it = begin; it != end; ++it)
284 BattlegroundContainer::const_iterator itr = bgs.find(instanceId);
285 if (itr != bgs.end())
286 return itr->second.get();
294 BattlegroundDataContainer::const_iterator itr =
bgDataStore.find(bgTypeId);
300 return bgs.empty() ? nullptr : bgs.begin()->second.get();
317 for (BattlegroundClientIdsContainer::const_iterator itr = clientIds.begin(); itr != clientIds.end();)
319 if ((++lastId) != *itr)
324 clientIds.insert(++lastId);
338 TC_LOG_ERROR(
"bg.battleground",
"Battleground: CreateNewBattleground - bg template not found for {}", bgTypeId);
385 bool isRandom = bgTypeId != originalBgTypeId && !bg->
isArena();
401 uint32 maxPlayersPerTeam = 0;
405 maxPlayersPerTeam = 2;
408 maxPlayersPerTeam = 3;
411 maxPlayersPerTeam = 5;
429 switch (bgTemplate->
Id)
504 QueryResult result =
WorldDatabase.Query(
"SELECT ID, MinPlayersPerTeam, MaxPlayersPerTeam, MinLvl, MaxLvl, AllianceStartLoc, AllianceStartO, HordeStartLoc, HordeStartO, StartMaxDist, Weight, ScriptName FROM battleground_template");
507 TC_LOG_INFO(
"server.loading",
">> Loaded 0 battlegrounds. DB table `battleground_template` is empty.");
515 Field* fields = result->Fetch();
526 TC_LOG_ERROR(
"bg.battleground",
"Battleground ID {} could not be found in BattlemasterList.dbc. The battleground was not created.", bgTypeId);
531 bgTemplate.
Id = bgTypeId;
543 bgTemplate.
MapIDs.push_back(mapId);
547 TC_LOG_ERROR(
"sql.sql",
"Table `battleground_template` for id {} contains bad values for MinPlayersPerTeam ({}) and MaxPlayersPerTeam({}).",
554 TC_LOG_ERROR(
"sql.sql",
"Table `battleground_template` for id {} contains bad values for MinLevel ({}) and MaxLevel ({}).",
568 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);
579 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);
589 if (bgTemplate.
MapIDs.size() == 1)
594 while (result->NextRow());
606 TC_LOG_DEBUG(
"bg.battleground",
"Initializing Automatic Arena Point Distribution");
607 if (wstime < curtime)
610 TC_LOG_DEBUG(
"bg.battleground",
"Battleground: Next arena point distribution time in the past, reseting it now.");
614 TC_LOG_DEBUG(
"bg.battleground",
"Automatic Arena Point Distribution initialized.");
652 battlefieldList.
Battlefields = &battlegrounds->m_ClientBattlegroundIds[bracketEntry->GetBracketId()];
663 uint32 mapid = bg->GetMapId();
669 TC_LOG_DEBUG(
"bg.battleground",
"BattlegroundMgr::SendToBattleground: Sending {} to map {}, {} (bgType {})", player->
GetName(), mapid, pos->
ToString(), bgTypeId);
673 TC_LOG_ERROR(
"bg.battleground",
"BattlegroundMgr::SendToBattleground: Instance {} (bgType {}) not found while trying to teleport player {}", instanceId, bgTypeId, player->
GetName());
720 bg->SetHoliday(
false);
726 bg->SetHoliday(
true);
732 if (!battlemasterList)
749 if (battlemasterList->
MapIDs.empty())
796 TC_LOG_INFO(
"server.loading",
">> Loaded 0 battlemaster entries. DB table `battlemaster_entry` is empty!");
806 Field* fields = result->Fetch();
812 TC_LOG_ERROR(
"sql.sql",
"Creature (Entry: {}) listed in `battlemaster_entry` is not a battlemaster.", entry);
816 TC_LOG_ERROR(
"sql.sql",
"Creature (Entry: {}) listed in `battlemaster_entry` does not exist.", entry);
823 TC_LOG_ERROR(
"sql.sql",
"Table `battlemaster_entry` contains entry {} for a non-existing battleground type {}, ignored.", entry, bgTypeId);
829 while (result->NextRow());
839 for (
auto const& creatureTemplatePair : ctc)
843 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);
886 std::vector<BattlegroundTemplate const*> ids;
887 ids.reserve(bgTemplate->MapIDs.size());
888 for (
int32 mapId : bgTemplate->MapIDs)
906 bgDataStore[bgTypeId].BGFreeSlotQueue.push_front(bg);
913 auto itr = std::ranges::find(battlegroundData->BGFreeSlotQueue, instanceId, [](
Battleground const* bg) { return bg->GetInstanceID(); });
914 if (itr != battlegroundData->BGFreeSlotQueue.end())
915 battlegroundData->BGFreeSlotQueue.erase(itr);
@ BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY
@ BATTLEGROUND_OBJECTIVE_UPDATE_INTERVAL
std::set< uint32 > BattlegroundClientIdsContainer
std::map< uint32, Trinity::unique_trackable_ptr< Battleground > > BattlegroundContainer
std::list< Battleground * > BGFreeSlotQueueContainer
#define MAX_BATTLEGROUND_BRACKETS
DBCStorage< WorldSafeLocsEntry > sWorldSafeLocsStore(WorldSafeLocsEntryfmt)
DBCStorage< BattlemasterListEntry > sBattlemasterListStore(BattlemasterListEntryfmt)
PvPDifficultyEntry const * GetBattlegroundBracketByLevel(uint32 mapid, uint32 level)
PvPDifficultyEntry const * GetBattlegroundBracketById(uint32 mapid, BattlegroundBracketId id)
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
@ DISABLE_TYPE_BATTLEGROUND
bool IsHolidayActive(HolidayIds id)
#define TC_LOG_DEBUG(filterType__,...)
#define TC_LOG_TRACE(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_INFO(filterType__,...)
std::unordered_map< uint32, CreatureTemplate > CreatureTemplateContainer
GroupJoinBattlegroundResult
@ ERR_BATTLEGROUND_JOIN_TIMED_OUT
@ ERR_BATTLEGROUND_NOT_IN_BATTLEGROUND
@ HOLIDAY_CALL_TO_ARMS_AB
@ HOLIDAY_CALL_TO_ARMS_EY
@ HOLIDAY_CALL_TO_ARMS_SA
@ HOLIDAY_CALL_TO_ARMS_IC
@ HOLIDAY_CALL_TO_ARMS_AV
@ HOLIDAY_CALL_TO_ARMS_WS
#define MAX_BATTLEGROUND_TYPE_ID
@ WS_ARENA_DISTRIBUTION_TIME
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
@ UNIT_NPC_FLAG_BATTLEMASTER
Battleground * GetBattlegroundThroughClientInstance(uint32 instanceId, BattlegroundTypeId bgTypeId)
BattlegroundMapTemplateContainer _battlegroundMapTemplates
static void BuildBattlegroundStatusHeader(WorldPackets::Battleground::BattlefieldStatusHeader *header, Battleground const *bg, uint32 queueSlot, BattlegroundQueueTypeId queueId)
void LoadBattleMastersEntry()
std::map< BattlegroundQueueTypeId, BattlegroundQueue > m_BattlegroundQueues
BattlegroundTemplate const * GetBattlegroundTemplateByMapId(uint32 mapId)
void AddToBGFreeSlotQueue(BattlegroundTypeId bgTypeId, Battleground *bg)
std::vector< ScheduledQueueUpdate > m_QueueUpdateScheduler
static void BuildGroupJoinedBattlegroundPacket(WorldPackets::Battleground::GroupJoinedBattleground *groupJoinedBattleground, BattlegroundTypeId bgTypeId)
void DeleteAllBattlegrounds()
Battleground * GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId)
static void BuildBattlegroundStatusNeedConfirmation(WorldPackets::Battleground::BattlefieldStatusNeedConfirmation *battlefieldStatus, Battleground const *bg, uint32 queueSlot, uint32 timeout, BattlegroundQueueTypeId queueId)
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 bracketId, uint8 arenaType)
BattlegroundTemplateMap _battlegroundTemplates
uint32 GetMaxRatingDifference() const
void SetHolidayActive(uint32 battlegroundId)
static BattlegroundMgr * instance()
uint32 m_AutoDistributionTimeChecker
bool IsValidQueueId(BattlegroundQueueTypeId bgQueueTypeId)
static void BuildBattlegroundStatusQueued(WorldPackets::Battleground::BattlefieldStatusQueued *battlefieldStatus, Battleground const *bg, uint32 queueSlot, uint32 joinTime, BattlegroundQueueTypeId queueId, uint32 avgWaitTime)
BattlegroundTypeId GetRandomBG(BattlegroundTypeId id)
bool CreateBattleground(BattlegroundTemplate const *bgTemplate)
static bool IsArenaType(BattlegroundTypeId bgTypeId)
BGFreeSlotQueueContainer & GetBGFreeSlotQueueStore(BattlegroundTypeId bgTypeId)
BattlegroundQueue & GetBattlegroundQueue(BattlegroundQueueTypeId bgQueueTypeId)
void AddBattleground(Battleground *bg)
time_t m_NextAutoDistributionTime
void ToggleArenaTesting()
void RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint32 instanceId)
void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, BattlegroundQueueTypeId bgQueueTypeId)
BattleMastersMap mBattleMastersMap
static bool IsRandomBattleground(uint32 battlemasterListId)
void SendBattlegroundList(Player *player, ObjectGuid const &guid, BattlegroundTypeId bgTypeId)
BattlegroundTemplate const * GetBattlegroundTemplateByTypeId(BattlegroundTypeId id)
Battleground * CreateNewBattleground(BattlegroundTypeId bgTypeId, PvPDifficultyEntry const *bracketEntry, uint8 arenaType, bool isRated)
void SendToBattleground(Player *player, uint32 InstanceID, BattlegroundTypeId bgTypeId)
void InitAutomaticArenaPointDistribution()
uint32 GetRatingDiscardTimer() const
static void BuildBattlegroundStatusFailed(WorldPackets::Battleground::BattlefieldStatusFailed *battlefieldStatus, GroupJoinBattlegroundResult result, ObjectGuid const *errorGuid=nullptr)
static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday)
static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId)
Battleground * GetBattlegroundTemplate(BattlegroundTypeId bgTypeId)
uint32 GetPrematureFinishTime() const
void SendAreaSpiritHealerQueryOpcode(Player *player, Battleground *bg, ObjectGuid guid)
uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
static void BuildBattlegroundStatusNone(WorldPackets::Battleground::BattlefieldStatusNone *battlefieldStatus, uint32 queueSlot)
uint32 m_NextRatedArenaUpdate
static bool IsBGWeekend(BattlegroundTypeId bgTypeId)
BattlegroundDataContainer bgDataStore
static void BuildBattlegroundStatusActive(WorldPackets::Battleground::BattlefieldStatusActive *battlefieldStatus, Battleground const *bg, Player const *player, uint32 queueSlot, BattlegroundQueueTypeId queueId)
void CheckBattleMasters()
void LoadBattlegroundTemplates()
void BattlegroundQueueUpdate(uint32 diff, bool isRated=false, uint32 minRating=0)
Class for manage Strand of Ancient battleground.
void SetMapId(uint32 MapID)
void SetInstanceID(uint32 InstanceID)
BattlegroundTypeId GetTypeID(bool GetRandom=false) const
uint32 GetMinLevel() const
void SetRandom(bool isRandom)
void SetMaxPlayers(uint32 MaxPlayers)
static TeamId GetTeamIndexByTeamId(uint32 Team)
void SetName(std::string const &name)
uint32 GetEndTime() const
void SetScriptId(uint32 scriptId)
void SetBracket(PvPDifficultyEntry const *bracketEntry)
void SetMinPlayersPerTeam(uint32 MinPlayers)
void SetRated(bool state)
void SetStartMaxDist(float startMaxDist)
uint32 GetInstanceID() const
void SetLevelRange(uint32 min, uint32 max)
uint32 GetClientInstanceID() const
void SetClientInstanceID(uint32 InstanceID)
void SetStatus(BattlegroundStatus Status)
void SetArenaType(uint8 type)
void SetRandomTypeID(BattlegroundTypeId TypeID)
uint32 GetStartTime() const
void SetArenaorBGType(bool _isArena)
uint32 GetLastResurrectTime() const
void SetTeamStartPosition(TeamId teamId, Position const &pos)
BattlegroundBracketId GetBracketId() const
uint32 GetMaxLevel() const
void SetMinPlayers(uint32 MinPlayers)
void SetMaxPlayersPerTeam(uint32 MaxPlayers)
void SetWeakPtr(Trinity::unique_weak_ptr< Battleground > weakRef)
void SetTypeID(BattlegroundTypeId TypeID)
Class used to access individual fields of database query result.
void SendDirectMessage(WorldPacket const *data) const
bool GetRandomWinner() const
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
Specialized variant of std::shared_ptr that enforces unique ownership and/or std::unique_ptr with std...
std::string const & GetName() const
WorldPacket const * Write() override
uint32 RandomWinHonorCurrencyBonus
uint32 HolidayFirstWinArenaCurrencyBonus
uint32 HolidayLossHonorCurrencyBonus
uint32 HolidayWinHonorCurrencyBonus
uint32 RandomLossHonorCurrencyBonus
uint32 RandomFirstWinArenaCurrencyBonus
WorldPacket const * Write() override
ObjectGuid BattlemasterGuid
std::set< uint32 > const * Battlefields
BattlefieldStatusHeader Hdr
BattlefieldStatusHeader Hdr
BattlefieldStatusHeader Hdr
@ CONFIG_ARENA_MAX_RATING_DIFFERENCE
@ CONFIG_BG_REWARD_LOSER_HONOR_LAST
@ CONFIG_ARENA_RATED_UPDATE_TIMER
@ CONFIG_BG_REWARD_WINNER_ARENA_FIRST
@ CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS
@ CONFIG_BG_REWARD_WINNER_ARENA_LAST
@ CONFIG_BG_REWARD_WINNER_HONOR_FIRST
@ CONFIG_BG_REWARD_LOSER_HONOR_FIRST
@ CONFIG_ARENA_RATING_DISCARD_TIMER
@ CONFIG_BATTLEGROUND_PREMATURE_FINISH_TIMER
@ CONFIG_BG_REWARD_WINNER_HONOR_LAST
@ CONFIG_ARENA_AUTO_DISTRIBUTE_POINTS
@ CONFIG_ARENA_SEASON_IN_PROGRESS
bool IsDisabledFor(DisableType type, uint32 entry, WorldObject const *ref, uint8 flags)
auto SelectRandomWeightedContainerElement(C const &container, std::vector< double > weights) -> decltype(std::begin(container))
auto MapGetValuePtr(M &map, typename M::key_type const &key)
uint32 hk_honor_at_level(uint8 level, float multiplier=1.0f)
constexpr uint64 GetPacked() const
uint16 BattlemasterListId
BattlemasterListEntry const * BattlemasterEntry
Position StartLocation[PVP_TEAMS_COUNT]
std::vector< int32 > MapIDs
std::string ToString() const
float GetPositionZ() const
float GetOrientation() const
float GetPositionX() const
float GetPositionY() const
void Relocate(float x, float y)
BattlegroundBracketId GetBracketId() const