Core/Misc: Some refactoring
Port From (https://github.com/TrinityCore/TrinityCore/commit/94a79bac7a06aa0f931e9d651928de7eea0a8b5c)
This commit is contained in:
@@ -53,6 +53,9 @@ namespace Game.Entities
|
||||
if (!IsInWorld)
|
||||
{
|
||||
GetMap().GetObjectsStore().Add(GetGUID(), this);
|
||||
if (_spawnId != 0)
|
||||
GetMap().GetAreaTriggerBySpawnIdStore().Add(_spawnId, this);
|
||||
|
||||
base.AddToWorld();
|
||||
}
|
||||
}
|
||||
@@ -74,6 +77,9 @@ namespace Game.Entities
|
||||
_ai.OnRemove();
|
||||
|
||||
base.RemoveFromWorld();
|
||||
if (_spawnId != 0)
|
||||
GetMap().GetAreaTriggerBySpawnIdStore().Remove(_spawnId, this);
|
||||
|
||||
GetMap().GetObjectsStore().Remove(GetGUID());
|
||||
}
|
||||
}
|
||||
@@ -236,7 +242,7 @@ namespace Game.Entities
|
||||
if (position == null)
|
||||
return false;
|
||||
|
||||
AreaTriggerTemplate areaTriggerTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerTemplate(position.Id);
|
||||
AreaTriggerTemplate areaTriggerTemplate = Global.AreaTriggerDataStorage.GetAreaTriggerTemplate(position.TriggerId);
|
||||
if (areaTriggerTemplate == null)
|
||||
return false;
|
||||
|
||||
@@ -246,7 +252,7 @@ namespace Game.Entities
|
||||
bool CreateServer(Map map, AreaTriggerTemplate areaTriggerTemplate, AreaTriggerSpawn position)
|
||||
{
|
||||
SetMap(map);
|
||||
Relocate(position.Location);
|
||||
Relocate(position.SpawnPoint);
|
||||
if (!IsPositionValid())
|
||||
{
|
||||
Log.outError(LogFilter.AreaTrigger, $"AreaTriggerServer (id {areaTriggerTemplate.Id}) not created. Invalid coordinates (X: {GetPositionX()} Y: {GetPositionY()})");
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Dynamic;
|
||||
using Game.Maps;
|
||||
using Game.Networking;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -319,18 +320,12 @@ namespace Game.Entities
|
||||
public uint ScriptId;
|
||||
}
|
||||
|
||||
public class AreaTriggerSpawn
|
||||
public class AreaTriggerSpawn : SpawnData
|
||||
{
|
||||
public ulong SpawnId;
|
||||
public AreaTriggerId Id;
|
||||
public WorldLocation Location;
|
||||
public uint PhaseId;
|
||||
public uint PhaseGroup;
|
||||
public byte PhaseUseFlags;
|
||||
|
||||
public AreaTriggerId TriggerId;
|
||||
public AreaTriggerShapeInfo Shape = new();
|
||||
|
||||
public uint ScriptId;
|
||||
public AreaTriggerSpawn() : base(SpawnObjectType.AreaTrigger) { }
|
||||
}
|
||||
|
||||
public struct AreaTriggerAction
|
||||
|
||||
@@ -793,7 +793,7 @@ namespace Game.Entities
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
PhasingHandler.InitDbPhaseShift(GetPhaseShift(), data.phaseUseFlags, data.phaseId, data.phaseGroup);
|
||||
PhasingHandler.InitDbPhaseShift(GetPhaseShift(), data.PhaseUseFlags, data.PhaseId, data.PhaseGroup);
|
||||
PhasingHandler.InitDbVisibleMapId(GetPhaseShift(), data.terrainSwapMap);
|
||||
}
|
||||
|
||||
@@ -1246,18 +1246,24 @@ namespace Game.Entities
|
||||
dynamicflags = 0;
|
||||
}
|
||||
|
||||
if (data.spawnId == 0)
|
||||
data.spawnId = m_spawnId;
|
||||
Cypher.Assert(data.spawnId == m_spawnId);
|
||||
if (data.SpawnId == 0)
|
||||
data.SpawnId = m_spawnId;
|
||||
Cypher.Assert(data.SpawnId == m_spawnId);
|
||||
|
||||
data.Id = GetEntry();
|
||||
data.displayid = displayId;
|
||||
data.equipmentId = (sbyte)GetCurrentEquipmentId();
|
||||
|
||||
if (GetTransport() == null)
|
||||
data.spawnPoint.WorldRelocate(this);
|
||||
{
|
||||
data.MapId = GetMapId();
|
||||
data.SpawnPoint.Relocate(this);
|
||||
}
|
||||
else
|
||||
data.spawnPoint.WorldRelocate(mapid, GetTransOffsetX(), GetTransOffsetY(), GetTransOffsetZ(), GetTransOffsetO());
|
||||
{
|
||||
data.MapId = mapid;
|
||||
data.SpawnPoint.Relocate(GetTransOffsetX(), GetTransOffsetY(), GetTransOffsetZ(), GetTransOffsetO());
|
||||
}
|
||||
|
||||
data.spawntimesecs = (int)m_respawnDelay;
|
||||
// prevent add data integrity problems
|
||||
@@ -1277,8 +1283,8 @@ namespace Game.Entities
|
||||
if (data.spawnGroupData == null)
|
||||
data.spawnGroupData = Global.ObjectMgr.GetDefaultSpawnGroup();
|
||||
|
||||
data.phaseId = GetDBPhase() > 0 ? (uint)GetDBPhase() : data.phaseId;
|
||||
data.phaseGroup = GetDBPhase() < 0 ? (uint)-GetDBPhase() : data.phaseGroup;
|
||||
data.PhaseId = GetDBPhase() > 0 ? (uint)GetDBPhase() : data.PhaseId;
|
||||
data.PhaseGroup = GetDBPhase() < 0 ? (uint)-GetDBPhase() : data.PhaseGroup;
|
||||
|
||||
// update in DB
|
||||
SQLTransaction trans = new();
|
||||
@@ -1294,8 +1300,8 @@ namespace Game.Entities
|
||||
stmt.AddValue(index++, GetEntry());
|
||||
stmt.AddValue(index++, mapid);
|
||||
stmt.AddValue(index++, data.spawnDifficulties.Empty() ? "" : string.Join(',', data.spawnDifficulties));
|
||||
stmt.AddValue(index++, data.phaseId);
|
||||
stmt.AddValue(index++, data.phaseGroup);
|
||||
stmt.AddValue(index++, data.PhaseId);
|
||||
stmt.AddValue(index++, data.PhaseGroup);
|
||||
stmt.AddValue(index++, displayId);
|
||||
stmt.AddValue(index++, GetCurrentEquipmentId());
|
||||
stmt.AddValue(index++, GetPositionX());
|
||||
@@ -1610,7 +1616,7 @@ namespace Game.Entities
|
||||
|
||||
SQLTransaction trans = new();
|
||||
|
||||
Global.MapMgr.DoForAllMapsWithMapId(data.spawnPoint.GetMapId(), map =>
|
||||
Global.MapMgr.DoForAllMapsWithMapId(data.MapId, map =>
|
||||
{
|
||||
// despawn all active creatures, and remove their respawns
|
||||
List<Creature> toUnload = new();
|
||||
@@ -2448,7 +2454,7 @@ namespace Game.Entities
|
||||
{
|
||||
if (m_creatureData != null)
|
||||
{
|
||||
m_creatureData.spawnPoint.GetPosition(out x, out y, out z, out ori);
|
||||
m_creatureData.SpawnPoint.GetPosition(out x, out y, out z, out ori);
|
||||
dist = m_creatureData.spawndist;
|
||||
}
|
||||
else
|
||||
@@ -2459,7 +2465,7 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
bool IsSpawnedOnTransport() { return m_creatureData != null && m_creatureData.spawnPoint.GetMapId() != GetMapId(); }
|
||||
bool IsSpawnedOnTransport() { return m_creatureData != null && m_creatureData.MapId != GetMapId(); }
|
||||
|
||||
void InitializeMovementFlags()
|
||||
{
|
||||
@@ -3157,7 +3163,7 @@ namespace Game.Entities
|
||||
m_respawnradius = data.spawndist;
|
||||
m_respawnDelay = (uint)data.spawntimesecs;
|
||||
|
||||
if (!Create(map.GenerateLowGuid(HighGuid.Creature), map, data.Id, data.spawnPoint, data, 0, !m_respawnCompatibilityMode))
|
||||
if (!Create(map.GenerateLowGuid(HighGuid.Creature), map, data.Id, data.SpawnPoint, data, 0, !m_respawnCompatibilityMode))
|
||||
return false;
|
||||
|
||||
//We should set first home position, because then AI calls home movement
|
||||
@@ -3198,9 +3204,9 @@ namespace Game.Entities
|
||||
m_deathState = DeathState.Dead;
|
||||
if (CanFly())
|
||||
{
|
||||
float tz = map.GetHeight(GetPhaseShift(), data.spawnPoint, true, MapConst.MaxFallDistance);
|
||||
if (data.spawnPoint.GetPositionZ() - tz > 0.1f && GridDefines.IsValidMapCoord(tz))
|
||||
Relocate(data.spawnPoint.GetPositionX(), data.spawnPoint.GetPositionY(), tz);
|
||||
float tz = map.GetHeight(GetPhaseShift(), data.SpawnPoint, true, MapConst.MaxFallDistance);
|
||||
if (data.SpawnPoint.GetPositionZ() - tz > 0.1f && GridDefines.IsValidMapCoord(tz))
|
||||
Relocate(data.SpawnPoint.GetPositionX(), data.SpawnPoint.GetPositionY(), tz);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1034,12 +1034,13 @@ namespace Game.Entities
|
||||
// update in loaded data (changing data only in this place)
|
||||
GameObjectData data = Global.ObjectMgr.NewOrExistGameObjectData(m_spawnId);
|
||||
|
||||
if (data.spawnId == 0)
|
||||
data.spawnId = m_spawnId;
|
||||
Cypher.Assert(data.spawnId == m_spawnId);
|
||||
if (data.SpawnId == 0)
|
||||
data.SpawnId = m_spawnId;
|
||||
Cypher.Assert(data.SpawnId == m_spawnId);
|
||||
|
||||
data.Id = GetEntry();
|
||||
data.spawnPoint.WorldRelocate(this);
|
||||
data.MapId = GetMapId();
|
||||
data.SpawnPoint.Relocate(this);
|
||||
data.rotation = m_localRotation;
|
||||
data.spawntimesecs = (int)(m_spawnedByDefault ? m_respawnDelayTime : -m_respawnDelayTime);
|
||||
data.animprogress = GetGoAnimProgress();
|
||||
@@ -1049,8 +1050,8 @@ namespace Game.Entities
|
||||
if (data.spawnGroupData == null)
|
||||
data.spawnGroupData = Global.ObjectMgr.GetDefaultSpawnGroup();
|
||||
|
||||
data.phaseId = GetDBPhase() > 0 ? (uint)GetDBPhase() : data.phaseId;
|
||||
data.phaseGroup = GetDBPhase() < 0 ? (uint)-GetDBPhase() : data.phaseGroup;
|
||||
data.PhaseId = GetDBPhase() > 0 ? (uint)GetDBPhase() : data.PhaseId;
|
||||
data.PhaseGroup = GetDBPhase() < 0 ? (uint)-GetDBPhase() : data.PhaseGroup;
|
||||
|
||||
// Update in DB
|
||||
byte index = 0;
|
||||
@@ -1063,8 +1064,8 @@ namespace Game.Entities
|
||||
stmt.AddValue(index++, GetEntry());
|
||||
stmt.AddValue(index++, mapid);
|
||||
stmt.AddValue(index++, data.spawnDifficulties.Empty() ? "" : string.Join(",", data.spawnDifficulties));
|
||||
stmt.AddValue(index++, data.phaseId);
|
||||
stmt.AddValue(index++, data.phaseGroup);
|
||||
stmt.AddValue(index++, data.PhaseId);
|
||||
stmt.AddValue(index++, data.PhaseGroup);
|
||||
stmt.AddValue(index++, GetPositionX());
|
||||
stmt.AddValue(index++, GetPositionY());
|
||||
stmt.AddValue(index++, GetPositionZ());
|
||||
@@ -1096,10 +1097,10 @@ namespace Game.Entities
|
||||
|
||||
m_spawnId = spawnId;
|
||||
m_respawnCompatibilityMode = ((data.spawnGroupData.flags & SpawnGroupFlags.CompatibilityMode) != 0);
|
||||
if (!Create(entry, map, data.spawnPoint, data.rotation, animprogress, go_state, artKit, !m_respawnCompatibilityMode, spawnId))
|
||||
if (!Create(entry, map, data.SpawnPoint, data.rotation, animprogress, go_state, artKit, !m_respawnCompatibilityMode, spawnId))
|
||||
return false;
|
||||
|
||||
PhasingHandler.InitDbPhaseShift(GetPhaseShift(), data.phaseUseFlags, data.phaseId, data.phaseGroup);
|
||||
PhasingHandler.InitDbPhaseShift(GetPhaseShift(), data.PhaseUseFlags, data.PhaseId, data.PhaseGroup);
|
||||
PhasingHandler.InitDbVisibleMapId(GetPhaseShift(), data.terrainSwapMap);
|
||||
|
||||
if (data.spawntimesecs >= 0)
|
||||
@@ -1154,7 +1155,7 @@ namespace Game.Entities
|
||||
|
||||
SQLTransaction trans = new();
|
||||
|
||||
Global.MapMgr.DoForAllMapsWithMapId(data.spawnPoint.GetMapId(), map =>
|
||||
Global.MapMgr.DoForAllMapsWithMapId(data.MapId, map =>
|
||||
{
|
||||
// despawn all active objects, and remove their respawns
|
||||
List<GameObject> toUnload = new();
|
||||
@@ -2805,7 +2806,7 @@ namespace Game.Entities
|
||||
public void GetRespawnPosition(out float x, out float y, out float z, out float ori)
|
||||
{
|
||||
if (m_goData != null)
|
||||
m_goData.spawnPoint.GetPosition(out x, out y, out z, out ori);
|
||||
m_goData.SpawnPoint.GetPosition(out x, out y, out z, out ori);
|
||||
else
|
||||
GetPosition(out x, out y, out z, out ori);
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ namespace Game.Entities
|
||||
return null;
|
||||
|
||||
float x, y, z, o;
|
||||
data.spawnPoint.GetPosition(out x, out y, out z, out o);
|
||||
data.SpawnPoint.GetPosition(out x, out y, out z, out o);
|
||||
|
||||
creature.SetTransport(this);
|
||||
creature.m_movementInfo.transport.guid = GetGUID();
|
||||
@@ -347,7 +347,7 @@ namespace Game.Entities
|
||||
return null;
|
||||
}
|
||||
|
||||
PhasingHandler.InitDbPhaseShift(creature.GetPhaseShift(), data.phaseUseFlags, data.phaseId, data.phaseGroup);
|
||||
PhasingHandler.InitDbPhaseShift(creature.GetPhaseShift(), data.PhaseUseFlags, data.PhaseId, data.PhaseGroup);
|
||||
PhasingHandler.InitDbVisibleMapId(creature.GetPhaseShift(), data.terrainSwapMap);
|
||||
|
||||
if (!map.AddToMap(creature))
|
||||
@@ -369,7 +369,7 @@ namespace Game.Entities
|
||||
return null;
|
||||
|
||||
float x, y, z, o;
|
||||
data.spawnPoint.GetPosition(out x, out y, out z, out o);
|
||||
data.SpawnPoint.GetPosition(out x, out y, out z, out o);
|
||||
|
||||
go.SetTransport(this);
|
||||
go.m_movementInfo.transport.guid = GetGUID();
|
||||
@@ -385,7 +385,7 @@ namespace Game.Entities
|
||||
return null;
|
||||
}
|
||||
|
||||
PhasingHandler.InitDbPhaseShift(go.GetPhaseShift(), data.phaseUseFlags, data.phaseId, data.phaseGroup);
|
||||
PhasingHandler.InitDbPhaseShift(go.GetPhaseShift(), data.PhaseUseFlags, data.PhaseId, data.PhaseGroup);
|
||||
PhasingHandler.InitDbVisibleMapId(go.GetPhaseShift(), data.terrainSwapMap);
|
||||
|
||||
if (!map.AddToMap(go))
|
||||
|
||||
Reference in New Issue
Block a user