feat(modules): Allow modules to extend Battlegrounds (#1444)

This commit is contained in:
Stefano Borzì
2019-03-02 12:09:39 +01:00
committed by Francesco Borzì
parent 9643ccdb9d
commit 75bf44d168
3 changed files with 118 additions and 156 deletions
+98 -144
View File
@@ -35,6 +35,7 @@
#include "Opcodes.h" #include "Opcodes.h"
#include "BattlegroundQueue.h" #include "BattlegroundQueue.h"
#include "GameGraveyard.h" #include "GameGraveyard.h"
#include <unordered_map>
#ifdef ELUNA #ifdef ELUNA
#include "LuaEngine.h" #include "LuaEngine.h"
#endif #endif
@@ -108,14 +109,14 @@ void BattlegroundMgr::Update(uint32 diff)
if (m_NextPeriodicQueueUpdateTime < diff) if (m_NextPeriodicQueueUpdateTime < diff)
{ {
// for rated arenas // for rated arenas
for (uint32 qtype = BATTLEGROUND_QUEUE_2v2; qtype <= BATTLEGROUND_QUEUE_5v5; ++qtype) for (uint32 qtype = BATTLEGROUND_QUEUE_2v2; qtype < MAX_BATTLEGROUND_QUEUE_TYPES; ++qtype)
for (uint32 bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket) for (uint32 bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
m_BattlegroundQueues[qtype].BattlegroundQueueUpdate(BattlegroundBracketId(bracket), 0x03, true, 0); // pussywizard: 0 for rated means looking for opponents for every team m_BattlegroundQueues[qtype].BattlegroundQueueUpdate(BattlegroundBracketId(bracket), 0x03, true, 0); // pussywizard: 0 for rated means looking for opponents for every team
// for battlegrounds and not rated arenas // for battlegrounds and not rated arenas
// in first loop try to fill already running battlegrounds, then in a second loop try to create new battlegrounds // in first loop try to fill already running battlegrounds, then in a second loop try to create new battlegrounds
for (uint8 action = 1; action <= 2; ++action) for (uint8 action = 1; action <= 2; ++action)
for (uint32 qtype = BATTLEGROUND_QUEUE_AV; qtype <= BATTLEGROUND_QUEUE_5v5; ++qtype) for (uint32 qtype = BATTLEGROUND_QUEUE_AV; qtype < MAX_BATTLEGROUND_QUEUE_TYPES; ++qtype)
for (uint32 bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket) for (uint32 bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket)
m_BattlegroundQueues[qtype].BattlegroundQueueUpdate(BattlegroundBracketId(bracket), action, false, 0); m_BattlegroundQueues[qtype].BattlegroundQueueUpdate(BattlegroundBracketId(bracket), action, false, 0);
@@ -434,49 +435,12 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId bgTypeId
Battleground* bg = NULL; Battleground* bg = NULL;
// create a copy of the BG template // create a copy of the BG template
switch (bgTypeId) if (BattlegroundMgr::bgTypeToTemplate.find(bgTypeId) == BattlegroundMgr::bgTypeToTemplate.end()) {
{ return NULL;
case BATTLEGROUND_AV:
bg = new BattlegroundAV(*(BattlegroundAV*)bg_template);
break;
case BATTLEGROUND_WS:
bg = new BattlegroundWS(*(BattlegroundWS*)bg_template);
break;
case BATTLEGROUND_AB:
bg = new BattlegroundAB(*(BattlegroundAB*)bg_template);
break;
case BATTLEGROUND_NA:
bg = new BattlegroundNA(*(BattlegroundNA*)bg_template);
break;
case BATTLEGROUND_BE:
bg = new BattlegroundBE(*(BattlegroundBE*)bg_template);
break;
case BATTLEGROUND_EY:
bg = new BattlegroundEY(*(BattlegroundEY*)bg_template);
break;
case BATTLEGROUND_RL:
bg = new BattlegroundRL(*(BattlegroundRL*)bg_template);
break;
case BATTLEGROUND_SA:
bg = new BattlegroundSA(*(BattlegroundSA*)bg_template);
break;
case BATTLEGROUND_DS:
bg = new BattlegroundDS(*(BattlegroundDS*)bg_template);
break;
case BATTLEGROUND_RV:
bg = new BattlegroundRV(*(BattlegroundRV*)bg_template);
break;
case BATTLEGROUND_IC:
bg = new BattlegroundIC(*(BattlegroundIC*)bg_template);
break;
case BATTLEGROUND_RB:
case BATTLEGROUND_AA:
bg = new Battleground(*bg_template);
break;
default:
return NULL;
} }
bg = BattlegroundMgr::bgTypeToTemplate[bgTypeId](bg_template);
bg->SetLevelRange(minLevel, maxLevel); bg->SetLevelRange(minLevel, maxLevel);
bg->SetInstanceID(sMapMgr->GenerateInstanceId()); bg->SetInstanceID(sMapMgr->GenerateInstanceId());
bg->SetClientInstanceID(IsArenaType(bgTypeId) ? 0 : GetNextClientVisibleInstanceId()); bg->SetClientInstanceID(IsArenaType(bgTypeId) ? 0 : GetNextClientVisibleInstanceId());
@@ -514,50 +478,10 @@ bool BattlegroundMgr::CreateBattleground(CreateBattlegroundData& data)
{ {
// Create the BG // Create the BG
Battleground* bg = NULL; Battleground* bg = NULL;
switch (data.bgTypeId) bg = BattlegroundMgr::bgtypeToBattleground[data.bgTypeId];
{
case BATTLEGROUND_AV: if (bg == NULL)
bg = new BattlegroundAV; return false;
break;
case BATTLEGROUND_WS:
bg = new BattlegroundWS;
break;
case BATTLEGROUND_AB:
bg = new BattlegroundAB;
break;
case BATTLEGROUND_NA:
bg = new BattlegroundNA;
break;
case BATTLEGROUND_BE:
bg = new BattlegroundBE;
break;
case BATTLEGROUND_EY:
bg = new BattlegroundEY;
break;
case BATTLEGROUND_RL:
bg = new BattlegroundRL;
break;
case BATTLEGROUND_SA:
bg = new BattlegroundSA;
break;
case BATTLEGROUND_DS:
bg = new BattlegroundDS;
break;
case BATTLEGROUND_RV:
bg = new BattlegroundRV;
break;
case BATTLEGROUND_IC:
bg = new BattlegroundIC;
break;
case BATTLEGROUND_AA:
bg = new Battleground;
break;
case BATTLEGROUND_RB:
bg = new Battleground;
break;
default:
return false;
}
bg->SetMapId(data.bgTypeId == BATTLEGROUND_RB ? randomBgDifficultyEntry.mapId : data.MapID); bg->SetMapId(data.bgTypeId == BATTLEGROUND_RB ? randomBgDifficultyEntry.mapId : data.MapID);
bg->SetBgTypeID(data.bgTypeId); bg->SetBgTypeID(data.bgTypeId);
@@ -796,69 +720,33 @@ bool BattlegroundMgr::IsArenaType(BattlegroundTypeId bgTypeId)
BattlegroundQueueTypeId BattlegroundMgr::BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType) BattlegroundQueueTypeId BattlegroundMgr::BGQueueTypeId(BattlegroundTypeId bgTypeId, uint8 arenaType)
{ {
switch (bgTypeId) if (arenaType) {
{ switch (arenaType) {
case BATTLEGROUND_AB: case ARENA_TYPE_2v2:
return BATTLEGROUND_QUEUE_AB; return BATTLEGROUND_QUEUE_2v2;
case BATTLEGROUND_AV: case ARENA_TYPE_3v3:
return BATTLEGROUND_QUEUE_AV; return BATTLEGROUND_QUEUE_3v3;
case BATTLEGROUND_EY: case ARENA_TYPE_5v5:
return BATTLEGROUND_QUEUE_EY; return BATTLEGROUND_QUEUE_5v5;
case BATTLEGROUND_IC: default:
return BATTLEGROUND_QUEUE_IC; return BATTLEGROUND_QUEUE_NONE;
case BATTLEGROUND_RB: }
return BATTLEGROUND_QUEUE_RB;
case BATTLEGROUND_SA:
return BATTLEGROUND_QUEUE_SA;
case BATTLEGROUND_WS:
return BATTLEGROUND_QUEUE_WS;
case BATTLEGROUND_AA:
case BATTLEGROUND_BE:
case BATTLEGROUND_DS:
case BATTLEGROUND_NA:
case BATTLEGROUND_RL:
case BATTLEGROUND_RV:
switch (arenaType)
{
case ARENA_TYPE_2v2:
return BATTLEGROUND_QUEUE_2v2;
case ARENA_TYPE_3v3:
return BATTLEGROUND_QUEUE_3v3;
case ARENA_TYPE_5v5:
return BATTLEGROUND_QUEUE_5v5;
default:
return BATTLEGROUND_QUEUE_NONE;
}
default:
return BATTLEGROUND_QUEUE_NONE;
} }
if (BattlegroundMgr::bgToQueue.find(bgTypeId) == BattlegroundMgr::bgToQueue.end()) {
return BATTLEGROUND_QUEUE_NONE;
}
return BattlegroundMgr::bgToQueue[bgTypeId];
} }
BattlegroundTypeId BattlegroundMgr::BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId) BattlegroundTypeId BattlegroundMgr::BGTemplateId(BattlegroundQueueTypeId bgQueueTypeId)
{ {
switch (bgQueueTypeId) if (BattlegroundMgr::queueToBg.find(bgQueueTypeId) == BattlegroundMgr::queueToBg.end()) {
{ return BattlegroundTypeId(0);
case BATTLEGROUND_QUEUE_WS:
return BATTLEGROUND_WS;
case BATTLEGROUND_QUEUE_AB:
return BATTLEGROUND_AB;
case BATTLEGROUND_QUEUE_AV:
return BATTLEGROUND_AV;
case BATTLEGROUND_QUEUE_EY:
return BATTLEGROUND_EY;
case BATTLEGROUND_QUEUE_SA:
return BATTLEGROUND_SA;
case BATTLEGROUND_QUEUE_IC:
return BATTLEGROUND_IC;
case BATTLEGROUND_QUEUE_RB:
return BATTLEGROUND_RB;
case BATTLEGROUND_QUEUE_2v2:
case BATTLEGROUND_QUEUE_3v3:
case BATTLEGROUND_QUEUE_5v5:
return BATTLEGROUND_AA;
default:
return BattlegroundTypeId(0); // used for unknown template (it existed and do nothing)
} }
return BattlegroundMgr::queueToBg[bgQueueTypeId];
} }
uint8 BattlegroundMgr::BGArenaType(BattlegroundQueueTypeId bgQueueTypeId) uint8 BattlegroundMgr::BGArenaType(BattlegroundQueueTypeId bgQueueTypeId)
@@ -1145,3 +1033,69 @@ void RandomBattlegroundSystem::BattlegroundCreated(BattlegroundTypeId bgTypeId)
if (bgTypeId == m_CurrentRandomBg) if (bgTypeId == m_CurrentRandomBg)
Update(0xffffffff); Update(0xffffffff);
} }
// init/update unordered_map
// Battlegrounds
std::unordered_map<int, BattlegroundQueueTypeId> BattlegroundMgr::bgToQueue = {
{ BATTLEGROUND_AV, BATTLEGROUND_QUEUE_AV},
{ BATTLEGROUND_WS, BATTLEGROUND_QUEUE_WS},
{ BATTLEGROUND_AB, BATTLEGROUND_QUEUE_AB},
{ BATTLEGROUND_EY, BATTLEGROUND_QUEUE_EY},
{ BATTLEGROUND_SA, BATTLEGROUND_QUEUE_SA},
{ BATTLEGROUND_IC, BATTLEGROUND_QUEUE_IC},
{ BATTLEGROUND_RB, BATTLEGROUND_QUEUE_RB},
// Arena Battlegrounds
{ BATTLEGROUND_NA, BattlegroundQueueTypeId(0)}, // Nagrand Arena
{ BATTLEGROUND_BE, BattlegroundQueueTypeId(0)}, // Blade's Edge Arena
{ BATTLEGROUND_AA, BattlegroundQueueTypeId(0)}, // All Arena
{ BATTLEGROUND_RL, BattlegroundQueueTypeId(0)}, // Ruins of Lordaernon
{ BATTLEGROUND_DS, BattlegroundQueueTypeId(0)}, // Dalaran Sewer
{ BATTLEGROUND_RV, BattlegroundQueueTypeId(0)}, // Ring of Valor
};
std::unordered_map<int, BattlegroundTypeId> BattlegroundMgr::queueToBg = {
{ BATTLEGROUND_QUEUE_NONE, BATTLEGROUND_TYPE_NONE },
{ BATTLEGROUND_QUEUE_AV, BATTLEGROUND_AV },
{ BATTLEGROUND_QUEUE_WS, BATTLEGROUND_WS },
{ BATTLEGROUND_QUEUE_AB, BATTLEGROUND_AB },
{ BATTLEGROUND_QUEUE_EY, BATTLEGROUND_EY },
{ BATTLEGROUND_QUEUE_SA, BATTLEGROUND_SA },
{ BATTLEGROUND_QUEUE_IC, BATTLEGROUND_IC },
{ BATTLEGROUND_QUEUE_RB, BATTLEGROUND_RB },
{ BATTLEGROUND_QUEUE_2v2, BATTLEGROUND_AA },
{ BATTLEGROUND_QUEUE_3v3, BATTLEGROUND_AA },
{ BATTLEGROUND_QUEUE_5v5, BATTLEGROUND_AA },
};
std::unordered_map<int, Battleground*> BattlegroundMgr::bgtypeToBattleground = {
{ BATTLEGROUND_AV, new BattlegroundAV },
{ BATTLEGROUND_WS, new BattlegroundWS },
{ BATTLEGROUND_AB, new BattlegroundAB },
{ BATTLEGROUND_NA, new BattlegroundNA },
{ BATTLEGROUND_BE, new BattlegroundBE },
{ BATTLEGROUND_EY, new BattlegroundEY },
{ BATTLEGROUND_RL, new BattlegroundRL },
{ BATTLEGROUND_SA, new BattlegroundSA },
{ BATTLEGROUND_DS, new BattlegroundDS },
{ BATTLEGROUND_RV, new BattlegroundRV },
{ BATTLEGROUND_IC, new BattlegroundIC },
{ BATTLEGROUND_AA, new Battleground },
{ BATTLEGROUND_RB, new Battleground },
};
std::unordered_map<int, bgRef> BattlegroundMgr::bgTypeToTemplate = {
{ BATTLEGROUND_AV, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundAV(*(BattlegroundAV*)bg_t); } },
{ BATTLEGROUND_WS, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundWS(*(BattlegroundWS*)bg_t); } },
{ BATTLEGROUND_AB, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundAB(*(BattlegroundAB*)bg_t); } },
{ BATTLEGROUND_NA, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundNA(*(BattlegroundNA*)bg_t); } },
{ BATTLEGROUND_BE, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundBE(*(BattlegroundBE*)bg_t); } },
{ BATTLEGROUND_EY, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundEY(*(BattlegroundEY*)bg_t); } },
{ BATTLEGROUND_RL, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundRL(*(BattlegroundRL*)bg_t); } },
{ BATTLEGROUND_SA, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundSA(*(BattlegroundSA*)bg_t); } },
{ BATTLEGROUND_DS, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundDS(*(BattlegroundDS*)bg_t); } },
{ BATTLEGROUND_RV, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundRV(*(BattlegroundRV*)bg_t); } },
{ BATTLEGROUND_IC, [](Battleground *bg_t) -> Battleground*{ return new BattlegroundIC(*(BattlegroundIC*)bg_t); } },
{ BATTLEGROUND_RB, [](Battleground *bg_t) -> Battleground*{ return new Battleground(*bg_t); }, },
{ BATTLEGROUND_AA, [](Battleground *bg_t) -> Battleground*{ return new Battleground(*bg_t); }, },
};
@@ -13,9 +13,12 @@
#include "BattlegroundQueue.h" #include "BattlegroundQueue.h"
#include "CreatureAIImpl.h" #include "CreatureAIImpl.h"
#include <ace/Singleton.h> #include <ace/Singleton.h>
#include <unordered_map>
typedef std::map<uint32, Battleground*> BattlegroundContainer; typedef std::map<uint32, Battleground*> BattlegroundContainer;
typedef UNORDERED_MAP<uint32, BattlegroundTypeId> BattleMastersMap; typedef UNORDERED_MAP<uint32, BattlegroundTypeId> BattleMastersMap;
typedef Battleground*(*bgRef)(Battleground*);
#define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // how many seconds in day #define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // how many seconds in day
@@ -133,6 +136,11 @@ class BattlegroundMgr
const BattlegroundContainer& GetBattlegroundList() { return m_Battlegrounds; } // pussywizard const BattlegroundContainer& GetBattlegroundList() { return m_Battlegrounds; } // pussywizard
RandomBattlegroundSystem RandomSystem; // pussywizard RandomBattlegroundSystem RandomSystem; // pussywizard
static std::unordered_map<int, BattlegroundQueueTypeId> bgToQueue; // BattlegroundTypeId -> BattlegroundQueueTypeId
static std::unordered_map<int, BattlegroundTypeId> queueToBg; // BattlegroundQueueTypeId -> BattlegroundTypeId
static std::unordered_map<int, Battleground*> bgtypeToBattleground; // BattlegroundTypeId -> Battleground*
static std::unordered_map<int, bgRef> bgTypeToTemplate; // BattlegroundTypeId -> bgRef
private: private:
bool CreateBattleground(CreateBattlegroundData& data); bool CreateBattleground(CreateBattlegroundData& data);
uint32 GetNextClientVisibleInstanceId(); uint32 GetNextClientVisibleInstanceId();
+12 -12
View File
@@ -3431,18 +3431,18 @@ enum DuelCompleteType
// handle the queue types and bg types separately to enable joining queue for different sized arenas at the same time // handle the queue types and bg types separately to enable joining queue for different sized arenas at the same time
enum BattlegroundQueueTypeId enum BattlegroundQueueTypeId
{ {
BATTLEGROUND_QUEUE_NONE = 0, BATTLEGROUND_QUEUE_NONE = 0,
BATTLEGROUND_QUEUE_AV = 1, BATTLEGROUND_QUEUE_AV = 1,
BATTLEGROUND_QUEUE_WS = 2, BATTLEGROUND_QUEUE_WS = 2,
BATTLEGROUND_QUEUE_AB = 3, BATTLEGROUND_QUEUE_AB = 3,
BATTLEGROUND_QUEUE_EY = 4, BATTLEGROUND_QUEUE_EY = 4,
BATTLEGROUND_QUEUE_SA = 5, BATTLEGROUND_QUEUE_SA = 5,
BATTLEGROUND_QUEUE_IC = 6, BATTLEGROUND_QUEUE_IC = 6,
BATTLEGROUND_QUEUE_RB = 7, BATTLEGROUND_QUEUE_RB = 7,
BATTLEGROUND_QUEUE_2v2 = 8, BATTLEGROUND_QUEUE_2v2 = 8,
BATTLEGROUND_QUEUE_3v3 = 9, BATTLEGROUND_QUEUE_3v3 = 9,
BATTLEGROUND_QUEUE_5v5 = 10, BATTLEGROUND_QUEUE_5v5 = 10,
MAX_BATTLEGROUND_QUEUE_TYPES MAX_BATTLEGROUND_QUEUE_TYPES = 20,
}; };
enum GroupJoinBattlegroundResult enum GroupJoinBattlegroundResult