Core/Movement: modify MovementInform trigger condition & checks in FollowMovementGenerator

Port From (https://github.com/TrinityCore/TrinityCore/commit/e6c0022a4d814a536800b7834a35db7d4d484f57)
This commit is contained in:
hondacrx
2022-02-22 13:32:22 -05:00
parent 14ec7655ad
commit ccfec6a37f
@@ -24,13 +24,13 @@ namespace Game.Movement
{ {
public class FollowMovementGenerator : MovementGenerator public class FollowMovementGenerator : MovementGenerator
{ {
static uint CHECK_INTERVAL = 500; static int CHECK_INTERVAL = 250;
static float FOLLOW_RANGE_TOLERANCE = 1.0f; static float FOLLOW_RANGE_TOLERANCE = 1.0f;
float _range; float _range;
ChaseAngle _angle; ChaseAngle _angle;
uint _checkTimer = CHECK_INTERVAL; TimeTrackerSmall _checkTimer;
PathGenerator _path; PathGenerator _path;
Position _lastTargetPosition; Position _lastTargetPosition;
@@ -46,12 +46,14 @@ namespace Game.Movement
Priority = MovementGeneratorPriority.Normal; Priority = MovementGeneratorPriority.Normal;
Flags = MovementGeneratorFlags.InitializationPending; Flags = MovementGeneratorFlags.InitializationPending;
BaseUnitState = UnitState.Follow; BaseUnitState = UnitState.Follow;
_checkTimer = new(CHECK_INTERVAL);
} }
public override void Initialize(Unit owner) public override void Initialize(Unit owner)
{ {
RemoveFlag(MovementGeneratorFlags.InitializationPending | MovementGeneratorFlags.Deactivated); RemoveFlag(MovementGeneratorFlags.InitializationPending | MovementGeneratorFlags.Deactivated);
AddFlag(MovementGeneratorFlags.Initialized); AddFlag(MovementGeneratorFlags.Initialized | MovementGeneratorFlags.InformEnabled);
owner.StopMoving(); owner.StopMoving();
UpdatePetSpeed(owner); UpdatePetSpeed(owner);
@@ -78,35 +80,27 @@ namespace Game.Movement
if (owner.HasUnitState(UnitState.NotMove) || owner.IsMovementPreventedByCasting()) if (owner.HasUnitState(UnitState.NotMove) || owner.IsMovementPreventedByCasting())
{ {
_path = null;
owner.StopMoving(); owner.StopMoving();
_lastTargetPosition = null; _lastTargetPosition = null;
return true; return true;
} }
if (owner.HasUnitState(UnitState.FollowMove)) _checkTimer.Update((int)diff);
if (_checkTimer.Passed())
{ {
if (_checkTimer > diff) _checkTimer.Reset(CHECK_INTERVAL);
_checkTimer -= diff; if (HasFlag(MovementGeneratorFlags.InformEnabled) && PositionOkay(owner, target, _range, _angle))
else
{ {
_checkTimer = CHECK_INTERVAL; RemoveFlag(MovementGeneratorFlags.InformEnabled);
if (PositionOkay(owner, target, _range, _angle)) _path = null;
{ owner.StopMoving();
_path = null; _lastTargetPosition = new();
owner.StopMoving(); DoMovementInform(owner, target);
DoMovementInform(owner, target); return true;
return true;
}
} }
} }
if (owner.HasUnitState(UnitState.FollowMove) && owner.MoveSpline.Finalized())
{
_path = null;
owner.ClearUnitState(UnitState.FollowMove);
DoMovementInform(owner, target);
}
if (_lastTargetPosition == null || _lastTargetPosition.GetExactDistSq(target.GetPosition()) > 0.0f) if (_lastTargetPosition == null || _lastTargetPosition.GetExactDistSq(target.GetPosition()) > 0.0f)
{ {
_lastTargetPosition = new(target.GetPosition()); _lastTargetPosition = new(target.GetPosition());
@@ -152,6 +146,7 @@ namespace Game.Movement
} }
owner.AddUnitState(UnitState.FollowMove); owner.AddUnitState(UnitState.FollowMove);
AddFlag(MovementGeneratorFlags.InformEnabled);
MoveSplineInit init = new(owner); MoveSplineInit init = new(owner);
init.MovebyPath(_path.GetPath()); init.MovebyPath(_path.GetPath());
@@ -166,6 +161,7 @@ namespace Game.Movement
public override void Deactivate(Unit owner) public override void Deactivate(Unit owner)
{ {
AddFlag(MovementGeneratorFlags.Deactivated); AddFlag(MovementGeneratorFlags.Deactivated);
RemoveFlag(MovementGeneratorFlags.Transitory | MovementGeneratorFlags.InformEnabled);
owner.ClearUnitState(UnitState.FollowMove); owner.ClearUnitState(UnitState.FollowMove);
} }