Dynamic Creature/Go spawning
Port From (https://github.com/TrinityCore/TrinityCore/commit/03b125e6d1947258316c931499746696a95aded2)
This commit is contained in:
@@ -80,10 +80,46 @@ namespace Game.Maps
|
||||
foreach (var guid in guid_set)
|
||||
{
|
||||
T obj = new T();
|
||||
if (!obj.LoadFromDB(guid, map))
|
||||
continue;
|
||||
// Don't spawn at all if there's a respawn time
|
||||
if ((obj.IsTypeId(TypeId.Unit) && map.GetCreatureRespawnTime(guid) == 0) || (obj.IsTypeId(TypeId.GameObject) && map.GetGORespawnTime(guid) == 0))
|
||||
{
|
||||
//TC_LOG_INFO("misc", "DEBUG: LoadHelper from table: %s for (guid: %u) Loading", table, guid);
|
||||
if (obj.IsTypeId(TypeId.Unit))
|
||||
{
|
||||
CreatureData cdata = Global.ObjectMgr.GetCreatureData(guid);
|
||||
Cypher.Assert(cdata != null, $"Tried to load creature with spawnId {guid}, but no such creature exists.");
|
||||
|
||||
AddObjectHelper(cell, ref count, map, obj);
|
||||
SpawnGroupTemplateData group = cdata.spawnGroupData;
|
||||
// If creature in manual spawn group, don't spawn here, unless group is already active.
|
||||
if (group.flags.HasFlag(SpawnGroupFlags.ManualSpawn) && !group.isActive)
|
||||
continue;
|
||||
|
||||
// If script is blocking spawn, don't spawn but queue for a re-check in a little bit
|
||||
if (!group.flags.HasFlag(SpawnGroupFlags.CompatibilityMode) && !Global.ScriptMgr.CanSpawn(guid, cdata.Id, cdata, map))
|
||||
{
|
||||
map.SaveRespawnTime(SpawnObjectType.Creature, guid, cdata.Id, Time.UnixTime + RandomHelper.URand(4, 7), map.GetZoneId(PhasingHandler.EmptyPhaseShift, cdata.spawnPoint), GridDefines.ComputeGridCoord(cdata.spawnPoint.GetPositionX(), cdata.spawnPoint.GetPositionY()).GetId(), false);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (obj.IsTypeId(TypeId.GameObject))
|
||||
{
|
||||
// If gameobject in manual spawn group, don't spawn here, unless group is already active.
|
||||
GameObjectData godata = Global.ObjectMgr.GetGameObjectData(guid);
|
||||
Cypher.Assert(godata != null, $"Tried to load gameobject with spawnId {guid}, but no such object exists.");
|
||||
|
||||
if (godata.spawnGroupData.flags.HasFlag(SpawnGroupFlags.ManualSpawn) && !godata.spawnGroupData.isActive)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!obj.LoadFromDB(guid, map, false, false))
|
||||
{
|
||||
obj.Dispose();
|
||||
continue;
|
||||
}
|
||||
AddObjectHelper(cell, ref count, map, obj);
|
||||
}
|
||||
else
|
||||
obj.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user