From 7307438a7f681ade95ecb7fd6d1002a37a54e63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Thu, 18 Jun 2020 00:13:14 +0200 Subject: [PATCH] fix(Core/BG): fix BG_QUEUE_INVITATION_TYPE_NO_BALANCE (#3134) --- .../game/Battlegrounds/Battleground.cpp | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index faeca1d74..4b1a1bdbd 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -1310,8 +1310,11 @@ void Battleground::AddOrSetPlayerToCorrectBgGroup(Player* player, TeamId teamId) uint32 Battleground::GetFreeSlotsForTeam(TeamId teamId) const { - // if BG is starting and CONFIG_BATTLEGROUND_INVITATION_TYPE == BG_QUEUE_INVITATION_TYPE_NO_BALANCE, invite anyone - if (GetStatus() == STATUS_WAIT_JOIN && sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) == BG_QUEUE_INVITATION_TYPE_NO_BALANCE) + if (!(GetStatus() == STATUS_IN_PROGRESS || GetStatus() == STATUS_WAIT_JOIN)) + return 0; + + // if CONFIG_BATTLEGROUND_INVITATION_TYPE == BG_QUEUE_INVITATION_TYPE_NO_BALANCE, invite everyone unless the BG is full + if (sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE) == BG_QUEUE_INVITATION_TYPE_NO_BALANCE) return (GetInvitedCount(teamId) < GetMaxPlayersPerTeam()) ? GetMaxPlayersPerTeam() - GetInvitedCount(teamId) : 0; // if BG is already started or CONFIG_BATTLEGROUND_INVITATION_TYPE != BG_QUEUE_INVITATION_TYPE_NO_BALANCE, do not allow to join too many players of one faction @@ -1320,41 +1323,36 @@ uint32 Battleground::GetFreeSlotsForTeam(TeamId teamId) const uint32 otherTeamInvitedCount = teamId == TEAM_ALLIANCE ? GetInvitedCount(TEAM_HORDE) : GetInvitedCount(TEAM_ALLIANCE); uint32 otherTeamPlayersCount = teamId == TEAM_ALLIANCE ? GetPlayersCountByTeam(TEAM_HORDE) : GetPlayersCountByTeam(TEAM_ALLIANCE); - if (GetStatus() == STATUS_IN_PROGRESS || GetStatus() == STATUS_WAIT_JOIN) - { - // difference based on ppl invited (not necessarily entered battle) - // default: allow 0 - uint32 diff = 0; - uint32 maxPlayersPerTeam = GetMaxPlayersPerTeam(); - uint32 minPlayersPerTeam = GetMinPlayersPerTeam(); + // difference based on ppl invited (not necessarily entered battle) + // default: allow 0 + uint32 diff = 0; + uint32 maxPlayersPerTeam = GetMaxPlayersPerTeam(); + uint32 minPlayersPerTeam = GetMinPlayersPerTeam(); - // allow join one person if the sides are equal (to fill up bg to minPlayerPerTeam) - if (otherTeamInvitedCount == thisTeamInvitedCount) - diff = 1; - else if (otherTeamInvitedCount > thisTeamInvitedCount) // allow join more ppl if the other side has more players - diff = otherTeamInvitedCount - thisTeamInvitedCount; + // allow join one person if the sides are equal (to fill up bg to minPlayerPerTeam) + if (otherTeamInvitedCount == thisTeamInvitedCount) + diff = 1; + else if (otherTeamInvitedCount > thisTeamInvitedCount) // allow join more ppl if the other side has more players + diff = otherTeamInvitedCount - thisTeamInvitedCount; - // difference based on max players per team (don't allow inviting more) - uint32 diff2 = (thisTeamInvitedCount < maxPlayersPerTeam) ? maxPlayersPerTeam - thisTeamInvitedCount : 0; + // difference based on max players per team (don't allow inviting more) + uint32 diff2 = (thisTeamInvitedCount < maxPlayersPerTeam) ? maxPlayersPerTeam - thisTeamInvitedCount : 0; - // difference based on players who already entered - // default: allow 0 - uint32 diff3 = 0; + // difference based on players who already entered + // default: allow 0 + uint32 diff3 = 0; - // allow join one person if the sides are equal (to fill up bg minPlayerPerTeam) - if (otherTeamPlayersCount == thisTeamPlayersCount) - diff3 = 1; - else if (otherTeamPlayersCount > thisTeamPlayersCount) // allow join more ppl if the other side has more players - diff3 = otherTeamPlayersCount - thisTeamPlayersCount; - else if (thisTeamInvitedCount <= minPlayersPerTeam) // or other side has less than minPlayersPerTeam - diff3 = minPlayersPerTeam - thisTeamInvitedCount + 1; + // allow join one person if the sides are equal (to fill up bg minPlayerPerTeam) + if (otherTeamPlayersCount == thisTeamPlayersCount) + diff3 = 1; + else if (otherTeamPlayersCount > thisTeamPlayersCount) // allow join more ppl if the other side has more players + diff3 = otherTeamPlayersCount - thisTeamPlayersCount; + else if (thisTeamInvitedCount <= minPlayersPerTeam) // or other side has less than minPlayersPerTeam + diff3 = minPlayersPerTeam - thisTeamInvitedCount + 1; - // return the minimum of the 3 differences - // min of diff, diff2 and diff3 - return std::min({ diff, diff2, diff3 }); - } - - return 0; + // return the minimum of the 3 differences + // min of diff, diff2 and diff3 + return std::min({ diff, diff2, diff3 }); } uint32 Battleground::GetMaxFreeSlots() const