mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-01 09:53:47 +00:00
Fix over-queuing in BG's (#887)
* Fix overqueue * Update RandomPlayerbotMgr.cpp * Restore if self-bot * Update RandomPlayerbotMgr.cpp
This commit is contained in:
@@ -171,7 +171,8 @@ RandomPlayerbotMgr::RandomPlayerbotMgr() : PlayerbotHolder(), processTicks(0)
|
|||||||
PrepareTeleportCache();
|
PrepareTeleportCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
BattlegroundData.clear();
|
BattlegroundData.clear(); // Clear here and here only.
|
||||||
|
|
||||||
for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
|
for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
|
||||||
{
|
{
|
||||||
for (int queueType = BATTLEGROUND_QUEUE_AV; queueType < MAX_BATTLEGROUND_QUEUE_TYPES; ++queueType)
|
for (int queueType = BATTLEGROUND_QUEUE_AV; queueType < MAX_BATTLEGROUND_QUEUE_TYPES; ++queueType)
|
||||||
@@ -360,7 +361,7 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/)
|
|||||||
|
|
||||||
if (sPlayerbotAIConfig->randomBotJoinBG /* && !players.empty()*/)
|
if (sPlayerbotAIConfig->randomBotJoinBG /* && !players.empty()*/)
|
||||||
{
|
{
|
||||||
if (time(nullptr) > (BgCheckTimer + 45))
|
if (time(nullptr) > (BgCheckTimer + 35))
|
||||||
sRandomPlayerbotMgr->CheckBgQueue();
|
sRandomPlayerbotMgr->CheckBgQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -652,9 +653,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
|
|
||||||
LOG_DEBUG("playerbots", "Checking BG Queue...");
|
LOG_DEBUG("playerbots", "Checking BG Queue...");
|
||||||
|
|
||||||
BattlegroundData.clear();
|
// Initialize Battleground Data (do not clear here)
|
||||||
|
|
||||||
// Initialize Battleground Data
|
|
||||||
for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
|
for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
|
||||||
{
|
{
|
||||||
for (int queueType = BATTLEGROUND_QUEUE_AV; queueType < MAX_BATTLEGROUND_QUEUE_TYPES; ++queueType)
|
for (int queueType = BATTLEGROUND_QUEUE_AV; queueType < MAX_BATTLEGROUND_QUEUE_TYPES; ++queueType)
|
||||||
@@ -663,9 +662,11 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process players
|
// Process real players and populate Battleground Data with player/queue count
|
||||||
|
// Opens a queue for bots to join
|
||||||
for (Player* player : players)
|
for (Player* player : players)
|
||||||
{
|
{
|
||||||
|
// Skip player if not currently in a queue
|
||||||
if (!player->InBattlegroundQueue())
|
if (!player->InBattlegroundQueue())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -681,17 +682,19 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
if (queueTypeId == BATTLEGROUND_QUEUE_NONE)
|
if (queueTypeId == BATTLEGROUND_QUEUE_NONE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Check if real player is able to create/join this queue
|
||||||
BattlegroundTypeId bgTypeId = sBattlegroundMgr->BGTemplateId(queueTypeId);
|
BattlegroundTypeId bgTypeId = sBattlegroundMgr->BGTemplateId(queueTypeId);
|
||||||
bg = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId);
|
uint32 mapId = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId)->GetMapId();
|
||||||
uint32 mapId = bg->GetMapId();
|
|
||||||
PvPDifficultyEntry const* pvpDiff = GetBattlegroundBracketByLevel(mapId, player->GetLevel());
|
PvPDifficultyEntry const* pvpDiff = GetBattlegroundBracketByLevel(mapId, player->GetLevel());
|
||||||
if (!pvpDiff)
|
if (!pvpDiff)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// If player is allowed, populate the BattlegroundData with the appropriate level requirements
|
||||||
BattlegroundBracketId bracketId = pvpDiff->GetBracketId();
|
BattlegroundBracketId bracketId = pvpDiff->GetBracketId();
|
||||||
BattlegroundData[queueTypeId][bracketId].minLevel = pvpDiff->minLevel;
|
BattlegroundData[queueTypeId][bracketId].minLevel = pvpDiff->minLevel;
|
||||||
BattlegroundData[queueTypeId][bracketId].maxLevel = pvpDiff->maxLevel;
|
BattlegroundData[queueTypeId][bracketId].maxLevel = pvpDiff->maxLevel;
|
||||||
|
|
||||||
|
// Arena logic
|
||||||
bool isRated = false;
|
bool isRated = false;
|
||||||
if (uint8 arenaType = BattlegroundMgr::BGArenaType(queueTypeId))
|
if (uint8 arenaType = BattlegroundMgr::BGArenaType(queueTypeId))
|
||||||
{
|
{
|
||||||
@@ -711,21 +714,25 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
else
|
else
|
||||||
BattlegroundData[queueTypeId][bracketId].skirmishArenaPlayerCount++;
|
BattlegroundData[queueTypeId][bracketId].skirmishArenaPlayerCount++;
|
||||||
}
|
}
|
||||||
|
// BG Logic
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (GET_PLAYERBOT_AI(player))
|
if (teamId == TEAM_ALLIANCE)
|
||||||
{
|
BattlegroundData[queueTypeId][bracketId].bgAlliancePlayerCount++;
|
||||||
if (teamId == TEAM_ALLIANCE)
|
|
||||||
BattlegroundData[queueTypeId][bracketId].bgAllianceBotCount++;
|
|
||||||
else
|
|
||||||
BattlegroundData[queueTypeId][bracketId].bgHordeBotCount++;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
|
BattlegroundData[queueTypeId][bracketId].bgHordePlayerCount++;
|
||||||
|
|
||||||
|
// If a player has joined the BG, update the instance count in BattlegroundData (for consistency)
|
||||||
|
if (player->InBattleground())
|
||||||
{
|
{
|
||||||
if (teamId == TEAM_ALLIANCE)
|
std::vector<uint32>* instanceIds = nullptr;
|
||||||
BattlegroundData[queueTypeId][bracketId].bgAlliancePlayerCount++;
|
uint32 instanceId = player->GetBattleground()->GetInstanceID();
|
||||||
else
|
|
||||||
BattlegroundData[queueTypeId][bracketId].bgHordePlayerCount++;
|
instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances;
|
||||||
|
if (instanceIds && std::find(instanceIds->begin(), instanceIds->end(), instanceId) == instanceIds->end())
|
||||||
|
instanceIds->push_back(instanceId);
|
||||||
|
|
||||||
|
BattlegroundData[queueTypeId][bracketId].bgInstanceCount = instanceIds->size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,7 +756,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
// Process player bots
|
// Process player bots
|
||||||
for (auto& [guid, bot] : playerBots)
|
for (auto& [guid, bot] : playerBots)
|
||||||
{
|
{
|
||||||
if (!bot || !bot->IsInWorld() || !bot->InBattlegroundQueue() || !IsRandomBot(bot))
|
if (!bot || !bot->InBattlegroundQueue() || !bot->IsInWorld() || !IsRandomBot(bot))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Battleground* bg = bot->GetBattleground();
|
Battleground* bg = bot->GetBattleground();
|
||||||
@@ -765,8 +772,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
BattlegroundTypeId bgTypeId = sBattlegroundMgr->BGTemplateId(queueTypeId);
|
BattlegroundTypeId bgTypeId = sBattlegroundMgr->BGTemplateId(queueTypeId);
|
||||||
bg = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId);
|
uint32 mapId = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId)->GetMapId();
|
||||||
uint32 mapId = bg->GetMapId();
|
|
||||||
PvPDifficultyEntry const* pvpDiff = GetBattlegroundBracketByLevel(mapId, bot->GetLevel());
|
PvPDifficultyEntry const* pvpDiff = GetBattlegroundBracketByLevel(mapId, bot->GetLevel());
|
||||||
if (!pvpDiff)
|
if (!pvpDiff)
|
||||||
continue;
|
continue;
|
||||||
@@ -781,12 +787,12 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(queueTypeId);
|
BattlegroundQueue& bgQueue = sBattlegroundMgr->GetBattlegroundQueue(queueTypeId);
|
||||||
GroupQueueInfo ginfo;
|
GroupQueueInfo ginfo;
|
||||||
|
|
||||||
if (bgQueue.GetPlayerGroupInfoData(bot->GetGUID(), &ginfo))
|
if (bgQueue.GetPlayerGroupInfoData(guid, &ginfo))
|
||||||
{
|
{
|
||||||
isRated = ginfo.IsRated;
|
isRated = ginfo.IsRated;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bgQueue.IsPlayerInvitedToRatedArena(bot->GetGUID()) || (bot->InArena() && bot->GetBattleground()->isRated()))
|
if (bgQueue.IsPlayerInvitedToRatedArena(guid) || (bot->InArena() && bot->GetBattleground()->isRated()))
|
||||||
isRated = true;
|
isRated = true;
|
||||||
|
|
||||||
if (isRated)
|
if (isRated)
|
||||||
@@ -809,6 +815,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
bool isArena = false;
|
bool isArena = false;
|
||||||
bool isRated = false;
|
bool isRated = false;
|
||||||
|
|
||||||
|
// Arena logic
|
||||||
if (bot->InArena())
|
if (bot->InArena())
|
||||||
{
|
{
|
||||||
isArena = true;
|
isArena = true;
|
||||||
@@ -822,6 +829,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
instanceIds = &BattlegroundData[queueTypeId][bracketId].skirmishArenaInstances;
|
instanceIds = &BattlegroundData[queueTypeId][bracketId].skirmishArenaInstances;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// BG Logic
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances;
|
instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances;
|
||||||
@@ -867,7 +875,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
|
|
||||||
auto updateRatedArenaInstanceCount = [&](uint32 queueType, uint32 bracket, uint32 minCount) {
|
auto updateRatedArenaInstanceCount = [&](uint32 queueType, uint32 bracket, uint32 minCount) {
|
||||||
if (BattlegroundData[queueType][bracket].activeRatedArenaQueue == 0 &&
|
if (BattlegroundData[queueType][bracket].activeRatedArenaQueue == 0 &&
|
||||||
BattlegroundData[queueType][bracket].ratedArenaInstanceCount < minCount)
|
BattlegroundData[queueType][bracket].ratedArenaInstances.size() < minCount)
|
||||||
BattlegroundData[queueType][bracket].activeRatedArenaQueue = 1;
|
BattlegroundData[queueType][bracket].activeRatedArenaQueue = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -875,7 +883,7 @@ void RandomPlayerbotMgr::CheckBgQueue()
|
|||||||
for (uint32 bracket : brackets)
|
for (uint32 bracket : brackets)
|
||||||
{
|
{
|
||||||
if (BattlegroundData[queueType][bracket].activeBgQueue == 0 &&
|
if (BattlegroundData[queueType][bracket].activeBgQueue == 0 &&
|
||||||
BattlegroundData[queueType][bracket].bgInstanceCount < minCount)
|
BattlegroundData[queueType][bracket].bgInstances.size() < minCount)
|
||||||
BattlegroundData[queueType][bracket].activeBgQueue = 1;
|
BattlegroundData[queueType][bracket].activeBgQueue = 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -962,11 +970,11 @@ void RandomPlayerbotMgr::LogBattlegroundInfo()
|
|||||||
if (bgInfo.minLevel == 0)
|
if (bgInfo.minLevel == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
LOG_INFO("playerbots", "BG:{} {}: Player ({}:{}) Bot ({}:{}) Total (A:{} H:{}), Instances {}", _bgType,
|
LOG_INFO("playerbots", "BG:{} {}: Player ({}:{}) Bot ({}:{}) Total (A:{} H:{}), Instances {}, Active Queue: {}", _bgType,
|
||||||
std::to_string(bgInfo.minLevel) + "-" + std::to_string(bgInfo.maxLevel),
|
std::to_string(bgInfo.minLevel) + "-" + std::to_string(bgInfo.maxLevel),
|
||||||
bgInfo.bgAlliancePlayerCount, bgInfo.bgHordePlayerCount, bgInfo.bgAllianceBotCount,
|
bgInfo.bgAlliancePlayerCount, bgInfo.bgHordePlayerCount, bgInfo.bgAllianceBotCount,
|
||||||
bgInfo.bgHordeBotCount, bgInfo.bgAlliancePlayerCount + bgInfo.bgAllianceBotCount,
|
bgInfo.bgHordeBotCount, bgInfo.bgAlliancePlayerCount + bgInfo.bgAllianceBotCount,
|
||||||
bgInfo.bgHordePlayerCount + bgInfo.bgHordeBotCount, bgInfo.bgInstanceCount);
|
bgInfo.bgHordePlayerCount + bgInfo.bgHordeBotCount, bgInfo.bgInstanceCount, bgInfo.activeBgQueue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG_DEBUG("playerbots", "BG Queue check finished");
|
LOG_DEBUG("playerbots", "BG Queue check finished");
|
||||||
|
|||||||
Reference in New Issue
Block a user