Core/Spells: Expose number of targets selected for each spell effect to scripts to allow implementing spells that do something depending on number of targets hit

This commit is contained in:
Shauren
2021-05-13 00:38:09 +02:00
parent 1b39612b33
commit 1a7779a6e6
5 changed files with 79 additions and 11 deletions

View File

@@ -413,6 +413,15 @@ bool SpellScript::IsInCheckCastHook() const
{
return m_currentScriptState == SPELL_SCRIPT_HOOK_CHECK_CAST;
}
bool SpellScript::IsAfterTargetSelectionPhase() const
{
return IsInHitPhase()
|| m_currentScriptState == SPELL_SCRIPT_HOOK_ON_CAST
|| m_currentScriptState == SPELL_SCRIPT_HOOK_AFTER_CAST
|| m_currentScriptState == SPELL_SCRIPT_HOOK_CALC_CRIT_CHANCE;
}
bool SpellScript::IsInTargetHook() const
{
switch (m_currentScriptState)
@@ -485,6 +494,39 @@ Item* SpellScript::GetExplTargetItem() const
return m_spell->m_targets.GetItemTarget();
}
int64 SpellScript::GetUnitTargetCountForEffect(SpellEffIndex effect) const
{
if (!IsAfterTargetSelectionPhase())
{
TC_LOG_ERROR("scripts", "Script: `%s` Spell: `%u`: function SpellScript::GetUnitTargetCountForEffect was called, but function has no effect in current hook! (spell has not selected targets yet)",
m_scriptName->c_str(), m_scriptSpellId);
return 0;
}
return m_spell->GetUnitTargetCountForEffect(effect);
}
int64 SpellScript::GetGameObjectTargetCountForEffect(SpellEffIndex effect) const
{
if (!IsAfterTargetSelectionPhase())
{
TC_LOG_ERROR("scripts", "Script: `%s` Spell: `%u`: function SpellScript::GetGameObjectTargetCountForEffect was called, but function has no effect in current hook! (spell has not selected targets yet)",
m_scriptName->c_str(), m_scriptSpellId);
return 0;
}
return m_spell->GetGameObjectTargetCountForEffect(effect);
}
int64 SpellScript::GetItemTargetCountForEffect(SpellEffIndex effect) const
{
if (!IsAfterTargetSelectionPhase())
{
TC_LOG_ERROR("scripts", "Script: `%s` Spell: `%u`: function SpellScript::GetItemTargetCountForEffect was called, but function has no effect in current hook! (spell has not selected targets yet)",
m_scriptName->c_str(), m_scriptSpellId);
return 0;
}
return m_spell->GetItemTargetCountForEffect(effect);
}
Unit* SpellScript::GetHitUnit() const
{
if (!IsInTargetHook())