Core/AreaTriggers: Add missing null checks for serverside areatriggers

Port From (https://github.com/TrinityCore/TrinityCore/commit/9c0bfc7c8c8af8d13378231b4b45c97f91c64a37)
This commit is contained in:
hondacrx
2024-01-31 12:58:44 -05:00
parent 5e46dd951b
commit 7545d9395d
+45 -33
View File
@@ -318,8 +318,9 @@ namespace Game.Entities
if (target != null) if (target != null)
{ {
float orientation = 0.0f; float orientation = 0.0f;
if (GetCreateProperties().FacingCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
orientation = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().FacingCurveId, GetProgress()); if (createProperties != null && createProperties.FacingCurveId != 0)
orientation = Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress());
if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation)) if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation))
orientation += target.GetOrientation(); orientation += target.GetOrientation();
@@ -333,9 +334,10 @@ namespace Game.Entities
} }
else else
{ {
if (GetCreateProperties().FacingCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
if (createProperties != null && createProperties.FacingCurveId != 0)
{ {
float orientation = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().FacingCurveId, GetProgress()); float orientation = Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress());
if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation)) if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation))
orientation += GetStationaryO(); orientation += GetStationaryO();
@@ -645,8 +647,9 @@ namespace Game.Entities
void SearchUnitInSphere(List<Unit> targetList) void SearchUnitInSphere(List<Unit> targetList)
{ {
float progress = GetProgress(); float progress = GetProgress();
if (GetCreateProperties().MorphCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MorphCurveId, progress); if (createProperties != null && createProperties.MorphCurveId != 0)
progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MorphCurveId, progress);
float scale = CalcCurrentScale(); float scale = CalcCurrentScale();
float radius = MathFunctions.Lerp(_shape.SphereDatas.Radius, _shape.SphereDatas.RadiusTarget, progress) * scale; float radius = MathFunctions.Lerp(_shape.SphereDatas.Radius, _shape.SphereDatas.RadiusTarget, progress) * scale;
@@ -657,8 +660,9 @@ namespace Game.Entities
void SearchUnitInBox(List<Unit> targetList) void SearchUnitInBox(List<Unit> targetList)
{ {
float progress = GetProgress(); float progress = GetProgress();
if (GetCreateProperties().MorphCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MorphCurveId, progress); if (createProperties != null && createProperties.MorphCurveId != 0)
progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MorphCurveId, progress);
unsafe unsafe
{ {
@@ -678,8 +682,9 @@ namespace Game.Entities
void SearchUnitInPolygon(List<Unit> targetList) void SearchUnitInPolygon(List<Unit> targetList)
{ {
float progress = GetProgress(); float progress = GetProgress();
if (GetCreateProperties().MorphCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MorphCurveId, progress); if (createProperties != null && createProperties.MorphCurveId != 0)
progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MorphCurveId, progress);
float height = MathFunctions.Lerp(_shape.PolygonDatas.Height, _shape.PolygonDatas.HeightTarget, progress); float height = MathFunctions.Lerp(_shape.PolygonDatas.Height, _shape.PolygonDatas.HeightTarget, progress);
float minZ = GetPositionZ() - height; float minZ = GetPositionZ() - height;
@@ -693,8 +698,9 @@ namespace Game.Entities
void SearchUnitInCylinder(List<Unit> targetList) void SearchUnitInCylinder(List<Unit> targetList)
{ {
float progress = GetProgress(); float progress = GetProgress();
if (GetCreateProperties().MorphCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MorphCurveId, progress); if (createProperties != null && createProperties.MorphCurveId != 0)
progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MorphCurveId, progress);
float scale = CalcCurrentScale(); float scale = CalcCurrentScale();
float radius = MathFunctions.Lerp(_shape.CylinderDatas.Radius, _shape.CylinderDatas.RadiusTarget, progress) * scale; float radius = MathFunctions.Lerp(_shape.CylinderDatas.Radius, _shape.CylinderDatas.RadiusTarget, progress) * scale;
@@ -713,8 +719,9 @@ namespace Game.Entities
void SearchUnitInDisk(List<Unit> targetList) void SearchUnitInDisk(List<Unit> targetList)
{ {
float progress = GetProgress(); float progress = GetProgress();
if (GetCreateProperties().MorphCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MorphCurveId, progress); if (createProperties != null && createProperties.MorphCurveId != 0)
progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MorphCurveId, progress);
float scale = CalcCurrentScale(); float scale = CalcCurrentScale();
float innerRadius = MathFunctions.Lerp(_shape.DiskDatas.InnerRadius, _shape.DiskDatas.InnerRadiusTarget, progress) * scale; float innerRadius = MathFunctions.Lerp(_shape.DiskDatas.InnerRadius, _shape.DiskDatas.InnerRadiusTarget, progress) * scale;
@@ -734,8 +741,9 @@ namespace Game.Entities
void SearchUnitInBoundedPlane(List<Unit> targetList) void SearchUnitInBoundedPlane(List<Unit> targetList)
{ {
float progress = GetProgress(); float progress = GetProgress();
if (GetCreateProperties().MorphCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MorphCurveId, progress); if (createProperties != null && createProperties.MorphCurveId != 0)
progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MorphCurveId, progress);
unsafe unsafe
{ {
@@ -817,8 +825,9 @@ namespace Game.Entities
if (_spawnId != 0) if (_spawnId != 0)
return Global.AreaTriggerDataStorage.GetAreaTriggerSpawn(_spawnId).ScriptId; return Global.AreaTriggerDataStorage.GetAreaTriggerSpawn(_spawnId).ScriptId;
if (GetCreateProperties() != null) AreaTriggerCreateProperties createProperties = GetCreateProperties();
return GetCreateProperties().ScriptId; if (createProperties != null)
return createProperties.ScriptId;
return 0; return 0;
} }
@@ -849,24 +858,25 @@ namespace Game.Entities
void UpdatePolygonVertices() void UpdatePolygonVertices()
{ {
AreaTriggerCreateProperties createProperties = GetCreateProperties();
float newOrientation = GetOrientation(); float newOrientation = GetOrientation();
// No need to recalculate, orientation didn't change // No need to recalculate, orientation didn't change
if (MathFunctions.fuzzyEq(_verticesUpdatePreviousOrientation, newOrientation) && GetCreateProperties().PolygonVerticesTarget.Empty()) if (MathFunctions.fuzzyEq(_verticesUpdatePreviousOrientation, newOrientation) && (createProperties == null) || createProperties.PolygonVerticesTarget.Empty())
return; return;
_polygonVertices = GetCreateProperties().PolygonVertices; _polygonVertices = createProperties.PolygonVertices;
if (!GetCreateProperties().PolygonVerticesTarget.Empty()) if (!createProperties.PolygonVerticesTarget.Empty())
{ {
float progress = GetProgress(); float progress = GetProgress();
if (GetCreateProperties().MorphCurveId != 0) if (createProperties.MorphCurveId != 0)
progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MorphCurveId, progress); progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MorphCurveId, progress);
for (var i = 0; i < _polygonVertices.Count; ++i) for (var i = 0; i < _polygonVertices.Count; ++i)
{ {
Vector2 vertex = _polygonVertices[i]; Vector2 vertex = _polygonVertices[i];
Vector2 vertexTarget = GetCreateProperties().PolygonVerticesTarget[i]; Vector2 vertexTarget = createProperties.PolygonVerticesTarget[i];
vertex.X = MathFunctions.Lerp(vertex.X, vertexTarget.X, progress); vertex.X = MathFunctions.Lerp(vertex.X, vertexTarget.X, progress);
vertex.Y = MathFunctions.Lerp(vertex.Y, vertexTarget.Y, progress); vertex.Y = MathFunctions.Lerp(vertex.Y, vertexTarget.Y, progress);
@@ -1165,12 +1175,13 @@ namespace Game.Entities
if (centerPos == null) if (centerPos == null)
return GetPosition(); return GetPosition();
AreaTriggerCreateProperties createProperties = GetCreateProperties();
AreaTriggerOrbitInfo cmi = _orbitInfo; AreaTriggerOrbitInfo cmi = _orbitInfo;
// AreaTrigger make exactly "Duration / TimeToTarget" loops during his life time // AreaTrigger make exactly "Duration / TimeToTarget" loops during his life time
float pathProgress = (float)cmi.ElapsedTimeForMovement / cmi.TimeToTarget; float pathProgress = (float)cmi.ElapsedTimeForMovement / cmi.TimeToTarget;
if (GetCreateProperties().MoveCurveId != 0) if (createProperties != null && createProperties.MoveCurveId != 0)
pathProgress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MoveCurveId, pathProgress); pathProgress = Global.DB2Mgr.GetCurveValueAt(createProperties.MoveCurveId, pathProgress);
// We already made one circle and can't loop // We already made one circle and can't loop
if (!cmi.CanLoop) if (!cmi.CanLoop)
@@ -1196,8 +1207,8 @@ namespace Game.Entities
float z = centerPos.GetPositionZ() + cmi.ZOffset; float z = centerPos.GetPositionZ() + cmi.ZOffset;
float orientation = 0.0f; float orientation = 0.0f;
if (GetCreateProperties().FacingCurveId != 0) if (createProperties != null && createProperties.FacingCurveId != 0)
orientation = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().FacingCurveId, GetProgress()); orientation = Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress());
if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation)) if (GetTemplate() == null || !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation))
{ {
@@ -1249,12 +1260,13 @@ namespace Game.Entities
if (currentTimePercent <= 0.0f) if (currentTimePercent <= 0.0f)
return; return;
if (GetCreateProperties().MoveCurveId != 0) AreaTriggerCreateProperties createProperties = GetCreateProperties();
if (createProperties != null && createProperties.MoveCurveId != 0)
{ {
float progress = Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().MoveCurveId, currentTimePercent); float progress = Global.DB2Mgr.GetCurveValueAt(createProperties.MoveCurveId, currentTimePercent);
if (progress < 0.0f || progress > 1.0f) if (progress < 0.0f || progress > 1.0f)
{ {
Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (Id: {GetEntry()}, AreaTriggerCreatePropertiesId: {GetCreateProperties().Id}) has wrong progress ({progress}) caused by curve calculation (MoveCurveId: {GetCreateProperties().MorphCurveId})"); Log.outError(LogFilter.AreaTrigger, $"AreaTrigger (Id: {GetEntry()}, AreaTriggerCreatePropertiesId: {createProperties.Id}) has wrong progress ({progress}) caused by curve calculation (MoveCurveId: {createProperties.MorphCurveId})");
} }
else else
currentTimePercent = progress; currentTimePercent = progress;
@@ -1268,8 +1280,8 @@ namespace Game.Entities
_spline.Evaluate_Percent(lastPositionIndex, percentFromLastPoint, out currentPosition); _spline.Evaluate_Percent(lastPositionIndex, percentFromLastPoint, out currentPosition);
float orientation = GetStationaryO(); float orientation = GetStationaryO();
if (GetCreateProperties().FacingCurveId != 0) if (createProperties != null && createProperties.FacingCurveId != 0)
orientation += Global.DB2Mgr.GetCurveValueAt(GetCreateProperties().FacingCurveId, GetProgress()); orientation += Global.DB2Mgr.GetCurveValueAt(createProperties.FacingCurveId, GetProgress());
if (GetTemplate() != null && !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation) && GetTemplate().HasFlag(AreaTriggerFlags.HasFaceMovementDir)) if (GetTemplate() != null && !GetTemplate().HasFlag(AreaTriggerFlags.HasAbsoluteOrientation) && GetTemplate().HasFlag(AreaTriggerFlags.HasFaceMovementDir))
{ {