From 72fa0cd4501fdad390dd283cb69d61cb4e3afabf Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 5 Jan 2022 23:55:47 -0500 Subject: [PATCH] Core/Creature: Clear creature focus after an evade Port From (https://github.com/TrinityCore/TrinityCore/commit/a7cf209428fae5b025a0dcdc6b00bcef12175ed6) --- Source/Game/AI/CoreAI/CreatureAI.cs | 1 + Source/Game/Entities/Creature/Creature.cs | 17 +++++++++++------ Source/Game/Spells/Spell.cs | 11 ++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Source/Game/AI/CoreAI/CreatureAI.cs b/Source/Game/AI/CoreAI/CreatureAI.cs index c1613e5b6..bb0b17e29 100644 --- a/Source/Game/AI/CoreAI/CreatureAI.cs +++ b/Source/Game/AI/CoreAI/CreatureAI.cs @@ -314,6 +314,7 @@ namespace Game.AI me.SetLastDamagedTime(0); me.SetCannotReachTarget(false); me.DoNotReacquireSpellFocusTarget(); + me.SetTarget(ObjectGuid.Empty); me.GetSpellHistory().ResetAllCooldowns(); EngagementOver(); diff --git a/Source/Game/Entities/Creature/Creature.cs b/Source/Game/Entities/Creature/Creature.cs index 947fbbf72..42d906ad0 100644 --- a/Source/Game/Entities/Creature/Creature.cs +++ b/Source/Game/Entities/Creature/Creature.cs @@ -1101,7 +1101,7 @@ namespace Game.Entities { return $"{base.GetDebugInfo()}\nAIName: {GetAIName()} ScriptName: {GetScriptName()} WaypointPath: {GetWaypointPath()} SpawnId: {GetSpawnId()}"; } - + public override bool IsMovementPreventedByCasting() { // first check if currently a movement allowed channel is active and we're not casting @@ -2903,11 +2903,11 @@ namespace Game.Entities public void SetSpellFocus(Spell focusSpell, WorldObject target) { - // already focused - if (_spellFocusInfo.Spell != null) + // Pointer validation and checking for a already existing focus + if (_spellFocusInfo.Spell != null || focusSpell == null) return; - // Prevent dead/feigning death creatures from setting a focus target, so they won't turn + // Prevent dead / feign death creatures from setting a focus target if (!IsAlive() || HasUnitFlag2(UnitFlags2.FeignDeath) || HasAuraType(AuraType.FeignDeath)) return; @@ -2925,7 +2925,8 @@ namespace Game.Entities if (spellInfo.HasAura(AuraType.ControlVehicle)) return; - if ((!target || target == this) && focusSpell.GetCastTime() == 0) // instant cast, untargeted (or self-targeted) spell doesn't need any facing updates + // instant non-channeled casts and non-target spells don't need facing updates + if (target == null && (focusSpell.GetCastTime() == 0 && !spellInfo.IsChanneled())) return; // store pre-cast values for target and orientation (used to later restore) @@ -3042,7 +3043,11 @@ namespace Game.Entities _spellFocusInfo.Delay = 0; } - public void DoNotReacquireSpellFocusTarget() { _spellFocusInfo.Delay = 0; } + public void DoNotReacquireSpellFocusTarget() + { + _spellFocusInfo.Delay = 0; + _spellFocusInfo.Spell = null; + } public ulong GetSpawnId() { return m_spawnId; } diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index e9b4d2112..9ef821c26 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -3994,13 +3994,10 @@ namespace Game.Spells if (m_UniqueTargetInfo.Count == 1 && m_UniqueGOTargetInfo.Empty()) { - if (target.TargetGUID != unitCaster.GetGUID()) - { - Creature creatureCaster = unitCaster.ToCreature(); - if (creatureCaster != null) - if (!creatureCaster.HasSpellFocus()) - creatureCaster.SetSpellFocus(this, Global.ObjAccessor.GetWorldObject(creatureCaster, target.TargetGUID)); - } + Creature creatureCaster = unitCaster.ToCreature(); + if (creatureCaster != null) + if (!creatureCaster.HasSpellFocus(this)) + creatureCaster.SetSpellFocus(this, Global.ObjAccessor.GetWorldObject(creatureCaster, target.TargetGUID)); } }