Core/SpellScripts: Add BeforeCast, OnCast and AfterCast hooks to SpellScripts.
This commit is contained in:
@@ -3091,6 +3091,8 @@ void Spell::cast(bool skipCheck)
|
||||
m_caster->ToPlayer()->SetSpellModTakingSpell(this, true);
|
||||
}
|
||||
|
||||
CallScriptBeforeCastHandlers();
|
||||
|
||||
// skip check if done already (for instant cast spells for example)
|
||||
if (!skipCheck)
|
||||
{
|
||||
@@ -3160,6 +3162,8 @@ void Spell::cast(bool skipCheck)
|
||||
|
||||
PrepareTriggersExecutedOnHit();
|
||||
|
||||
CallScriptOnCastHandlers();
|
||||
|
||||
// traded items have trade slot instead of guid in m_itemTargetGUID
|
||||
// set to real guid to be sent later to the client
|
||||
m_targets.UpdateTradeSlotItem();
|
||||
@@ -3219,6 +3223,8 @@ void Spell::cast(bool skipCheck)
|
||||
handle_immediate();
|
||||
}
|
||||
|
||||
CallScriptAfterCastHandlers();
|
||||
|
||||
if (const std::vector<int32> *spell_triggered = sSpellMgr->GetSpellLinked(m_spellInfo->Id))
|
||||
{
|
||||
for (std::vector<int32>::const_iterator i = spell_triggered->begin(); i != spell_triggered->end(); ++i)
|
||||
@@ -6969,7 +6975,6 @@ void Spell::CheckEffectExecuteData()
|
||||
|
||||
void Spell::LoadScripts()
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell::LoadScripts");
|
||||
sScriptMgr->CreateSpellScripts(m_spellInfo->Id, m_loadedScripts);
|
||||
for (std::list<SpellScript*>::iterator itr = m_loadedScripts.begin(); itr != m_loadedScripts.end() ;)
|
||||
{
|
||||
@@ -6980,15 +6985,49 @@ void Spell::LoadScripts()
|
||||
m_loadedScripts.erase(bitr);
|
||||
continue;
|
||||
}
|
||||
sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "Spell::LoadScripts: Script `%s` for spell `%u` is loaded now", (*itr)->_GetScriptName()->c_str(), m_spellInfo->Id);
|
||||
(*itr)->Register();
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
void Spell::PrepareScriptHitHandlers()
|
||||
void Spell::CallScriptBeforeCastHandlers()
|
||||
{
|
||||
for (std::list<SpellScript*>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end() ; ++scritr)
|
||||
(*scritr)->_InitHit();
|
||||
{
|
||||
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_BEFORE_CAST);
|
||||
std::list<SpellScript::CastHandler>::iterator hookItrEnd = (*scritr)->BeforeCast.end(), hookItr = (*scritr)->BeforeCast.begin();
|
||||
for (; hookItr != hookItrEnd ; ++hookItr)
|
||||
(*hookItr).Call(*scritr);
|
||||
|
||||
(*scritr)->_FinishScriptCall();
|
||||
}
|
||||
}
|
||||
|
||||
void Spell::CallScriptOnCastHandlers()
|
||||
{
|
||||
for (std::list<SpellScript*>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end() ; ++scritr)
|
||||
{
|
||||
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_CAST);
|
||||
std::list<SpellScript::CastHandler>::iterator hookItrEnd = (*scritr)->OnCast.end(), hookItr = (*scritr)->OnCast.begin();
|
||||
for (; hookItr != hookItrEnd ; ++hookItr)
|
||||
(*hookItr).Call(*scritr);
|
||||
|
||||
(*scritr)->_FinishScriptCall();
|
||||
}
|
||||
}
|
||||
|
||||
void Spell::CallScriptAfterCastHandlers()
|
||||
{
|
||||
for (std::list<SpellScript*>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end() ; ++scritr)
|
||||
{
|
||||
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_AFTER_CAST);
|
||||
std::list<SpellScript::CastHandler>::iterator hookItrEnd = (*scritr)->AfterCast.end(), hookItr = (*scritr)->AfterCast.begin();
|
||||
for (; hookItr != hookItrEnd ; ++hookItr)
|
||||
(*hookItr).Call(*scritr);
|
||||
|
||||
(*scritr)->_FinishScriptCall();
|
||||
}
|
||||
}
|
||||
|
||||
SpellCastResult Spell::CallScriptCheckCastHandlers()
|
||||
@@ -7010,6 +7049,12 @@ SpellCastResult Spell::CallScriptCheckCastHandlers()
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void Spell::PrepareScriptHitHandlers()
|
||||
{
|
||||
for (std::list<SpellScript*>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end() ; ++scritr)
|
||||
(*scritr)->_InitHit();
|
||||
}
|
||||
|
||||
bool Spell::CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMode mode)
|
||||
{
|
||||
// execute script effect handler hooks and check if effects was prevented
|
||||
|
||||
Reference in New Issue
Block a user