From 0c527d206c345cd32465769756ae277a87daf312 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 23 Jun 2021 14:13:31 -0400 Subject: [PATCH] Core/Entities: don't allow client control if player is still affected by any lose of control state Port From (https://github.com/TrinityCore/TrinityCore/commit/29bfa32fc39de1d93fbdb272d48689174c547725) --- Source/Framework/Constants/UnitConst.cs | 10 +++--- Source/Game/BattleGrounds/BattleGround.cs | 3 +- Source/Game/Entities/Unit/Unit.Movement.cs | 39 +++++++++++++--------- Source/Game/Entities/Unit/Unit.Pets.cs | 4 ++- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/Source/Framework/Constants/UnitConst.cs b/Source/Framework/Constants/UnitConst.cs index 126cd7762..f215d5efd 100644 --- a/Source/Framework/Constants/UnitConst.cs +++ b/Source/Framework/Constants/UnitConst.cs @@ -484,11 +484,11 @@ namespace Framework.Constants Unattackable = InFlight, Moving = RoamingMove | ConfusedMove | FleeingMove | ChaseMove | FollowMove, - Controlled = (Confused | Stunned | Fleeing), - LostControl = (Controlled | Jumping | Charging), - Sightless = (LostControl | Evade), - CannotAutoattack = (LostControl | Casting), - CannotTurn = (LostControl | Rotating), + Controlled = Confused | Stunned | Fleeing, + LostControl = Controlled | Possessed | Jumping | Charging, + Sightless = LostControl | Evade, + CannotAutoattack = LostControl | Casting, + CannotTurn = LostControl | Rotating, NotMove = Root | Stunned | Died | Distracted, AllErasable = AllStateSupported & ~IgnorePathfinding, diff --git a/Source/Game/BattleGrounds/BattleGround.cs b/Source/Game/BattleGrounds/BattleGround.cs index f53544d97..72a66f925 100644 --- a/Source/Game/BattleGrounds/BattleGround.cs +++ b/Source/Game/BattleGrounds/BattleGround.cs @@ -820,7 +820,8 @@ namespace Game.BattleGrounds void BlockMovement(Player player) { - player.SetClientControl(player, false); // movement disabled NOTE: the effect will be automatically removed by client when the player is teleported from the Battleground, so no need to send with byte(1) in RemovePlayerAtLeave() + // movement disabled NOTE: the effect will be automatically removed by client when the player is teleported from the battleground, so no need to send with uint8(1) in RemovePlayerAtLeave() + player.SetClientControl(player, false); } public virtual void RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool SendPacket) diff --git a/Source/Game/Entities/Unit/Unit.Movement.cs b/Source/Game/Entities/Unit/Unit.Movement.cs index 4b4e79f6d..34a46ae94 100644 --- a/Source/Game/Entities/Unit/Unit.Movement.cs +++ b/Source/Game/Entities/Unit/Unit.Movement.cs @@ -1113,12 +1113,14 @@ namespace Game.Entities if (HasAuraType(AuraType.ModStun)) return; + ClearUnitState(state); SetStunned(false); break; case UnitState.Root: if (HasAuraType(AuraType.ModRoot) || HasAuraType(AuraType.ModRoot2) || GetVehicle() != null) return; + ClearUnitState(state); if (!HasUnitState(UnitState.Stunned)) SetRooted(false); break; @@ -1126,33 +1128,32 @@ namespace Game.Entities if (HasAuraType(AuraType.ModConfuse)) return; + ClearUnitState(state); SetConfused(false); break; case UnitState.Fleeing: if (HasAuraType(AuraType.ModFear)) return; + ClearUnitState(state); SetFeared(false); break; default: return; } - ClearUnitState(state); - // Unit States might have been already cleared but auras still present. I need to check with HasAuraType if (HasAuraType(AuraType.ModStun)) SetStunned(true); - else - { - if (HasAuraType(AuraType.ModRoot) || HasAuraType(AuraType.ModRoot2)) - SetRooted(true); - if (HasAuraType(AuraType.ModConfuse)) - SetConfused(true); - else if (HasAuraType(AuraType.ModFear)) - SetFeared(true); - } + if (HasAuraType(AuraType.ModRoot) || HasAuraType(AuraType.ModRoot2)) + SetRooted(true); + + if (HasAuraType(AuraType.ModConfuse)) + SetConfused(true); + + if (HasAuraType(AuraType.ModFear)) + SetFeared(true); } } @@ -1251,8 +1252,12 @@ namespace Game.Entities Player player = ToPlayer(); if (player) - if (player.HasUnitState(UnitState.Possessed)) - player.SetClientControl(this, !apply); + { + if (apply) + player.SetClientControl(this, false); + else if (!HasUnitState(UnitState.LostControl)) + player.SetClientControl(this, true); + } } void SetConfused(bool apply) @@ -1275,8 +1280,12 @@ namespace Game.Entities Player player = ToPlayer(); if (player) - if (player.HasUnitState(UnitState.Possessed)) - player.SetClientControl(this, !apply); + { + if (apply) + player.SetClientControl(this, false); + else if (!HasUnitState(UnitState.LostControl)) + player.SetClientControl(this, true); + } } public bool CanFreeMove() diff --git a/Source/Game/Entities/Unit/Unit.Pets.cs b/Source/Game/Entities/Unit/Unit.Pets.cs index ea4b4fde0..5fa6cdd34 100644 --- a/Source/Game/Entities/Unit/Unit.Pets.cs +++ b/Source/Game/Entities/Unit/Unit.Pets.cs @@ -541,7 +541,9 @@ namespace Game.Entities NeedChangeAI = true; IsAIEnabled = false; } - player.SetClientControl(this, true); + + if (!HasUnitState(UnitState.LostControl)) + player.SetClientControl(this, true); } EngageWithTarget(charmer);