Scripts/Spells: Modernize spell script internals a bit - this makes Prepare macros unneccessary

This commit is contained in:
Shauren
2023-07-24 00:27:25 +02:00
parent 576ca241ec
commit 228c56f3c5
6 changed files with 1941 additions and 1688 deletions

View File

@@ -6044,7 +6044,7 @@ void ObjectMgr::ValidateSpellScripts()
if (spellScript)
{
spellScript->_Init(&spellScriptLoader->GetName(), spellEntry->Id);
spellScript->_Init(spellScriptLoader->GetName(), spellEntry->Id);
spellScript->_Register();
if (!spellScript->_Validate(spellEntry))
@@ -6056,7 +6056,7 @@ void ObjectMgr::ValidateSpellScripts()
if (auraScript)
{
auraScript->_Init(&spellScriptLoader->GetName(), spellEntry->Id);
auraScript->_Init(spellScriptLoader->GetName(), spellEntry->Id);
auraScript->_Register();
if (!auraScript->_Validate(spellEntry))

View File

@@ -1350,8 +1350,8 @@ void ScriptMgr::FillSpellSummary()
UnitAI::FillAISpellInfo();
}
template<typename T, typename F, typename O>
void CreateSpellOrAuraScripts(uint32 spellId, std::vector<T*>& scriptVector, F&& extractor, O* objectInvoker)
template<typename T, typename O>
void CreateSpellOrAuraScripts(uint32 spellId, std::vector<T*>& scriptVector, T*(SpellScriptLoader::*extractor)() const, O* objectInvoker)
{
SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spellId);
for (auto itr = bounds.first; itr != bounds.second; ++itr)
@@ -1364,11 +1364,11 @@ void CreateSpellOrAuraScripts(uint32 spellId, std::vector<T*>& scriptVector, F&&
if (!tmpscript)
continue;
T* script = (*tmpscript.*extractor)();
T* script = (tmpscript->*extractor)();
if (!script)
continue;
script->_Init(&tmpscript->GetName(), spellId);
script->_Init(tmpscript->GetName(), spellId);
if (!script->_Load(objectInvoker))
{
delete script;

View File

@@ -476,9 +476,9 @@ m_lastProcAttemptTime(GameTime::Now() - Seconds(10)), m_lastProcSuccessTime(Game
AuraScript* Aura::GetScriptByType(std::type_info const& type) const
{
for (AuraScript* loadedScript : m_loadedScripts)
if (typeid(*loadedScript) == type)
return loadedScript;
for (AuraScript* script : m_loadedScripts)
if (typeid(*script) == type)
return script;
return nullptr;
}
@@ -495,10 +495,10 @@ void Aura::_InitEffects(uint32 effMask, Unit* caster, int32 const* baseAmount)
Aura::~Aura()
{
// unload scripts
for (auto itr = m_loadedScripts.begin(); itr != m_loadedScripts.end(); ++itr)
for (AuraScript* script : m_loadedScripts)
{
(*itr)->_Unload();
delete (*itr);
script->_Unload();
delete script;
}
for (AuraEffect* effect : _effects)
@@ -2008,69 +2008,65 @@ void Aura::_DeleteRemovedApplications()
void Aura::LoadScripts()
{
sScriptMgr->CreateAuraScripts(m_spellInfo->Id, m_loadedScripts, this);
for (auto itr = m_loadedScripts.begin(); itr != m_loadedScripts.end(); ++itr)
for (AuraScript* script : m_loadedScripts)
{
TC_LOG_DEBUG("spells", "Aura::LoadScripts: Script `{}` for aura `{}` is loaded now", (*itr)->_GetScriptName()->c_str(), m_spellInfo->Id);
(*itr)->Register();
TC_LOG_DEBUG("spells", "Aura::LoadScripts: Script `{}` for aura `{}` is loaded now", script->GetScriptName(), m_spellInfo->Id);
script->Register();
}
}
bool Aura::CallScriptCheckAreaTargetHandlers(Unit* target)
{
bool result = true;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_CHECK_AREA_TARGET);
auto hookItrEnd = (*scritr)->DoCheckAreaTarget.end(), hookItr = (*scritr)->DoCheckAreaTarget.begin();
for (; hookItr != hookItrEnd; ++hookItr)
result &= hookItr->Call(*scritr, target);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_CHECK_AREA_TARGET);
for (AuraScript::CheckAreaTargetHandler const& checkAreaTarget : script->DoCheckAreaTarget)
result &= checkAreaTarget.Call(script, target);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return result;
}
void Aura::CallScriptDispel(DispelInfo* dispelInfo)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_DISPEL);
auto hookItrEnd = (*scritr)->OnDispel.end(), hookItr = (*scritr)->OnDispel.begin();
for (; hookItr != hookItrEnd; ++hookItr)
hookItr->Call(*scritr, dispelInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_DISPEL);
for (AuraScript::AuraDispelHandler const& onDispel : script->OnDispel)
onDispel.Call(script, dispelInfo);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptAfterDispel(DispelInfo* dispelInfo)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_AFTER_DISPEL);
auto hookItrEnd = (*scritr)->AfterDispel.end(), hookItr = (*scritr)->AfterDispel.begin();
for (; hookItr != hookItrEnd; ++hookItr)
hookItr->Call(*scritr, dispelInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_AFTER_DISPEL);
for (AuraScript::AuraDispelHandler const& afterDispel : script->AfterDispel)
afterDispel.Call(script, dispelInfo);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
bool Aura::CallScriptEffectApplyHandlers(AuraEffect const* aurEff, AuraApplication const* aurApp, AuraEffectHandleModes mode)
{
bool preventDefault = false;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_APPLY, aurApp);
auto effEndItr = (*scritr)->OnEffectApply.end(), effItr = (*scritr)->OnEffectApply.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, mode);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_APPLY, aurApp);
for (AuraScript::EffectApplyHandler const& onEffectApply : script->OnEffectApply)
if (onEffectApply.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()) && onEffectApply.GetMode() & mode)
onEffectApply.Call(script, aurEff, mode);
if (!preventDefault)
preventDefault = (*scritr)->_IsDefaultActionPrevented();
preventDefault = script->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return preventDefault;
@@ -2079,65 +2075,61 @@ bool Aura::CallScriptEffectApplyHandlers(AuraEffect const* aurEff, AuraApplicati
bool Aura::CallScriptEffectRemoveHandlers(AuraEffect const* aurEff, AuraApplication const* aurApp, AuraEffectHandleModes mode)
{
bool preventDefault = false;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_REMOVE, aurApp);
auto effEndItr = (*scritr)->OnEffectRemove.end(), effItr = (*scritr)->OnEffectRemove.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, mode);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_REMOVE, aurApp);
for (AuraScript::EffectApplyHandler const& onEffectRemove : script->OnEffectRemove)
if (onEffectRemove.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()) && onEffectRemove.GetMode() & mode)
onEffectRemove.Call(script, aurEff, mode);
if (!preventDefault)
preventDefault = (*scritr)->_IsDefaultActionPrevented();
preventDefault = script->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return preventDefault;
}
void Aura::CallScriptAfterEffectApplyHandlers(AuraEffect const* aurEff, AuraApplication const* aurApp, AuraEffectHandleModes mode)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_APPLY, aurApp);
auto effEndItr = (*scritr)->AfterEffectApply.end(), effItr = (*scritr)->AfterEffectApply.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, mode);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_APPLY, aurApp);
for (AuraScript::EffectApplyHandler const& afterEffectApply : script->AfterEffectApply)
if (afterEffectApply.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()) && afterEffectApply.GetMode() & mode)
afterEffectApply.Call(script, aurEff, mode);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptAfterEffectRemoveHandlers(AuraEffect const* aurEff, AuraApplication const* aurApp, AuraEffectHandleModes mode)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_REMOVE, aurApp);
auto effEndItr = (*scritr)->AfterEffectRemove.end(), effItr = (*scritr)->AfterEffectRemove.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, mode);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_REMOVE, aurApp);
for (AuraScript::EffectApplyHandler const& afterEffectRemove : script->AfterEffectRemove)
if (afterEffectRemove.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()) && afterEffectRemove.GetMode() & mode)
afterEffectRemove.Call(script, aurEff, mode);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
bool Aura::CallScriptEffectPeriodicHandlers(AuraEffect const* aurEff, AuraApplication const* aurApp)
{
bool preventDefault = false;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_PERIODIC, aurApp);
auto effEndItr = (*scritr)->OnEffectPeriodic.end(), effItr = (*scritr)->OnEffectPeriodic.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_PERIODIC, aurApp);
for (AuraScript::EffectPeriodicHandler const& onEffectPeriodic : script->OnEffectPeriodic)
if (onEffectPeriodic.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
onEffectPeriodic.Call(script, aurEff);
if (!preventDefault)
preventDefault = (*scritr)->_IsDefaultActionPrevented();
preventDefault = script->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return preventDefault;
@@ -2145,202 +2137,191 @@ bool Aura::CallScriptEffectPeriodicHandlers(AuraEffect const* aurEff, AuraApplic
void Aura::CallScriptEffectUpdatePeriodicHandlers(AuraEffect* aurEff)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_UPDATE_PERIODIC);
auto effEndItr = (*scritr)->OnEffectUpdatePeriodic.end(), effItr = (*scritr)->OnEffectUpdatePeriodic.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_UPDATE_PERIODIC);
for (AuraScript::EffectUpdatePeriodicHandler const& onEffectUpdatePeriodic : script->OnEffectUpdatePeriodic)
if (onEffectUpdatePeriodic.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
onEffectUpdatePeriodic.Call(script, aurEff);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectCalcAmountHandlers(AuraEffect const* aurEff, int32& amount, bool& canBeRecalculated)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_AMOUNT);
auto effEndItr = (*scritr)->DoEffectCalcAmount.end(), effItr = (*scritr)->DoEffectCalcAmount.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, amount, canBeRecalculated);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_AMOUNT);
for (AuraScript::EffectCalcAmountHandler const& effectCalcAmount : script->DoEffectCalcAmount)
if (effectCalcAmount.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effectCalcAmount.Call(script, aurEff, amount, canBeRecalculated);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectCalcPeriodicHandlers(AuraEffect const* aurEff, bool& isPeriodic, int32& amplitude)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_PERIODIC);
auto effEndItr = (*scritr)->DoEffectCalcPeriodic.end(), effItr = (*scritr)->DoEffectCalcPeriodic.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, isPeriodic, amplitude);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_PERIODIC);
for (AuraScript::EffectCalcPeriodicHandler const& effectCalcPeriodic : script->DoEffectCalcPeriodic)
if (effectCalcPeriodic.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effectCalcPeriodic.Call(script, aurEff, isPeriodic, amplitude);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectCalcSpellModHandlers(AuraEffect const* aurEff, SpellModifier*& spellMod)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_SPELLMOD);
auto effEndItr = (*scritr)->DoEffectCalcSpellMod.end(), effItr = (*scritr)->DoEffectCalcSpellMod.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, spellMod);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_SPELLMOD);
for (AuraScript::EffectCalcSpellModHandler const& effectCalcSpellMod : script->DoEffectCalcSpellMod)
if (effectCalcSpellMod.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effectCalcSpellMod.Call(script, aurEff, spellMod);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectCalcCritChanceHandlers(AuraEffect const* aurEff, AuraApplication const* aurApp, Unit const* victim, float& critChance)
{
for (AuraScript* loadedScript : m_loadedScripts)
for (AuraScript* script : m_loadedScripts)
{
loadedScript->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_CRIT_CHANCE, aurApp);
for (AuraScript::EffectCalcCritChanceHandler const& hook : loadedScript->DoEffectCalcCritChance)
if (hook.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
hook.Call(loadedScript, aurEff, victim, critChance);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_CALC_CRIT_CHANCE, aurApp);
for (AuraScript::EffectCalcCritChanceHandler const& effectCalcCritChance : script->DoEffectCalcCritChance)
if (effectCalcCritChance.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effectCalcCritChance.Call(script, aurEff, victim, critChance);
loadedScript->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectAbsorbHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, DamageInfo& dmgInfo, uint32& absorbAmount, bool& defaultPrevented)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_ABSORB, aurApp);
auto effEndItr = (*scritr)->OnEffectAbsorb.end(), effItr = (*scritr)->OnEffectAbsorb.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, dmgInfo, absorbAmount);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_ABSORB, aurApp);
for (AuraScript::EffectAbsorbHandler const& onEffectAbsorb : script->OnEffectAbsorb)
if (onEffectAbsorb.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
onEffectAbsorb.Call(script, aurEff, dmgInfo, absorbAmount);
if (!defaultPrevented)
defaultPrevented = (*scritr)->_IsDefaultActionPrevented();
defaultPrevented = script->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectAfterAbsorbHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, DamageInfo& dmgInfo, uint32& absorbAmount)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB, aurApp);
auto effEndItr = (*scritr)->AfterEffectAbsorb.end(), effItr = (*scritr)->AfterEffectAbsorb.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, dmgInfo, absorbAmount);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB, aurApp);
for (AuraScript::EffectAbsorbHandler const& afterEffectAbsorb : script->AfterEffectAbsorb)
if (afterEffectAbsorb.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
afterEffectAbsorb.Call(script, aurEff, dmgInfo, absorbAmount);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectAbsorbHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, HealInfo& healInfo, uint32& absorbAmount, bool& defaultPrevented)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_ABSORB, aurApp);
auto effEndItr = (*scritr)->OnEffectAbsorbHeal.end(), effItr = (*scritr)->OnEffectAbsorbHeal.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, healInfo, absorbAmount);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_ABSORB, aurApp);
for (AuraScript::EffectAbsorbHealHandler const& onEffectAbsorbHeal : script->OnEffectAbsorbHeal)
if (onEffectAbsorbHeal.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
onEffectAbsorbHeal.Call(script, aurEff, healInfo, absorbAmount);
if (!defaultPrevented)
defaultPrevented = (*scritr)->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
defaultPrevented = script->_IsDefaultActionPrevented();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectAfterAbsorbHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, HealInfo& healInfo, uint32& absorbAmount)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB, aurApp);
auto effEndItr = (*scritr)->AfterEffectAbsorbHeal.end(), effItr = (*scritr)->AfterEffectAbsorbHeal.begin();
for (; effItr != effEndItr; ++effItr)
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_ABSORB, aurApp);
for (AuraScript::EffectAbsorbHealHandler const& afterEffectAbsorbHeal : script->AfterEffectAbsorbHeal)
if (afterEffectAbsorbHeal.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
afterEffectAbsorbHeal.Call(script, aurEff, healInfo, absorbAmount);
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, healInfo, absorbAmount);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectManaShieldHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, DamageInfo& dmgInfo, uint32& absorbAmount, bool& /*defaultPrevented*/)
void Aura::CallScriptEffectManaShieldHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, DamageInfo& dmgInfo, uint32& absorbAmount, bool& defaultPrevented)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_MANASHIELD, aurApp);
auto effEndItr = (*scritr)->OnEffectManaShield.end(), effItr = (*scritr)->OnEffectManaShield.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, dmgInfo, absorbAmount);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_MANASHIELD, aurApp);
for (AuraScript::EffectAbsorbHandler const& onEffectManaShield : script->OnEffectManaShield)
if (onEffectManaShield.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
onEffectManaShield.Call(script, aurEff, dmgInfo, absorbAmount);
(*scritr)->_FinishScriptCall();
if (!defaultPrevented)
defaultPrevented = script->_IsDefaultActionPrevented();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectAfterManaShieldHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, DamageInfo& dmgInfo, uint32& absorbAmount)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_MANASHIELD, aurApp);
auto effEndItr = (*scritr)->AfterEffectManaShield.end(), effItr = (*scritr)->AfterEffectManaShield.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, dmgInfo, absorbAmount);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_MANASHIELD, aurApp);
for (AuraScript::EffectAbsorbHandler const& afterEffectManaShield : script->AfterEffectManaShield)
if (afterEffectManaShield.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
afterEffectManaShield.Call(script, aurEff, dmgInfo, absorbAmount);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEffectSplitHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, DamageInfo& dmgInfo, uint32& splitAmount)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_SPLIT, aurApp);
auto effEndItr = (*scritr)->OnEffectSplit.end(), effItr = (*scritr)->OnEffectSplit.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, dmgInfo, splitAmount);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_SPLIT, aurApp);
for (AuraScript::EffectAbsorbHandler const& effectSplit : script->OnEffectSplit)
if (effectSplit.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effectSplit.Call(script, aurEff, dmgInfo, splitAmount);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Aura::CallScriptEnterLeaveCombatHandlers(AuraApplication const* aurApp, bool isNowInCombat)
{
for (AuraScript* loadedScript : m_loadedScripts)
for (AuraScript* script : m_loadedScripts)
{
loadedScript->_PrepareScriptCall(AURA_SCRIPT_HOOK_ENTER_LEAVE_COMBAT, aurApp);
for (AuraScript::EnterLeaveCombatHandler const& hook : loadedScript->OnEnterLeaveCombat)
hook.Call(loadedScript, isNowInCombat);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_ENTER_LEAVE_COMBAT, aurApp);
for (AuraScript::EnterLeaveCombatHandler const& onEnterLeaveCombat : script->OnEnterLeaveCombat)
onEnterLeaveCombat.Call(script, isNowInCombat);
loadedScript->_FinishScriptCall();
script->_FinishScriptCall();
}
}
bool Aura::CallScriptCheckProcHandlers(AuraApplication const* aurApp, ProcEventInfo& eventInfo)
{
bool result = true;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_CHECK_PROC, aurApp);
auto hookItrEnd = (*scritr)->DoCheckProc.end(), hookItr = (*scritr)->DoCheckProc.begin();
for (; hookItr != hookItrEnd; ++hookItr)
result &= hookItr->Call(*scritr, eventInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_CHECK_PROC, aurApp);
for (AuraScript::CheckProcHandler const& checkProc : script->DoCheckProc)
result &= checkProc.Call(script, eventInfo);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return result;
@@ -2349,17 +2330,16 @@ bool Aura::CallScriptCheckProcHandlers(AuraApplication const* aurApp, ProcEventI
bool Aura::CallScriptPrepareProcHandlers(AuraApplication const* aurApp, ProcEventInfo& eventInfo)
{
bool prepare = true;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_PREPARE_PROC, aurApp);
auto effEndItr = (*scritr)->DoPrepareProc.end(), effItr = (*scritr)->DoPrepareProc.begin();
for (; effItr != effEndItr; ++effItr)
effItr->Call(*scritr, eventInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_PREPARE_PROC, aurApp);
for (AuraScript::AuraProcHandler const& prepareProc : script->DoPrepareProc)
prepareProc.Call(script, eventInfo);
if (prepare)
prepare = !(*scritr)->_IsDefaultActionPrevented();
prepare = !script->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return prepare;
@@ -2368,15 +2348,14 @@ bool Aura::CallScriptPrepareProcHandlers(AuraApplication const* aurApp, ProcEven
bool Aura::CallScriptProcHandlers(AuraApplication const* aurApp, ProcEventInfo& eventInfo)
{
bool handled = false;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_PROC, aurApp);
auto hookItrEnd = (*scritr)->OnProc.end(), hookItr = (*scritr)->OnProc.begin();
for (; hookItr != hookItrEnd; ++hookItr)
hookItr->Call(*scritr, eventInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_PROC, aurApp);
for (AuraScript::AuraProcHandler const& onProc : script->OnProc)
onProc.Call(script, eventInfo);
handled |= (*scritr)->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
handled |= script->_IsDefaultActionPrevented();
script->_FinishScriptCall();
}
return handled;
@@ -2384,29 +2363,27 @@ bool Aura::CallScriptProcHandlers(AuraApplication const* aurApp, ProcEventInfo&
void Aura::CallScriptAfterProcHandlers(AuraApplication const* aurApp, ProcEventInfo& eventInfo)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_AFTER_PROC, aurApp);
auto hookItrEnd = (*scritr)->AfterProc.end(), hookItr = (*scritr)->AfterProc.begin();
for (; hookItr != hookItrEnd; ++hookItr)
hookItr->Call(*scritr, eventInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_AFTER_PROC, aurApp);
for (AuraScript::AuraProcHandler const& afterProc : script->AfterProc)
afterProc.Call(script, eventInfo);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
bool Aura::CallScriptCheckEffectProcHandlers(AuraEffect const* aurEff, AuraApplication const* aurApp, ProcEventInfo& eventInfo)
{
bool result = true;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_CHECK_EFFECT_PROC, aurApp);
auto hookItrEnd = (*scritr)->DoCheckEffectProc.end(), hookItr = (*scritr)->DoCheckEffectProc.begin();
for (; hookItr != hookItrEnd; ++hookItr)
if (hookItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
result &= hookItr->Call(*scritr, aurEff, eventInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_CHECK_EFFECT_PROC, aurApp);
for (AuraScript::CheckEffectProcHandler const& checkEffectProc : script->DoCheckEffectProc)
if (checkEffectProc.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
result &= checkEffectProc.Call(script, aurEff, eventInfo);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return result;
@@ -2415,33 +2392,31 @@ bool Aura::CallScriptCheckEffectProcHandlers(AuraEffect const* aurEff, AuraAppli
bool Aura::CallScriptEffectProcHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, ProcEventInfo& eventInfo)
{
bool preventDefault = false;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_PROC, aurApp);
auto effEndItr = (*scritr)->OnEffectProc.end(), effItr = (*scritr)->OnEffectProc.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, eventInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_PROC, aurApp);
for (AuraScript::EffectProcHandler const& onEffectProc : script->OnEffectProc)
if (onEffectProc.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
onEffectProc.Call(script, aurEff, eventInfo);
if (!preventDefault)
preventDefault = (*scritr)->_IsDefaultActionPrevented();
preventDefault = script->_IsDefaultActionPrevented();
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return preventDefault;
}
void Aura::CallScriptAfterEffectProcHandlers(AuraEffect* aurEff, AuraApplication const* aurApp, ProcEventInfo& eventInfo)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (AuraScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_PROC, aurApp);
auto effEndItr = (*scritr)->AfterEffectProc.end(), effItr = (*scritr)->AfterEffectProc.begin();
for (; effItr != effEndItr; ++effItr)
if (effItr->IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
effItr->Call(*scritr, aurEff, eventInfo);
script->_PrepareScriptCall(AURA_SCRIPT_HOOK_EFFECT_AFTER_PROC, aurApp);
for (AuraScript::EffectProcHandler const& afterEffectProc : script->AfterEffectProc)
if (afterEffectProc.IsEffectAffected(m_spellInfo, aurEff->GetEffIndex()))
afterEffectProc.Call(script, aurEff, eventInfo);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}

View File

@@ -8484,88 +8484,84 @@ void Spell::FinishTargetProcessing()
void Spell::LoadScripts()
{
sScriptMgr->CreateSpellScripts(m_spellInfo->Id, m_loadedScripts, this);
for (auto itr = m_loadedScripts.begin(); itr != m_loadedScripts.end(); ++itr)
for (SpellScript* script : m_loadedScripts)
{
TC_LOG_DEBUG("spells", "Spell::LoadScripts: Script `{}` for spell `{}` is loaded now", (*itr)->_GetScriptName()->c_str(), m_spellInfo->Id);
(*itr)->Register();
TC_LOG_DEBUG("spells", "Spell::LoadScripts: Script `{}` for spell `{}` is loaded now", script->GetScriptName(), m_spellInfo->Id);
script->Register();
}
}
void Spell::CallScriptOnPrecastHandler()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_PRECAST);
(*scritr)->OnPrecast();
(*scritr)->_FinishScriptCall();
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_PRECAST);
script->OnPrecast();
script->_FinishScriptCall();
}
}
void Spell::CallScriptBeforeCastHandlers()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_BEFORE_CAST);
auto hookItrEnd = (*scritr)->BeforeCast.end(), hookItr = (*scritr)->BeforeCast.begin();
for (; hookItr != hookItrEnd; ++hookItr)
(*hookItr).Call(*scritr);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_BEFORE_CAST);
for (SpellScript::CastHandler const& beforeCast : script->BeforeCast)
beforeCast.Call(script);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptOnCastHandlers()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_CAST);
auto hookItrEnd = (*scritr)->OnCast.end(), hookItr = (*scritr)->OnCast.begin();
for (; hookItr != hookItrEnd; ++hookItr)
(*hookItr).Call(*scritr);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_CAST);
for (SpellScript::CastHandler const& onCast : script->OnCast)
onCast.Call(script);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptAfterCastHandlers()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_AFTER_CAST);
auto hookItrEnd = (*scritr)->AfterCast.end(), hookItr = (*scritr)->AfterCast.begin();
for (; hookItr != hookItrEnd; ++hookItr)
(*hookItr).Call(*scritr);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_AFTER_CAST);
for (SpellScript::CastHandler const& afterCast : script->AfterCast)
afterCast.Call(script);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
SpellCastResult Spell::CallScriptCheckCastHandlers()
{
SpellCastResult retVal = SPELL_CAST_OK;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_CHECK_CAST);
auto hookItrEnd = (*scritr)->OnCheckCast.end(), hookItr = (*scritr)->OnCheckCast.begin();
for (; hookItr != hookItrEnd; ++hookItr)
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_CHECK_CAST);
for (SpellScript::CheckCastHandler const& checkCast : script->OnCheckCast)
{
SpellCastResult tempResult = (*hookItr).Call(*scritr);
SpellCastResult tempResult = checkCast.Call(script);
if (retVal == SPELL_CAST_OK)
retVal = tempResult;
}
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return retVal;
}
int32 Spell::CallScriptCalcCastTimeHandlers(int32 castTime)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_CALC_CAST_TIME);
castTime = (*scritr)->CalcCastTime(castTime);
(*scritr)->_FinishScriptCall();
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_CALC_CAST_TIME);
castTime = script->CalcCastTime(castTime);
script->_FinishScriptCall();
}
return castTime;
}
@@ -8574,156 +8570,157 @@ bool Spell::CallScriptEffectHandlers(SpellEffIndex effIndex, SpellEffectHandleMo
{
// execute script effect handler hooks and check if effects was prevented
bool preventDefault = false;
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_InitHit();
script->_InitHit();
HookList<SpellScript::EffectHandler>::iterator effItr, effEndItr;
Trinity::IteratorPair<HookList<SpellScript::EffectHandler>::iterator> effectHandlers;
SpellScriptHookType hookType;
switch (mode)
{
case SPELL_EFFECT_HANDLE_LAUNCH:
effItr = (*scritr)->OnEffectLaunch.begin();
effEndItr = (*scritr)->OnEffectLaunch.end();
effectHandlers = Trinity::Containers::MakeIteratorPair(script->OnEffectLaunch.begin(), script->OnEffectLaunch.end());
hookType = SPELL_SCRIPT_HOOK_EFFECT_LAUNCH;
break;
case SPELL_EFFECT_HANDLE_LAUNCH_TARGET:
effItr = (*scritr)->OnEffectLaunchTarget.begin();
effEndItr = (*scritr)->OnEffectLaunchTarget.end();
effectHandlers = Trinity::Containers::MakeIteratorPair(script->OnEffectLaunchTarget.begin(), script->OnEffectLaunchTarget.end());
hookType = SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET;
break;
case SPELL_EFFECT_HANDLE_HIT:
effItr = (*scritr)->OnEffectHit.begin();
effEndItr = (*scritr)->OnEffectHit.end();
effectHandlers = Trinity::Containers::MakeIteratorPair(script->OnEffectHit.begin(), script->OnEffectHit.end());
hookType = SPELL_SCRIPT_HOOK_EFFECT_HIT;
break;
case SPELL_EFFECT_HANDLE_HIT_TARGET:
effItr = (*scritr)->OnEffectHitTarget.begin();
effEndItr = (*scritr)->OnEffectHitTarget.end();
effectHandlers = Trinity::Containers::MakeIteratorPair(script->OnEffectHitTarget.begin(), script->OnEffectHitTarget.end());
hookType = SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET;
break;
default:
ABORT();
return false;
}
(*scritr)->_PrepareScriptCall(hookType);
for (; effItr != effEndItr; ++effItr)
script->_PrepareScriptCall(hookType);
for (SpellScript::EffectHandler const& effectHandler : effectHandlers)
// effect execution can be prevented
if (!(*scritr)->_IsEffectPrevented(effIndex) && (*effItr).IsEffectAffected(m_spellInfo, effIndex))
(*effItr).Call(*scritr, effIndex);
if (!script->_IsEffectPrevented(effIndex) && effectHandler.IsEffectAffected(m_spellInfo, effIndex))
effectHandler.Call(script, effIndex);
if (!preventDefault)
preventDefault = (*scritr)->_IsDefaultEffectPrevented(effIndex);
preventDefault = script->_IsDefaultEffectPrevented(effIndex);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
return preventDefault;
}
void Spell::CallScriptSuccessfulDispel(SpellEffIndex effIndex)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_EFFECT_SUCCESSFUL_DISPEL);
auto hookItrEnd = (*scritr)->OnEffectSuccessfulDispel.end(), hookItr = (*scritr)->OnEffectSuccessfulDispel.begin();
for (; hookItr != hookItrEnd; ++hookItr)
hookItr->Call(*scritr, effIndex);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_EFFECT_SUCCESSFUL_DISPEL);
for (SpellScript::EffectHandler const& onDispel : script->OnEffectSuccessfulDispel)
onDispel.Call(script, effIndex);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptBeforeHitHandlers(SpellMissInfo missInfo)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_InitHit();
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_BEFORE_HIT);
auto hookItrEnd = (*scritr)->BeforeHit.end(), hookItr = (*scritr)->BeforeHit.begin();
for (; hookItr != hookItrEnd; ++hookItr)
(*hookItr).Call(*scritr, missInfo);
script->_InitHit();
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_BEFORE_HIT);
for (SpellScript::BeforeHitHandler const& beforeHit : script->BeforeHit)
beforeHit.Call(script, missInfo);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptOnHitHandlers()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_HIT);
auto hookItrEnd = (*scritr)->OnHit.end(), hookItr = (*scritr)->OnHit.begin();
for (; hookItr != hookItrEnd; ++hookItr)
(*hookItr).Call(*scritr);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_HIT);
for (SpellScript::HitHandler const& onHit : script->OnHit)
onHit.Call(script);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptAfterHitHandlers()
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_AFTER_HIT);
auto hookItrEnd = (*scritr)->AfterHit.end(), hookItr = (*scritr)->AfterHit.begin();
for (; hookItr != hookItrEnd; ++hookItr)
(*hookItr).Call(*scritr);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_AFTER_HIT);
for (SpellScript::HitHandler const& afterHit : script->AfterHit)
afterHit.Call(script);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptCalcCritChanceHandlers(Unit const* victim, float& critChance)
{
for (SpellScript* loadedScript : m_loadedScripts)
for (SpellScript* script : m_loadedScripts)
{
loadedScript->_PrepareScriptCall(SPELL_SCRIPT_HOOK_CALC_CRIT_CHANCE);
for (SpellScript::OnCalcCritChanceHandler const& hook : loadedScript->OnCalcCritChance)
hook.Call(loadedScript, victim, critChance);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_CALC_CRIT_CHANCE);
for (SpellScript::OnCalcCritChanceHandler const& calcCritChance : script->OnCalcCritChance)
calcCritChance.Call(script, victim, critChance);
loadedScript->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptObjectAreaTargetSelectHandlers(std::list<WorldObject*>& targets, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_OBJECT_AREA_TARGET_SELECT);
auto hookItrEnd = (*scritr)->OnObjectAreaTargetSelect.end(), hookItr = (*scritr)->OnObjectAreaTargetSelect.begin();
for (; hookItr != hookItrEnd; ++hookItr)
if (hookItr->IsEffectAffected(m_spellInfo, effIndex) && targetType.GetTarget() == hookItr->GetTarget())
hookItr->Call(*scritr, targets);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_OBJECT_AREA_TARGET_SELECT);
for (SpellScript::ObjectAreaTargetSelectHandler const& objectAreaTargetSelect : script->OnObjectAreaTargetSelect)
if (objectAreaTargetSelect.IsEffectAffected(m_spellInfo, effIndex) && targetType.GetTarget() == objectAreaTargetSelect.GetTarget())
objectAreaTargetSelect.Call(script, targets);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptObjectTargetSelectHandlers(WorldObject*& target, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_OBJECT_TARGET_SELECT);
auto hookItrEnd = (*scritr)->OnObjectTargetSelect.end(), hookItr = (*scritr)->OnObjectTargetSelect.begin();
for (; hookItr != hookItrEnd; ++hookItr)
if (hookItr->IsEffectAffected(m_spellInfo, effIndex) && targetType.GetTarget() == hookItr->GetTarget())
hookItr->Call(*scritr, target);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_OBJECT_TARGET_SELECT);
for (SpellScript::ObjectTargetSelectHandler const& objectTargetSelect : script->OnObjectTargetSelect)
if (objectTargetSelect.IsEffectAffected(m_spellInfo, effIndex) && targetType.GetTarget() == objectTargetSelect.GetTarget())
objectTargetSelect.Call(script, target);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptDestinationTargetSelectHandlers(SpellDestination& target, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
for (SpellScript* script : m_loadedScripts)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_DESTINATION_TARGET_SELECT);
auto hookItrEnd = (*scritr)->OnDestinationTargetSelect.end(), hookItr = (*scritr)->OnDestinationTargetSelect.begin();
for (; hookItr != hookItrEnd; ++hookItr)
if (hookItr->IsEffectAffected(m_spellInfo, effIndex) && targetType.GetTarget() == hookItr->GetTarget())
hookItr->Call(*scritr, target);
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_DESTINATION_TARGET_SELECT);
for (SpellScript::DestinationTargetSelectHandler const& destinationTargetSelect : script->OnDestinationTargetSelect)
if (destinationTargetSelect.IsEffectAffected(m_spellInfo, effIndex) && targetType.GetTarget() == destinationTargetSelect.GetTarget())
destinationTargetSelect.Call(script, target);
(*scritr)->_FinishScriptCall();
script->_FinishScriptCall();
}
}
void Spell::CallScriptOnResistAbsorbCalculateHandlers(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount)
{
for (SpellScript* script : m_loadedScripts)
{
script->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_RESIST_ABSORB_CALCULATION);
for (SpellScript::OnCalculateResistAbsorbHandler const& calculateResistAbsorb : script->OnCalculateResistAbsorb)
calculateResistAbsorb.Call(script, damageInfo, resistAmount, absorbAmount);
script->_FinishScriptCall();
}
}
@@ -8733,18 +8730,16 @@ bool Spell::CheckScriptEffectImplicitTargets(uint32 effIndex, uint32 effIndexToC
if (m_loadedScripts.empty())
return true;
for (auto itr = m_loadedScripts.begin(); itr != m_loadedScripts.end(); ++itr)
for (SpellScript* script : m_loadedScripts)
{
auto targetSelectHookEnd = (*itr)->OnObjectTargetSelect.end(), targetSelectHookItr = (*itr)->OnObjectTargetSelect.begin();
for (; targetSelectHookItr != targetSelectHookEnd; ++targetSelectHookItr)
if (((*targetSelectHookItr).IsEffectAffected(m_spellInfo, effIndex) && !(*targetSelectHookItr).IsEffectAffected(m_spellInfo, effIndexToCheck)) ||
(!(*targetSelectHookItr).IsEffectAffected(m_spellInfo, effIndex) && (*targetSelectHookItr).IsEffectAffected(m_spellInfo, effIndexToCheck)))
for (SpellScript::ObjectTargetSelectHandler const& objectTargetSelect : script->OnObjectTargetSelect)
if ((objectTargetSelect.IsEffectAffected(m_spellInfo, effIndex) && !objectTargetSelect.IsEffectAffected(m_spellInfo, effIndexToCheck)) ||
(!objectTargetSelect.IsEffectAffected(m_spellInfo, effIndex) && objectTargetSelect.IsEffectAffected(m_spellInfo, effIndexToCheck)))
return false;
auto areaTargetSelectHookEnd = (*itr)->OnObjectAreaTargetSelect.end(), areaTargetSelectHookItr = (*itr)->OnObjectAreaTargetSelect.begin();
for (; areaTargetSelectHookItr != areaTargetSelectHookEnd; ++areaTargetSelectHookItr)
if (((*areaTargetSelectHookItr).IsEffectAffected(m_spellInfo, effIndex) && !(*areaTargetSelectHookItr).IsEffectAffected(m_spellInfo, effIndexToCheck)) ||
(!(*areaTargetSelectHookItr).IsEffectAffected(m_spellInfo, effIndex) && (*areaTargetSelectHookItr).IsEffectAffected(m_spellInfo, effIndexToCheck)))
for (SpellScript::ObjectAreaTargetSelectHandler const& objectAreaTargetSelect : script->OnObjectAreaTargetSelect)
if ((objectAreaTargetSelect.IsEffectAffected(m_spellInfo, effIndex) && !objectAreaTargetSelect.IsEffectAffected(m_spellInfo, effIndexToCheck)) ||
(!objectAreaTargetSelect.IsEffectAffected(m_spellInfo, effIndex) && objectAreaTargetSelect.IsEffectAffected(m_spellInfo, effIndexToCheck)))
return false;
}
return true;
@@ -8890,19 +8885,6 @@ std::string Spell::GetDebugInfo() const
return sstr.str();
}
void Spell::CallScriptOnResistAbsorbCalculateHandlers(DamageInfo const& damageInfo, uint32& resistAmount, int32& absorbAmount)
{
for (auto scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
{
(*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_ON_RESIST_ABSORB_CALCULATION);
auto hookItrEnd = (*scritr)->OnCalculateResistAbsorb.end(), hookItr = (*scritr)->OnCalculateResistAbsorb.begin();
for (; hookItr != hookItrEnd; ++hookItr)
hookItr->Call(*scritr, damageInfo, resistAmount, absorbAmount);
(*scritr)->_FinishScriptCall();
}
}
bool Spell::IsWithinLOS(WorldObject const* source, WorldObject const* target, bool targetAsSourceLocation, VMAP::ModelIgnoreFlags ignoreFlags) const
{
if (m_spellInfo->HasAttribute(SPELL_ATTR2_IGNORE_LINE_OF_SIGHT))

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff