mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-15 16:26:08 +00:00
fix(Core/Battlegrounds) Rewrite RandomBG and enabling bg/arenas weights (#2516)
This commit is contained in:
@@ -46,7 +46,7 @@
|
||||
/*** BATTLEGROUND MANAGER ***/
|
||||
/*********************************************************/
|
||||
|
||||
BattlegroundMgr::BattlegroundMgr() : randomBgDifficultyEntry(999, 0, 80, 80, 0), m_ArenaTesting(false), m_Testing(false),
|
||||
BattlegroundMgr::BattlegroundMgr() : m_ArenaTesting(false), m_Testing(false),
|
||||
m_lastClientVisibleInstanceId(0), m_NextAutoDistributionTime(0), m_AutoDistributionTimeChecker(0), m_NextPeriodicQueueUpdateTime(5*IN_MILLISECONDS)
|
||||
{
|
||||
for (uint32 qtype = BATTLEGROUND_QUEUE_NONE; qtype < MAX_BATTLEGROUND_QUEUE_TYPES; ++qtype)
|
||||
@@ -92,9 +92,6 @@ void BattlegroundMgr::Update(uint32 diff)
|
||||
}
|
||||
}
|
||||
|
||||
// update to change current bg type the random system is trying to create
|
||||
RandomSystem.Update(diff);
|
||||
|
||||
// update events
|
||||
for (int qtype = BATTLEGROUND_QUEUE_NONE; qtype < MAX_BATTLEGROUND_QUEUE_TYPES; ++qtype)
|
||||
m_BattlegroundQueues[qtype].UpdateEvents(diff);
|
||||
@@ -427,14 +424,12 @@ uint32 BattlegroundMgr::GetNextClientVisibleInstanceId()
|
||||
}
|
||||
|
||||
// create a new battleground that will really be used to play
|
||||
Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId bgTypeId, uint32 minLevel, uint32 maxLevel, uint8 arenaType, bool isRated)
|
||||
Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId originalBgTypeId, uint32 minLevel, uint32 maxLevel, uint8 arenaType, bool isRated)
|
||||
{
|
||||
// pussywizard: random battleground is chosen before calling this function!
|
||||
ASSERT(bgTypeId != BATTLEGROUND_RB);
|
||||
BattlegroundTypeId bgTypeId = GetRandomBG(originalBgTypeId);
|
||||
|
||||
// pussywizard: randomize for all arena
|
||||
if (bgTypeId == BATTLEGROUND_AA)
|
||||
bgTypeId = RAND<BattlegroundTypeId>(BATTLEGROUND_NA, BATTLEGROUND_BE, BATTLEGROUND_RL, BATTLEGROUND_DS, BATTLEGROUND_RV);
|
||||
if (originalBgTypeId == BATTLEGROUND_AA)
|
||||
originalBgTypeId = bgTypeId;
|
||||
|
||||
// get the template BG
|
||||
Battleground* bg_template = GetBattlegroundTemplate(bgTypeId);
|
||||
@@ -449,14 +444,18 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId bgTypeId
|
||||
|
||||
bg = BattlegroundMgr::bgTypeToTemplate[bgTypeId](bg_template);
|
||||
|
||||
bool isRandom = bgTypeId != originalBgTypeId && !bg->isArena();
|
||||
|
||||
bg->SetLevelRange(minLevel, maxLevel);
|
||||
bg->SetInstanceID(sMapMgr->GenerateInstanceId());
|
||||
bg->SetClientInstanceID(IsArenaType(bgTypeId) ? 0 : GetNextClientVisibleInstanceId());
|
||||
bg->SetClientInstanceID(IsArenaType(originalBgTypeId) ? 0 : GetNextClientVisibleInstanceId());
|
||||
bg->Init();
|
||||
bg->SetStatus(STATUS_WAIT_JOIN); // start the joining of the bg
|
||||
bg->SetArenaType(arenaType);
|
||||
bg->SetBgTypeID(bgTypeId);
|
||||
bg->SetBgTypeID(originalBgTypeId);
|
||||
bg->SetRandomTypeID(bgTypeId);
|
||||
bg->SetRated(isRated);
|
||||
bg->SetRandom(isRandom);
|
||||
|
||||
// Set up correct min/max player counts for scoreboards
|
||||
if (bg->isArena())
|
||||
@@ -491,7 +490,10 @@ bool BattlegroundMgr::CreateBattleground(CreateBattlegroundData& data)
|
||||
if (bg == NULL)
|
||||
return false;
|
||||
|
||||
bg->SetMapId(data.bgTypeId == BATTLEGROUND_RB ? randomBgDifficultyEntry.mapId : data.MapID);
|
||||
if (data.bgTypeId == BATTLEGROUND_RB)
|
||||
bg->SetRandom(true);
|
||||
|
||||
bg->SetMapId(data.MapID);
|
||||
bg->SetBgTypeID(data.bgTypeId);
|
||||
bg->SetInstanceID(0);
|
||||
bg->SetArenaorBGType(data.IsArena);
|
||||
@@ -512,6 +514,10 @@ bool BattlegroundMgr::CreateBattleground(CreateBattlegroundData& data)
|
||||
void BattlegroundMgr::CreateInitialBattlegrounds()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
_battlegroundMapTemplates.clear();
|
||||
_battlegroundTemplates.clear();
|
||||
|
||||
// 0 1 2 3 4 5 6 7 8 9 10 11
|
||||
QueryResult result = WorldDatabase.Query("SELECT ID, MinPlayersPerTeam, MaxPlayersPerTeam, MinLvl, MaxLvl, AllianceStartLoc, AllianceStartO, HordeStartLoc, HordeStartO, StartMaxDist, Weight, ScriptName FROM battleground_template");
|
||||
|
||||
@@ -549,6 +555,7 @@ void BattlegroundMgr::CreateInitialBattlegrounds()
|
||||
data.LevelMax = fields[4].GetUInt8();
|
||||
float dist = fields[9].GetFloat();
|
||||
data.StartMaxDist = dist * dist;
|
||||
data.Weight = fields[10].GetUInt8();
|
||||
|
||||
data.scriptId = sObjectMgr->GetScriptId(fields[11].GetCString());
|
||||
data.BattlegroundName = bl->name[sWorld->GetDefaultDbcLocale()];
|
||||
@@ -613,6 +620,11 @@ void BattlegroundMgr::CreateInitialBattlegrounds()
|
||||
if (!CreateBattleground(data))
|
||||
continue;
|
||||
|
||||
_battlegroundTemplates[BattlegroundTypeId(bgTypeId)] = data;
|
||||
|
||||
if (bl->mapid[1] == -1) // in this case we have only one mapId
|
||||
_battlegroundMapTemplates[bl->mapid[0]] = &_battlegroundTemplates[BattlegroundTypeId(bgTypeId)];
|
||||
|
||||
++count;
|
||||
}
|
||||
while (result->NextRow());
|
||||
@@ -910,6 +922,34 @@ bool BattlegroundMgr::IsBGWeekend(BattlegroundTypeId bgTypeId)
|
||||
return IsHolidayActive(BGTypeToWeekendHolidayId(bgTypeId));
|
||||
}
|
||||
|
||||
BattlegroundTypeId BattlegroundMgr::GetRandomBG(BattlegroundTypeId bgTypeId)
|
||||
{
|
||||
if (CreateBattlegroundData const* bgTemplate = GetBattlegroundTemplateByTypeId(bgTypeId))
|
||||
{
|
||||
std::vector<BattlegroundTypeId> ids;
|
||||
ids.reserve(16);
|
||||
std::vector<double> weights;
|
||||
weights.reserve(16);
|
||||
BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId);
|
||||
|
||||
for (int32 mapId : bl->mapid)
|
||||
{
|
||||
if (mapId == -1)
|
||||
break;
|
||||
|
||||
if (CreateBattlegroundData const* bg = GetBattlegroundTemplateByMapId(mapId))
|
||||
{
|
||||
ids.push_back(bg->bgTypeId);
|
||||
weights.push_back(bg->Weight);
|
||||
}
|
||||
}
|
||||
|
||||
return acore::Containers::SelectRandomWeightedContainerElement(ids, weights);
|
||||
}
|
||||
|
||||
return BATTLEGROUND_TYPE_NONE;
|
||||
}
|
||||
|
||||
void BattlegroundMgr::AddBattleground(Battleground* bg)
|
||||
{
|
||||
if (bg->GetInstanceID() == 0)
|
||||
@@ -986,65 +1026,6 @@ void BattlegroundMgr::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, T
|
||||
}
|
||||
}
|
||||
|
||||
RandomBattlegroundSystem::RandomBattlegroundSystem() : m_CurrentRandomBg(BATTLEGROUND_TYPE_NONE), m_SwitchTimer(0)
|
||||
{
|
||||
}
|
||||
|
||||
void RandomBattlegroundSystem::Update(uint32 diff)
|
||||
{
|
||||
if (m_SwitchTimer <= diff)
|
||||
{
|
||||
if (m_BgOrder.empty())
|
||||
{
|
||||
// order it like: big, small, big, small, small, small (stored backwards, actually)
|
||||
|
||||
std::vector<BattlegroundTypeId> big, small;
|
||||
big.push_back(BATTLEGROUND_AV);
|
||||
big.push_back(BATTLEGROUND_IC);
|
||||
small.push_back(BATTLEGROUND_WS);
|
||||
small.push_back(BATTLEGROUND_EY);
|
||||
small.push_back(BATTLEGROUND_AB);
|
||||
small.push_back(BATTLEGROUND_SA);
|
||||
|
||||
std::random_device rd;
|
||||
auto rng = std::default_random_engine{rd()};
|
||||
|
||||
std::shuffle(big.begin(), big.end(), rng);
|
||||
std::shuffle(small.begin(), small.end(), rng);
|
||||
|
||||
m_BgOrder.push_back(small.back()); small.pop_back();
|
||||
m_BgOrder.push_back(small.back()); small.pop_back();
|
||||
m_BgOrder.push_back(small.back()); small.pop_back();
|
||||
m_BgOrder.push_back(big.back()); big.pop_back();
|
||||
m_BgOrder.push_back(small.back()); small.pop_back();
|
||||
m_BgOrder.push_back(big.back()); big.pop_back();
|
||||
}
|
||||
|
||||
m_CurrentRandomBg = m_BgOrder.back();
|
||||
m_BgOrder.pop_back();
|
||||
|
||||
switch (m_CurrentRandomBg)
|
||||
{
|
||||
case BATTLEGROUND_AV: m_SwitchTimer = 180*IN_MILLISECONDS; break; // max 40 per team
|
||||
case BATTLEGROUND_WS: m_SwitchTimer = 30*IN_MILLISECONDS; break; // max 10 per team
|
||||
case BATTLEGROUND_IC: m_SwitchTimer = 180*IN_MILLISECONDS; break; // max 40 per team
|
||||
case BATTLEGROUND_EY: m_SwitchTimer = 40*IN_MILLISECONDS; break; // max 15 per team
|
||||
case BATTLEGROUND_AB: m_SwitchTimer = 40*IN_MILLISECONDS; break; // max 15 per team
|
||||
case BATTLEGROUND_SA: m_SwitchTimer = 40*IN_MILLISECONDS; break; // max 15 per team
|
||||
default: ABORT(); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
m_SwitchTimer -= diff;
|
||||
}
|
||||
|
||||
void RandomBattlegroundSystem::BattlegroundCreated(BattlegroundTypeId bgTypeId)
|
||||
{
|
||||
// if created current random bg, set current to another one
|
||||
if (bgTypeId == m_CurrentRandomBg)
|
||||
Update(0xffffffff);
|
||||
}
|
||||
|
||||
// init/update unordered_map
|
||||
// Battlegrounds
|
||||
std::unordered_map<int, BattlegroundQueueTypeId> BattlegroundMgr::bgToQueue = {
|
||||
|
||||
Reference in New Issue
Block a user