Core/Battleground: New CrossFaction Battleground queue system with enabled premades and pre-balancing system

This commit is contained in:
mik1893
2016-08-14 13:31:19 +01:00
parent aaa5f2ec67
commit 5de7bae617
5 changed files with 101 additions and 16 deletions
+20
View File
@@ -178,6 +178,12 @@ Battleground::Battleground()
m_BgInvitedPlayers[TEAM_ALLIANCE]= 0;
m_BgInvitedPlayers[TEAM_HORDE] = 0;
// [AZTH] crossfaction system
m_premadeAssigned[TEAM_ALLIANCE] = 0;
m_premadeAssigned[TEAM_HORDE] = 0;
m_hasPlayerJoinedPremade.clear();
// [/AZTH]
m_TeamScores[TEAM_ALLIANCE] = 0;
m_TeamScores[TEAM_HORDE] = 0;
@@ -1201,6 +1207,11 @@ void Battleground::AddPlayer(Player* player)
UpdatePlayersCountByTeam(teamId, false); // +1 player
//[AZTH] the player has joined premade - he went into the player count of BG, need to remove it from the pre-count
if (HasPlayerJoinPremade(guid))
DecreasePremadeCount(teamId);
//[/AZTH]
WorldPacket data;
sBattlegroundMgr->BuildPlayerJoinedBattlegroundPacket(&data, player);
SendPacketToTeam(teamId, &data, player, false);
@@ -1997,4 +2008,13 @@ void Battleground::RewardXPAtKill(Player* killer, Player* victim)
uint8 Battleground::GetUniqueBracketId() const
{
return GetMinLevel() / 10;
}
bool Battleground::HasPlayerJoinPremade(uint64 guid)
{
for (UNORDERED_MAP<uint64, bool>::iterator itr = m_hasPlayerJoinedPremade.begin(); itr != m_hasPlayerJoinedPremade.end(); itr++)
if (itr->first == guid)
return itr->second;
return false;
}
+13
View File
@@ -415,6 +415,14 @@ class Battleground
void IncreaseInvitedCount(TeamId teamId) { ++m_BgInvitedPlayers[teamId]; }
uint32 GetInvitedCount(TeamId teamId) const { return m_BgInvitedPlayers[teamId]; }
//[AZTH] CrossFaction Battleground
void SetPlayerJoinPremade(uint64 guid, bool premade) { m_hasPlayerJoinedPremade[guid] = premade; }
bool HasPlayerJoinPremade(uint64 guid);
void DecreasePremadeCount(TeamId teamId) { if(m_premadeAssigned[teamId] > 0) --m_premadeAssigned[teamId]; }
void IncreasePremadeCount(TeamId teamId) { ++m_premadeAssigned[teamId]; }
uint32 GetPremadeCount(TeamId teamId) { return m_premadeAssigned[teamId]; }
//[/AZTH]
bool HasFreeSlots() const;
uint32 GetFreeSlotsForTeam(TeamId teamId) const;
uint32 GetMaxFreeSlots() const;
@@ -733,6 +741,11 @@ class Battleground
// Invited players counters
uint32 m_BgInvitedPlayers[BG_TEAMS_COUNT];
// [AZTH] Crossfaction Battleground
UNORDERED_MAP<uint64, bool> m_hasPlayerJoinedPremade;
uint32 m_premadeAssigned[BG_TEAMS_COUNT];
// [AZTH]
// Raid Group
Group* m_BgRaids[BG_TEAMS_COUNT]; // 0 - alliance, 1 - horde
@@ -1049,6 +1049,8 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T
{
ASSERT(!ginfo->IsInvitedToBGInstanceGUID);
bool increaseCountPremade = false; //[AZTH] needed later
// set side if needed
if (teamId != TEAM_NEUTRAL)
ginfo->teamId = teamId;
@@ -1065,6 +1067,39 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T
ginfo->RemoveInviteTime = World::GetGameTimeMS() + INVITE_ACCEPT_WAIT_TIME;
//[AZTH] Preassign people to factions based on invite count as we ignore it completely during queuing
if (!bg->isArena() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_RANDOM_CROSSFACTION) && bgQueueTypeId == BATTLEGROUND_QUEUE_RB)
{
// if it's a premade group, set the player as joined premade.
// also decide now where the premade group will go. The rest of the player will be switched later
if (ginfo->Players.size() > 1)
increaseCountPremade = true;
if (increaseCountPremade)
{
uint32 allyPremadeCount = bg->GetPremadeCount(TEAM_ALLIANCE);
uint32 hordePremadeCount = bg->GetPremadeCount(TEAM_HORDE);
TeamId nextTeam = ginfo->teamId;
if (hordePremadeCount < allyPremadeCount) // if there is already a premade in ally go horde
nextTeam = TEAM_HORDE;
else if (hordePremadeCount > allyPremadeCount) // else if premade horde go ally
nextTeam = TEAM_ALLIANCE;
else
{
if(roll_chance_i(50)) // else randomize where the group goes (50-50)
nextTeam = ginfo->teamId == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE;
}
ginfo->teamId = nextTeam;
sLog->outError("A new team of size %u joined premade random battleground", uint32(ginfo->Players.size()));
}
}
// [/AZTH]
// loop through the players
for (std::set<uint64>::iterator itr = ginfo->Players.begin(); itr != ginfo->Players.end(); ++itr)
{
@@ -1077,6 +1112,14 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T
// update average wait time
bgQueue.PlayerInvitedToBGUpdateAverageWaitTime(ginfo);
// [AZTH] Set player has joined premade if more than 1 player
if (increaseCountPremade)
{
bg->SetPlayerJoinPremade(*itr, true);
bg->IncreasePremadeCount(ginfo->teamId);
}
// [/AZTH]
// increase invited counter for each invited player
bg->IncreaseInvitedCount(ginfo->teamId);
@@ -314,8 +314,16 @@ void BattlegroundQueue::RemovePlayer(uint64 guid, bool sentToBg, uint32 playerQu
// sending player to bg will increase it again
if (groupInfo->IsInvitedToBGInstanceGUID)
if (Battleground* bg = sBattlegroundMgr->GetBattleground(groupInfo->IsInvitedToBGInstanceGUID))
{
bg->DecreaseInvitedCount(groupInfo->teamId);
//[AZTH] Crossfaction BG - need to decrease premade count if the person is in a premade
if (bg->HasPlayerJoinPremade(guid))
bg->DecreasePremadeCount(groupInfo->teamId);
//[/AZTH]
}
// remove player queue info
m_QueuedPlayers.erase(itr);
+17 -16
View File
@@ -436,24 +436,25 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData)
TeamId teamId = ginfo.teamId;
// [AZTH] Random Battleground Randomizer - by Yehonal & Mik1893
if (bgQueueTypeId == BATTLEGROUND_QUEUE_RB && bg->isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_RANDOM_CROSSFACTION))
{
uint32 allyCount = bg->GetPlayersCountByTeam(TEAM_ALLIANCE);
uint32 hordeCount = bg->GetPlayersCountByTeam(TEAM_HORDE);
if (allyCount == hordeCount)
if(!bg->HasPlayerJoinPremade(_player->GetGUID())) // Premade players have already defined team and cf settings
if (bgQueueTypeId == BATTLEGROUND_QUEUE_RB && bg->isBattleground() && sWorld->getBoolConfig(CONFIG_BATTLEGROUND_RANDOM_CROSSFACTION))
{
if (roll_chance_i(50))
teamId = _player->GetTeamId(true) == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE;
}
else if (allyCount < hordeCount)
teamId = TEAM_ALLIANCE;
else
teamId = TEAM_HORDE;
uint32 allyCount = bg->GetPlayersCountByTeam(TEAM_ALLIANCE) + bg->GetPremadeCount(TEAM_ALLIANCE);
uint32 hordeCount = bg->GetPlayersCountByTeam(TEAM_HORDE) + bg->GetPremadeCount(TEAM_HORDE);
_player->setTeamId(teamId);
_player->setFaction(teamId == TEAM_ALLIANCE ? 1 : 2);
}
if (allyCount == hordeCount)
{
if (roll_chance_i(50))
teamId = _player->GetTeamId(true) == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE;
}
else if (allyCount < hordeCount)
teamId = TEAM_ALLIANCE;
else
teamId = TEAM_HORDE;
}
_player->setTeamId(teamId);
_player->setFaction(teamId == TEAM_ALLIANCE ? 1 : 2);
// [/AZTH]
// remove player from all bg queues