Core/Battlefields: Refactor Battlefield creation to be linked to host map creation instead of having globally accessible objects

This commit is contained in:
Shauren authored and Ovahlord committed 2022-12-26 13:24:59 +01:00
1 parent 28ad85c160
commit 265c2fa508
22 files changed
+253 -192

No files matched your search

@@ -270,8 +270,6 @@ bool BattlefieldTB::SetupBattlefield()
m_TypeId = BATTLEFIELD_TB; // See enum BattlefieldTypes
m_BattleId = BATTLEFIELD_BATTLEID_TB;
m_ZoneId = BATTLEFIELD_TB_ZONEID;
m_MapId = BATTLEFIELD_TB_MAPID;
m_Map = sMapMgr->CreateBaseMap(m_MapId);
InitStalker(NPC_DEBUG_ANNOUNCER, TolBaradDebugAnnouncerPos);
@@ -982,9 +980,9 @@ class Battlefield_tol_barad : public BattlefieldScript
public:
Battlefield_tol_barad() : BattlefieldScript("battlefield_tb") { }
Battlefield* GetBattlefield() const override
Battlefield* GetBattlefield(Map* map) const override
{
return new BattlefieldTB();
return new BattlefieldTB(map);
}
};
@@ -346,6 +346,7 @@ class TolBaradCapturePoint : public BfCapturePoint
class BattlefieldTB : public Battlefield
{
public:
using Battlefield::Battlefield;
~BattlefieldTB();
void OnStartGrouping() override;
@@ -412,8 +412,6 @@ bool BattlefieldWG::SetupBattlefield()
m_TypeId = BATTLEFIELD_WG; // See enum BattlefieldTypes
m_BattleId = BATTLEFIELD_BATTLEID_WG;
m_ZoneId = AREA_WINTERGRASP;
m_MapId = BATTLEFIELD_WG_MAPID;
m_Map = sMapMgr->CreateBaseMap(m_MapId);
InitStalker(BATTLEFIELD_WG_NPC_STALKER, WintergraspStalkerPos);
@@ -1454,6 +1452,26 @@ void BfWGGameObjectBuilding::Init(GameObject* go)
}
_state = WintergraspGameObjectState(sWorldStateMgr->GetValue(_worldState, _wg->GetMap()));
if (_state == BATTLEFIELD_WG_OBJECTSTATE_NONE)
{
// set to default state based on type
switch (_teamControl)
{
case TEAM_ALLIANCE:
_state = BATTLEFIELD_WG_OBJECTSTATE_ALLIANCE_INTACT;
break;
case TEAM_HORDE:
_state = BATTLEFIELD_WG_OBJECTSTATE_HORDE_INTACT;
break;
case TEAM_NEUTRAL:
_state = BATTLEFIELD_WG_OBJECTSTATE_NEUTRAL_INTACT;
break;
default:
break;
}
sWorldStateMgr->SetValueAndSaveInDb(_worldState, _state, false, _wg->GetMap());
}
switch (_state)
{
case BATTLEFIELD_WG_OBJECTSTATE_NEUTRAL_INTACT:
@@ -1751,9 +1769,9 @@ class Battlefield_wintergrasp : public BattlefieldScript
public:
Battlefield_wintergrasp() : BattlefieldScript("battlefield_wg") { }
Battlefield* GetBattlefield() const override
Battlefield* GetBattlefield(Map* map) const override
{
return new BattlefieldWG();
return new BattlefieldWG(map);
}
};
@@ -1771,7 +1789,7 @@ public:
if (!killer || killer->GetTypeId() != TYPEID_PLAYER)
return;
BattlefieldWG* wintergrasp = static_cast<BattlefieldWG*>(sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG));
BattlefieldWG* wintergrasp = static_cast<BattlefieldWG*>(sBattlefieldMgr->GetBattlefieldByBattleId(killer->GetMap(), BATTLEFIELD_BATTLEID_WG));
if (!wintergrasp)
return;
@@ -209,6 +209,7 @@ class WintergraspCapturePoint : public BfCapturePoint
class BattlefieldWG : public Battlefield
{
public:
using Battlefield::Battlefield;
~BattlefieldWG();
/**
* \brief Called when the battle start
+88 -76
View File
@@ -25,7 +25,9 @@ EndScriptData */
#include "ScriptMgr.h"
#include "BattlefieldMgr.h"
#include "Chat.h"
#include "Player.h"
#include "RBAC.h"
#include "WorldSession.h"
class bf_commandscript : public CommandScript
{
@@ -51,123 +53,133 @@ public:
static bool HandleBattlefieldStart(ChatHandler* handler, char const* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
if (WorldSession* session = handler->GetSession())
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(session->GetPlayer()->GetMap(), battleid);
if (!bf)
return false;
if (!bf)
return false;
bf->StartBattle();
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command start used)");
bf->StartBattle();
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command start used)");
}
return true;
}
static bool HandleBattlefieldEnd(ChatHandler* handler, char const* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
if (WorldSession* session = handler->GetSession())
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(session->GetPlayer()->GetMap(), battleid);
if (!bf)
return false;
if (!bf)
return false;
bf->EndBattle(true);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command stop used)");
bf->EndBattle(true);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command stop used)");
}
return true;
}
static bool HandleBattlefieldEnable(ChatHandler* handler, char const* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
if (!bf)
return false;
if (bf->IsEnabled())
if (WorldSession* session = handler->GetSession())
{
bf->ToggleBattlefield(false);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp is disabled");
}
else
{
bf->ToggleBattlefield(true);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp is enabled");
}
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(session->GetPlayer()->GetMap(), battleid);
if (!bf)
return false;
if (bf->IsEnabled())
{
bf->ToggleBattlefield(false);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp is disabled");
}
else
{
bf->ToggleBattlefield(true);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp is enabled");
}
}
return true;
}
static bool HandleBattlefieldSwitch(ChatHandler* handler, char const* args)
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
if (WorldSession* session = handler->GetSession())
{
uint32 battleid = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
battleid = atoi(battleid_str);
battleid = atoi(battleid_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(session->GetPlayer()->GetMap(), battleid);
if (!bf)
return false;
bf->EndBattle(false);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command switch used)");
if (!bf)
return false;
bf->EndBattle(false);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command switch used)");
}
return true;
}
static bool HandleBattlefieldTimer(ChatHandler* handler, char const* args)
{
uint32 battleid = 0;
uint32 time = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
char* time_str = strtok(nullptr, " ");
if (!time_str)
return false;
if (WorldSession* session = handler->GetSession())
{
uint32 battleid = 0;
uint32 time = 0;
char* battleid_str = strtok((char*)args, " ");
if (!battleid_str)
return false;
char* time_str = strtok(nullptr, " ");
if (!time_str)
return false;
battleid = atoi(battleid_str);
battleid = atoi(battleid_str);
time = atoi(time_str);
time = atoi(time_str);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleid);
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(session->GetPlayer()->GetMap(), battleid);
if (!bf)
return false;
bf->SetTimer(time * IN_MILLISECONDS);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command timer used)");
if (!bf)
return false;
bf->SetTimer(time * IN_MILLISECONDS);
if (battleid == 1)
handler->SendGlobalGMSysMessage("Wintergrasp (Command timer used)");
}
return true;
}
};
+1 -1
View File
@@ -1722,7 +1722,7 @@ public:
nearestLoc = bg->GetClosestGraveyard(player);
else
{
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetZoneId()))
if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(player->GetMap(), player->GetZoneId()))
nearestLoc = bf->GetClosestGraveyard(player);
else
nearestLoc = sObjectMgr->GetClosestGraveyard(*player, player->GetTeam(), player);
@@ -173,7 +173,7 @@ class npc_wg_demolisher_engineer : public CreatureScript
private:
bool CanBuild() const
{
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return false;
@@ -215,7 +215,7 @@ class npc_wg_spirit_guide : public CreatureScript
if (me->IsQuestGiver())
player->PrepareQuestMenu(me->GetGUID());
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return true;
@@ -233,7 +233,7 @@ class npc_wg_spirit_guide : public CreatureScript
uint32 const action = player->PlayerTalkClass->GetGossipOptionAction(gossipListId);
CloseGossipMenuFor(player);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (wintergrasp)
{
GraveyardVect gy = wintergrasp->GetGraveyardVector();
@@ -295,7 +295,7 @@ class npc_wg_queue : public CreatureScript
if (me->IsQuestGiver())
player->PrepareQuestMenu(me->GetGUID());
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return true;
@@ -323,7 +323,7 @@ class npc_wg_queue : public CreatureScript
{
CloseGossipMenuFor(player);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(me->GetMap(), BATTLEFIELD_BATTLEID_WG);
if (!wintergrasp)
return true;
@@ -496,10 +496,10 @@ class spell_wintergrasp_defender_teleport : public SpellScriptLoader
{
SpellCastResult CheckCast()
{
if (Battlefield* wg = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG))
if (Player* target = GetExplTargetUnit()->ToPlayer())
if (Player* target = GetExplTargetUnit()->ToPlayer())
if (Battlefield* wg = sBattlefieldMgr->GetBattlefieldByBattleId(target->GetMap(), BATTLEFIELD_BATTLEID_WG))
// check if we are in Wintergrasp at all, SotA uses same teleport spells
if ((target->GetZoneId() == 4197 && target->GetTeamId() != wg->GetDefenderTeam()) || target->HasAura(SPELL_WINTERGRASP_TELEPORT_TRIGGER))
if ((target->GetZoneId() == AREA_WINTERGRASP && target->GetTeamId() != wg->GetDefenderTeam()) || target->HasAura(SPELL_WINTERGRASP_TELEPORT_TRIGGER))
return SPELL_FAILED_BAD_TARGETS;
return SPELL_CAST_OK;
}
@@ -549,10 +549,12 @@ class condition_is_wintergrasp_horde : public ConditionScript
public:
condition_is_wintergrasp_horde() : ConditionScript("condition_is_wintergrasp_horde") { }
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& /* sourceInfo */)
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& sourceInfo)
{
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
if (wintergrasp && wintergrasp->IsEnabled() && wintergrasp->GetDefenderTeam() == TEAM_HORDE)
if (!sourceInfo.mConditionMap)
return false;
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(sourceInfo.mConditionMap, BATTLEFIELD_BATTLEID_WG);
if (wintergrasp->IsEnabled() && wintergrasp->GetDefenderTeam() == TEAM_HORDE)
return true;
return false;
}
@@ -563,10 +565,12 @@ class condition_is_wintergrasp_alliance : public ConditionScript
public:
condition_is_wintergrasp_alliance() : ConditionScript("condition_is_wintergrasp_alliance") { }
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& /* sourceInfo */)
bool OnConditionCheck(Condition const* /* condition */, ConditionSourceInfo& sourceInfo)
{
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG);
if (wintergrasp && wintergrasp->IsEnabled() && wintergrasp->GetDefenderTeam() == TEAM_ALLIANCE)
if (!sourceInfo.mConditionMap)
return false;
Battlefield* wintergrasp = sBattlefieldMgr->GetBattlefieldByBattleId(sourceInfo.mConditionMap, BATTLEFIELD_BATTLEID_WG);
if (wintergrasp->IsEnabled() && wintergrasp->GetDefenderTeam() == TEAM_ALLIANCE)
return true;
return false;
}