Core/Spells: implement OnSpellStart spellscript hook that is getting called when the cast check has been successfully passed and the spell starts casting with a cast time

This commit is contained in:
Ovahlord
2019-02-14 09:07:29 +01:00
parent 9b88acf4dc
commit 2e551a052e
3 changed files with 21 additions and 1 deletions

View File

@@ -3148,6 +3148,8 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered
if (!(_triggeredCastFlags & TRIGGERED_IGNORE_GCD))
TriggerGlobalCooldown();
CallScriptOnSpellStartHandlers();
// commented out !m_spellInfo->StartRecoveryTime, it forces instant spells with global cooldown to be processed in spell::update
// as a result a spell that passed CheckCast and should be processed instantly may suffer from this delayed process
// the easiest bug to observe is LoS check in AddUnitTarget, even if spell passed the CheckCast LoS check the situation can change in spell::update
@@ -7699,6 +7701,20 @@ SpellCastResult Spell::CallScriptCheckCastHandlers()
return retVal;
}
void Spell::CallScriptOnSpellStartHandlers()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_SPELL_START);
auto hookItrEnd = (*scritr)->OnSpellStart.end(), hookItr = (*scritr)->OnSpellStart.begin();
for (; hookItr != hookItrEnd; ++hookItr)
(*hookItr).Call(*scritr);
(*scritr)->_FinishScriptCall();
}
}
void Spell::PrepareScriptHitHandlers()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)

View File

@@ -689,6 +689,7 @@ class TC_GAME_API Spell
void CallScriptBeforeCastHandlers();
void CallScriptOnCastHandlers();
void CallScriptAfterCastHandlers();
void CallScriptOnSpellStartHandlers();
SpellCastResult CallScriptCheckCastHandlers();
void PrepareScriptHitHandlers();
bool CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMode mode);

View File

@@ -172,7 +172,8 @@ enum SpellScriptHookType
SPELL_SCRIPT_HOOK_CHECK_CAST,
SPELL_SCRIPT_HOOK_BEFORE_CAST,
SPELL_SCRIPT_HOOK_ON_CAST,
SPELL_SCRIPT_HOOK_AFTER_CAST
SPELL_SCRIPT_HOOK_AFTER_CAST,
SPELL_SCRIPT_HOOK_ON_SPELL_START
};
#define HOOK_SPELL_HIT_START SPELL_SCRIPT_HOOK_EFFECT_HIT
@@ -307,6 +308,8 @@ class TC_GAME_API SpellScript : public _SpellScript
// SpellScript interface
// hooks to which you can attach your functions
//
// example: OnSpellStart += SpellCastFn(class::function);
HookList<CastHandler> OnSpellStart;
// example: BeforeCast += SpellCastFn(class::function);
HookList<CastHandler> BeforeCast;
// example: OnCast += SpellCastFn(class::function);