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]
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,
+2 -2
View File
@@ -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
+5
View File
@@ -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;
+25 -24
View File
@@ -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);
}
}
+7 -2
View File
@@ -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<TempSummon> Minions, uint entry)