From 08aae42fe0ba4e70d19114b4b905e331f6d983e6 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 27 Feb 2022 14:33:22 -0500 Subject: [PATCH] Scripts/Spells: Implement OnPrecast scripting hook for spell scripts Port From (https://github.com/TrinityCore/TrinityCore/commit/12d00e2e5f7e2cc7efe1ea8d126f9408055c05f8) --- Source/Framework/Constants/ScriptsConst.cs | 3 ++- Source/Game/Scripting/SpellScript.cs | 2 ++ Source/Game/Spells/Spell.cs | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Framework/Constants/ScriptsConst.cs b/Source/Framework/Constants/ScriptsConst.cs index 31602bddb..ba61b434f 100644 --- a/Source/Framework/Constants/ScriptsConst.cs +++ b/Source/Framework/Constants/ScriptsConst.cs @@ -44,7 +44,8 @@ namespace Framework.Constants OnCast, OnResistAbsorbCalculation, AfterCast, - CalcCritChance + CalcCritChance, + OnPrecast } // AuraScript interface - enum used for runtime checks of script function calls diff --git a/Source/Game/Scripting/SpellScript.cs b/Source/Game/Scripting/SpellScript.cs index e80a31c43..ba904285b 100644 --- a/Source/Game/Scripting/SpellScript.cs +++ b/Source/Game/Scripting/SpellScript.cs @@ -502,6 +502,8 @@ namespace Game.Scripting || m_currentScriptState == (byte)SpellScriptHookType.EffectSuccessfulDispel; } + public virtual void OnPrecast() { } + Spell m_spell; uint m_hitPreventEffectMask; uint m_hitPreventDefaultEffectMask; diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 854e4f0be..77dbd0d87 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -2413,6 +2413,8 @@ namespace Game.Spells // set timer base at cast time ReSetTimer(); + CallScriptOnPrecastHandler(); + Log.outDebug(LogFilter.Spells, "Spell.prepare: spell id {0} source {1} caster {2} customCastFlags {3} mask {4}", m_spellInfo.Id, m_caster.GetEntry(), m_originalCaster != null ? (int)m_originalCaster.GetEntry() : -1, _triggeredCastFlags, m_targets.GetTargetMask()); if (m_spellInfo.HasAttribute(SpellAttr12.StartCooldownOnCastStart)) @@ -7131,6 +7133,16 @@ namespace Game.Spells } } + void CallScriptOnPrecastHandler() + { + foreach (var script in m_loadedScripts) + { + script._PrepareScriptCall(SpellScriptHookType.OnPrecast); + script.OnPrecast(); + script._FinishScriptCall(); + } + } + void CallScriptBeforeCastHandlers() { foreach (var script in m_loadedScripts)