Core/Battlegrounds: Move to scripts And a lot of misc commits i couldn't recover.
Port From (https://github.com/TrinityCore/TrinityCore/commit/d0d5d309bb5877dc2fcb27f6cb123707a31ec1e8)
This commit is contained in:
+45
-12
@@ -60,17 +60,10 @@ namespace Game.Maps
|
||||
m_terrain.LoadMMapInstance(GetId(), GetInstanceId());
|
||||
|
||||
_worldStateValues = Global.WorldStateMgr.GetInitialWorldStatesForMap(this);
|
||||
|
||||
Global.OutdoorPvPMgr.CreateOutdoorPvPForMap(this);
|
||||
Global.BattleFieldMgr.CreateBattlefieldsForMap(this);
|
||||
|
||||
Global.ScriptMgr.OnCreateMap(this);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Global.ScriptMgr.OnDestroyMap(this);
|
||||
|
||||
// Delete all waiting spawns
|
||||
// This doesn't delete from database.
|
||||
UnloadAllRespawnInfos();
|
||||
@@ -86,9 +79,6 @@ namespace Game.Maps
|
||||
if (!m_scriptSchedule.Empty())
|
||||
Global.MapMgr.DecreaseScheduledScriptCount((uint)m_scriptSchedule.Count);
|
||||
|
||||
Global.OutdoorPvPMgr.DestroyOutdoorPvPForMap(this);
|
||||
Global.BattleFieldMgr.DestroyBattlefieldsForMap(this);
|
||||
|
||||
m_terrain.UnloadMMapInstance(GetId(), GetInstanceId());
|
||||
}
|
||||
|
||||
@@ -5273,6 +5263,10 @@ namespace Game.Maps
|
||||
|
||||
public class BattlegroundMap : Map
|
||||
{
|
||||
Battleground m_bg;
|
||||
BattlegroundScript _battlegroundScript;
|
||||
uint _scriptId;
|
||||
|
||||
public BattlegroundMap(uint id, uint expiry, uint InstanceId, Difficulty spawnMode)
|
||||
: base(id, expiry, InstanceId, spawnMode)
|
||||
{
|
||||
@@ -5285,6 +5279,37 @@ namespace Game.Maps
|
||||
m_VisibilityNotifyPeriod = IsBattleArena() ? Global.WorldMgr.GetVisibilityNotifyPeriodInArenas() : Global.WorldMgr.GetVisibilityNotifyPeriodInBG();
|
||||
}
|
||||
|
||||
string GetScriptName()
|
||||
{
|
||||
return Global.ObjectMgr.GetScriptName(_scriptId);
|
||||
}
|
||||
|
||||
public void InitScriptData()
|
||||
{
|
||||
if (_battlegroundScript != null)
|
||||
return;
|
||||
|
||||
Cypher.Assert(GetBG() != null, "Battleground not set yet!");
|
||||
|
||||
BattlegroundScriptTemplate scriptTemplate = Global.BattlegroundMgr.FindBattlegroundScriptTemplate(GetId(), GetBG().GetTypeID());
|
||||
if (scriptTemplate != null)
|
||||
{
|
||||
_scriptId = scriptTemplate.ScriptId;
|
||||
_battlegroundScript = Global.ScriptMgr.CreateBattlegroundData(this);
|
||||
}
|
||||
|
||||
// Make sure every battleground has a default script
|
||||
if (_battlegroundScript == null)
|
||||
{
|
||||
if (IsBattleArena())
|
||||
_battlegroundScript = new ArenaScript(this);
|
||||
else
|
||||
_battlegroundScript = new BattlegroundScript(this);
|
||||
}
|
||||
|
||||
_battlegroundScript.OnInit();
|
||||
}
|
||||
|
||||
public override TransferAbortParams CannotEnter(Player player)
|
||||
{
|
||||
if (player.GetMap() == this)
|
||||
@@ -5327,10 +5352,18 @@ namespace Game.Maps
|
||||
player.TeleportTo(player.GetBattlegroundEntryPoint());
|
||||
}
|
||||
|
||||
public override void Update(uint diff)
|
||||
{
|
||||
base.Update(diff);
|
||||
_battlegroundScript.OnUpdate(diff);
|
||||
}
|
||||
|
||||
public Battleground GetBG() { return m_bg; }
|
||||
public void SetBG(Battleground bg) { m_bg = bg; }
|
||||
|
||||
Battleground m_bg;
|
||||
public uint GetScriptId() { return _scriptId; }
|
||||
|
||||
public BattlegroundScript GetBattlegroundScript() { return _battlegroundScript; }
|
||||
}
|
||||
|
||||
public class TransferAbortParams
|
||||
@@ -5396,7 +5429,7 @@ namespace Game.Maps
|
||||
public float FloorZ;
|
||||
public bool outdoors = true;
|
||||
public ZLiquidStatus LiquidStatus;
|
||||
public WmoLocation? wmoLocation;
|
||||
public WmoLocation wmoLocation;
|
||||
public LiquidData LiquidInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +99,7 @@ namespace Game.Entities
|
||||
Cypher.Assert(map.IsBattlegroundOrArena());
|
||||
map.SetBG(bg);
|
||||
bg.SetBgMap(map);
|
||||
map.InitScriptData();
|
||||
map.InitSpawnGroupState();
|
||||
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.BattlegroundMapLoadGrids))
|
||||
@@ -198,7 +199,7 @@ namespace Game.Entities
|
||||
|
||||
if (map == null)
|
||||
{
|
||||
map = CreateInstance(mapId, newInstanceId, instanceLock, difficulty, player.GetTeamId(), group);
|
||||
map = CreateInstance(mapId, newInstanceId, instanceLock, difficulty, SharedConst.GetTeamIdForTeam(Global.CharacterCacheStorage.GetCharacterTeamByGuid(instanceOwnerGuid)), group);
|
||||
if (group != null)
|
||||
group.SetRecentInstance(mapId, instanceOwnerGuid, newInstanceId);
|
||||
else
|
||||
@@ -224,8 +225,14 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
i_maps[(map.GetId(), map.GetInstanceId())] = map;
|
||||
|
||||
Global.ScriptMgr.OnCreateMap(map);
|
||||
Global.OutdoorPvPMgr.CreateOutdoorPvPForMap(map);
|
||||
Global.BattleFieldMgr.CreateBattlefieldsForMap(map);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -320,6 +327,10 @@ namespace Game.Entities
|
||||
|
||||
map.UnloadAll();
|
||||
|
||||
Global.OutdoorPvPMgr.DestroyOutdoorPvPForMap(map);
|
||||
Global.BattleFieldMgr.DestroyBattlefieldsForMap(map);
|
||||
Global.ScriptMgr.OnDestroyMap(map);
|
||||
|
||||
// Free up the instance id and allow it to be reused for normal dungeons, bgs and arenas
|
||||
if (map.IsBattlegroundOrArena() || (map.IsDungeon() && !map.GetMapDifficulty().HasResetSchedule()))
|
||||
FreeInstanceId(map.GetInstanceId());
|
||||
@@ -337,11 +348,17 @@ namespace Game.Entities
|
||||
public void UnloadAll()
|
||||
{
|
||||
// first unload maps
|
||||
foreach (var pair in i_maps)
|
||||
pair.Value.UnloadAll();
|
||||
foreach (var (_, map) in i_maps)
|
||||
{
|
||||
map.UnloadAll();
|
||||
|
||||
foreach (var pair in i_maps)
|
||||
pair.Value.Dispose();
|
||||
Global.OutdoorPvPMgr.DestroyOutdoorPvPForMap(map);
|
||||
Global.BattleFieldMgr.DestroyBattlefieldsForMap(map);
|
||||
Global.ScriptMgr.OnDestroyMap(map);
|
||||
}
|
||||
|
||||
foreach (var (_, map) in i_maps)
|
||||
map.Dispose();
|
||||
|
||||
i_maps.Clear();
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace Game.Maps
|
||||
{
|
||||
public class ZoneScript
|
||||
{
|
||||
protected EventMap _events = new();
|
||||
protected TaskScheduler _scheduler = new();
|
||||
|
||||
public virtual void TriggerGameEvent(uint gameEventId, WorldObject source = null, WorldObject target = null)
|
||||
{
|
||||
if (source != null)
|
||||
@@ -48,8 +51,6 @@ namespace Game.Maps
|
||||
|
||||
public virtual bool CanCaptureFlag(AreaTrigger areaTrigger, Player player) { return false; }
|
||||
public virtual void OnCaptureFlag(AreaTrigger areaTrigger, Player player) { }
|
||||
|
||||
protected EventMap _events = new();
|
||||
}
|
||||
|
||||
public class ControlZoneHandler
|
||||
|
||||
Reference in New Issue
Block a user