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:
@@ -663,21 +663,13 @@ namespace Game.BattleFields
|
|||||||
|
|
||||||
public Creature SpawnCreature(uint entry, Position pos)
|
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)
|
if (Global.ObjectMgr.GetCreatureTemplate(entry) == null)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnCreature: entry {0} does not exist.", entry);
|
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnCreature: entry {0} does not exist.", entry);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Creature creature = Creature.CreateCreature(entry, map, pos);
|
Creature creature = Creature.CreateCreature(entry, m_Map, pos);
|
||||||
if (!creature)
|
if (!creature)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnCreature: Can't create creature entry: {0}", entry);
|
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnCreature: Can't create creature entry: {0}", entry);
|
||||||
@@ -687,7 +679,7 @@ namespace Game.BattleFields
|
|||||||
creature.SetHomePosition(pos);
|
creature.SetHomePosition(pos);
|
||||||
|
|
||||||
// Set creature in world
|
// Set creature in world
|
||||||
map.AddToMap(creature);
|
m_Map.AddToMap(creature);
|
||||||
creature.SetActive(true);
|
creature.SetActive(true);
|
||||||
|
|
||||||
return creature;
|
return creature;
|
||||||
@@ -696,11 +688,6 @@ namespace Game.BattleFields
|
|||||||
// Method for spawning gameobject on map
|
// Method for spawning gameobject on map
|
||||||
public GameObject SpawnGameObject(uint entry, Position pos, Quaternion rotation)
|
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)
|
if (Global.ObjectMgr.GetGameObjectTemplate(entry) == null)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Battlefield, "Battlefield.SpawnGameObject: GameObject template {0} not found in database! Battlefield not created!", entry);
|
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
|
// 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)
|
if (!go)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Battlefield, "Battlefield:SpawnGameObject: Cannot create gameobject template {1}! Battlefield not created!", entry);
|
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
|
// Add to world
|
||||||
map.AddToMap(go);
|
m_Map.AddToMap(go);
|
||||||
go.SetActive(true);
|
go.SetActive(true);
|
||||||
|
|
||||||
return go;
|
return go;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace Game.BattleFields
|
|||||||
m_BattleId = BattlefieldIds.WG;
|
m_BattleId = BattlefieldIds.WG;
|
||||||
m_ZoneId = WGConst.ZoneId;
|
m_ZoneId = WGConst.ZoneId;
|
||||||
m_MapId = WGConst.MapId;
|
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_MaxPlayer = WorldConfig.GetUIntValue(WorldCfg.WintergraspPlrMax);
|
||||||
m_IsEnabled = WorldConfig.GetBoolValue(WorldCfg.WintergraspEnable);
|
m_IsEnabled = WorldConfig.GetBoolValue(WorldCfg.WintergraspEnable);
|
||||||
|
|||||||
@@ -1170,9 +1170,9 @@ namespace Game
|
|||||||
Global.ObjectMgr.AddCreatureToGrid(guid, data);
|
Global.ObjectMgr.AddCreatureToGrid(guid, data);
|
||||||
|
|
||||||
// Spawn if necessary (loaded grids only)
|
// 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
|
// 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);
|
Creature.CreateCreatureFromDB(guid, map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1193,9 +1193,9 @@ namespace Game
|
|||||||
Global.ObjectMgr.AddGameObjectToGrid(guid, data);
|
Global.ObjectMgr.AddGameObjectToGrid(guid, data);
|
||||||
// Spawn if necessary (loaded grids only)
|
// Spawn if necessary (loaded grids only)
|
||||||
// this base map checked as non-instanced and then only existed
|
// 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
|
// 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);
|
GameObject pGameobject = GameObject.CreateGameObjectFromDB(guid, map, false);
|
||||||
// @todo find out when it is add to map
|
// @todo find out when it is add to map
|
||||||
|
|||||||
@@ -655,8 +655,8 @@ namespace Game
|
|||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
Global.ObjectMgr.RemoveCreatureFromGrid(guid, data);
|
Global.ObjectMgr.RemoveCreatureFromGrid(guid, data);
|
||||||
Map map = Global.MapMgr.CreateBaseMap(data.mapid);
|
Map map = Global.MapMgr.FindMap(data.mapid, 0);
|
||||||
if (!map.Instanceable())
|
if (map != null && !map.Instanceable())
|
||||||
{
|
{
|
||||||
var creatureBounds = map.GetCreatureBySpawnIdStore().LookupByKey(guid);
|
var creatureBounds = map.GetCreatureBySpawnIdStore().LookupByKey(guid);
|
||||||
foreach (var creature in creatureBounds)
|
foreach (var creature in creatureBounds)
|
||||||
@@ -671,9 +671,8 @@ namespace Game
|
|||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
Global.ObjectMgr.RemoveGameObjectFromGrid(guid, data);
|
Global.ObjectMgr.RemoveGameObjectFromGrid(guid, data);
|
||||||
|
Map map = Global.MapMgr.FindMap(data.mapid, 0);
|
||||||
Map map = Global.MapMgr.CreateBaseMap(data.mapid);
|
if (map != null && !map.Instanceable())
|
||||||
if (!map.Instanceable())
|
|
||||||
{
|
{
|
||||||
var gameobjectBounds = map.GetGameObjectBySpawnIdStore().LookupByKey(guid);
|
var gameobjectBounds = map.GetGameObjectBySpawnIdStore().LookupByKey(guid);
|
||||||
foreach (var go in gameobjectBounds)
|
foreach (var go in gameobjectBounds)
|
||||||
@@ -857,28 +856,31 @@ namespace Game
|
|||||||
switch (typeof(T).Name)
|
switch (typeof(T).Name)
|
||||||
{
|
{
|
||||||
case "Creature":
|
case "Creature":
|
||||||
|
{
|
||||||
CreatureData data = Global.ObjectMgr.GetCreatureData(obj.guid);
|
CreatureData data = Global.ObjectMgr.GetCreatureData(obj.guid);
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
Global.ObjectMgr.AddCreatureToGrid(obj.guid, data);
|
Global.ObjectMgr.AddCreatureToGrid(obj.guid, data);
|
||||||
|
|
||||||
// Spawn if necessary (loaded grids only)
|
// 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
|
// 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);
|
Creature.CreateCreatureFromDB(obj.guid, map);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "GameObject":
|
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)
|
// Spawn if necessary (loaded grids only)
|
||||||
// this base map checked as non-instanced and then only existed
|
// 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
|
// 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);
|
GameObject go = GameObject.CreateGameObjectFromDB(obj.guid, map, false);
|
||||||
if (go)
|
if (go)
|
||||||
@@ -888,6 +890,7 @@ namespace Game
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "Pool":
|
case "Pool":
|
||||||
Global.PoolMgr.SpawnPool((uint)obj.guid);
|
Global.PoolMgr.SpawnPool((uint)obj.guid);
|
||||||
|
|||||||
Reference in New Issue
Block a user