Core/AreaTriggers: Replace fixed movement times in database for areatriggers with speed
Port From (https://github.com/TrinityCore/TrinityCore/commit/069771e22ef29e47298c62e6cb9d7dce72375348)
This commit is contained in:
@@ -124,8 +124,8 @@ namespace Game.DataStorage
|
|||||||
|
|
||||||
// 0 1 2 3 4
|
// 0 1 2 3 4
|
||||||
SQLResult areatriggerCreateProperties = DB.World.Query("SELECT Id, IsCustom, AreaTriggerId, IsAreatriggerCustom, Flags, " +
|
SQLResult areatriggerCreateProperties = DB.World.Query("SELECT Id, IsCustom, AreaTriggerId, IsAreatriggerCustom, Flags, " +
|
||||||
//5 6 7 8 9 10 11 12 13 14
|
//5 6 7 8 9 10 11 12 13 14
|
||||||
"MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, SpellForVisuals, TimeToTarget, TimeToTargetScale, " +
|
"MoveCurveId, ScaleCurveId, MorphCurveId, FacingCurveId, AnimId, AnimKitId, DecalPropertiesId, SpellForVisuals, TimeToTargetScale, Speed, " +
|
||||||
//15 16 17 18 19 20 21 22 23 24
|
//15 16 17 18 19 20 21 22 23 24
|
||||||
"Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ShapeData6, ShapeData7, ScriptName FROM `areatrigger_create_properties`");
|
"Shape, ShapeData0, ShapeData1, ShapeData2, ShapeData3, ShapeData4, ShapeData5, ShapeData6, ShapeData7, ScriptName FROM `areatrigger_create_properties`");
|
||||||
if (!areatriggerCreateProperties.IsEmpty())
|
if (!areatriggerCreateProperties.IsEmpty())
|
||||||
@@ -185,8 +185,8 @@ namespace Game.DataStorage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createProperties.TimeToTarget = areatriggerCreateProperties.Read<uint>(13);
|
createProperties.TimeToTargetScale = areatriggerCreateProperties.Read<uint>(13);
|
||||||
createProperties.TimeToTargetScale = areatriggerCreateProperties.Read<uint>(14);
|
createProperties.Speed = areatriggerCreateProperties.Read<float>(14);
|
||||||
|
|
||||||
createProperties.Shape.TriggerType = shape;
|
createProperties.Shape.TriggerType = shape;
|
||||||
unsafe
|
unsafe
|
||||||
@@ -315,7 +315,7 @@ namespace Game.DataStorage
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (createProperties.TimeToTarget != 0 || createProperties.TimeToTargetScale != 0 || createProperties.FacingCurveId != 0 || createProperties.MoveCurveId != 0)
|
if (createProperties.TimeToTargetScale != 0)
|
||||||
{
|
{
|
||||||
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with time to target values");
|
Log.outError(LogFilter.Sql, $"Table `areatrigger` has listed AreaTriggerCreatePropertiesId (Id: {createPropertiesId.Id}, IsCustom: {createPropertiesId.IsCustom}) with time to target values");
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ namespace Game.Entities
|
|||||||
|
|
||||||
m_areaTriggerData = new AreaTriggerFieldData();
|
m_areaTriggerData = new AreaTriggerFieldData();
|
||||||
|
|
||||||
_spline = new();
|
|
||||||
_stationaryPosition = new();
|
_stationaryPosition = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,8 +194,6 @@ namespace Game.Entities
|
|||||||
|
|
||||||
UpdateShape();
|
UpdateShape();
|
||||||
|
|
||||||
uint timeToTarget = GetCreateProperties().TimeToTarget != 0 ? GetCreateProperties().TimeToTarget : m_areaTriggerData.Duration;
|
|
||||||
|
|
||||||
if (GetCreateProperties().OrbitInfo != null)
|
if (GetCreateProperties().OrbitInfo != null)
|
||||||
{
|
{
|
||||||
AreaTriggerOrbitInfo orbit = GetCreateProperties().OrbitInfo;
|
AreaTriggerOrbitInfo orbit = GetCreateProperties().OrbitInfo;
|
||||||
@@ -205,11 +202,11 @@ namespace Game.Entities
|
|||||||
else
|
else
|
||||||
orbit.Center = new(pos.posX, pos.posY, pos.posZ);
|
orbit.Center = new(pos.posX, pos.posY, pos.posZ);
|
||||||
|
|
||||||
InitOrbit(orbit, timeToTarget);
|
InitOrbit(orbit, GetCreateProperties().Speed);
|
||||||
}
|
}
|
||||||
else if (GetCreateProperties().HasSplines())
|
else if (GetCreateProperties().HasSplines())
|
||||||
{
|
{
|
||||||
InitSplineOffsets(GetCreateProperties().SplinePoints, timeToTarget);
|
InitSplineOffsets(GetCreateProperties().SplinePoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
// movement on transport of areatriggers on unit is handled by themself
|
// movement on transport of areatriggers on unit is handled by themself
|
||||||
@@ -1035,7 +1032,7 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitSplineOffsets(List<Vector3> offsets, uint timeToTarget)
|
void InitSplineOffsets(List<Vector3> offsets, float? overrideSpeed = null)
|
||||||
{
|
{
|
||||||
float angleSin = (float)Math.Sin(GetOrientation());
|
float angleSin = (float)Math.Sin(GetOrientation());
|
||||||
float angleCos = (float)Math.Cos(GetOrientation());
|
float angleCos = (float)Math.Cos(GetOrientation());
|
||||||
@@ -1054,19 +1051,25 @@ namespace Game.Entities
|
|||||||
rotatedPoints.Add(new Vector3(x, y, z));
|
rotatedPoints.Add(new Vector3(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
InitSplines(rotatedPoints.ToArray(), timeToTarget);
|
InitSplines(rotatedPoints.ToArray(), overrideSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitSplines(Vector3[] splinePoints, uint timeToTarget)
|
public void InitSplines(Vector3[] splinePoints, float? overrideSpeed = null)
|
||||||
{
|
{
|
||||||
if (splinePoints.Length < 2)
|
if (splinePoints.Length < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_movementTime = 0;
|
_movementTime = 0;
|
||||||
|
|
||||||
|
_spline = new Spline<int>();
|
||||||
_spline.InitSpline(splinePoints, splinePoints.Length, EvaluationMode.Linear);
|
_spline.InitSpline(splinePoints, splinePoints.Length, EvaluationMode.Linear);
|
||||||
_spline.InitLengths();
|
_spline.InitLengths();
|
||||||
|
|
||||||
|
float speed = overrideSpeed.GetValueOrDefault(GetCreateProperties().Speed);
|
||||||
|
if (speed <= 0.0f)
|
||||||
|
speed = 1.0f;
|
||||||
|
|
||||||
|
uint timeToTarget = _spline.Length() / speed * (float)Time.InMilliseconds;
|
||||||
SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.TimeToTarget), timeToTarget);
|
SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.TimeToTarget), timeToTarget);
|
||||||
|
|
||||||
if (IsInWorld)
|
if (IsInWorld)
|
||||||
@@ -1083,28 +1086,28 @@ namespace Game.Entities
|
|||||||
reshape.AreaTriggerSpline = new();
|
reshape.AreaTriggerSpline = new();
|
||||||
reshape.AreaTriggerSpline.ElapsedTimeForMovement = GetElapsedTimeForMovement();
|
reshape.AreaTriggerSpline.ElapsedTimeForMovement = GetElapsedTimeForMovement();
|
||||||
reshape.AreaTriggerSpline.TimeToTarget = timeToTarget;
|
reshape.AreaTriggerSpline.TimeToTarget = timeToTarget;
|
||||||
reshape.AreaTriggerSpline.Points = splinePoints;
|
reshape.AreaTriggerSpline.Points = _spline.GetPoints();
|
||||||
SendMessageToSet(reshape, true);
|
SendMessageToSet(reshape, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_reachedDestination = false;
|
_reachedDestination = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitOrbit(AreaTriggerOrbitInfo orbit, uint timeToTarget)
|
void InitOrbit(AreaTriggerOrbitInfo orbit, float? overrideSpeed = null)
|
||||||
{
|
{
|
||||||
// Circular movement requires either a center position or an attached unit
|
// Circular movement requires either a center position or an attached unit
|
||||||
Cypher.Assert(orbit.Center.HasValue || orbit.PathTarget.HasValue);
|
Cypher.Assert(orbit.Center.HasValue || orbit.PathTarget.HasValue);
|
||||||
|
|
||||||
// should be sent in object create packets only
|
float speed = overrideSpeed.GetValueOrDefault(GetCreateProperties().Speed);
|
||||||
DoWithSuppressingObjectUpdates(() =>
|
if (speed <= 0.0f)
|
||||||
{
|
speed = 1.0f;
|
||||||
SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.TimeToTarget), timeToTarget);
|
|
||||||
m_areaTriggerData.ClearChanged(m_areaTriggerData.TimeToTarget);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
uint timeToTarget = (uint)(orbit.Radius * 2.0f * MathF.PI * (float)Time.InMilliseconds / speed);
|
||||||
|
|
||||||
|
SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.TimeToTarget), timeToTarget);
|
||||||
SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.OrbitPathTarget), orbit.PathTarget.GetValueOrDefault(ObjectGuid.Empty));
|
SetUpdateFieldValue(m_values.ModifyValue(m_areaTriggerData).ModifyValue(m_areaTriggerData.OrbitPathTarget), orbit.PathTarget.GetValueOrDefault(ObjectGuid.Empty));
|
||||||
|
|
||||||
_orbitInfo = orbit;
|
_orbitInfo = new AreaTriggerOrbitInfo();
|
||||||
|
|
||||||
_orbitInfo.TimeToTarget = timeToTarget;
|
_orbitInfo.TimeToTarget = timeToTarget;
|
||||||
_orbitInfo.ElapsedTimeForMovement = 0;
|
_orbitInfo.ElapsedTimeForMovement = 0;
|
||||||
@@ -1126,7 +1129,7 @@ namespace Game.Entities
|
|||||||
|
|
||||||
Position GetOrbitCenterPosition()
|
Position GetOrbitCenterPosition()
|
||||||
{
|
{
|
||||||
if (_orbitInfo == null)
|
if (!HasOrbit())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (_orbitInfo.PathTarget.HasValue)
|
if (_orbitInfo.PathTarget.HasValue)
|
||||||
@@ -1149,7 +1152,7 @@ namespace Game.Entities
|
|||||||
return GetPosition();
|
return GetPosition();
|
||||||
|
|
||||||
AreaTriggerCreateProperties createProperties = GetCreateProperties();
|
AreaTriggerCreateProperties createProperties = GetCreateProperties();
|
||||||
AreaTriggerOrbitInfo cmi = _orbitInfo;
|
AreaTriggerOrbitInfo cmi = GetOrbit();
|
||||||
|
|
||||||
// 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;
|
||||||
|
|||||||
@@ -266,13 +266,14 @@ namespace Game.Entities
|
|||||||
|
|
||||||
public uint? SpellForVisuals;
|
public uint? SpellForVisuals;
|
||||||
|
|
||||||
public uint TimeToTarget;
|
|
||||||
public uint TimeToTargetScale;
|
public uint TimeToTargetScale;
|
||||||
|
|
||||||
public AreaTriggerScaleCurveTemplate OverrideScale;
|
public AreaTriggerScaleCurveTemplate OverrideScale;
|
||||||
public AreaTriggerScaleCurveTemplate ExtraScale;
|
public AreaTriggerScaleCurveTemplate ExtraScale;
|
||||||
|
|
||||||
public AreaTriggerShapeInfo Shape = new();
|
public AreaTriggerShapeInfo Shape = new();
|
||||||
|
|
||||||
|
public float Speed = 1.0f;
|
||||||
public List<Vector3> SplinePoints = new();
|
public List<Vector3> SplinePoints = new();
|
||||||
public AreaTriggerOrbitInfo OrbitInfo;
|
public AreaTriggerOrbitInfo OrbitInfo;
|
||||||
|
|
||||||
|
|||||||
@@ -960,7 +960,6 @@ namespace Scripts.Spells.Priest
|
|||||||
TaskScheduler _scheduler = new();
|
TaskScheduler _scheduler = new();
|
||||||
Position _casterCurrentPosition;
|
Position _casterCurrentPosition;
|
||||||
List<ObjectGuid> _affectedUnits = new();
|
List<ObjectGuid> _affectedUnits = new();
|
||||||
float _maxTravelDistance;
|
|
||||||
|
|
||||||
public areatrigger_pri_divine_star(AreaTrigger areatrigger) : base(areatrigger) { }
|
public areatrigger_pri_divine_star(AreaTrigger areatrigger) : base(areatrigger) { }
|
||||||
|
|
||||||
@@ -980,18 +979,15 @@ namespace Scripts.Spells.Priest
|
|||||||
_casterCurrentPosition = caster.GetPosition();
|
_casterCurrentPosition = caster.GetPosition();
|
||||||
|
|
||||||
// Note: max. distance at which the Divine Star can travel to is 1's BasePoints yards.
|
// Note: max. distance at which the Divine Star can travel to is 1's BasePoints yards.
|
||||||
_maxTravelDistance = (float)(spellInfo.GetEffect(1).CalcValue(caster));
|
float maxTravelDistance = (float)(spellInfo.GetEffect(1).CalcValue(caster));
|
||||||
|
|
||||||
Position destPos = _casterCurrentPosition;
|
Position destPos = _casterCurrentPosition;
|
||||||
at.MovePositionToFirstCollision(destPos, _maxTravelDistance, 0.0f);
|
at.MovePositionToFirstCollision(destPos, maxTravelDistance, 0.0f);
|
||||||
|
|
||||||
PathGenerator firstPath = new(at);
|
PathGenerator firstPath = new(at);
|
||||||
firstPath.CalculatePath(destPos.GetPositionX(), destPos.GetPositionY(), destPos.GetPositionZ(), false);
|
firstPath.CalculatePath(destPos.GetPositionX(), destPos.GetPositionY(), destPos.GetPositionZ(), false);
|
||||||
|
|
||||||
Vector3 endPoint = firstPath.GetPath().Last();
|
at.InitSplines(firstPath.GetPath());
|
||||||
|
|
||||||
// Note: it takes TimeSpan.FromMilliseconds(1000) to reach 1's BasePoints yards, so it takes (1000 / 1's BasePoints)ms to run 1 yard.
|
|
||||||
at.InitSplines(firstPath.GetPath(), (uint)(at.GetDistance(endPoint.X, endPoint.Y, endPoint.Z) * (float)(1000 / _maxTravelDistance)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnUpdate(uint diff)
|
public override void OnUpdate(uint diff)
|
||||||
@@ -1060,11 +1056,9 @@ namespace Scripts.Spells.Priest
|
|||||||
Vector3[] returnSplinePoints = new Vector3[4];
|
Vector3[] returnSplinePoints = new Vector3[4];
|
||||||
|
|
||||||
returnSplinePoints[0] = at.GetPosition();
|
returnSplinePoints[0] = at.GetPosition();
|
||||||
returnSplinePoints[1] = at.GetPosition();
|
returnSplinePoints[1] = caster.GetPosition();
|
||||||
returnSplinePoints[2] = caster.GetPosition();
|
|
||||||
returnSplinePoints[3] = caster.GetPosition();
|
|
||||||
|
|
||||||
at.InitSplines(returnSplinePoints, (uint)(at.GetDistance(caster) / _maxTravelDistance * 1000));
|
at.InitSplines(returnSplinePoints);
|
||||||
|
|
||||||
task.Repeat(TimeSpan.FromMilliseconds(250));
|
task.Repeat(TimeSpan.FromMilliseconds(250));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -418,8 +418,7 @@ namespace Scripts.World.Areatriggers
|
|||||||
PathGenerator path = new(at);
|
PathGenerator path = new(at);
|
||||||
path.CalculatePath(destPos.GetPositionX(), destPos.GetPositionY(), destPos.GetPositionZ(), false);
|
path.CalculatePath(destPos.GetPositionX(), destPos.GetPositionY(), destPos.GetPositionZ(), false);
|
||||||
|
|
||||||
float timeToTarget = at.GetDistance(destPos.GetPositionX(), destPos.GetPositionY(), destPos.GetPositionZ()) * 144.5f;
|
at.InitSplines(path.GetPath());
|
||||||
at.InitSplines(path.GetPath(), (uint)timeToTarget);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user