diff --git a/Source/Framework/Constants/UnitConst.cs b/Source/Framework/Constants/UnitConst.cs index 81f2b197d..9244c8526 100644 --- a/Source/Framework/Constants/UnitConst.cs +++ b/Source/Framework/Constants/UnitConst.cs @@ -448,23 +448,23 @@ namespace Framework.Constants [Flags] public enum UnitState : uint { - Died = 0x01, // Player Has Fake Death Aura - MeleeAttacking = 0x02, // Player Is Melee Attacking Someone - //Melee_Attack_By = 0x04, // Player Is Melee Attack By Someone + Died = 0x01, // Player Has Fake Death Aura + MeleeAttacking = 0x02, // Player Is Melee Attacking Someone + Charmed = 0x04, // having any kind of charm aura on self Stunned = 0x08, Roaming = 0x10, Chase = 0x20, - //Searching = 0x40, + Focusing = 0x40, Fleeing = 0x80, - InFlight = 0x100, // Player Is In Flight Mode + InFlight = 0x100, // Player Is In Flight Mode Follow = 0x200, Root = 0x400, Confused = 0x800, Distracted = 0x1000, - Isolated = 0x2000, // Area Auras Do Not Affect Other Players + Isolated = 0x2000, // Area Auras Do Not Affect Other Players AttackPlayer = 0x4000, Casting = 0x8000, - Possessed = 0x10000, + Possessed = 0x10000, // being possessed by another unit Charging = 0x20000, Jumping = 0x40000, Move = 0x100000, @@ -476,8 +476,8 @@ namespace Framework.Constants ChaseMove = 0x4000000, FollowMove = 0x8000000, IgnorePathfinding = 0x10000000, - AllStateSupported = Died | MeleeAttacking | Stunned | Roaming | Chase - | Fleeing | InFlight | Follow | Root | Confused + 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 @@ -486,10 +486,11 @@ namespace Framework.Constants Unattackable = InFlight, Moving = RoamingMove | ConfusedMove | FleeingMove | ChaseMove | FollowMove, Controlled = Confused | Stunned | Fleeing, + CantClientControl = Confused | Charmed | Possessed | Fleeing, LostControl = Controlled | Possessed | Jumping | Charging, + CannotAutoattack = Controlled | Charging | Casting, Sightless = LostControl | Evade, - CannotAutoattack = LostControl | Casting, - CannotTurn = LostControl | Rotating, + CannotTurn = LostControl | Rotating | Focusing, NotMove = Root | Stunned | Died | Distracted, AllErasable = AllStateSupported & ~IgnorePathfinding, diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index bde35d9aa..205ba0e19 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -2945,7 +2945,7 @@ namespace Game.Entities } if (!noTurnDuringCast) - AddUnitState(UnitState.CannotTurn); + AddUnitState(UnitState.Focusing); } public override bool IsFocusing(Spell focusSpell = null, bool withDelay = false) @@ -3000,7 +3000,7 @@ namespace Game.Entities MustReacquireTarget(); if (_focusSpell.GetSpellInfo().HasAttribute(SpellAttr5.DontTurnDuringCast)) - ClearUnitState(UnitState.CannotTurn); + ClearUnitState(UnitState.Focusing); _focusSpell = null; _focusDelay = (!IsPet() && withDelay) ? GameTime.GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index 1560bfb88..d9aff5240 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -7231,6 +7231,10 @@ namespace Game.Entities public void SetClientControl(Unit target, bool allowMove) { + // still affected by some aura that shouldn't allow control, only allow on last such aura to be removed + if (allowMove && target.HasUnitState(UnitState.CantClientControl)) + return; + ControlUpdate packet = new(); packet.Guid = target.GetGUID(); packet.On = allowMove; @@ -7242,6 +7246,7 @@ namespace Game.Entities if (allowMove) SetMover(target); } + public void SetMover(Unit target) { m_unitMovedByMe.m_playerMovingMe = null; diff --git a/Source/Game/Entities/Unit/Unit.Movement.cs b/Source/Game/Entities/Unit/Unit.Movement.cs index e5412030c..cd4962b0c 100644 --- a/Source/Game/Entities/Unit/Unit.Movement.cs +++ b/Source/Game/Entities/Unit/Unit.Movement.cs @@ -1142,21 +1142,26 @@ namespace Game.Entities return; } - // Unit States might have been already cleared but auras still present. I need to check with HasAuraType - if (HasAuraType(AuraType.ModStun)) - SetStunned(true); - - if (HasAuraType(AuraType.ModRoot) || HasAuraType(AuraType.ModRoot2)) - SetRooted(true); - - if (HasAuraType(AuraType.ModConfuse)) - SetConfused(true); - - if (HasAuraType(AuraType.ModFear)) - SetFeared(true); + ApplyControlStatesIfNeeded(); } } + void ApplyControlStatesIfNeeded() + { + // Unit States might have been already cleared but auras still present. I need to check with HasAuraType + if (HasUnitState(UnitState.Stunned) || HasAuraType(AuraType.ModStun)) + SetStunned(true); + + if (HasUnitState(UnitState.Root) || HasAuraType(AuraType.ModRoot) || HasAuraType(AuraType.ModRoot2)) + SetRooted(true); + + if (HasUnitState(UnitState.Confused) || HasAuraType(AuraType.ModConfuse)) + SetConfused(true); + + if (HasUnitState(UnitState.Fleeing) || HasAuraType(AuraType.ModFear)) + SetFeared(true); + } + void SetStunned(bool apply) { if (apply) @@ -1250,13 +1255,11 @@ namespace Game.Entities } } - Player player = ToPlayer(); - if (player) + // block / allow control to real player in control (eg charmer) + if (IsPlayer()) { - if (apply) - player.SetClientControl(this, false); - else if (!HasUnitState(UnitState.LostControl)) - player.SetClientControl(this, true); + if (m_playerMovingMe) + m_playerMovingMe.SetClientControl(this, !apply); } } @@ -1278,13 +1281,11 @@ namespace Game.Entities } } - Player player = ToPlayer(); - if (player) + // block / allow control to real player in control (eg charmer) + if (IsPlayer()) { - if (apply) - player.SetClientControl(this, false); - else if (!HasUnitState(UnitState.LostControl)) - player.SetClientControl(this, true); + if (m_playerMovingMe) + m_playerMovingMe.SetClientControl(this, !apply); } } diff --git a/Source/Game/Entities/Unit/Unit.Pets.cs b/Source/Game/Entities/Unit/Unit.Pets.cs index 5fa6cdd34..08f3d8eca 100644 --- a/Source/Game/Entities/Unit/Unit.Pets.cs +++ b/Source/Game/Entities/Unit/Unit.Pets.cs @@ -441,6 +441,8 @@ namespace Game.Entities break; } } + + AddUnitState(UnitState.Charmed); return true; } @@ -542,8 +544,7 @@ namespace Game.Entities IsAIEnabled = false; } - if (!HasUnitState(UnitState.LostControl)) - player.SetClientControl(this, true); + player.SetClientControl(this, true); } EngageWithTarget(charmer); @@ -553,6 +554,10 @@ namespace Game.Entities playerCharmer.SendRemoveControlBar(); else if (IsTypeId(TypeId.Player) || (IsTypeId(TypeId.Unit) && !IsGuardian())) DeleteCharmInfo(); + + // reset confused movement for example + ApplyControlStatesIfNeeded(); + ClearUnitState(UnitState.Charmed); } public void GetAllMinionsByEntry(List Minions, uint entry)