From 8c71ecf0b20e4c8dd477814e77d7436b5a0c1fa4 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Thu, 6 Jan 2022 10:24:20 -0500 Subject: [PATCH] Core/Movement: properly fix aura interrupts during movement Port From (https://github.com/TrinityCore/TrinityCore/commit/43a7091e8a86179e195e2bc021133ce751d48d48) --- Source/Framework/Constants/UnitConst.cs | 6 ++++++ Source/Game/Entities/Unit/Unit.Fields.cs | 13 +++++++++++++ Source/Game/Entities/Unit/Unit.Movement.cs | 19 ++++++++++++++----- Source/Game/Entities/Unit/Unit.cs | 9 +++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Source/Framework/Constants/UnitConst.cs b/Source/Framework/Constants/UnitConst.cs index a23466c41..a2c1eb807 100644 --- a/Source/Framework/Constants/UnitConst.cs +++ b/Source/Framework/Constants/UnitConst.cs @@ -79,10 +79,16 @@ namespace Framework.Constants public enum SummonSlot { + Any = -1, Pet = 0, Totem = 1, + Totem2 = 2, + Totem3 = 3, + Totem4 = 4, MiniPet = 5, Quest = 6, + + Max } public enum BaseModType diff --git a/Source/Game/Entities/Unit/Unit.Fields.cs b/Source/Game/Entities/Unit/Unit.Fields.cs index ab654ee6f..8718b99c3 100644 --- a/Source/Game/Entities/Unit/Unit.Fields.cs +++ b/Source/Game/Entities/Unit/Unit.Fields.cs @@ -43,6 +43,7 @@ namespace Game.Entities public uint m_movementCounter; //< Incrementing counter used in movement packets TimeTrackerSmall movesplineTimer; MovementForces _movementForces; + PositionUpdateInfo _positionUpdateInfo; protected Unit m_unitMovedByMe; // only ever set for players, and only for direct client control protected Player m_playerMovingMe; // only set for direct client control (possess effects, vehicles and similar) @@ -555,4 +556,16 @@ namespace Game.Entities { public StringArray name = new(SharedConst.MaxDeclinedNameCases); } + + struct PositionUpdateInfo + { + public bool Relocated; + public bool Turned; + + public void Reset() + { + Relocated = false; + Turned = false; + } + } } diff --git a/Source/Game/Entities/Unit/Unit.Movement.cs b/Source/Game/Entities/Unit/Unit.Movement.cs index d7d45873c..dc5fbf37b 100644 --- a/Source/Game/Entities/Unit/Unit.Movement.cs +++ b/Source/Game/Entities/Unit/Unit.Movement.cs @@ -600,13 +600,8 @@ namespace Game.Entities Math.Abs(GetPositionY() - y) > 0.001f || Math.Abs(GetPositionZ() - z) > 0.001f); - if (turn) - RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Turning); - if (relocated) { - RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Moving); - // move and update visible state if need if (IsTypeId(TypeId.Player)) GetMap().PlayerRelocation(ToPlayer(), x, y, z, orientation); @@ -618,6 +613,9 @@ namespace Game.Entities UpdatePositionData(); + _positionUpdateInfo.Relocated = relocated; + _positionUpdateInfo.Turned = turn; + bool isInWater = IsInWater(); if (!IsFalling() || isInWater || IsFlying()) RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags2.Ground); @@ -1741,6 +1739,17 @@ namespace Game.Entities UpdatePosition(loc.X, loc.Y, loc.Z, loc.W); } + + void InterruptMovementBasedAuras() + { + // TODO: Check if orientation transport offset changed instead of only global orientation + if (_positionUpdateInfo.Turned) + RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Turning); + + if (_positionUpdateInfo.Relocated && !GetVehicle()) + RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Moving); + } + public void DisableSpline() { m_movementInfo.RemoveMovementFlag(MovementFlag.Forward); diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 647fb0a53..ad3fdab02 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -172,6 +172,15 @@ namespace Game.Entities UpdateSplineMovement(diff); GetMotionMaster().Update(diff); + // Wait with the aura interrupts until we have updated our movement generators and position + if (IsPlayer()) + InterruptMovementBasedAuras(); + else if (!MoveSpline.Finalized()) + InterruptMovementBasedAuras(); + + // All position info based actions have been executed, reset info + _positionUpdateInfo.Reset(); + if (GetAI() == null && (!IsPlayer() || (IsCharmed() && GetCharmerGUID().IsCreature()))) UpdateCharmAI();