From a911dd50f669a5d6d20fad9e732d89eed8c12a01 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 22 Feb 2022 13:26:27 -0500 Subject: [PATCH] Core/Movement: followup Port From (https://github.com/TrinityCore/TrinityCore/commit/875da437806b8956324078bc9abd0a495345d2e5) --- Source/Framework/Constants/UnitConst.cs | 7 ++-- .../Game/Entities/Creature/CreatureGroups.cs | 3 +- .../Movement/Generators/FormationMovement.cs | 34 +++++++------------ 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Source/Framework/Constants/UnitConst.cs b/Source/Framework/Constants/UnitConst.cs index a2c1eb807..e10d39851 100644 --- a/Source/Framework/Constants/UnitConst.cs +++ b/Source/Framework/Constants/UnitConst.cs @@ -474,6 +474,7 @@ namespace Framework.Constants Possessed = 0x10000, // being possessed by another unit Charging = 0x20000, Jumping = 0x40000, + FollowFormation = 0x80000, Move = 0x100000, Rotating = 0x200000, Evade = 0x400000, @@ -483,15 +484,17 @@ namespace Framework.Constants ChaseMove = 0x4000000, FollowMove = 0x8000000, IgnorePathfinding = 0x10000000, + FollowFormationMove = 0x20000000, + AllStateSupported = Died | MeleeAttacking | Charmed | Stunned | Roaming | Chase | Focusing | Fleeing | InFlight | Follow | Root | Confused | Distracted | Isolated | AttackPlayer | Casting | Possessed | Charging | Jumping | Move | Rotating | Evade | RoamingMove | ConfusedMove | FleeingMove - | ChaseMove | FollowMove | IgnorePathfinding, + | ChaseMove | FollowMove | IgnorePathfinding | FollowFormationMove, Unattackable = InFlight, - Moving = RoamingMove | ConfusedMove | FleeingMove | ChaseMove | FollowMove, + Moving = RoamingMove | ConfusedMove | FleeingMove | ChaseMove | FollowMove | FollowFormationMove, Controlled = Confused | Stunned | Fleeing, LostControl = Controlled | Possessed | Jumping | Charging, CannotAutoattack = Controlled | Charging | Casting, diff --git a/Source/Game/Entities/Creature/CreatureGroups.cs b/Source/Game/Entities/Creature/CreatureGroups.cs index 8429cdafa..9eff4c2a7 100644 --- a/Source/Game/Entities/Creature/CreatureGroups.cs +++ b/Source/Game/Entities/Creature/CreatureGroups.cs @@ -288,8 +288,7 @@ namespace Game.Entities float angle = pair.Value.FollowAngle + MathF.PI; // for some reason, someone thought it was a great idea to invert relativ angles... float dist = pair.Value.FollowDist; - var moveGen = member.GetMotionMaster().GetMovementGenerator(movement => { return movement.GetMovementGeneratorType() == MovementGeneratorType.Formation; }, MovementSlot.Default); - if (moveGen == null) + if (!member.HasUnitState(UnitState.Formation)) member.GetMotionMaster().MoveFormation(_leader, dist, angle, pair.Value.LeaderWaypointIDs[0], pair.Value.LeaderWaypointIDs[1]); } } diff --git a/Source/Game/Movement/Generators/FormationMovement.cs b/Source/Game/Movement/Generators/FormationMovement.cs index fa6e31118..79e1069c6 100644 --- a/Source/Game/Movement/Generators/FormationMovement.cs +++ b/Source/Game/Movement/Generators/FormationMovement.cs @@ -47,7 +47,7 @@ namespace Game.Movement Mode = MovementGeneratorMode.Default; Priority = MovementGeneratorPriority.Normal; Flags = MovementGeneratorFlags.InitializationPending; - BaseUnitState = UnitState.Roaming; + BaseUnitState = UnitState.FollowFormation; } public override void DoInitialize(Creature owner) @@ -83,15 +83,6 @@ namespace Game.Movement if (owner.HasUnitState(UnitState.NotMove) || owner.IsMovementPreventedByCasting()) { AddFlag(MovementGeneratorFlags.Interrupted); - owner.ClearUnitState(UnitState.RoamingMove); - owner.StopMoving(); - return true; - } - - // Leader has stopped moving, so do we as well - if (target.MoveSpline.Finalized() && target.MoveSpline.GetId() == _lastLeaderSplineID && _hasPredictedDestination) - { - owner.ClearUnitState(UnitState.RoamingMove); owner.StopMoving(); _nextMoveTimer.Reset(0); _hasPredictedDestination = false; @@ -99,19 +90,19 @@ namespace Game.Movement } // Update home position - owner.SetHomePosition(owner.GetPosition()); - if (HasFlag(MovementGeneratorFlags.Interrupted)) - RemoveFlag(MovementGeneratorFlags.Interrupted); - - // Leader has stopped moving, so do we as well - if (owner.HasUnitState(UnitState.RoamingMove) && _hasPredictedDestination && target.MoveSpline.Finalized() && target.MoveSpline.GetId() == _lastLeaderSplineID) + // If target is not moving and destination has been predicted and if we are on the same spline, we stop as well + if (target.MoveSpline.Finalized() && target.MoveSpline.GetId() == _lastLeaderSplineID && _hasPredictedDestination) { + AddFlag(MovementGeneratorFlags.Interrupted); owner.StopMoving(); _nextMoveTimer.Reset(0); _hasPredictedDestination = false; return true; } + if (!owner.MoveSpline.Finalized()) + owner.SetHomePosition(owner.GetPosition()); + // Formation leader has launched a new spline, launch a new one for our member as well // This action does not reset the regular movement launch cycle interval if (!target.MoveSpline.Finalized() && target.MoveSpline.GetId() != _lastLeaderSplineID) @@ -151,9 +142,9 @@ namespace Game.Movement } // We have reached our destination before launching a new movement. Alling facing with leader - if (owner.HasUnitState(UnitState.RoamingMove) && owner.MoveSpline.Finalized()) + if (owner.HasUnitState(UnitState.FollowFormationMove) && owner.MoveSpline.Finalized()) { - owner.ClearUnitState(UnitState.RoamingMove); + owner.ClearUnitState(UnitState.FollowFormationMove); owner.SetFacingTo(target.GetOrientation()); MovementInform(owner); } @@ -219,20 +210,21 @@ namespace Game.Movement init.Launch(); _lastLeaderPosition = target.GetPosition(); - owner.AddUnitState(UnitState.RoamingMove); + owner.AddUnitState(UnitState.FollowFormationMove); + RemoveFlag(MovementGeneratorFlags.Interrupted); } public override void DoDeactivate(Creature owner) { AddFlag(MovementGeneratorFlags.Deactivated); - owner.ClearUnitState(UnitState.RoamingMove); + owner.ClearUnitState(UnitState.FollowFormationMove); } public override void DoFinalize(Creature owner, bool active, bool movementInform) { AddFlag(MovementGeneratorFlags.Finalized); if (active) - owner.ClearUnitState(UnitState.RoamingMove); + owner.ClearUnitState(UnitState.FollowFormationMove); if (movementInform && HasFlag(MovementGeneratorFlags.InformEnabled)) MovementInform(owner);