From f959a0fd910659e05c9a07be05dd88c785df0d85 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 23 Jun 2021 16:02:44 -0400 Subject: [PATCH] Core/Spells: fix logic error causing near teleports to drop combat for players Port From (https://github.com/TrinityCore/TrinityCore/commit/8c379e920ca184d520c81ada26c42c5dfeac770d) --- Source/Framework/Constants/ScriptsConst.cs | 2 +- Source/Game/Scripting/SpellScript.cs | 23 +++++++++++++++++++--- Source/Game/Spells/Spell.cs | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Source/Framework/Constants/ScriptsConst.cs b/Source/Framework/Constants/ScriptsConst.cs index bd15065a2..057a26fac 100644 --- a/Source/Framework/Constants/ScriptsConst.cs +++ b/Source/Framework/Constants/ScriptsConst.cs @@ -34,7 +34,7 @@ namespace Framework.Constants EffectHitTarget, EffectSuccessfulDispel, BeforeHit, - OnHit, + Hit, AfterHit, ObjectAreaTargetSelect, ObjectTargetSelect, diff --git a/Source/Game/Scripting/SpellScript.cs b/Source/Game/Scripting/SpellScript.cs index 42e3c4221..033f9839f 100644 --- a/Source/Game/Scripting/SpellScript.cs +++ b/Source/Game/Scripting/SpellScript.cs @@ -447,16 +447,33 @@ namespace Game.Scripting case SpellScriptHookType.EffectHitTarget: case SpellScriptHookType.EffectSuccessfulDispel: case SpellScriptHookType.BeforeHit: - case SpellScriptHookType.OnHit: + case SpellScriptHookType.Hit: case SpellScriptHookType.AfterHit: return true; } return false; } + + bool IsInModifiableHook() + { + // after hit hook executed after damage/healing is already done + // modifying it at this point has no effect + switch ((SpellScriptHookType)m_currentScriptState) + { + case SpellScriptHookType.LaunchTarget: + case SpellScriptHookType.EffectHitTarget: + case SpellScriptHookType.BeforeHit: + case SpellScriptHookType.Hit: + return true; + } + return false; + } + public bool IsInHitPhase() { return (m_currentScriptState >= (byte)SpellScriptHookType.EffectHit && m_currentScriptState < (byte)SpellScriptHookType.AfterHit + 1); } + public bool IsInEffectHook() { return (m_currentScriptState >= (byte)SpellScriptHookType.Launch && m_currentScriptState <= (byte)SpellScriptHookType.EffectHitTarget) @@ -675,7 +692,7 @@ namespace Game.Scripting } public void SetHitDamage(int damage) { - if (!IsInTargetHook()) + if (!IsInModifiableHook()) { Log.outError(LogFilter.Scripts, "Script: `{0}` Spell: `{1}`: function SpellScript.SetHitDamage was called, but function has no effect in current hook!", m_scriptName, m_scriptSpellId); return; @@ -696,7 +713,7 @@ namespace Game.Scripting } public void SetHitHeal(int heal) { - if (!IsInTargetHook()) + if (!IsInModifiableHook()) { Log.outError(LogFilter.Scripts, "Script: `{0}` Spell: `{1}`: function SpellScript.SetHitHeal was called, but function has no effect in current hook!", m_scriptName, m_scriptSpellId); return; diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 9eac48a3d..92a93cb0e 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -7132,7 +7132,7 @@ namespace Game.Spells { foreach (var script in m_loadedScripts) { - script._PrepareScriptCall(SpellScriptHookType.OnHit); + script._PrepareScriptCall(SpellScriptHookType.Hit); foreach (var hook in script.OnHit) hook.Call();