Core/Creature: Fix an issue that sometimes prevented spellcast focus targets from being reacquired.

Port From (https://github.com/TrinityCore/TrinityCore/commit/4b588694caed2ccab36241abb61e2c93ce8b5bb1)
This commit is contained in:
hondacrx
2022-01-04 17:55:02 -05:00
parent 964542023c
commit 8c8e78bcbf
2 changed files with 30 additions and 31 deletions
@@ -103,9 +103,9 @@ namespace Game.Entities
struct SpellFocusInfo struct SpellFocusInfo
{ {
public Spell spell; public Spell Spell;
public uint delay; // ms until the creature's target should snap back (0 = no snapback scheduled) public uint Delay; // ms until the creature's target should snap back (0 = no snapback scheduled)
public ObjectGuid target; // the creature's "real" target while casting public ObjectGuid Target; // the creature's "real" target while casting
public float orientation; // the creature's "real" orientation while casting public float Orientation; // the creature's "real" orientation while casting
} }
} }
+26 -27
View File
@@ -532,12 +532,12 @@ namespace Game.Entities
GetThreatManager().Update(diff); GetThreatManager().Update(diff);
if (_spellFocusInfo.delay != 0) if (_spellFocusInfo.Delay != 0)
{ {
if (_spellFocusInfo.delay <= diff) if (_spellFocusInfo.Delay <= diff)
ReacquireSpellFocusTarget(); ReacquireSpellFocusTarget();
else else
_spellFocusInfo.delay -= diff; _spellFocusInfo.Delay -= diff;
} }
// periodic check to see if the creature has passed an evade boundary // periodic check to see if the creature has passed an evade boundary
@@ -2897,7 +2897,7 @@ namespace Game.Entities
public override void SetTarget(ObjectGuid guid) public override void SetTarget(ObjectGuid guid)
{ {
if (HasSpellFocus()) if (HasSpellFocus())
_spellFocusInfo.target = guid; _spellFocusInfo.Target = guid;
else else
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Target), guid); SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Target), guid);
} }
@@ -2905,7 +2905,7 @@ namespace Game.Entities
public void SetSpellFocus(Spell focusSpell, WorldObject target) public void SetSpellFocus(Spell focusSpell, WorldObject target)
{ {
// already focused // already focused
if (_spellFocusInfo.spell != null) if (_spellFocusInfo.Spell != null)
return; return;
// Prevent dead/feigning death creatures from setting a focus target, so they won't turn // Prevent dead/feigning death creatures from setting a focus target, so they won't turn
@@ -2930,15 +2930,15 @@ namespace Game.Entities
return; return;
// store pre-cast values for target and orientation (used to later restore) // store pre-cast values for target and orientation (used to later restore)
if (_spellFocusInfo.delay == 0) if (_spellFocusInfo.Delay == 0)
{ // only overwrite these fields if we aren't transitioning from one spell focus to another { // only overwrite these fields if we aren't transitioning from one spell focus to another
_spellFocusInfo.target = GetTarget(); _spellFocusInfo.Target = GetTarget();
_spellFocusInfo.orientation = GetOrientation(); _spellFocusInfo.Orientation = GetOrientation();
} }
else // don't automatically reacquire target for the previous spellcast else // don't automatically reacquire target for the previous spellcast
_spellFocusInfo.delay = 0; _spellFocusInfo.Delay = 0;
_spellFocusInfo.spell = focusSpell; _spellFocusInfo.Spell = focusSpell;
bool noTurnDuringCast = spellInfo.HasAttribute(SpellAttr5.DontTurnDuringCast); bool noTurnDuringCast = spellInfo.HasAttribute(SpellAttr5.DontTurnDuringCast);
// set target, then force send update packet to players if it changed to provide appropriate facing // set target, then force send update packet to players if it changed to provide appropriate facing
@@ -2983,28 +2983,28 @@ namespace Game.Entities
{ {
if (!IsAlive()) // dead creatures cannot focus if (!IsAlive()) // dead creatures cannot focus
{ {
if (_spellFocusInfo.spell != null || _spellFocusInfo.delay != 0) if (_spellFocusInfo.Spell != null || _spellFocusInfo.Delay != 0)
Log.outWarn(LogFilter.Unit, $"Creature '{GetName()}' (entry {GetEntry()}) has spell focus (spell id {(_spellFocusInfo.spell != null ? _spellFocusInfo.spell.GetSpellInfo().Id : 0)}, delay {_spellFocusInfo.delay}ms) despite being dead."); Log.outWarn(LogFilter.Unit, $"Creature '{GetName()}' (entry {GetEntry()}) has spell focus (spell id {(_spellFocusInfo.Spell != null ? _spellFocusInfo.Spell.GetSpellInfo().Id : 0)}, delay {_spellFocusInfo.Delay}ms) despite being dead.");
return false; return false;
} }
if (focusSpell) if (focusSpell)
return focusSpell == _spellFocusInfo.spell; return focusSpell == _spellFocusInfo.Spell;
else else
return _spellFocusInfo.spell != null || _spellFocusInfo.delay != 0; return _spellFocusInfo.Spell != null || _spellFocusInfo.Delay != 0;
} }
public void ReleaseSpellFocus(Spell focusSpell = null, bool withDelay = true) public void ReleaseSpellFocus(Spell focusSpell = null, bool withDelay = true)
{ {
if (!_spellFocusInfo.spell) if (!_spellFocusInfo.Spell)
return; return;
// focused to something else // focused to something else
if (focusSpell && focusSpell != _spellFocusInfo.spell) if (focusSpell && focusSpell != _spellFocusInfo.Spell)
return; return;
if (_spellFocusInfo.spell.GetSpellInfo().HasAttribute(SpellAttr5.DontTurnDuringCast)) if (_spellFocusInfo.Spell.GetSpellInfo().HasAttribute(SpellAttr5.DontTurnDuringCast))
ClearUnitState(UnitState.Focusing); ClearUnitState(UnitState.Focusing);
if (IsPet()) // player pets do not use delay system if (IsPet()) // player pets do not use delay system
@@ -3013,34 +3013,33 @@ namespace Game.Entities
ReacquireSpellFocusTarget(); ReacquireSpellFocusTarget();
} }
else // don't allow re-target right away to prevent visual bugs else // don't allow re-target right away to prevent visual bugs
_spellFocusInfo.delay = withDelay ? 1000 : 1u; _spellFocusInfo.Delay = withDelay ? 1000 : 1u;
_spellFocusInfo.spell = null; _spellFocusInfo.Spell = null;
} }
void ReacquireSpellFocusTarget() void ReacquireSpellFocusTarget()
{ {
if (!HasSpellFocus()) Cypher.Assert(HasSpellFocus());
return;
SetTarget(_spellFocusInfo.target); SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.Target), _spellFocusInfo.Target);
if (!HasUnitFlag2(UnitFlags2.DisableTurn)) if (!HasUnitFlag2(UnitFlags2.DisableTurn))
{ {
if (!_spellFocusInfo.target.IsEmpty()) if (!_spellFocusInfo.Target.IsEmpty())
{ {
WorldObject objTarget = Global.ObjAccessor.GetWorldObject(this, _spellFocusInfo.target); WorldObject objTarget = Global.ObjAccessor.GetWorldObject(this, _spellFocusInfo.Target);
if (objTarget) if (objTarget)
SetFacingToObject(objTarget, false); SetFacingToObject(objTarget, false);
} }
else else
SetFacingTo(_spellFocusInfo.orientation, false); SetFacingTo(_spellFocusInfo.Orientation, false);
} }
_spellFocusInfo.delay = 0; _spellFocusInfo.Delay = 0;
} }
public void DoNotReacquireSpellFocusTarget() { _spellFocusInfo.delay = 0; } public void DoNotReacquireSpellFocusTarget() { _spellFocusInfo.Delay = 0; }
public ulong GetSpawnId() { return m_spawnId; } public ulong GetSpawnId() { return m_spawnId; }