Core/Movement: MoveRotate improvements
* Allow overriding rotation speed * Allow limiting rotation using total rotation angle instead of duration Port From (https://github.com/TrinityCore/TrinityCore/commit/59f92412d0f2172772155591ee7fa98a54dab06a)
This commit is contained in:
@@ -47,12 +47,24 @@ namespace Game.Movement
|
|||||||
|
|
||||||
public class RotateMovementGenerator : MovementGenerator
|
public class RotateMovementGenerator : MovementGenerator
|
||||||
{
|
{
|
||||||
public RotateMovementGenerator(uint id, uint time, RotateDirection direction)
|
static float MIN_ANGLE_DELTA_FOR_FACING_UPDATE = 0.05f;
|
||||||
|
|
||||||
|
uint _id;
|
||||||
|
RotateDirection _direction;
|
||||||
|
TimeTracker _duration;
|
||||||
|
float? _turnSpeed; ///< radians per sec
|
||||||
|
float? _totalTurnAngle;
|
||||||
|
uint _diffSinceLastUpdate;
|
||||||
|
|
||||||
|
public RotateMovementGenerator(uint id, RotateDirection direction, TimeSpan? duration, float? turnSpeed, float? totalTurnAngle)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_duration = time;
|
|
||||||
_maxDuration = time;
|
|
||||||
_direction = direction;
|
_direction = direction;
|
||||||
|
if (duration.HasValue)
|
||||||
|
_duration = new TimeTracker(duration.Value);
|
||||||
|
|
||||||
|
_turnSpeed = turnSpeed;
|
||||||
|
_totalTurnAngle = totalTurnAngle;
|
||||||
|
|
||||||
Mode = MovementGeneratorMode.Default;
|
Mode = MovementGeneratorMode.Default;
|
||||||
Priority = MovementGeneratorPriority.Normal;
|
Priority = MovementGeneratorPriority.Normal;
|
||||||
@@ -64,7 +76,7 @@ namespace Game.Movement
|
|||||||
{
|
{
|
||||||
RemoveFlag(MovementGeneratorFlags.InitializationPending | MovementGeneratorFlags.Deactivated);
|
RemoveFlag(MovementGeneratorFlags.InitializationPending | MovementGeneratorFlags.Deactivated);
|
||||||
AddFlag(MovementGeneratorFlags.Initialized);
|
AddFlag(MovementGeneratorFlags.Initialized);
|
||||||
|
|
||||||
owner.StopMoving();
|
owner.StopMoving();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -85,28 +97,38 @@ namespace Game.Movement
|
|||||||
|
|
||||||
public override bool Update(Unit owner, uint diff)
|
public override bool Update(Unit owner, uint diff)
|
||||||
{
|
{
|
||||||
if (owner == null)
|
_diffSinceLastUpdate += diff;
|
||||||
return false;
|
|
||||||
|
|
||||||
float angle = owner.GetOrientation();
|
float currentAngle = owner.GetOrientation();
|
||||||
angle += diff * MathFunctions.TwoPi / _maxDuration * (_direction == RotateDirection.Left ? 1.0f : -1.0f);
|
float angleDelta = _turnSpeed.GetValueOrDefault(owner.GetSpeed(UnitMoveType.TurnRate)) * ((float)_diffSinceLastUpdate / (float)Time.InMilliseconds);
|
||||||
angle = Math.Clamp(angle, 0.0f, MathF.PI * 2);
|
|
||||||
|
|
||||||
MoveSplineInit init = new(owner);
|
if (_duration != null)
|
||||||
init.MoveTo(owner, false);
|
_duration.Update(diff);
|
||||||
if (!owner.GetTransGUID().IsEmpty())
|
|
||||||
init.DisableTransportPathTransformations();
|
|
||||||
|
|
||||||
init.SetFacing(angle);
|
if (_totalTurnAngle.HasValue)
|
||||||
init.Launch();
|
_totalTurnAngle = _totalTurnAngle - angleDelta;
|
||||||
|
|
||||||
if (_duration > diff)
|
bool expired = (_duration != null && _duration.Passed()) || (_totalTurnAngle.HasValue && _totalTurnAngle < 0.0f);
|
||||||
_duration -= diff;
|
|
||||||
else
|
if (angleDelta >= MIN_ANGLE_DELTA_FOR_FACING_UPDATE || expired)
|
||||||
|
{
|
||||||
|
float newAngle = Position.NormalizeOrientation(currentAngle + angleDelta * (_direction == RotateDirection.Left ? 1.0f : -1.0f));
|
||||||
|
|
||||||
|
MoveSplineInit init = new(owner);
|
||||||
|
init.MoveTo(owner.GetPosition(), false);
|
||||||
|
if (!owner.GetTransGUID().IsEmpty())
|
||||||
|
init.DisableTransportPathTransformations();
|
||||||
|
init.SetFacing(newAngle);
|
||||||
|
init.Launch();
|
||||||
|
|
||||||
|
_diffSinceLastUpdate = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expired)
|
||||||
{
|
{
|
||||||
AddFlag(MovementGeneratorFlags.InformEnabled);
|
AddFlag(MovementGeneratorFlags.InformEnabled);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -125,11 +147,6 @@ namespace Game.Movement
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Rotate; }
|
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Rotate; }
|
||||||
|
|
||||||
uint _id;
|
|
||||||
uint _duration;
|
|
||||||
uint _maxDuration;
|
|
||||||
RotateDirection _direction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DistractMovementGenerator : MovementGenerator
|
public class DistractMovementGenerator : MovementGenerator
|
||||||
@@ -163,7 +180,7 @@ namespace Game.Movement
|
|||||||
init.Launch();
|
init.Launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Reset(Unit owner)
|
public override void Reset(Unit owner)
|
||||||
{
|
{
|
||||||
RemoveFlag(MovementGeneratorFlags.Deactivated);
|
RemoveFlag(MovementGeneratorFlags.Deactivated);
|
||||||
Initialize(owner);
|
Initialize(owner);
|
||||||
|
|||||||
@@ -1046,12 +1046,19 @@ namespace Game.Movement
|
|||||||
Add(new WaypointMovementGenerator(path, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd, wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, generatePath), MovementSlot.Default);
|
Add(new WaypointMovementGenerator(path, repeatable, duration, speed, speedSelectionMode, waitTimeRangeAtPathEnd, wanderDistanceAtPathEnds, followPathBackwardsFromEndToStart, generatePath), MovementSlot.Default);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveRotate(uint id, uint time, RotateDirection direction)
|
/// <summary>
|
||||||
|
/// Makes the Unit turn in place
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">Movement identifier, later passed to script MovementInform hooks</param>
|
||||||
|
/// <param name="direction">Rotation direction</param>
|
||||||
|
/// <param name="time">How long should this movement last, infinite if not set</param>
|
||||||
|
/// <param name="turnSpeed">How fast should the unit rotate, in radians per second. Uses unit's turn speed if not set</param>
|
||||||
|
/// <param name="totalTurnAngle">Total angle of the entire movement, infinite if not set</param>
|
||||||
|
public void MoveRotate(uint id, RotateDirection direction, TimeSpan? time = null, float? turnSpeed = null, float? totalTurnAngle = null)
|
||||||
{
|
{
|
||||||
if (time == 0)
|
Log.outDebug(LogFilter.Movement, $"MotionMaster::MoveRotate: '{_owner.GetGUID()}', starts rotate (time: {time.GetValueOrDefault(TimeSpan.Zero)}ms, turnSpeed: {turnSpeed}, totalTurnAngle: {totalTurnAngle}, direction: {direction})");
|
||||||
return;
|
|
||||||
|
|
||||||
Add(new RotateMovementGenerator(id, time, direction));
|
Add(new RotateMovementGenerator(id, direction, time, turnSpeed, totalTurnAngle));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveFormation(Unit leader, float range, float angle, uint point1, uint point2)
|
public void MoveFormation(Unit leader, float range, float angle, uint point1, uint point2)
|
||||||
|
|||||||
Reference in New Issue
Block a user