diff --git a/src/game/BattleGround/BattleGround.cpp b/src/game/BattleGround/BattleGround.cpp index 9b81e9b43d..639fd6b1e9 100644 --- a/src/game/BattleGround/BattleGround.cpp +++ b/src/game/BattleGround/BattleGround.cpp @@ -272,7 +272,7 @@ BattleGround::~BattleGround() m_bgMap->SetUnload(); // remove from bg free slot queue - this->RemovedFromBgFreeSlotQueue(); + this->RemovedFromBgFreeSlotQueue(true); for (BattleGroundScoreMap::const_iterator itr = m_playerScores.begin(); itr != m_playerScores.end(); ++itr) delete itr->second; @@ -735,7 +735,7 @@ void BattleGround::UpdateWorldStateForPlayer(uint32 field, uint32 value, Player* */ void BattleGround::EndBattleGround(Team winner) { - this->RemovedFromBgFreeSlotQueue(); + this->RemovedFromBgFreeSlotQueue(true); ArenaTeam* winner_arena_team = nullptr; ArenaTeam* loser_arena_team = nullptr; @@ -928,7 +928,7 @@ void BattleGround::EndBattleGround(Team winner) plr->GetSession()->SendPacket(data); BattleGroundQueueTypeId bgQueueTypeId = BattleGroundMgr::BgQueueTypeId(GetTypeId(), GetArenaType()); - sBattleGroundMgr.BuildBattleGroundStatusPacket(data, this, plr->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, TIME_TO_AUTOREMOVE, GetStartTime(), GetArenaType(), plr->GetBGTeam()); + sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, GetTypeId(), GetClientInstanceId(), IsRated(), GetMapId(), plr->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, TIME_TO_AUTOREMOVE, GetStartTime(), GetArenaType(), plr->GetBGTeam()); plr->GetSession()->SendPacket(data); } @@ -1237,7 +1237,7 @@ void BattleGround::RemovePlayerAtLeave(ObjectGuid playerGuid, bool isOnTransport if (doSendPacket) { WorldPacket data; - sBattleGroundMgr.BuildBattleGroundStatusPacket(data, this, player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE); + sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, GetTypeId(), GetClientInstanceId(), IsRated(), GetMapId(), player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE); player->GetSession()->SendPacket(data); } @@ -1272,7 +1272,10 @@ void BattleGround::RemovePlayerAtLeave(ObjectGuid playerGuid, bool isOnTransport { // a player has left the battleground, so there are free slots -> add to queue AddToBgFreeSlotQueue(); - sBattleGroundMgr.ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, GetBracketId()); + sWorld.GetBGQueue().GetMessager().AddMessage([bgQueueTypeId, bgTypeId, bracketId = GetBracketId()](BattleGroundQueue* queue) + { + queue->ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, bracketId); + }); } // Let others know @@ -1509,18 +1512,29 @@ void BattleGround::AddToBgFreeSlotQueue() if (!m_hasBgFreeSlotQueue && IsBattleGround()) { m_hasBgFreeSlotQueue = true; - // TODO: Resolve adding to queue + BattleGroundInQueueInfo bgInfo; + // TODO: Fill + sWorld.GetBGQueue().GetMessager().AddMessage([bgInfo](BattleGroundQueue* queue) + { + queue->AddBgToFreeSlots(bgInfo); + }); } } /** Method that removes this battleground from free queue - it must be called when deleting battleground */ -void BattleGround::RemovedFromBgFreeSlotQueue() +void BattleGround::RemovedFromBgFreeSlotQueue(bool removeFromQueue) { // set to be able to re-add if needed + if (m_hasBgFreeSlotQueue && removeFromQueue) + { + sWorld.GetBGQueue().GetMessager().AddMessage([instanceId = GetInstanceId()](BattleGroundQueue* queue) + { + queue->RemoveBgFromFreeSlots(instanceId); + }); + } m_hasBgFreeSlotQueue = false; - // TODO: Resolve if called from queue or elsewhere } /** @@ -1953,7 +1967,7 @@ void BattleGround::SendBcdToTeam(int32 bcdEntry, ChatMsg msgtype, Creature const */ void BattleGround::EndNow() { - RemovedFromBgFreeSlotQueue(); + RemovedFromBgFreeSlotQueue(true); SetStatus(STATUS_WAIT_LEAVE); SetEndTime(0); } @@ -2048,7 +2062,7 @@ void BattleGround::PlayerAddedToBgCheckIfBgIsRunning(Player* player) sBattleGroundMgr.BuildPvpLogDataPacket(data, this); player->GetSession()->SendPacket(data); - sBattleGroundMgr.BuildBattleGroundStatusPacket(data, this, player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, GetEndTime(), GetStartTime(), GetArenaType(), player->GetBGTeam()); + sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, GetTypeId(), GetClientInstanceId(), IsRated(), GetMapId(), player->GetBattleGroundQueueIndex(bgQueueTypeId), STATUS_IN_PROGRESS, GetEndTime(), GetStartTime(), GetArenaType(), player->GetBGTeam()); player->GetSession()->SendPacket(data); } diff --git a/src/game/BattleGround/BattleGround.h b/src/game/BattleGround/BattleGround.h index 5e75ef55fa..16385cf27c 100644 --- a/src/game/BattleGround/BattleGround.h +++ b/src/game/BattleGround/BattleGround.h @@ -354,7 +354,7 @@ class BattleGround void SetMinPlayersPerTeam(uint32 minPlayers) { m_minPlayersPerTeam = minPlayers; } void AddToBgFreeSlotQueue(); // this queue will be useful when more battlegrounds instances will be available - void RemovedFromBgFreeSlotQueue(); // this method could delete whole BG instance, if another free is available + void RemovedFromBgFreeSlotQueue(bool removeFromQueue); // this method could delete whole BG instance, if another free is available // Functions to decrease or increase player count void DecreaseInvitedCount(Team team) { (team == ALLIANCE) ? --m_invitedAlliance : --m_invitedHorde; } diff --git a/src/game/BattleGround/BattleGroundQueue.cpp b/src/game/BattleGround/BattleGroundQueue.cpp index 52930ef40d..b239e5f8c8 100644 --- a/src/game/BattleGround/BattleGroundQueue.cpp +++ b/src/game/BattleGround/BattleGroundQueue.cpp @@ -896,7 +896,7 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId { if (BattleGround* bg = sBattleGroundMgr.GetBattleGround(instanceId, typeId)) { - bg->RemovedFromBgFreeSlotQueue(); + bg->RemovedFromBgFreeSlotQueue(false); } }); } @@ -1450,7 +1450,7 @@ void BattleGroundQueue::ScheduleQueueUpdate(uint32 arenaRating, ArenaType arenaT m_queueUpdateScheduler.push_back(schedule_id); } -void BattleGroundQueue::AddBgToFreeSlots(BattleGroundInQueueInfo& info) +void BattleGroundQueue::AddBgToFreeSlots(BattleGroundInQueueInfo const& info) { // TODO: } diff --git a/src/game/BattleGround/BattleGroundQueue.h b/src/game/BattleGround/BattleGroundQueue.h index bdfcac0334..0662028b96 100644 --- a/src/game/BattleGround/BattleGroundQueue.h +++ b/src/game/BattleGround/BattleGroundQueue.h @@ -244,7 +244,7 @@ class BattleGroundQueue void ScheduleQueueUpdate(uint32 /*arenaRating*/, ArenaType /*arenaType*/, BattleGroundQueueTypeId /*bgQueueTypeId*/, BattleGroundTypeId /*bgTypeId*/, BattleGroundBracketId /*bracketId*/); - void AddBgToFreeSlots(BattleGroundInQueueInfo& info); + void AddBgToFreeSlots(BattleGroundInQueueInfo const& info); void RemoveBgFromFreeSlots(uint32 instanceId); void RemovePlayer(BattleGroundQueueTypeId bgQueueTypeId, ObjectGuid player, bool decreaseInvitedCount);