mirror of
https://gitcode.com/GitHub_Trending/az/azerothcore-wotlk.git
synced 2026-07-11 03:13:10 +00:00
[Core/Custom] Implement new Crossfaction Battleground mechanics
This commit is contained in:
@@ -7,7 +7,110 @@
|
||||
|
||||
#include "CrossFaction.h"
|
||||
|
||||
// Crossfaction class functionalities
|
||||
void CrossFaction::DoForgetPlayersInBG(Battleground* pBattleGround, Player* player)
|
||||
{
|
||||
for (Battleground::BattlegroundPlayerMap::const_iterator itr = pBattleGround->GetPlayers().begin(); itr != pBattleGround->GetPlayers().end(); ++itr)
|
||||
{
|
||||
// Here we invalidate players in the bg to the added player
|
||||
WorldPacket data1(SMSG_INVALIDATE_PLAYER, 8);
|
||||
data1 << itr->first;
|
||||
player->GetSession()->SendPacket(&data1);
|
||||
|
||||
if (Player* pPlayer = ObjectAccessor::FindPlayer(itr->first))
|
||||
{
|
||||
player->GetSession()->SendNameQueryOpcode(pPlayer->GetGUID()); // Send namequery answer instantly if player is available
|
||||
// Here we invalidate the player added to players in the bg
|
||||
WorldPacket data2(SMSG_INVALIDATE_PLAYER, 8);
|
||||
data2 << player->GetGUID();
|
||||
pPlayer->GetSession()->SendPacket(&data2);
|
||||
pPlayer->GetSession()->SendNameQueryOpcode(player->GetGUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Crossfaction - race update functionalities
|
||||
/// pre-save a fake race and morph for a player in case his faction is switched in BG.
|
||||
void CrossFaction::SetFakeRaceAndMorph(Player* player)
|
||||
{
|
||||
if (player->getClass() == CLASS_DRUID)
|
||||
{
|
||||
if (player->GetTeamId(true) == TEAM_ALLIANCE)
|
||||
{
|
||||
m_FakeMorph[player->GetGUID()] = player->getGender() == GENDER_MALE ? FAKE_M_TAUREN : FAKE_F_TAUREN;
|
||||
m_FakeRace[player->GetGUID()] = RACE_TAUREN;
|
||||
}
|
||||
else if (player->getGender() == GENDER_MALE) // HORDE PLAYER, ONLY HAVE MALE NELF ID
|
||||
{
|
||||
m_FakeMorph[player->GetGUID()] = FAKE_M_NELF;
|
||||
m_FakeRace[player->GetGUID()] = RACE_NIGHTELF;
|
||||
}
|
||||
else
|
||||
m_FakeRace[player->GetGUID()] = player->GetTeamId(true) == TEAM_ALLIANCE ? RACE_BLOODELF : RACE_HUMAN;
|
||||
}
|
||||
else if (player->getClass() == CLASS_SHAMAN && player->GetTeamId(true) == TEAM_HORDE && player->getGender() == GENDER_FEMALE)
|
||||
{
|
||||
m_FakeMorph[player->GetGUID()] = FAKE_F_DRAENEI; // Female Draenei
|
||||
m_FakeRace[player->GetGUID()] = RACE_DRAENEI;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_FakeRace[player->GetGUID()] = player->GetTeamId(true) == TEAM_ALLIANCE ? RACE_BLOODELF : RACE_HUMAN;
|
||||
|
||||
if (player->GetTeamId(true) == TEAM_HORDE)
|
||||
{
|
||||
if (player->getGender() == GENDER_MALE)
|
||||
m_FakeMorph[player->GetGUID()] = 19723;
|
||||
else
|
||||
m_FakeMorph[player->GetGUID()] = 19724;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player->getGender() == GENDER_MALE)
|
||||
m_FakeMorph[player->GetGUID()] = 20578;
|
||||
else
|
||||
m_FakeMorph[player->GetGUID()] = 20579;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8 CrossFaction::GetFakeRace(uint64 playerGuid)
|
||||
{
|
||||
UNORDERED_MAP<uint64, uint8>::iterator itr = m_FakeRace.find(playerGuid);
|
||||
if (itr != m_FakeRace.end())
|
||||
return itr->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32 CrossFaction::GetFakeMorph(uint64 playerGuid)
|
||||
{
|
||||
UNORDERED_MAP<uint64, uint32>::iterator itr = m_FakeMorph.find(playerGuid);
|
||||
if (itr != m_FakeMorph.end())
|
||||
return itr->second;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CrossFaction::SetMorph(Player* player, bool value)
|
||||
{
|
||||
if (player)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
player->setRace(GetFakeRace(player->GetGUID()));
|
||||
player->SetDisplayId(GetFakeMorph(player->GetGUID()));
|
||||
}
|
||||
else
|
||||
{
|
||||
player->setRace(player->getRace(true));
|
||||
player->SetDisplayId(player->GetNativeDisplayId());
|
||||
player->InitDisplayIds();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Crossfaction team update functionalities
|
||||
/// Update player team and update the map of the leaders
|
||||
void CrossFaction::UpdatePlayerTeam(Group* group, uint64 guid, bool reset /* = false */)
|
||||
{
|
||||
Player* player = ObjectAccessor::FindPlayer(guid);
|
||||
@@ -30,13 +133,20 @@ void CrossFaction::UpdatePlayerTeam(Group* group, uint64 guid, bool reset /* = f
|
||||
{
|
||||
if (Battleground * bg = player->GetBattleground())
|
||||
{
|
||||
player->setTeamId(player->GetBgTeamId());
|
||||
player->setFaction(player->GetTeamId() == TEAM_ALLIANCE ? 1 : 2);
|
||||
sLog->outDebug(LOG_FILTER_CROSSFACTION, "Crossfaction: Battleground team id set for player %s", player->GetName().c_str());
|
||||
return;
|
||||
if (player->GetTeamId(true) != player->GetBgTeamId())
|
||||
{
|
||||
SetMorph(player, true); // setup the new display ID for the player, and the new race
|
||||
player->setTeamId(player->GetBgTeamId());
|
||||
player->setFaction(player->GetTeamId() == TEAM_ALLIANCE ? 1 : 2);
|
||||
DoForgetPlayersInBG(bg, player); // force to resend race information for this player
|
||||
sLog->outDebug(LOG_FILTER_CROSSFACTION, "Crossfaction: Battleground team id set for player %s", player->GetName().c_str());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SetMorph(player, false); // reset morph if not in bg
|
||||
|
||||
// standard group
|
||||
uint64 leaderGuid = group ? group->GetLeaderGUID() : player->GetGUID();
|
||||
if (leaderGuid != player->GetGUID())
|
||||
@@ -66,10 +176,10 @@ void CrossFaction::UpdatePlayerTeam(Group* group, uint64 guid, bool reset /* = f
|
||||
}
|
||||
|
||||
// all the other cases: reset to the original faction
|
||||
|
||||
player->setTeamId(player->GetTeamId(true));
|
||||
ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(player->getRace());
|
||||
ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(player->getRace(true));
|
||||
player->setFaction(rEntry ? rEntry->FactionID : 0);
|
||||
SetMorph(player, false);
|
||||
sLog->outDebug(LOG_FILTER_CROSSFACTION, "Crossfaction: reset done for player %s", player->GetName().c_str());
|
||||
}
|
||||
else
|
||||
@@ -81,7 +191,7 @@ void CrossFaction::UpdateGroupLeaderMap(uint64 leaderGuid, bool remove)
|
||||
if (remove)
|
||||
LeaderRaceMap.erase(leaderGuid);
|
||||
else
|
||||
LeaderRaceMap[leaderGuid] = GetPlayerRace(leaderGuid);
|
||||
LeaderRaceMap[leaderGuid] = GetLeaderRace(leaderGuid);
|
||||
}
|
||||
|
||||
void CrossFaction::UpdateAllGroups()
|
||||
@@ -170,10 +280,10 @@ void CrossFaction::LoadConfig(bool reload)
|
||||
}
|
||||
|
||||
// This function is used to retrieve
|
||||
uint8 CrossFaction::GetPlayerRace(uint64 playerGuid)
|
||||
uint8 CrossFaction::GetLeaderRace(uint64 playerGuid)
|
||||
{
|
||||
if (Player* player = ObjectAccessor::FindPlayer(playerGuid))
|
||||
return player->getRace();
|
||||
return player->getRace(true);
|
||||
else
|
||||
{
|
||||
// Query informations from the DB
|
||||
@@ -277,11 +387,25 @@ public:
|
||||
sCrossFaction->UpdatePlayerTeam(player->GetGroup(), player->GetGUID());
|
||||
}
|
||||
|
||||
void OnUpdateFaction(Player *player) override
|
||||
void OnUpdateFaction(Player* player) override
|
||||
{
|
||||
sCrossFaction->SetFakeRaceAndMorph(player); // set fake race information
|
||||
sCrossFaction->UpdatePlayerTeam(player->GetGroup(), player->GetGUID());
|
||||
}
|
||||
|
||||
void OnAddToBattleground(Player* player, Battleground* bg) override
|
||||
{
|
||||
sCrossFaction->SetFakeRaceAndMorph(player); // set (re-set) fake race information
|
||||
sCrossFaction->UpdatePlayerTeam(player->GetGroup(), player->GetGUID()); // this will morph player if he's in BG with switched faction
|
||||
}
|
||||
|
||||
void OnRemoveFromBattleground(Player* player, Battleground* bg) override
|
||||
{
|
||||
sCrossFaction->UpdatePlayerTeam(player->GetGroup(), player->GetGUID(), true);
|
||||
sCrossFaction->SetMorph(player,false); // force reset any morph, then forget players in BG.
|
||||
sCrossFaction->DoForgetPlayersInBG(bg, player);
|
||||
}
|
||||
|
||||
void OnLogout(Player* player) override
|
||||
{
|
||||
// force faction reset on logout to prevent issues with DB save
|
||||
|
||||
@@ -9,21 +9,44 @@
|
||||
#include "Group.h"
|
||||
#include "Map.h"
|
||||
#include "Log.h"
|
||||
#include "Opcodes.h"
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
enum FakeMorphs
|
||||
{
|
||||
FAKE_F_TAUREN = 20584,
|
||||
FAKE_M_TAUREN = 20585,
|
||||
FAKE_M_NELF = 20318,
|
||||
FAKE_F_DRAENEI = 20323,
|
||||
};
|
||||
|
||||
class CrossFaction
|
||||
{
|
||||
public:
|
||||
// Race Update
|
||||
void SetFakeRaceAndMorph(Player* player);
|
||||
uint8 GetFakeRace(uint64 playerGuid);
|
||||
uint32 GetFakeMorph(uint64 playerGuid);
|
||||
void SetMorph(Player* player, bool value);
|
||||
|
||||
// Team Update
|
||||
void LoadConfig(bool reload);
|
||||
void UpdatePlayerTeam(Group* group, uint64 guid, bool reset = false);
|
||||
void UpdateGroupLeaderMap(uint64 leaderGuid, bool remove = false);
|
||||
void UpdateAllGroups();
|
||||
|
||||
// Battleground race player invalidation - retrieval
|
||||
void DoForgetPlayersInBG(Battleground* pBattleGround, Player* player);
|
||||
|
||||
private:
|
||||
// Group leader guid-race caching
|
||||
UNORDERED_MAP<uint64, uint8> LeaderRaceMap;
|
||||
uint8 GetPlayerRace(uint64 playerGuid);
|
||||
uint8 GetLeaderRace(uint64 playerGuid);
|
||||
|
||||
// Fake race caching
|
||||
UNORDERED_MAP<uint64, uint8> m_FakeRace;
|
||||
UNORDERED_MAP<uint64, uint32> m_FakeMorph;
|
||||
|
||||
// Disables system
|
||||
typedef std::vector<uint32> CrossFactionDisableList;
|
||||
|
||||
@@ -1065,6 +1065,8 @@ void Battleground::BlockMovement(Player* player)
|
||||
|
||||
void Battleground::RemovePlayerAtLeave(Player* player)
|
||||
{
|
||||
sScriptMgr->OnPlayerRemoveFromBattleground(player, this);
|
||||
|
||||
TeamId teamId = player->GetBgTeamId();
|
||||
|
||||
// check if the player was a participant of the match, or only entered through gm command
|
||||
@@ -1250,9 +1252,10 @@ void Battleground::AddPlayer(Player* player)
|
||||
// setup BG group membership
|
||||
PlayerAddedToBGCheckIfBGIsRunning(player);
|
||||
AddOrSetPlayerToCorrectBgGroup(player, teamId);
|
||||
|
||||
|
||||
sScriptMgr->OnPlayerAddToBattleground(player, this);
|
||||
// Log
|
||||
;//sLog->outDetail("BATTLEGROUND: Player %s joined the battle.", player->GetName().c_str());
|
||||
//sLog->outDetail("BATTLEGROUND: Player %s joined the battle.", player->GetName().c_str());
|
||||
}
|
||||
|
||||
// this method adds player to his team's bg group, or sets his correct group if player is already in bg group
|
||||
|
||||
@@ -388,11 +388,14 @@ void BattlegroundQueue::FillPlayersToBG(const int32 aliFree, const int32 hordeFr
|
||||
m_SelectionPools[TEAM_ALLIANCE].Init();
|
||||
m_SelectionPools[TEAM_HORDE].Init();
|
||||
|
||||
// quick check if nothing we can do:
|
||||
// [AZTH] quick check if nothing we can do:
|
||||
if (!sBattlegroundMgr->isTesting())
|
||||
if (aliFree > hordeFree && m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].empty() ||
|
||||
hordeFree > aliFree && m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].empty())
|
||||
return;
|
||||
if(m_bgTypeId != BATTLEGROUND_RB)
|
||||
{
|
||||
if (aliFree > hordeFree && m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].empty() ||
|
||||
hordeFree > aliFree && m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].empty())
|
||||
return;
|
||||
}
|
||||
|
||||
// ally: at first fill as much as possible
|
||||
GroupsQueueType::const_iterator Ali_itr = m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].begin();
|
||||
@@ -406,53 +409,63 @@ void BattlegroundQueue::FillPlayersToBG(const int32 aliFree, const int32 hordeFr
|
||||
int32 aliDiff = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
|
||||
int32 hordeDiff = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
|
||||
|
||||
// Mik1893: Battleground Balance system 2.0
|
||||
// [AZTH] Mik1893: Battleground Balance system 2.0
|
||||
int32 invType = sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE);
|
||||
int32 invDiff = 0;
|
||||
|
||||
// check balance configuration and set the max difference between teams
|
||||
switch (invType)
|
||||
if (m_bgTypeId != BATTLEGROUND_RB) // if not RANDOM BATTLEGROUND, use the balance system
|
||||
{
|
||||
case BG_QUEUE_INVITATION_TYPE_NO_BALANCE:
|
||||
return;
|
||||
case BG_QUEUE_INVITATION_TYPE_BALANCED:
|
||||
invDiff = 1;
|
||||
case BG_QUEUE_INVITATION_TYPE_EVEN:
|
||||
invDiff = 0;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// balance the teams based on the difference allowed
|
||||
while (abs(aliDiff - hordeDiff) > invDiff && (m_SelectionPools[TEAM_HORDE].GetPlayerCount() > 0 || m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() > 0))
|
||||
{
|
||||
// if results in more alliance players than horde:
|
||||
if (aliDiff < hordeDiff)
|
||||
// check balance configuration and set the max difference between teams
|
||||
switch (invType)
|
||||
{
|
||||
// no more alliance in pool, invite whatever we can from horde
|
||||
if (!m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick alliance, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_ALLIANCE].KickGroup(hordeDiff - aliDiff))
|
||||
for (; Ali_itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].end() && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree >= hordeDiff ? aliFree - hordeDiff : 0); ++Ali_itr);
|
||||
}
|
||||
// if results in more horde players than alliance:
|
||||
else
|
||||
{
|
||||
// no more horde in pool, invite whatever we can from alliance
|
||||
if (!m_SelectionPools[TEAM_HORDE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick horde, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_HORDE].KickGroup(aliDiff - hordeDiff))
|
||||
for (; Horde_itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].end() && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree >= aliDiff ? hordeFree - aliDiff : 0); ++Horde_itr);
|
||||
case BG_QUEUE_INVITATION_TYPE_NO_BALANCE:
|
||||
return;
|
||||
case BG_QUEUE_INVITATION_TYPE_BALANCED:
|
||||
invDiff = 1;
|
||||
case BG_QUEUE_INVITATION_TYPE_EVEN:
|
||||
invDiff = 0;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// recalculate free space after adding
|
||||
aliDiff = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
|
||||
hordeDiff = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
|
||||
// balance the teams based on the difference allowed
|
||||
while (abs(aliDiff - hordeDiff) > invDiff && (m_SelectionPools[TEAM_HORDE].GetPlayerCount() > 0 || m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() > 0))
|
||||
{
|
||||
// if results in more alliance players than horde:
|
||||
if (aliDiff < hordeDiff)
|
||||
{
|
||||
// no more alliance in pool, invite whatever we can from horde
|
||||
if (!m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick alliance, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_ALLIANCE].KickGroup(hordeDiff - aliDiff))
|
||||
for (; Ali_itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].end() && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree >= hordeDiff ? aliFree - hordeDiff : 0); ++Ali_itr);
|
||||
}
|
||||
// if results in more horde players than alliance:
|
||||
else
|
||||
{
|
||||
// no more horde in pool, invite whatever we can from alliance
|
||||
if (!m_SelectionPools[TEAM_HORDE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick horde, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_HORDE].KickGroup(aliDiff - hordeDiff))
|
||||
for (; Horde_itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].end() && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree >= aliDiff ? hordeFree - aliDiff : 0); ++Horde_itr);
|
||||
}
|
||||
|
||||
// recalculate free space after adding
|
||||
aliDiff = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
|
||||
hordeDiff = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
|
||||
}
|
||||
}
|
||||
else // unified queues, basically
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_BATTLEGROUND,"check min count for players - unified queue... - FILL PLAYERS TO BG ");
|
||||
for (; Ali_itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].end() && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), 100); ++Ali_itr);
|
||||
for (; Horde_itr != m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].end() && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), 100); ++Horde_itr);
|
||||
}
|
||||
// [/AZTH]
|
||||
}
|
||||
|
||||
void BattlegroundQueue::FillPlayersToBGWithSpecific(const int32 aliFree, const int32 hordeFree, BattlegroundBracketId thisBracketId, BattlegroundQueue* specificQueue, BattlegroundBracketId specificBracketId)
|
||||
@@ -461,11 +474,14 @@ void BattlegroundQueue::FillPlayersToBGWithSpecific(const int32 aliFree, const i
|
||||
m_SelectionPools[TEAM_ALLIANCE].Init();
|
||||
m_SelectionPools[TEAM_HORDE].Init();
|
||||
|
||||
// quick check if nothing we can do:
|
||||
// [AZTH] quick check if nothing we can do:
|
||||
if (!sBattlegroundMgr->isTesting())
|
||||
if (m_QueuedGroups[thisBracketId][BG_QUEUE_NORMAL_ALLIANCE].empty() && specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_NORMAL_ALLIANCE].empty() ||
|
||||
m_QueuedGroups[thisBracketId][BG_QUEUE_NORMAL_HORDE].empty() && specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_NORMAL_HORDE].empty())
|
||||
return;
|
||||
if (m_bgTypeId != BATTLEGROUND_RB)
|
||||
{
|
||||
if (m_QueuedGroups[thisBracketId][BG_QUEUE_NORMAL_ALLIANCE].empty() && specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_NORMAL_ALLIANCE].empty() ||
|
||||
m_QueuedGroups[thisBracketId][BG_QUEUE_NORMAL_HORDE].empty() && specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_NORMAL_HORDE].empty())
|
||||
return;
|
||||
}
|
||||
|
||||
// copy groups from both queues to new joined container
|
||||
GroupsQueueType m_QueuedBoth[BG_TEAMS_COUNT];
|
||||
@@ -490,48 +506,57 @@ void BattlegroundQueue::FillPlayersToBGWithSpecific(const int32 aliFree, const i
|
||||
int32 invType = sWorld->getIntConfig(CONFIG_BATTLEGROUND_INVITATION_TYPE);
|
||||
int32 invDiff = 0;
|
||||
|
||||
// check balance configuration and set the max difference between teams
|
||||
switch (invType)
|
||||
if (m_bgTypeId != BATTLEGROUND_RB) // if not RANDOM BATTLEGROUND, use the balance system
|
||||
{
|
||||
case BG_QUEUE_INVITATION_TYPE_NO_BALANCE:
|
||||
return;
|
||||
case BG_QUEUE_INVITATION_TYPE_BALANCED:
|
||||
invDiff = 1;
|
||||
case BG_QUEUE_INVITATION_TYPE_EVEN:
|
||||
invDiff = 0;
|
||||
default:
|
||||
return;
|
||||
// check balance configuration and set the max difference between teams
|
||||
switch (invType)
|
||||
{
|
||||
case BG_QUEUE_INVITATION_TYPE_NO_BALANCE:
|
||||
return;
|
||||
case BG_QUEUE_INVITATION_TYPE_BALANCED:
|
||||
invDiff = 1;
|
||||
case BG_QUEUE_INVITATION_TYPE_EVEN:
|
||||
invDiff = 0;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// if free space differs too much, ballance
|
||||
while (abs(aliDiff - hordeDiff) > invDiff && (m_SelectionPools[TEAM_HORDE].GetPlayerCount() > 0 || m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() > 0))
|
||||
{
|
||||
// if results in more alliance players than horde:
|
||||
if (aliDiff < hordeDiff)
|
||||
{
|
||||
// no more alliance in pool, invite whatever we can from horde
|
||||
if (!m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick alliance, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_ALLIANCE].KickGroup(hordeDiff - aliDiff))
|
||||
for (; Ali_itr != m_QueuedBoth[TEAM_ALLIANCE].end() && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree >= hordeDiff ? aliFree - hordeDiff : 0); ++Ali_itr);
|
||||
}
|
||||
// if results in more horde players than alliance:
|
||||
else
|
||||
{
|
||||
// no more horde in pool, invite whatever we can from alliance
|
||||
if (!m_SelectionPools[TEAM_HORDE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick horde, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_HORDE].KickGroup(aliDiff - hordeDiff))
|
||||
for (; Horde_itr != m_QueuedBoth[TEAM_HORDE].end() && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree >= aliDiff ? hordeFree - aliDiff : 0); ++Horde_itr);
|
||||
}
|
||||
|
||||
// recalculate free space after adding
|
||||
aliDiff = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
|
||||
hordeDiff = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
|
||||
}
|
||||
}
|
||||
|
||||
// if free space differs too much, ballance
|
||||
while (abs(aliDiff - hordeDiff) > invDiff && (m_SelectionPools[TEAM_HORDE].GetPlayerCount() > 0 || m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() > 0))
|
||||
else // unified queues, basically - let everyone in and we handle it later
|
||||
{
|
||||
// if results in more alliance players than horde:
|
||||
if (aliDiff < hordeDiff)
|
||||
{
|
||||
// no more alliance in pool, invite whatever we can from horde
|
||||
if (!m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick alliance, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_ALLIANCE].KickGroup(hordeDiff - aliDiff))
|
||||
for (; Ali_itr != m_QueuedBoth[TEAM_ALLIANCE].end() && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree >= hordeDiff ? aliFree - hordeDiff : 0); ++Ali_itr);
|
||||
}
|
||||
// if results in more horde players than alliance:
|
||||
else
|
||||
{
|
||||
// no more horde in pool, invite whatever we can from alliance
|
||||
if (!m_SelectionPools[TEAM_HORDE].GetPlayerCount())
|
||||
break;
|
||||
|
||||
// kick horde, returns true if kicked more than needed, so then try to fill up
|
||||
if (m_SelectionPools[TEAM_HORDE].KickGroup(aliDiff - hordeDiff))
|
||||
for (; Horde_itr != m_QueuedBoth[TEAM_HORDE].end() && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree >= aliDiff ? hordeFree - aliDiff : 0); ++Horde_itr);
|
||||
}
|
||||
|
||||
// recalculate free space after adding
|
||||
aliDiff = aliFree - int32(m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount());
|
||||
hordeDiff = hordeFree - int32(m_SelectionPools[TEAM_HORDE].GetPlayerCount());
|
||||
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "check min count for players - unified queue... - FILL PLAYERS TO BG WITH SPECIFIC ");
|
||||
for (; Ali_itr != m_QueuedBoth[TEAM_ALLIANCE].end() && m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), 100); ++Ali_itr);
|
||||
for (; Horde_itr != m_QueuedBoth[TEAM_HORDE].end() && m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), 100);++Horde_itr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,7 +640,10 @@ bool BattlegroundQueue::CheckNormalMatch(Battleground* bgTemplate, BattlegroundB
|
||||
if (sBattlegroundMgr->isTesting() && bgTemplate->isBattleground() && (m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() || m_SelectionPools[TEAM_HORDE].GetPlayerCount()))
|
||||
return true;
|
||||
|
||||
return m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() >= std::min<uint32>(specificTemplate->GetMinPlayersPerTeam(), 15) && m_SelectionPools[TEAM_HORDE].GetPlayerCount() >= std::min<uint32>(specificTemplate->GetMinPlayersPerTeam(), 15);
|
||||
sLog->outDebug(LOG_FILTER_BATTLEGROUND, "check min count for players - unified queue...");
|
||||
|
||||
//[AZTH] - Check for sum of queues >= 2* minplayerperteam
|
||||
return (m_SelectionPools[TEAM_ALLIANCE].GetPlayerCount() + m_SelectionPools[TEAM_HORDE].GetPlayerCount()) >= 2 * (std::min<uint32>(specificTemplate->GetMinPlayersPerTeam(), 15));
|
||||
}
|
||||
// if this is not random bg queue - use players only from this queue
|
||||
else
|
||||
@@ -704,11 +732,14 @@ typedef std::set<Battleground*, BgEmptinessComp> BattlegroundNeedSet;
|
||||
|
||||
void BattlegroundQueue::BattlegroundQueueUpdate(BattlegroundBracketId bracket_id, uint8 actionMask, bool isRated, uint32 arenaRatedTeamId)
|
||||
{
|
||||
// if no players in queue - do nothing
|
||||
if (m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty() &&
|
||||
bool validRandomQueue = !(m_bgTypeId == BATTLEGROUND_RB && (!m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].empty() || !m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].empty()));
|
||||
// [AZTH] on random bg you want to check sum of both queues - if no players in queue - do nothing
|
||||
if (
|
||||
m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_ALLIANCE].empty() &&
|
||||
m_QueuedGroups[bracket_id][BG_QUEUE_PREMADE_HORDE].empty() &&
|
||||
m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_ALLIANCE].empty() &&
|
||||
m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].empty())
|
||||
m_QueuedGroups[bracket_id][BG_QUEUE_NORMAL_HORDE].empty() &&
|
||||
!validRandomQueue)
|
||||
return;
|
||||
|
||||
Battleground* bg_template = sBattlegroundMgr->GetBattlegroundTemplate(m_bgTypeId);
|
||||
|
||||
@@ -435,6 +435,27 @@ 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 (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
|
||||
for (uint32 qslot = 0; qslot < PLAYER_MAX_BATTLEGROUND_QUEUES; ++qslot)
|
||||
if (BattlegroundQueueTypeId q = _player->GetBattlegroundQueueTypeId(qslot))
|
||||
|
||||
@@ -44,23 +44,15 @@ void WorldSession::SendNameQueryOpcode(uint64 guid)
|
||||
return;
|
||||
}
|
||||
|
||||
Player* player = ObjectAccessor::FindPlayer(guid); //[AZTH] CrossFaction battleground
|
||||
|
||||
data << uint8(0); // name known
|
||||
data << playerData->name; // played name
|
||||
data << uint8(0); // realm name - only set for cross realm interaction (such as Battlegrounds)
|
||||
data << uint8(playerData->race);
|
||||
data << uint8(player ? player->getRace() : playerData->race); //[AZTH]
|
||||
data << uint8(playerData->gender);
|
||||
data << uint8(playerData->playerClass);
|
||||
|
||||
// pussywizard: optimization
|
||||
/*Player* player = ObjectAccessor::FindPlayerInOrOutOfWorld(guid);
|
||||
if (DeclinedName const* names = (player ? player->GetDeclinedNames() : NULL))
|
||||
{
|
||||
data << uint8(1); // Name is declined
|
||||
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
|
||||
data << names->name[i];
|
||||
}
|
||||
else*/
|
||||
data << uint8(0); // Name is not declined
|
||||
data << uint8(0); // Name is not declined
|
||||
|
||||
SendPacket(&data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user