From c3407ecc8081ba246e15dff226fae8927db639df Mon Sep 17 00:00:00 2001 From: killerwife Date: Sun, 6 Oct 2024 12:36:16 +0200 Subject: [PATCH] Make it work again --- src/game/BattleGround/BattleGround.cpp | 35 ++++++- src/game/BattleGround/BattleGround.h | 7 +- src/game/BattleGround/BattleGroundHandler.cpp | 30 +++--- src/game/BattleGround/BattleGroundMgr.cpp | 11 ++- src/game/BattleGround/BattleGroundMgr.h | 4 +- src/game/BattleGround/BattleGroundQueue.cpp | 99 ++++++++++++++----- src/game/BattleGround/BattleGroundQueue.h | 26 +++-- 7 files changed, 156 insertions(+), 56 deletions(-) diff --git a/src/game/BattleGround/BattleGround.cpp b/src/game/BattleGround/BattleGround.cpp index e6e9b9d9e4..851c18d308 100644 --- a/src/game/BattleGround/BattleGround.cpp +++ b/src/game/BattleGround/BattleGround.cpp @@ -962,6 +962,16 @@ uint32 BattleGround::GetBonusHonorFromKill(uint32 kills) const return (uint32)MaNGOS::Honor::hk_honor_at_level(GetMaxLevel(), kills); } +void BattleGround::SetStatus(BattleGroundStatus status) +{ + m_status = status; + sWorld.GetBGQueue().GetMessager().AddMessage([status, bgTypeId = GetTypeId(), instanceId = GetInstanceId()](BattleGroundQueue* queue) + { + if (BattleGroundInQueueInfo* bgInstance = queue->GetFreeSlotInstance(bgTypeId, instanceId)) + bgInstance->status = status; + }); +} + /** Function that returns the battleground master entry */ @@ -1266,12 +1276,19 @@ void BattleGround::RemovePlayerAtLeave(ObjectGuid playerGuid, bool isOnTransport delete group; } } - DecreaseInvitedCount(team); + // we should update battleground queue, but only if bg isn't ending if (IsBattleGround() && GetStatus() < STATUS_WAIT_LEAVE) { // a player has left the battleground, so there are free slots -> add to queue - AddToBgFreeSlotQueue(); + if (!AddToBgFreeSlotQueue()) // avoid setting two messages - if was already in queue, just update count + { + sWorld.GetBGQueue().GetMessager().AddMessage([bgTypeId, instanceId = GetInstanceId(), team](BattleGroundQueue* queue) + { + if (BattleGroundInQueueInfo* bgInstance = queue->GetFreeSlotInstance(bgTypeId, instanceId)) + bgInstance->DecreaseInvitedCount(team); + }); + } sWorld.GetBGQueue().GetMessager().AddMessage([bgQueueTypeId, bgTypeId, bracketId = GetBracketId()](BattleGroundQueue* queue) { queue->ScheduleQueueUpdate(0, ARENA_TYPE_NONE, bgQueueTypeId, bgTypeId, bracketId); @@ -1506,19 +1523,21 @@ void BattleGround::EventPlayerLoggedOut(Player* player) /** Function that returns the number of players that can join a battleground based on the provided team */ -void BattleGround::AddToBgFreeSlotQueue() +bool BattleGround::AddToBgFreeSlotQueue() { // make sure to add only once if (!m_hasBgFreeSlotQueue && IsBattleGround()) { m_hasBgFreeSlotQueue = true; BattleGroundInQueueInfo bgInfo; - // TODO: Fill + bgInfo.Fill(this); sWorld.GetBGQueue().GetMessager().AddMessage([bgInfo](BattleGroundQueue* queue) { queue->AddBgToFreeSlots(bgInfo); }); + return true; } + return false; } /** @@ -1537,6 +1556,14 @@ void BattleGround::RemovedFromBgFreeSlotQueue(bool removeFromQueue) m_hasBgFreeSlotQueue = false; } +void BattleGround::SetInvitedCount(Team team, uint32 count) +{ + if (team == ALLIANCE) + m_invitedAlliance = count; + else + m_invitedHorde = count; +} + /** Function that returns the number of players that can join a battleground based on the provided team diff --git a/src/game/BattleGround/BattleGround.h b/src/game/BattleGround/BattleGround.h index 16385cf27c..3b2e024da0 100644 --- a/src/game/BattleGround/BattleGround.h +++ b/src/game/BattleGround/BattleGround.h @@ -335,7 +335,7 @@ class BattleGround void SetName(char const* name) { m_name = name; } void SetTypeId(BattleGroundTypeId typeId) { m_typeId = typeId; } void SetBracketId(BattleGroundBracketId id) { m_bracketId = id; } - void SetStatus(BattleGroundStatus status) { m_status = status; } + void SetStatus(BattleGroundStatus status); void SetClientInstanceId(uint32 instanceId) { m_clientInstanceId = instanceId; } void SetStartTime(uint32 time) { m_startTime = time; } void SetEndTime(uint32 time) { m_endTime = time; } @@ -353,12 +353,11 @@ class BattleGround void SetMaxPlayersPerTeam(uint32 maxPlayers) { m_maxPlayersPerTeam = maxPlayers; } void SetMinPlayersPerTeam(uint32 minPlayers) { m_minPlayersPerTeam = minPlayers; } - void AddToBgFreeSlotQueue(); // this queue will be useful when more battlegrounds instances will be available + bool AddToBgFreeSlotQueue(); // this queue will be useful when more battlegrounds instances will be 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; } - void IncreaseInvitedCount(Team team) { (team == ALLIANCE) ? ++m_invitedAlliance : ++m_invitedHorde; } + void SetInvitedCount(Team team, uint32 count); uint32 GetInvitedCount(Team team) const { if (team == ALLIANCE) diff --git a/src/game/BattleGround/BattleGroundHandler.cpp b/src/game/BattleGround/BattleGroundHandler.cpp index 7d43462a28..b24413e717 100644 --- a/src/game/BattleGround/BattleGroundHandler.cpp +++ b/src/game/BattleGround/BattleGroundHandler.cpp @@ -465,7 +465,7 @@ void WorldSession::HandleBattlefieldPortOpcode(WorldPacket& recv_data) MANGOS_ASSERT(bgInQueue); // at this point must always exist // remove battleground queue status from BGmgr - queueItem.RemovePlayer(playerGuid, false); + queueItem.RemovePlayer(*queue, playerGuid, false); sWorld.GetMessager().AddMessage([playerGuid, invitedTo = queueInfo.isInvitedToBgInstanceGuid, bgTypeId, bgQueueTypeId, groupTeam = queueInfo.groupTeam, queueSlot, bgClientInstanceId = bgInQueue->GetClientInstanceId(), isRated = bgInQueue->IsRated(), mapId = bgInQueue->GetMapId(), arenaType = bgInQueue->GetArenaType()](World* world) { @@ -524,22 +524,22 @@ void WorldSession::HandleBattlefieldPortOpcode(WorldPacket& recv_data) at->SaveToDB(); } }); + } - queueItem.RemovePlayer(playerGuid, true); - sWorld.GetMessager().AddMessage([playerGuid, bgQueueTypeId, queueSlot, bgTypeId, bgClientInstanceId = queueInfo.clientInstanceId, isRated = queueInfo.isRated, mapId = queueInfo.mapId](World* world) - { - Player* player = sObjectMgr.GetPlayer(playerGuid); - if (!player) - return; - player->RemoveBattleGroundQueueId(bgQueueTypeId); - WorldPacket data; - sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, bgTypeId, bgClientInstanceId, isRated, mapId, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE); - player->GetSession()->SendPacket(data); - }); + queueItem.RemovePlayer(*queue, playerGuid, true); + sWorld.GetMessager().AddMessage([playerGuid, bgQueueTypeId, queueSlot, bgTypeId, bgClientInstanceId = queueInfo.clientInstanceId, isRated = queueInfo.isRated, mapId = queueInfo.mapId](World* world) + { + Player* player = sObjectMgr.GetPlayer(playerGuid); + if (!player) + return; + player->RemoveBattleGroundQueueId(bgQueueTypeId); + WorldPacket data; + sBattleGroundMgr.BuildBattleGroundStatusPacket(data, true, bgTypeId, bgClientInstanceId, isRated, mapId, queueSlot, STATUS_NONE, 0, 0, ARENA_TYPE_NONE, TEAM_NONE); + player->GetSession()->SendPacket(data); + }); - if (queueInfo.arenaType == ARENA_TYPE_NONE) - queue->ScheduleQueueUpdate(queueInfo.arenaTeamRating, queueInfo.arenaType, bgQueueTypeId, bgTypeId, queueInfo.bgBracketId); - } + if (queueInfo.arenaType == ARENA_TYPE_NONE) + queue->ScheduleQueueUpdate(queueInfo.arenaTeamRating, queueInfo.arenaType, bgQueueTypeId, bgTypeId, queueInfo.bgBracketId); break; default: sLog.outError("Battleground port: unknown action %u", action); diff --git a/src/game/BattleGround/BattleGroundMgr.cpp b/src/game/BattleGround/BattleGroundMgr.cpp index 7994ea2980..2c2514c259 100644 --- a/src/game/BattleGround/BattleGroundMgr.cpp +++ b/src/game/BattleGround/BattleGroundMgr.cpp @@ -47,11 +47,10 @@ INSTANTIATE_SINGLETON_1(BattleGroundMgr); /*** BATTLEGROUND MANAGER ***/ /*********************************************************/ -BattleGroundMgr::BattleGroundMgr() : m_arenaTesting(false) +BattleGroundMgr::BattleGroundMgr() : m_arenaTesting(false), m_testing(false) { for (uint8 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; ++i) m_battleGrounds[i].clear(); - m_testing = false; } BattleGroundMgr::~BattleGroundMgr() @@ -1139,6 +1138,10 @@ void BattleGroundMgr::ToggleTesting() sWorld.SendWorldText(LANG_DEBUG_BG_ON); else sWorld.SendWorldText(LANG_DEBUG_BG_OFF); + sWorld.GetBGQueue().GetMessager().AddMessage([testing = m_testing](BattleGroundQueue* queue) + { + queue->SetTesting(testing); + }); } /** @@ -1151,6 +1154,10 @@ void BattleGroundMgr::ToggleArenaTesting() sWorld.SendWorldText(LANG_DEBUG_ARENA_ON); else sWorld.SendWorldText(LANG_DEBUG_ARENA_OFF); + sWorld.GetBGQueue().GetMessager().AddMessage([arenaTesting = m_arenaTesting](BattleGroundQueue* queue) + { + queue->SetArenaTesting(arenaTesting); + }); } /** diff --git a/src/game/BattleGround/BattleGroundMgr.h b/src/game/BattleGround/BattleGroundMgr.h index 2a19e64f3d..d44d04fe99 100644 --- a/src/game/BattleGround/BattleGroundMgr.h +++ b/src/game/BattleGround/BattleGroundMgr.h @@ -145,8 +145,8 @@ class BattleGroundMgr BattleGroundSet m_battleGrounds[MAX_BATTLEGROUND_TYPE_ID]; typedef std::set ClientBattleGroundIdSet; ClientBattleGroundIdSet m_clientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_BRACKETS]; // the instanceids just visible for the client - bool m_arenaTesting; - bool m_testing; + bool m_arenaTesting; + bool m_testing; std::set m_usedRefloot; }; diff --git a/src/game/BattleGround/BattleGroundQueue.cpp b/src/game/BattleGround/BattleGroundQueue.cpp index 8cb5379e9b..010a18acc4 100644 --- a/src/game/BattleGround/BattleGroundQueue.cpp +++ b/src/game/BattleGround/BattleGroundQueue.cpp @@ -329,7 +329,7 @@ uint32 BattleGroundQueueItem::GetAverageQueueWaitTime(GroupQueueInfo* queueInfo, @param guid @param decrease invite count */ -void BattleGroundQueueItem::RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount) +void BattleGroundQueueItem::RemovePlayer(BattleGroundQueue& queue, ObjectGuid guid, bool decreaseInvitedCount) { int32 bracketId = -1; // signed for proper for-loop finish @@ -389,9 +389,8 @@ void BattleGroundQueueItem::RemovePlayer(ObjectGuid guid, bool decreaseInvitedCo // if invited to bg, and should decrease invited count, then do it if (decreaseInvitedCount && group->isInvitedToBgInstanceGuid) { - BattleGround* bg = sBattleGroundMgr.GetBattleGround(group->isInvitedToBgInstanceGuid, group->bgTypeId); - if (bg) - bg->DecreaseInvitedCount(group->groupTeam); + if (BattleGroundInQueueInfo* bgInstance = queue.GetFreeSlotInstance(group->bgTypeId, group->isInvitedToBgInstanceGuid)) + bgInstance->DecreaseInvitedCount(group->groupTeam); } // remove player queue info @@ -452,7 +451,7 @@ void BattleGroundQueueItem::RemovePlayer(ObjectGuid guid, bool decreaseInvitedCo }); // then actually delete, this may delete the group as well! - RemovePlayer(group->players.begin()->first, decreaseInvitedCount); + RemovePlayer(queue, group->players.begin()->first, decreaseInvitedCount); } } @@ -721,7 +720,7 @@ bool BattleGroundQueueItem::CheckPremadeMatch(BattleGroundBracketId bracketId, u @param min players @param max players */ -bool BattleGroundQueueItem::CheckNormalMatch(BattleGround* bgTemplate, BattleGroundBracketId bracketId, uint32 minPlayers, uint32 maxPlayers) +bool BattleGroundQueueItem::CheckNormalMatch(BattleGroundQueue& queue, BattleGround* bgTemplate, BattleGroundBracketId bracketId, uint32 minPlayers, uint32 maxPlayers) { GroupsQueueType::const_iterator itr_team[PVP_TEAM_COUNT]; for (uint8 i = 0; i < PVP_TEAM_COUNT; ++i) @@ -760,7 +759,7 @@ bool BattleGroundQueueItem::CheckNormalMatch(BattleGround* bgTemplate, BattleGro } // allow 1v0 if debug bg - if (sBattleGroundMgr.IsTesting() && bgTemplate->IsBattleGround() && (m_selectionPools[TEAM_INDEX_ALLIANCE].GetPlayerCount() || m_selectionPools[TEAM_INDEX_HORDE].GetPlayerCount())) + if (queue.IsTesting() && bgTemplate->IsBattleGround() && (m_selectionPools[TEAM_INDEX_ALLIANCE].GetPlayerCount() || m_selectionPools[TEAM_INDEX_HORDE].GetPlayerCount())) return true; // return true if there are enough players in selection pools - enable to work .debug bg command correctly @@ -915,12 +914,12 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId uint32 minPlayersPerTeam = bgTemplate->GetMinPlayersPerTeam(); uint32 maxPlayersPerTeam = bgTemplate->GetMaxPlayersPerTeam(); - if (sBattleGroundMgr.IsTesting()) + if (queue.IsTesting()) minPlayersPerTeam = 1; if (bgTemplate->IsArena()) { - if (sBattleGroundMgr.IsArenaTesting()) + if (queue.IsArenaTesting()) { maxPlayersPerTeam = 1; minPlayersPerTeam = 1; @@ -957,7 +956,6 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId if (CheckPremadeMatch(bracketId, minPlayersPerTeam, maxPlayersPerTeam)) { // create new battleground - BattleGroundInQueueInfo queueInfo; // TODO: Fill data BattleGround* bg2 = sBattleGroundMgr.CreateNewBattleGround(bgTypeId, bracketId, ARENA_TYPE_NONE, false); if (!bg2) { @@ -965,10 +963,15 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId return; } + BattleGroundInQueueInfo bgInfo; + bgInfo.Fill(bg2); + + queue.AddBgToFreeSlots(bgInfo); + // invite those selection pools for (uint8 i = 0; i < PVP_TEAM_COUNT; ++i) for (GroupsQueueType::const_iterator citr = m_selectionPools[TEAM_INDEX_ALLIANCE + i].selectedGroups.begin(); citr != m_selectionPools[TEAM_INDEX_ALLIANCE + i].selectedGroups.end(); ++citr) - InviteGroupToBg((*citr), queueInfo, (*citr)->groupTeam); + InviteGroupToBg((*citr), bgInfo, (*citr)->groupTeam); // clear structures m_selectionPools[TEAM_INDEX_ALLIANCE].Init(); @@ -986,11 +989,10 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId if (!isRated) { // if there are enough players in pools, start new battleground or non rated arena - if (CheckNormalMatch(bgTemplate, bracketId, minPlayersPerTeam, maxPlayersPerTeam) + if (CheckNormalMatch(queue, bgTemplate, bracketId, minPlayersPerTeam, maxPlayersPerTeam) || (bgTemplate->IsArena() && CheckSkirmishForSameFaction(bracketId, minPlayersPerTeam))) { // we successfully created a pool - BattleGroundInQueueInfo queueInfo; // TODO: Fill data BattleGround* bg2 = sBattleGroundMgr.CreateNewBattleGround(bgTypeId, bracketId, arenaType, false); if (!bg2) { @@ -998,10 +1000,18 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId return; } + BattleGroundInQueueInfo bgInfo; + bgInfo.Fill(bg2); + + queue.AddBgToFreeSlots(bgInfo); + // invite those selection pools for (uint8 i = 0; i < PVP_TEAM_COUNT; ++i) for (GroupsQueueType::const_iterator citr = m_selectionPools[TEAM_INDEX_ALLIANCE + i].selectedGroups.begin(); citr != m_selectionPools[TEAM_INDEX_ALLIANCE + i].selectedGroups.end(); ++citr) - InviteGroupToBg((*citr), queueInfo, (*citr)->groupTeam); + InviteGroupToBg((*citr), bgInfo, (*citr)->groupTeam); + + bg2->SetInvitedCount(ALLIANCE, bgInfo.GetInvitedCount(ALLIANCE)); + bg2->SetInvitedCount(HORDE, bgInfo.GetInvitedCount(HORDE)); sWorld.GetMessager().AddMessage([bg2](World* world) { @@ -1113,7 +1123,6 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId // if we have 2 teams, then start new arena and invite players! if (m_selectionPools[TEAM_INDEX_ALLIANCE].GetPlayerCount() && m_selectionPools[TEAM_INDEX_HORDE].GetPlayerCount()) { - BattleGroundInQueueInfo queueInfo; // TODO: Fill data BattleGround* arena = sBattleGroundMgr.CreateNewBattleGround(bgTypeId, bracketId, arenaType, true); if (!arena) { @@ -1121,6 +1130,11 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId return; } + BattleGroundInQueueInfo bgInfo; + bgInfo.Fill(arena); + + queue.AddBgToFreeSlots(bgInfo); + GroupQueueInfo* firstGroup = *(itr_team[TEAM_INDEX_ALLIANCE]); GroupQueueInfo* secondGroup = *(itr_team[TEAM_INDEX_HORDE]); @@ -1146,11 +1160,11 @@ void BattleGroundQueueItem::Update(BattleGroundQueue& queue, BattleGroundTypeId itr_team[TEAM_INDEX_HORDE] = m_queuedGroups[bracketId][BG_QUEUE_PREMADE_HORDE].begin(); } - InviteGroupToBg(firstGroup, queueInfo, ALLIANCE); - InviteGroupToBg(secondGroup, queueInfo, HORDE); + InviteGroupToBg(firstGroup, bgInfo, ALLIANCE); + InviteGroupToBg(secondGroup, bgInfo, HORDE); // set ArenaTeamId for rated matches - if (queueInfo.IsArena() && queueInfo.IsRated()) + if (bgInfo.IsArena() && bgInfo.IsRated()) { arena->SetArenaTeamIdForTeam(firstGroup->groupTeam, firstGroup->arenaTeamId); arena->SetArenaTeamIdForTeam(secondGroup->groupTeam, secondGroup->arenaTeamId); @@ -1255,11 +1269,13 @@ bool BgQueueRemoveEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) uint32 bgInstanceId = bg ? bg->GetClientInstanceId() : 0; bool isRated = bg ? bg->IsRated() : false; uint32 mapId = bg ? bg->GetMapId() : 0; + BattleGroundStatus bgStatus = bg ? bg->GetStatus() : STATUS_NONE; + BattleGroundBracketId bracketId = bg ? bg->GetBracketId() : BG_BRACKET_ID_TEMPLATE; uint32 queueSlot = plr->GetBattleGroundQueueIndex(event.m_bgQueueTypeId); if (queueSlot < PLAYER_MAX_BATTLEGROUND_QUEUES) // player is in queue, or in Battleground { - sWorld.GetBGQueue().GetMessager().AddMessage([bgQueueTypeId = event.m_bgQueueTypeId, bgTypeId, bracketId = bg->GetBracketId(), playerGuid = event.m_playerGuid, instanceGuid = event.m_bgInstanceGuid, removeTime = event.m_removeTime, isBattleGround, queueSlot, bgStatus = bg->GetStatus(), bgExists, bgInstanceId, isRated, mapId](BattleGroundQueue* queue) + sWorld.GetBGQueue().GetMessager().AddMessage([bgQueueTypeId = event.m_bgQueueTypeId, bgTypeId, bgStatus, playerGuid = event.m_playerGuid, instanceGuid = event.m_bgInstanceGuid, removeTime = event.m_removeTime, isBattleGround, queueSlot, bracketId, bgExists, bgInstanceId, isRated, mapId](BattleGroundQueue* queue) { // check if player is in queue for this BG and if we are removing his invite event BattleGroundQueueItem& bgQueue = queue->m_battleGroundQueues[bgQueueTypeId]; @@ -1267,7 +1283,7 @@ bool BgQueueRemoveEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/) { DEBUG_LOG("Battleground: removing player %u from bg queue for instance %u because of not pressing enter battle in time.", playerGuid.GetCounter(), instanceGuid); - bgQueue.RemovePlayer(playerGuid, true); + bgQueue.RemovePlayer(*queue, playerGuid, true); // update queues if battleground isn't ended if (isBattleGround && bgStatus != STATUS_WAIT_LEAVE) @@ -1298,7 +1314,7 @@ void BgQueueRemoveEvent::Abort(uint64 /*e_time*/) // do nothing } -BattleGroundQueue::BattleGroundQueue() +BattleGroundQueue::BattleGroundQueue() : m_testing(false), m_arenaTesting(false) { } @@ -1497,5 +1513,44 @@ void BattleGroundQueue::SetNextRatingDiscardUpdate(std::chrono::milliseconds& ti void BattleGroundQueue::RemovePlayer(BattleGroundQueueTypeId bgQueueTypeId, ObjectGuid player, bool decreaseInvitedCount) { - m_battleGroundQueues[bgQueueTypeId].RemovePlayer(player, decreaseInvitedCount); + m_battleGroundQueues[bgQueueTypeId].RemovePlayer(*this, player, decreaseInvitedCount); +} + +void BattleGroundInQueueInfo::DecreaseInvitedCount(Team team) +{ + uint32 count = (team == ALLIANCE) ? --m_invitedAlliance : --m_invitedHorde; + sWorld.GetMessager().AddMessage([bgTypeId = GetTypeId(), instanceId = GetInstanceId(), team, count](World* world) + { + if (BattleGround* bg = sBattleGroundMgr.GetBattleGround(instanceId, bgTypeId)) + bg->SetInvitedCount(team, count); + }); +} + +void BattleGroundInQueueInfo::IncreaseInvitedCount(Team team) +{ + uint32 count = (team == ALLIANCE) ? ++m_invitedAlliance : ++m_invitedHorde; + sWorld.GetMessager().AddMessage([bgTypeId = GetTypeId(), instanceId = GetInstanceId(), team, count](World* world) + { + if (BattleGround* bg = sBattleGroundMgr.GetBattleGround(instanceId, bgTypeId)) + bg->SetInvitedCount(team, count); + }); +} + +void BattleGroundInQueueInfo::Fill(BattleGround* bg) +{ + bgTypeId = bg->GetTypeId(); + instanceId = bg->GetInstanceId(); + isBattleGround = bg->IsBattleGround(); + bracketId = bg->GetBracketId(); + status = bg->GetStatus(); + m_clientInstanceId = bg->GetClientInstanceId(); + mapId = bg->GetMapId(); + arenaType = bg->GetArenaType(); + isRated = bg->IsRated(); + playersInside = bg->GetPlayersSize(); + maxPlayers = bg->GetTypeId(); + m_invitedAlliance = bg->GetInvitedCount(ALLIANCE); + m_invitedHorde = bg->GetInvitedCount(HORDE); + m_maxPlayersPerTeam = bg->GetMaxPlayersPerTeam(); + m_minPlayersPerTeam = bg->GetMinPlayersPerTeam(); } diff --git a/src/game/BattleGround/BattleGroundQueue.h b/src/game/BattleGround/BattleGroundQueue.h index 6908264d72..df7512878b 100644 --- a/src/game/BattleGround/BattleGroundQueue.h +++ b/src/game/BattleGround/BattleGroundQueue.h @@ -64,7 +64,7 @@ struct BattleGroundInQueueInfo uint32 instanceId; bool isBattleGround; BattleGroundBracketId bracketId; - BattleGroundStatus status; + BattleGroundStatus status; // only altered in bg and synched here uint32 m_clientInstanceId; uint32 mapId; @@ -73,8 +73,6 @@ struct BattleGroundInQueueInfo uint32 playersInside; uint32 maxPlayers; - uint32 m_invitedAlliance; - uint32 m_invitedHorde; uint32 m_maxPlayersPerTeam; uint32 m_minPlayersPerTeam; @@ -96,8 +94,8 @@ struct BattleGroundInQueueInfo uint32 GetMaxPlayersPerTeam() const { return m_maxPlayersPerTeam; } uint32 GetMinPlayersPerTeam() const { return m_minPlayersPerTeam; } - void DecreaseInvitedCount(Team team) { (team == ALLIANCE) ? --m_invitedAlliance : --m_invitedHorde; } - void IncreaseInvitedCount(Team team) { (team == ALLIANCE) ? ++m_invitedAlliance : ++m_invitedHorde; } + void DecreaseInvitedCount(Team team); + void IncreaseInvitedCount(Team team); uint32 GetInvitedCount(Team team) const { if (team == ALLIANCE) @@ -113,6 +111,12 @@ struct BattleGroundInQueueInfo return 0; } + + void Fill(BattleGround* bg); + + private: + uint32 m_invitedAlliance; + uint32 m_invitedHorde; }; // this container can't be deque, because deque doesn't like removing the last element - if you remove it, it invalidates next iterator and crash appears @@ -130,10 +134,10 @@ class BattleGroundQueueItem void FillPlayersToBg(BattleGroundInQueueInfo& queueInfo, BattleGroundBracketId /*bracketId*/); bool CheckPremadeMatch(BattleGroundBracketId /*bracketId*/, uint32 /*minPlayersPerTeam*/, uint32 /*maxPlayersPerTeam*/); - bool CheckNormalMatch(BattleGround* /*bgTemplate*/, BattleGroundBracketId /*bracketId*/, uint32 /*minPlayers*/, uint32 /*maxPlayers*/); + bool CheckNormalMatch(BattleGroundQueue& queue, BattleGround* /*bgTemplate*/, BattleGroundBracketId /*bracketId*/, uint32 /*minPlayers*/, uint32 /*maxPlayers*/); bool CheckSkirmishForSameFaction(BattleGroundBracketId /*bracketId*/, uint32 /*minPlayersPerTeam*/); GroupQueueInfo* AddGroup(ObjectGuid leader, AddGroupToQueueInfo const& /*groupInfo*/, BattleGroundTypeId /*bgTypeId*/, BattleGroundBracketId /*bracketEntry*/, ArenaType /*arenaType*/, bool /*isRated*/, bool /*isPremade*/, uint32 /*instanceId*/, uint32 /*arenaRating*/, uint32 arenaTeamId = 0); - void RemovePlayer(ObjectGuid guid, bool decreaseInvitedCount); + void RemovePlayer(BattleGroundQueue& queue, ObjectGuid guid, bool decreaseInvitedCount); bool IsPlayerInvited(ObjectGuid /*playerGuid*/, const uint32 /*bgInstanceGuid*/, const uint32 /*removeTime*/); bool GetPlayerGroupInfoData(ObjectGuid /*guid*/, GroupQueueInfo* /*groupInfo*/); void PlayerInvitedToBgUpdateAverageWaitTime(GroupQueueInfo* /*groupInfo*/, BattleGroundBracketId /*bracketId*/); @@ -255,6 +259,11 @@ class BattleGroundQueue BattleGroundQueueItem& GetBattleGroundQueue(BattleGroundQueueTypeId bgQueueTypeId); void SetNextRatingDiscardUpdate(std::chrono::milliseconds& timePoint); + + bool IsTesting() const { return m_testing; } + void SetTesting(bool state) { m_testing = state; } + bool IsArenaTesting() const { return m_arenaTesting; } + void SetArenaTesting(bool state) { m_arenaTesting = state; } private: BattleGroundQueueItem m_battleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; @@ -266,6 +275,9 @@ class BattleGroundQueue TimePoint m_autoDistributionTimeChecker; Messager m_messager; + + bool m_testing; + bool m_arenaTesting; }; #endif \ No newline at end of file