77 BattlegroundContainer::iterator itrDelete = bgs.begin();
79 for (BattlegroundContainer::iterator itr = ++itrDelete; itr != bgs.end();)
87 itrDelete->second = NULL;
106 std::vector<ScheduledQueueUpdate> scheduled;
108 for (
uint8 i = 0; i < scheduled.size(); i++)
110 uint32 arenaMMRating = scheduled[i].ArenaMMRating;
111 uint8 arenaType = scheduled[i].ArenaType;
115 m_BattlegroundQueues[bgQueueTypeId].BattlegroundQueueUpdate(diff, bgTypeId, bracket_id, arenaType, arenaMMRating > 0, arenaMMRating);
126 SF_LOG_TRACE(
"bg.arena",
"BattlegroundMgr: UPDATING ARENA QUEUES");
158 *data <<
uint32(QueueSlot);
222 *data <<
uint32(QueueSlot);
260 *data <<
uint32(QueueSlot);
321 *data <<
uint32(QueueSlot);
567 *data <<
uint32(QueueSlot);
571 data->
WriteBit(battlegroundGuid[2]);
572 data->
WriteBit(battlegroundGuid[7]);
575 data->
WriteBit(battlegroundGuid[6]);
578 data->
WriteBit(battlegroundGuid[0]);
579 data->
WriteBit(battlegroundGuid[3]);
585 data->
WriteBit(battlegroundGuid[4]);
589 data->
WriteBit(battlegroundGuid[5]);
695 BattlegroundDataContainer::const_iterator it =
bgDataStore.find(bgTypeId);
699 for (BattlegroundContainer::const_iterator itr = it->second.m_Battlegrounds.begin(); itr != it->second.m_Battlegrounds.end(); ++itr)
701 if (itr->second->GetClientInstanceID() == instanceId)
713 BattlegroundDataContainer::const_iterator begin, end;
728 for (BattlegroundDataContainer::const_iterator it = begin; it != end; ++it)
731 BattlegroundContainer::const_iterator itr = bgs.find(instanceId);
732 if (itr != bgs.end())
741 BattlegroundDataContainer::const_iterator itr =
bgDataStore.find(bgTypeId);
747 return bgs.empty() ? NULL : bgs.begin()->second;
765 for (BattlegroundClientIdsContainer::const_iterator itr = clientIds.begin(); itr != clientIds.end();)
767 if ((++lastId) != *itr)
772 clientIds.insert(++lastId);
780 bool isRandom =
false;
782 switch (originalBgTypeId)
799 SF_LOG_ERROR(
"bg.battleground",
"Battleground: CreateNewBattleground - bg template not found for %u",
uint32(bgTypeId));
875 uint32 maxPlayersPerTeam = 0;
879 maxPlayersPerTeam = 2;
882 maxPlayersPerTeam = 3;
885 maxPlayersPerTeam = 5;
984 QueryResult result =
WorldDatabase.Query(
"SELECT id, MinPlayersPerTeam, MaxPlayersPerTeam, MinLvl, MaxLvl, AllianceStartLoc, AllianceStartO, HordeStartLoc, HordeStartO, StartMaxDist, Weight, ScriptName FROM battleground_template");
988 SF_LOG_ERROR(
"server.loading",
">> Loaded 0 battlegrounds. DB table `battleground_template` is empty.");
996 Field* fields = result->Fetch();
1006 SF_LOG_ERROR(
"bg.battleground",
"Battleground ID %u not found in BattleMasterList.dbc. Battleground not created.", bgTypeId);
1026 SF_LOG_ERROR(
"sql.sql",
"Table `battleground_template` for id %u has bad values for MinPlayersPerTeam (%u) and MaxPlayersPerTeam(%u)",
1033 SF_LOG_ERROR(
"sql.sql",
"Table `battleground_template` for id %u has bad values for LevelMin (%u) and LevelMax(%u)",
1061 SF_LOG_ERROR(
"sql.sql",
"Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `AllianceStartLoc`. BG not created.", bgTypeId, startId);
1075 SF_LOG_ERROR(
"sql.sql",
"Table `battleground_template` for id %u have non-existed WorldSafeLocs.dbc id %u in field `HordeStartLoc`. BG not created.", bgTypeId, startId);
1092 }
while (result->NextRow());
1102 BattlegroundDataContainer::iterator it =
bgDataStore.find(bgTypeId);
1117 *data <<
uint32(winnerConquest)
1120 <<
uint32(winnerConquest)
1140 size_t count_pos = data->
bitwpos();
1157 for (BattlegroundClientIdsContainer::const_iterator itr = clientIds.begin(); itr != clientIds.end(); ++itr)
1162 data->
PutBits(count_pos, count, 22);
1170 uint32 mapid = bg->GetMapId();
1173 bg->GetTeamStartLoc(team, x, y, z, O);
1174 SF_LOG_DEBUG(
"bg.battleground",
"BattlegroundMgr::SendToBattleground: Sending %s to map %u, X %f, Y %f, Z %f, O %f (bgType %u)", player->
GetName().c_str(), mapid, x, y, z, O,
uint32(bgTypeId));
1178 SF_LOG_ERROR(
"bg.battleground",
"BattlegroundMgr::SendToBattleground: Instance %u (bgType %u) not found while trying to teleport player %s", instanceId,
uint32(bgTypeId), player->
GetName().c_str());
1258 switch (bgQueueTypeId)
1291 switch (bgQueueTypeId)
1322 bg->SetHoliday(mask & (1 << bgtype));
1331 ScheduledQueueUpdate scheduleId = { arenaMatchmakerRating, arenaType, bgQueueTypeId, bgTypeId, bracket_id };
1365 SF_LOG_INFO(
"server.loading",
">> Loaded 0 battlemaster entries. DB table `battlemaster_entry` is empty!");
1375 Field* fields = result->Fetch();
1381 SF_LOG_ERROR(
"sql.sql",
"Table `battlemaster_entry` contain entry %u for not existed battleground type %u, ignored.", entry, bgTypeId);
1386 }
while (result->NextRow());
1446 weight += it->second;
1447 selectionWeights[it->first] = it->second;
1457 weight += it->second;
1458 selectionWeights[it->first] = it->second;
1466 uint32 selectedWeight = std::rand() % (weight - 1);
1469 for (BattlegroundSelectionWeightMap::const_iterator it = selectionWeights.begin(); it != selectionWeights.end(); ++it)
1471 weight += it->second;
1472 if (selectedWeight < weight)
1474 returnBgTypeId = it->first;
1480 return returnBgTypeId;
1490 bgDataStore[bgTypeId].BGFreeSlotQueue.push_front(bg);
1496 for (BGFreeSlotQueueContainer::iterator itr = queues.begin(); itr != queues.end(); ++itr)
1497 if ((*itr)->GetInstanceID() == instanceId)
1512 bgDataStore[bgTypeId].m_Battlegrounds.erase(instanceId);
std::map< uint32, Battleground * > BattlegroundContainer
std::set< uint32 > BattlegroundClientIdsContainer
std::list< Battleground * > BGFreeSlotQueueContainer
#define MAX_BATTLEGROUND_BRACKETS
DBCStorage< WorldSafeLocsEntry > sWorldSafeLocsStore(WorldSafeLocsEntryfmt)
DBCStorage< BattlemasterListEntry > sBattlemasterListStore(BattlemasterListEntryfmt)
PvPDifficultyEntry const * GetBattlegroundBracketByLevel(uint32 mapid, uint32 level)
@ DISABLE_TYPE_BATTLEGROUND
bool IsHolidayActive(HolidayIds id)
#define SF_LOG_DEBUG(filterType__,...)
#define SF_LOG_ERROR(filterType__,...)
#define SF_LOG_TRACE(filterType__,...)
#define SF_LOG_INFO(filterType__,...)
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
GroupJoinBattlegroundResult
#define CURRENCY_PRECISION
@ MAX_BATTLEGROUND_QUEUE_TYPES
@ BATTLEGROUND_QUEUE_NONE
@ HOLIDAY_CALL_TO_ARMS_SM
@ HOLIDAY_CALL_TO_ARMS_TP
@ HOLIDAY_CALL_TO_ARMS_SA
@ HOLIDAY_CALL_TO_ARMS_WS
@ HOLIDAY_CALL_TO_ARMS_IC
@ HOLIDAY_CALL_TO_ARMS_EY
@ HOLIDAY_CALL_TO_ARMS_TK
@ HOLIDAY_CALL_TO_ARMS_DG
@ HOLIDAY_CALL_TO_ARMS_AB
@ HOLIDAY_CALL_TO_ARMS_AV
@ HOLIDAY_CALL_TO_ARMS_BFG
#define MAX_BATTLEGROUND_TYPE_ID
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
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)
uint32 GetPlayerScoresSize() const
uint32 GetPlayerActiveSpec(uint64 guid) const
void SetScriptId(uint32 scriptId)
void SetName(char const *Name)
void SetBracket(PvPDifficultyEntry const *bracketEntry)
void SetMinPlayersPerTeam(uint32 MinPlayers)
void SetRated(bool state)
void SetStartMaxDist(float startMaxDist)
uint32 GetRemainingTime() const
uint32 GetInstanceID() const
BattlegroundScoreMap::const_iterator GetPlayerScoresBegin() const
void SetLevelRange(uint32 min, uint32 max)
uint32 GetClientInstanceID() const
void SetGuid(uint64 newGuid)
void SetClientInstanceID(uint32 InstanceID)
void SetStatus(BattlegroundStatus Status)
void SetArenaType(uint8 type)
void SetRandomTypeID(BattlegroundTypeId TypeID)
void SetTeamStartLoc(uint32 TeamID, float X, float Y, float Z, float O)
BattlegroundStatus GetStatus() const
void SetArenaorBGType(bool _isArena)
uint32 GetPlayersCountByTeam(uint32 Team) const
uint32 GetLastResurrectTime() const
BattlegroundBracketId GetBracketId() const
bool IsPlayerInBattleground(uint64 guid) const
uint32 GetMaxLevel() const
BattlegroundScoreMap::const_iterator GetPlayerScoresEnd() const
void SetMinPlayers(uint32 MinPlayers)
void SetMaxPlayersPerTeam(uint32 MaxPlayers)
void SetTypeID(BattlegroundTypeId TypeID)
Battleground * GetBattlegroundThroughClientInstance(uint32 instanceId, BattlegroundTypeId bgTypeId)
void BuildUpdateWorldStatePacket(WorldPacket *data, uint32 field, uint32 value)
void LoadBattleMastersEntry()
void BuildPlayerJoinedBattlegroundPacket(WorldPacket *data, uint64 guid)
bool CreateBattleground(CreateBattlegroundData &data)
void AddToBGFreeSlotQueue(BattlegroundTypeId bgTypeId, Battleground *bg)
BattlegroundSelectionWeightMap m_BGSelectionWeights
std::vector< ScheduledQueueUpdate > m_QueueUpdateScheduler
std::map< BattlegroundTypeId, uint8 > BattlegroundSelectionWeightMap
void DeleteAllBattlegrounds()
Battleground * GetBattleground(uint32 InstanceID, BattlegroundTypeId bgTypeId)
void RemoveBattleground(BattlegroundTypeId bgTypeId, uint32 instanceId)
uint32 GetMaxRatingDifference() const
BattlegroundTypeId GetRandomBG(BattlegroundTypeId id)
void CreateInitialBattlegrounds()
BattlegroundQueue m_BattlegroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]
static bool IsArenaType(BattlegroundTypeId bgTypeId)
BGFreeSlotQueueContainer & GetBGFreeSlotQueueStore(BattlegroundTypeId bgTypeId)
static BattlegroundQueueTypeId BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
void AddBattleground(Battleground *bg)
void BuildBattlegroundStatusPacket(WorldPacket *data, Battleground *bg, Player *player, uint8 queueSlot, uint8 statusId, uint32 time1, uint32 time2, uint8 arenaType)
void ToggleArenaTesting()
static BattlegroundTypeId BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId)
void RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uint32 instanceId)
BattleMastersMap mBattleMastersMap
void ScheduleQueueUpdate(uint32 arenaMatchmakerRating, uint8 arenaType, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
Battleground * CreateNewBattleground(BattlegroundTypeId bgTypeId, PvPDifficultyEntry const *bracketEntry, uint8 arenaType, bool isRated)
BattlegroundSelectionWeightMap m_ArenaSelectionWeights
void SendToBattleground(Player *player, uint32 InstanceID, BattlegroundTypeId bgTypeId)
void SetHolidayWeekends(uint32 mask)
void BuildPvpLogDataPacket(WorldPacket *data, Battleground *bg)
uint32 GetRatingDiscardTimer() const
static BattlegroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday)
void BuildStatusFailedPacket(WorldPacket *data, Battleground *bg, Player *pPlayer, uint8 QueueSlot, GroupJoinBattlegroundResult result)
static HolidayIds BGTypeToWeekendHolidayId(BattlegroundTypeId bgTypeId)
void BuildBattlegroundListPacket(WorldPacket *data, uint64 guid, Player *player, BattlegroundTypeId bgTypeId)
Battleground * GetBattlegroundTemplate(BattlegroundTypeId bgTypeId)
void BuildPlaySoundPacket(WorldPacket *data, uint32 soundId)
void BuildPlayerLeftBattlegroundPacket(WorldPacket *data, uint64 guid)
uint32 GetPrematureFinishTime() const
uint32 CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
uint32 m_NextRatedArenaUpdate
void SendAreaSpiritHealerQueryOpcode(Player *player, Battleground *bg, uint64 guid)
static bool IsBGWeekend(BattlegroundTypeId bgTypeId)
static uint8 BGArenaType(BattlegroundQueueTypeId bgQueueTypeId)
BattlegroundDataContainer bgDataStore
Class for manage Strand of Ancient battleground.
void WriteGuidBytes(const ObjectGuid &guid, Offsets... offsets)
bool WriteBit(uint32 bit)
void WriteGuidMask(const ObjectGuid &guid, Offsets... offsets)
size_t bitwpos() const
Returns position of last written bit.
void PutBits(size_t pos, T value, uint32 bitCount)
void WriteBits(T value, size_t bits)
void WriteByteSeq(uint8 b)
static Player * FindPlayer(uint64)
uint32 GetBattlegroundQueueJoinTime(BattlegroundTypeId bgTypeId) const
WorldSession * GetSession() const
bool GetRandomWinner() const
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
std::string const & GetName() const
void Initialize(Opcodes opcode, size_t newres=200)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
@ SMSG_BATTLEFIELD_STATUS_ACTIVE
@ SMSG_AREA_SPIRIT_HEALER_TIME
@ SMSG_BATTLEFIELD_STATUS
@ SMSG_BATTLEFIELD_STATUS_NEEDCONFIRMATION
@ SMSG_UPDATE_WORLD_STATE
@ SMSG_BATTLEFIELD_STATUS_QUEUED
@ SMSG_BATTLEGROUND_PLAYER_LEFT
@ SMSG_BATTLEFIELD_STATUS_FAILED
@ SMSG_BATTLEGROUND_PLAYER_JOINED
@ CONFIG_BG_REWARD_WINNER_HONOR_FIRST
@ CONFIG_ARENA_RATED_UPDATE_TIMER
@ CONFIG_BG_REWARD_WINNER_HONOR_LAST
@ CONFIG_BG_REWARD_WINNER_CONQUEST_LAST
@ CONFIG_ARENA_RATING_DISCARD_TIMER
@ CONFIG_BG_REWARD_LOSER_HONOR_FIRST
@ CONFIG_BG_REWARD_LOSER_HONOR_LAST
@ CONFIG_BG_REWARD_WINNER_CONQUEST_FIRST
@ CONFIG_BATTLEGROUND_PREMATURE_FINISH_TIMER
@ CONFIG_ARENA_MAX_RATING_DIFFERENCE
bool IsDisabledFor(DisableType type, uint32 entry, Unit const *unit, uint8 flags)
BattlegroundContainer m_Battlegrounds
BGFreeSlotQueueContainer BGFreeSlotQueue
BattlegroundTypeId bgTypeId
BattlegroundBracketId GetBracketId() const