Core/Maps: Fixes nulls which unloading instance maps.

This commit is contained in:
hondacrx
2018-05-26 13:12:28 -04:00
parent 41bce64ffc
commit d94ad385b1
3 changed files with 29 additions and 24 deletions
+22 -19
View File
@@ -36,7 +36,7 @@ using System.Linq;
namespace Game.Maps
{
public class Map
public class Map : IDisposable
{
public Map(uint id, long expiry, uint instanceId, Difficulty spawnmode, Map parent = null)
{
@@ -86,6 +86,27 @@ namespace Game.Maps
Global.ScriptMgr.OnCreateMap(this);
}
public void Dispose()
{
Global.ScriptMgr.OnDestroyMap(this);
for (var i = 0; i < i_worldObjects.Count; ++i)
{
WorldObject obj = i_worldObjects[i];
Contract.Assert(obj.IsWorldObject());
obj.RemoveFromWorld();
obj.ResetMap();
}
if (!m_scriptSchedule.Empty())
Global.MapMgr.DecreaseScheduledScriptCount((uint)m_scriptSchedule.Count);
if (m_parentMap == this)
m_childTerrainMaps = null;
Global.MMapMgr.unloadMapInstance(GetId(), i_InstanceId);
}
public static bool ExistMap(uint mapid, uint gx, uint gy)
{
string fileName = $"{Global.WorldMgr.GetDataPath()}/maps/{mapid:D4}_{gx:D2}_{gy:D2}.map";
@@ -1647,24 +1668,6 @@ namespace Game.Maps
_corpsesByCell.Clear();
_corpsesByPlayer.Clear();
_corpseBones.Clear();
Global.ScriptMgr.OnDestroyMap(this);
for (var i = 0; i < i_worldObjects.Count; ++i)
{
WorldObject obj = i_worldObjects[i];
Contract.Assert(obj.IsWorldObject());
obj.RemoveFromWorld();
obj.ResetMap();
}
if (!m_scriptSchedule.Empty())
Global.MapMgr.DecreaseScheduledScriptCount((uint)m_scriptSchedule.Count);
if (m_parentMap == this)
m_childTerrainMaps = null;
Global.MMapMgr.unloadMapInstance(GetId(), i_InstanceId);
}
private GridMap GetGridMap(float x, float y)