Skip to content

Commit

Permalink
feat(Core/Battlegrounds) Reworked enhanced bg system for modules (#2521)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shard-MW authored and FrancescoBorzi committed Jan 19, 2020
1 parent bb42c7c commit eadcb1a
Show file tree
Hide file tree
Showing 6 changed files with 658 additions and 601 deletions.
35 changes: 31 additions & 4 deletions src/server/game/Battlegrounds/BattlegroundMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ void BattlegroundMgr::BuildPvpLogDataPacket(WorldPacket* data, Battleground* bg)
}
*data << uint32(itr2->second->DamageDone); // damage done
*data << uint32(itr2->second->HealingDone); // healing done
switch (bg->GetBgTypeID()) // battleground specific things

BattlegroundTypeId bgTypeId = bg->GetBgTypeID();
switch (bgTypeId) // battleground specific things
{
case BATTLEGROUND_RB:
switch (bg->GetMapId())
Expand Down Expand Up @@ -305,7 +307,10 @@ void BattlegroundMgr::BuildPvpLogDataPacket(WorldPacket* data, Battleground* bg)
*data << uint32(((BattlegroundICScore*)itr2->second)->BasesAssaulted); // bases asssulted
*data << uint32(((BattlegroundICScore*)itr2->second)->BasesDefended); // bases defended
default:
*data << uint32(0);
if (BattlegroundMgr::getBgFromMap.find(bg->GetMapId()) != BattlegroundMgr::getBgFromMap.end())
BattlegroundMgr::getBgFromMap[bg->GetMapId()](data, itr2);
else
*data << uint32(0);
break;
}
break;
Expand Down Expand Up @@ -350,13 +355,16 @@ void BattlegroundMgr::BuildPvpLogDataPacket(WorldPacket* data, Battleground* bg)
*data << uint32(0);
break;
default:
*data << uint32(0);
if (BattlegroundMgr::getBgFromTypeID.find(bgTypeId) != BattlegroundMgr::getBgFromTypeID.end())
BattlegroundMgr::getBgFromTypeID[bgTypeId](data, itr2, bg);
else
*data << uint32(0);
break;
}
// should never happen
if (++scoreCount >= bg->GetMaxPlayersPerTeam()*2 && itr != bg->GetPlayerScoresEnd())
{
sLog->outMisc("Battleground %u scoreboard has more entries (%u) than allowed players in this bg (%u)", bg->GetBgTypeID(), bg->GetPlayerScoresSize(), bg->GetMaxPlayersPerTeam()*2);
sLog->outMisc("Battleground %u scoreboard has more entries (%u) than allowed players in this bg (%u)", bgTypeId, bg->GetPlayerScoresSize(), bg->GetMaxPlayersPerTeam()*2);
break;
}
}
Expand Down Expand Up @@ -1091,3 +1099,22 @@ std::unordered_map<int, bgRef> BattlegroundMgr::bgTypeToTemplate = {
{ BATTLEGROUND_RB, [](Battleground *bg_t) -> Battleground*{ return new Battleground(*bg_t); }, },
{ BATTLEGROUND_AA, [](Battleground *bg_t) -> Battleground*{ return new Battleground(*bg_t); }, },
};

std::unordered_map<int, bgMapRef> BattlegroundMgr::getBgFromMap = {};

std::unordered_map<int, bgTypeRef> BattlegroundMgr::getBgFromTypeID = {
{
BATTLEGROUND_RB,
[](WorldPacket* data, Battleground::BattlegroundScoreMap::const_iterator itr2, Battleground* bg)
{
if (BattlegroundMgr::getBgFromMap.find(bg->GetMapId()) == BattlegroundMgr::getBgFromMap.end()) // this should not happen
{
*data << uint32(0);
}
else
{
BattlegroundMgr::getBgFromMap[bg->GetMapId()](data, itr2);
}
}
}
};
13 changes: 9 additions & 4 deletions src/server/game/Battlegrounds/BattlegroundMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ typedef std::map<uint32, Battleground*> BattlegroundContainer;
typedef std::unordered_map<uint32, BattlegroundTypeId> BattleMastersMap;
typedef Battleground*(*bgRef)(Battleground*);

typedef void(*bgMapRef)(WorldPacket*, Battleground::BattlegroundScoreMap::const_iterator);
typedef void(*bgTypeRef)(WorldPacket*, Battleground::BattlegroundScoreMap::const_iterator, Battleground*);

#define BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY 86400 // how many seconds in day

struct CreateBattlegroundData
Expand Down Expand Up @@ -118,10 +121,12 @@ class BattlegroundMgr

const BattlegroundContainer& GetBattlegroundList() { return m_Battlegrounds; } // 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
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
static std::unordered_map<int, bgMapRef> getBgFromMap; // BattlegroundMapID -> bgMapRef
static std::unordered_map<int, bgTypeRef> getBgFromTypeID; // BattlegroundTypeID -> bgTypeRef

private:
bool CreateBattleground(CreateBattlegroundData& data);
Expand Down
29 changes: 19 additions & 10 deletions src/server/game/Entities/GameObject/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1780,17 +1780,24 @@ void GameObject::Use(Unit* user)
GameObjectTemplate const* info = GetGOInfo();
if (info)
{
switch (info->entry)
if (GameObject::gameObjectToEventFlag.find(info->entry) != GameObject::gameObjectToEventFlag.end())
{
case 179785: // Silverwing Flag
case 179786: // Warsong Flag
if (bg->GetBgTypeID(true) == BATTLEGROUND_WS)
bg->EventPlayerClickedOnFlag(player, this);
break;
case 184142: // Netherstorm Flag
if (bg->GetBgTypeID(true) == BATTLEGROUND_EY)
bg->EventPlayerClickedOnFlag(player, this);
break;
GameObject::gameObjectToEventFlag[info->entry](player, this, bg);
}
else
{
switch (info->entry)
{
case 179785: // Silverwing Flag
case 179786: // Warsong Flag
if (bg->GetBgTypeID(true) == BATTLEGROUND_WS)
bg->EventPlayerClickedOnFlag(player, this);
break;
case 184142: // Netherstorm Flag
if (bg->GetBgTypeID(true) == BATTLEGROUND_EY)
bg->EventPlayerClickedOnFlag(player, this);
break;
}
}
}
//this cause to call return, all flags must be deleted here!!
Expand Down Expand Up @@ -2490,3 +2497,5 @@ void GameObject::UpdateModelPosition()
GetMap()->InsertGameObjectModel(*m_model);
}
}

std::unordered_map<int, goEventFlag> GameObject::gameObjectToEventFlag = {};
4 changes: 4 additions & 0 deletions src/server/game/Entities/GameObject/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Transport;
class StaticTransport;
class MotionTransport;

typedef void(*goEventFlag)(Player*, GameObject*, Battleground*);

#define MAX_GAMEOBJECT_QUEST_ITEMS 6

// from `gameobject_template`
Expand Down Expand Up @@ -879,6 +881,8 @@ class GameObject : public WorldObject, public GridObject<GameObject>, public Mov

void UpdateModelPosition();

static std::unordered_map<int, goEventFlag> gameObjectToEventFlag; // Gameobject -> event flag

protected:
bool AIM_Initialize();
void UpdateModel(); // updates model in case displayId were changed
Expand Down
Loading

0 comments on commit eadcb1a

Please sign in to comment.