Core/Maps: Use FindMap instead of CreateBaseMap in places where the intent was to check for a existing map (and a loaded grid on that map)

Port From (https://github.com/TrinityCore/TrinityCore/commit/4c173e4b7b35161fcaaa4917da8fde2e4f3cbdd8)
This commit is contained in:
hondacrx
2020-07-24 18:14:35 -04:00
parent 97ee7c437d
commit b628eaec35
4 changed files with 37 additions and 47 deletions
+4 -17
View File
@@ -663,21 +663,13 @@ namespace Game.BattleFields
public Creature SpawnCreature(uint entry, Position pos)
{
//Get map object
Map map = Global.MapMgr.CreateBaseMap(m_MapId);
if (!map)
{
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnCreature: Can't create creature entry: {0} map not found", entry);
return null;
}
if (Global.ObjectMgr.GetCreatureTemplate(entry) == null)
{
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnCreature: entry {0} does not exist.", entry);
return null;
}
Creature creature = Creature.CreateCreature(entry, map, pos);
Creature creature = Creature.CreateCreature(entry, m_Map, pos);
if (!creature)
{
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnCreature: Can't create creature entry: {0}", entry);
@@ -687,7 +679,7 @@ namespace Game.BattleFields
creature.SetHomePosition(pos);
// Set creature in world
map.AddToMap(creature);
m_Map.AddToMap(creature);
creature.SetActive(true);
return creature;
@@ -696,11 +688,6 @@ namespace Game.BattleFields
// Method for spawning gameobject on map
public GameObject SpawnGameObject(uint entry, Position pos, Quaternion rotation)
{
// Get map object
Map map = Global.MapMgr.CreateBaseMap(m_MapId);
if (!map)
return null;
if (Global.ObjectMgr.GetGameObjectTemplate(entry) == null)
{
Log.outError(LogFilter.Battlefield, "Battlefield.SpawnGameObject: GameObject template {0} not found in database! Battlefield not created!", entry);
@@ -708,7 +695,7 @@ namespace Game.BattleFields
}
// Create gameobject
GameObject go = GameObject.CreateGameObject(entry, map, pos, rotation, 255, GameObjectState.Ready);
GameObject go = GameObject.CreateGameObject(entry, m_Map, pos, rotation, 255, GameObjectState.Ready);
if (!go)
{
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnGameObject: Cannot create gameobject template {1}! Battlefield not created!", entry);
@@ -716,7 +703,7 @@ namespace Game.BattleFields
}
// Add to world
map.AddToMap(go);
m_Map.AddToMap(go);
go.SetActive(true);
return go;
@@ -34,7 +34,7 @@ namespace Game.BattleFields
m_BattleId = BattlefieldIds.WG;
m_ZoneId = WGConst.ZoneId;
m_MapId = WGConst.MapId;
m_Map = Global.MapMgr.FindMap(m_MapId, 0);
m_Map = Global.MapMgr.CreateBaseMap(m_MapId);
m_MaxPlayer = WorldConfig.GetUIntValue(WorldCfg.WintergraspPlrMax);
m_IsEnabled = WorldConfig.GetBoolValue(WorldCfg.WintergraspEnable);
+4 -4
View File
@@ -1170,9 +1170,9 @@ namespace Game
Global.ObjectMgr.AddCreatureToGrid(guid, data);
// Spawn if necessary (loaded grids only)
Map map = Global.MapMgr.CreateBaseMap(data.mapid);
Map map = Global.MapMgr.FindMap(data.mapid, 0);
// We use spawn coords to spawn
if (!map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
if (map != null && !map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
Creature.CreateCreatureFromDB(guid, map);
}
}
@@ -1193,9 +1193,9 @@ namespace Game
Global.ObjectMgr.AddGameObjectToGrid(guid, data);
// Spawn if necessary (loaded grids only)
// this base map checked as non-instanced and then only existed
Map map = Global.MapMgr.CreateBaseMap(data.mapid);
Map map = Global.MapMgr.FindMap(data.mapid, 0);
// We use current coords to unspawn, not spawn coords since creature can have changed grid
if (!map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
if (map != null && !map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
{
GameObject pGameobject = GameObject.CreateGameObjectFromDB(guid, map, false);
// @todo find out when it is add to map
+15 -12
View File
@@ -655,8 +655,8 @@ namespace Game
if (data != null)
{
Global.ObjectMgr.RemoveCreatureFromGrid(guid, data);
Map map = Global.MapMgr.CreateBaseMap(data.mapid);
if (!map.Instanceable())
Map map = Global.MapMgr.FindMap(data.mapid, 0);
if (map != null && !map.Instanceable())
{
var creatureBounds = map.GetCreatureBySpawnIdStore().LookupByKey(guid);
foreach (var creature in creatureBounds)
@@ -671,9 +671,8 @@ namespace Game
if (data != null)
{
Global.ObjectMgr.RemoveGameObjectFromGrid(guid, data);
Map map = Global.MapMgr.CreateBaseMap(data.mapid);
if (!map.Instanceable())
Map map = Global.MapMgr.FindMap(data.mapid, 0);
if (map != null && !map.Instanceable())
{
var gameobjectBounds = map.GetGameObjectBySpawnIdStore().LookupByKey(guid);
foreach (var go in gameobjectBounds)
@@ -857,28 +856,31 @@ namespace Game
switch (typeof(T).Name)
{
case "Creature":
{
CreatureData data = Global.ObjectMgr.GetCreatureData(obj.guid);
if (data != null)
{
Global.ObjectMgr.AddCreatureToGrid(obj.guid, data);
// Spawn if necessary (loaded grids only)
Map map = Global.MapMgr.CreateBaseMap(data.mapid);
Map map = Global.MapMgr.FindMap(data.mapid, 0);
// We use spawn coords to spawn
if (!map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
if (map != null && !map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
Creature.CreateCreatureFromDB(obj.guid, map);
}
}
break;
case "GameObject":
GameObjectData data_ = Global.ObjectMgr.GetGOData(obj.guid);
if (data_ != null)
{
Global.ObjectMgr.AddGameObjectToGrid(obj.guid, data_);
GameObjectData data = Global.ObjectMgr.GetGOData(obj.guid);
if (data != null)
{
Global.ObjectMgr.AddGameObjectToGrid(obj.guid, data);
// Spawn if necessary (loaded grids only)
// this base map checked as non-instanced and then only existed
Map map = Global.MapMgr.CreateBaseMap(data_.mapid);
Map map = Global.MapMgr.FindMap(data.mapid, 0);
// We use current coords to unspawn, not spawn coords since creature can have changed grid
if (!map.Instanceable() && map.IsGridLoaded(data_.posX, data_.posY))
if (map != null && !map.Instanceable() && map.IsGridLoaded(data.posX, data.posY))
{
GameObject go = GameObject.CreateGameObjectFromDB(obj.guid, map, false);
if (go)
@@ -888,6 +890,7 @@ namespace Game
}
}
}
}
break;
case "Pool":
Global.PoolMgr.SpawnPool((uint)obj.guid);