Core/Entities: unit states cleanup

Port From (https://github.com/TrinityCore/TrinityCore/commit/70c26d53cb94f0e78a57ecc2279c960370891aa4)
This commit is contained in:
hondacrx
2021-08-08 23:44:54 -04:00
parent 26a2eced6e
commit b039353f1a
5 changed files with 51 additions and 39 deletions
+12 -11
View File
@@ -448,23 +448,23 @@ namespace Framework.Constants
[Flags] [Flags]
public enum UnitState : uint public enum UnitState : uint
{ {
Died = 0x01, // Player Has Fake Death Aura Died = 0x01, // Player Has Fake Death Aura
MeleeAttacking = 0x02, // Player Is Melee Attacking Someone MeleeAttacking = 0x02, // Player Is Melee Attacking Someone
//Melee_Attack_By = 0x04, // Player Is Melee Attack By Someone Charmed = 0x04, // having any kind of charm aura on self
Stunned = 0x08, Stunned = 0x08,
Roaming = 0x10, Roaming = 0x10,
Chase = 0x20, Chase = 0x20,
//Searching = 0x40, Focusing = 0x40,
Fleeing = 0x80, Fleeing = 0x80,
InFlight = 0x100, // Player Is In Flight Mode InFlight = 0x100, // Player Is In Flight Mode
Follow = 0x200, Follow = 0x200,
Root = 0x400, Root = 0x400,
Confused = 0x800, Confused = 0x800,
Distracted = 0x1000, Distracted = 0x1000,
Isolated = 0x2000, // Area Auras Do Not Affect Other Players Isolated = 0x2000, // Area Auras Do Not Affect Other Players
AttackPlayer = 0x4000, AttackPlayer = 0x4000,
Casting = 0x8000, Casting = 0x8000,
Possessed = 0x10000, Possessed = 0x10000, // being possessed by another unit
Charging = 0x20000, Charging = 0x20000,
Jumping = 0x40000, Jumping = 0x40000,
Move = 0x100000, Move = 0x100000,
@@ -476,8 +476,8 @@ namespace Framework.Constants
ChaseMove = 0x4000000, ChaseMove = 0x4000000,
FollowMove = 0x8000000, FollowMove = 0x8000000,
IgnorePathfinding = 0x10000000, IgnorePathfinding = 0x10000000,
AllStateSupported = Died | MeleeAttacking | Stunned | Roaming | Chase AllStateSupported = Died | MeleeAttacking | Charmed | Stunned | Roaming | Chase
| Fleeing | InFlight | Follow | Root | Confused | Focusing | Fleeing | InFlight | Follow | Root | Confused
| Distracted | Isolated | AttackPlayer | Casting | Distracted | Isolated | AttackPlayer | Casting
| Possessed | Charging | Jumping | Move | Rotating | Possessed | Charging | Jumping | Move | Rotating
| Evade | RoamingMove | ConfusedMove | FleeingMove | Evade | RoamingMove | ConfusedMove | FleeingMove
@@ -486,10 +486,11 @@ namespace Framework.Constants
Unattackable = InFlight, Unattackable = InFlight,
Moving = RoamingMove | ConfusedMove | FleeingMove | ChaseMove | FollowMove, Moving = RoamingMove | ConfusedMove | FleeingMove | ChaseMove | FollowMove,
Controlled = Confused | Stunned | Fleeing, Controlled = Confused | Stunned | Fleeing,
CantClientControl = Confused | Charmed | Possessed | Fleeing,
LostControl = Controlled | Possessed | Jumping | Charging, LostControl = Controlled | Possessed | Jumping | Charging,
CannotAutoattack = Controlled | Charging | Casting,
Sightless = LostControl | Evade, Sightless = LostControl | Evade,
CannotAutoattack = LostControl | Casting, CannotTurn = LostControl | Rotating | Focusing,
CannotTurn = LostControl | Rotating,
NotMove = Root | Stunned | Died | Distracted, NotMove = Root | Stunned | Died | Distracted,
AllErasable = AllStateSupported & ~IgnorePathfinding, AllErasable = AllStateSupported & ~IgnorePathfinding,
+2 -2
View File
@@ -2945,7 +2945,7 @@ namespace Game.Entities
} }
if (!noTurnDuringCast) if (!noTurnDuringCast)
AddUnitState(UnitState.CannotTurn); AddUnitState(UnitState.Focusing);
} }
public override bool IsFocusing(Spell focusSpell = null, bool withDelay = false) public override bool IsFocusing(Spell focusSpell = null, bool withDelay = false)
@@ -3000,7 +3000,7 @@ namespace Game.Entities
MustReacquireTarget(); MustReacquireTarget();
if (_focusSpell.GetSpellInfo().HasAttribute(SpellAttr5.DontTurnDuringCast)) if (_focusSpell.GetSpellInfo().HasAttribute(SpellAttr5.DontTurnDuringCast))
ClearUnitState(UnitState.CannotTurn); ClearUnitState(UnitState.Focusing);
_focusSpell = null; _focusSpell = null;
_focusDelay = (!IsPet() && withDelay) ? GameTime.GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs _focusDelay = (!IsPet() && withDelay) ? GameTime.GetGameTimeMS() : 0; // don't allow re-target right away to prevent visual bugs
+5
View File
@@ -7231,6 +7231,10 @@ namespace Game.Entities
public void SetClientControl(Unit target, bool allowMove) 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(); ControlUpdate packet = new();
packet.Guid = target.GetGUID(); packet.Guid = target.GetGUID();
packet.On = allowMove; packet.On = allowMove;
@@ -7242,6 +7246,7 @@ namespace Game.Entities
if (allowMove) if (allowMove)
SetMover(target); SetMover(target);
} }
public void SetMover(Unit target) public void SetMover(Unit target)
{ {
m_unitMovedByMe.m_playerMovingMe = null; m_unitMovedByMe.m_playerMovingMe = null;
+25 -24
View File
@@ -1142,21 +1142,26 @@ namespace Game.Entities
return; return;
} }
// Unit States might have been already cleared but auras still present. I need to check with HasAuraType ApplyControlStatesIfNeeded();
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);
} }
} }
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) void SetStunned(bool apply)
{ {
if (apply) if (apply)
@@ -1250,13 +1255,11 @@ namespace Game.Entities
} }
} }
Player player = ToPlayer(); // block / allow control to real player in control (eg charmer)
if (player) if (IsPlayer())
{ {
if (apply) if (m_playerMovingMe)
player.SetClientControl(this, false); m_playerMovingMe.SetClientControl(this, !apply);
else if (!HasUnitState(UnitState.LostControl))
player.SetClientControl(this, true);
} }
} }
@@ -1278,13 +1281,11 @@ namespace Game.Entities
} }
} }
Player player = ToPlayer(); // block / allow control to real player in control (eg charmer)
if (player) if (IsPlayer())
{ {
if (apply) if (m_playerMovingMe)
player.SetClientControl(this, false); m_playerMovingMe.SetClientControl(this, !apply);
else if (!HasUnitState(UnitState.LostControl))
player.SetClientControl(this, true);
} }
} }
+7 -2
View File
@@ -441,6 +441,8 @@ namespace Game.Entities
break; break;
} }
} }
AddUnitState(UnitState.Charmed);
return true; return true;
} }
@@ -542,8 +544,7 @@ namespace Game.Entities
IsAIEnabled = false; IsAIEnabled = false;
} }
if (!HasUnitState(UnitState.LostControl)) player.SetClientControl(this, true);
player.SetClientControl(this, true);
} }
EngageWithTarget(charmer); EngageWithTarget(charmer);
@@ -553,6 +554,10 @@ namespace Game.Entities
playerCharmer.SendRemoveControlBar(); playerCharmer.SendRemoveControlBar();
else if (IsTypeId(TypeId.Player) || (IsTypeId(TypeId.Unit) && !IsGuardian())) else if (IsTypeId(TypeId.Player) || (IsTypeId(TypeId.Unit) && !IsGuardian()))
DeleteCharmInfo(); DeleteCharmInfo();
// reset confused movement for example
ApplyControlStatesIfNeeded();
ClearUnitState(UnitState.Charmed);
} }
public void GetAllMinionsByEntry(List<TempSummon> Minions, uint entry) public void GetAllMinionsByEntry(List<TempSummon> Minions, uint entry)