aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Maps/Map.cpp
diff options
context:
space:
mode:
authorJeremy <Golrag@users.noreply.github.com>2024-03-28 19:29:22 +0100
committerGitHub <noreply@github.com>2024-03-28 19:29:22 +0100
commitbe11f42a16d1fa0482e9572bf54e99e4dedd3c78 (patch)
tree3d33413d7ed5cada34d7ced7f430380731160d5b /src/server/game/Maps/Map.cpp
parent78635f640ee3b632a487a50dcf492ae62c2a0933 (diff)
Core/Battlegrounds: Move to scripts (#29799)
* Introduce new BattlegroundScript class for map/bg specific scripts * Remove all sub, zone specific, battleground classes except Arena * Move all bg zone scripts to new BattlegroundScripts class in script folder * Remove ZoneScript from Battleground class * Remove some unused hooks from Battleground
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
-rw-r--r--src/server/game/Maps/Map.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index b603d704f97..aa0f35abf15 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -17,6 +17,8 @@
#include "Map.h"
#include "Battleground.h"
+#include "BattlegroundMgr.h"
+#include "BattlegroundScript.h"
#include "CellImpl.h"
#include "CharacterPackets.h"
#include "Containers.h"
@@ -3385,7 +3387,7 @@ TeamId InstanceMap::GetTeamIdInInstance() const
/* ******* Battleground Instance Maps ******* */
BattlegroundMap::BattlegroundMap(uint32 id, time_t expiry, uint32 InstanceId, Difficulty spawnMode)
- : Map(id, expiry, InstanceId, spawnMode), m_bg(nullptr)
+ : Map(id, expiry, InstanceId, spawnMode), m_bg(nullptr), _battlegroundScript(nullptr), _scriptId(0)
{
//lets initialize visibility distance for BG/Arenas
BattlegroundMap::InitVisibilityDistance();
@@ -3408,6 +3410,36 @@ void BattlegroundMap::InitVisibilityDistance()
m_VisibilityNotifyPeriod = IsBattleArena() ? World::GetVisibilityNotifyPeriodInArenas() : World::GetVisibilityNotifyPeriodInBG();
}
+std::string const& BattlegroundMap::GetScriptName() const
+{
+ return sObjectMgr->GetScriptName(_scriptId);
+}
+
+void BattlegroundMap::InitScriptData()
+{
+ if (_battlegroundScript)
+ return;
+
+ ASSERT(GetBG(), "Battleground not set yet!");
+
+ if (BattlegroundScriptTemplate const* scriptTemplate = sBattlegroundMgr->FindBattlegroundScriptTemplate(GetId(), GetBG()->GetTypeID()))
+ {
+ _scriptId = scriptTemplate->ScriptId;
+ _battlegroundScript.reset(sScriptMgr->CreateBattlegroundData(this));
+ }
+
+ // Make sure every battleground has a default script
+ if (!_battlegroundScript)
+ {
+ if (IsBattleArena())
+ _battlegroundScript = std::make_unique<ArenaScript>(this);
+ else
+ _battlegroundScript = std::make_unique<BattlegroundScript>(this);
+ }
+
+ _battlegroundScript->OnInit();
+}
+
TransferAbortParams BattlegroundMap::CannotEnter(Player* player)
{
if (player->GetMapRef().getTarget() == this)
@@ -3451,6 +3483,12 @@ void BattlegroundMap::RemoveAllPlayers()
player->TeleportTo(player->GetBattlegroundEntryPoint());
}
+void BattlegroundMap::Update(uint32 diff)
+{
+ Map::Update(diff);
+ _battlegroundScript->OnUpdate(diff);
+}
+
AreaTrigger* Map::GetAreaTrigger(ObjectGuid const& guid)
{
return _objectsStore.Find<AreaTrigger>(guid);