Core/Misc: movement cleanup

Port From (https://github.com/TrinityCore/TrinityCore/commit/4793b073eec2af32622ff703911721100730e868)
This commit is contained in:
hondacrx
2021-09-26 12:17:10 -04:00
parent e747de7608
commit 569e20ebc1
12 changed files with 76 additions and 48 deletions
@@ -49,6 +49,7 @@ namespace Game.Movement
{
owner.AddUnitState(UnitState.Chase);
owner.SetWalk(false);
_path = null;
}
public bool Update(Unit owner, uint diff)
@@ -187,18 +188,18 @@ namespace Game.Movement
cOwner.SetCannotReachTarget(false);
}
public MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Chase; }
public void Reset(Unit owner) { Initialize(owner); }
public MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Chase; }
public void UnitSpeedChanged() { _lastTargetPosition.Relocate(0.0f, 0.0f, 0.0f); }
static bool IsMutualChase(Unit owner, Unit target)
{
IMovementGenerator gen = target.GetMotionMaster().TopOrNull();
if (gen == null || gen.GetMovementGeneratorType() != MovementGeneratorType.Chase)
if (target.GetMotionMaster().GetCurrentMovementGeneratorType() != MovementGeneratorType.Chase)
return false;
return ((ChaseMovementGenerator)gen).GetTarget() == owner;
return ((ChaseMovementGenerator)target.GetMotionMaster().Top()).GetTarget() == owner;
}
static bool PositionOkay(Unit owner, Unit target, float? minDistance, float? maxDistance, ChaseAngle? angle)
@@ -39,6 +39,7 @@ namespace Game.Movement
_timer.Reset(0);
_reference = owner.GetPosition();
_path = null;
}
public override void DoReset(T owner)
@@ -55,6 +56,7 @@ namespace Game.Movement
{
_interrupt = true;
owner.StopMoving();
_path = null;
return true;
}
else
@@ -73,9 +75,11 @@ namespace Game.Movement
owner.MovePositionToFirstCollision(destination, distance, angle);
if (_path == null)
{
_path = new PathGenerator(owner);
_path.SetPathLengthLimit(30.0f);
}
_path.SetPathLengthLimit(30.0f);
bool result = _path.CalculatePath(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ());
if (!result || _path.GetPathType().HasAnyFlag(PathType.NoPath))
{
@@ -40,6 +40,7 @@ namespace Game.Movement
owner.AddUnitFlag(UnitFlags.Fleeing);
owner.AddUnitState(UnitState.Fleeing);
SetTargetLocation(owner);
_path = null;
}
public override void DoReset(T owner)
@@ -56,6 +57,7 @@ namespace Game.Movement
{
_interrupt = true;
owner.StopMoving();
_path = null;
return true;
}
else
@@ -94,6 +96,7 @@ namespace Game.Movement
{
_interrupt = true;
owner.StopMoving();
_path = null;
return;
}
@@ -110,9 +113,11 @@ namespace Game.Movement
}
if (_path == null)
{
_path = new PathGenerator(owner);
_path.SetPathLengthLimit(30.0f);
}
_path.SetPathLengthLimit(30.0f);
bool result = _path.CalculatePath(destination.GetPositionX(), destination.GetPositionY(), destination.GetPositionZ());
if (!result || _path.GetPathType().HasAnyFlag(PathType.NoPath))
{
@@ -218,6 +223,11 @@ namespace Game.Movement
return base.Update(owner, diff);
}
public override MovementGeneratorType GetMovementGeneratorType()
{
return MovementGeneratorType.TimedFleeing;
}
TimeTracker _totalFleeTime;
}
}
@@ -44,6 +44,7 @@ namespace Game.Movement
{
owner.AddUnitState(UnitState.Follow);
UpdatePetSpeed(owner);
_path = null;
}
public bool Update(Unit owner, uint diff)
@@ -55,14 +55,17 @@ namespace Game.Movement
DoInitialize((T)owner);
IsActive = true;
}
public virtual void Finalize(Unit owner)
{
DoFinalize((T)owner);
}
public virtual void Reset(Unit owner)
{
DoReset((T)owner);
}
public virtual bool Update(Unit owner, uint diff)
{
return DoUpdate((T)owner, diff);
@@ -43,6 +43,7 @@ namespace Game.Movement
_wanderDistance = owner.GetRespawnRadius();
_timer.Reset(0);
_path = null;
}
public override void DoReset(Creature owner)
@@ -59,6 +60,7 @@ namespace Game.Movement
{
_interrupt = true;
owner.StopMoving();
_path = null;
return true;
}
else
@@ -87,6 +89,7 @@ namespace Game.Movement
{
_interrupt = true;
owner.StopMoving();
_path = null;
return;
}
@@ -100,9 +103,11 @@ namespace Game.Movement
uint resetTimer = RandomHelper.randChance(50) ? RandomHelper.URand(5000, 10000) : RandomHelper.URand(1000, 2000);
if (_path == null)
{
_path = new PathGenerator(owner);
_path.SetPathLengthLimit(30.0f);
}
_path.SetPathLengthLimit(30.0f);
bool result = _path.CalculatePath(position.GetPositionX(), position.GetPositionY(), position.GetPositionZ());
if (!result || _path.GetPathType().HasAnyFlag(PathType.NoPath))
{
@@ -257,7 +257,7 @@ namespace Game.Movement
// check if there is a wait time for the next movement
if (!_nextMoveTime.Passed())
{
// dont update wait timer while moving
// update timer since it's not moving
_nextMoveTime.Update((int)diff);
if (_nextMoveTime.Passed())
{
@@ -268,7 +268,7 @@ namespace Game.Movement
else // if it's not moving and there is no timer, assume node is reached
{
OnArrived(creature); // hooks and wait timer reset (if necessary)
_isArrivalDone = true; // signals that the next move will happen after reaching a node
_isArrivalDone = true; // signals to future StartMove that it reached a node
if (_nextMoveTime.Passed())
StartMove(creature); // check path status, get next point and move if necessary & can