Core/Scripts: Expose IsCrit to hit hooks for spell scripts

This commit is contained in:
Shauren
2022-01-30 12:36:29 +01:00
parent ea82454932
commit 2cc652b305
2 changed files with 21 additions and 0 deletions

View File

@@ -686,6 +686,25 @@ void SpellScript::SetHitHeal(int32 heal)
m_spell->m_healing = heal;
}
bool SpellScript::IsHitCrit() const
{
if (!IsInTargetHook())
{
TC_LOG_ERROR("scripts", "Script: `%s` Spell: `%u`: function SpellScript::IsHitCrit was called, but function has no effect in current hook!", m_scriptName->c_str(), m_scriptSpellId);
return false;
}
if (Unit* hitUnit = GetHitUnit())
{
auto itr = std::find_if(m_spell->m_UniqueTargetInfo.begin(), m_spell->m_UniqueTargetInfo.end(), [hitUnit](Spell::TargetInfo const& targetInfo)
{
return targetInfo.TargetGUID == hitUnit->GetGUID();
});
ASSERT(itr != m_spell->m_UniqueTargetInfo.end());
return itr->IsCrit;
}
return false;
}
Aura* SpellScript::GetHitAura(bool dynObjAura /*= false*/) const
{
if (!IsInTargetHook())

View File

@@ -514,6 +514,8 @@ class TC_GAME_API SpellScript : public _SpellScript
int32 GetHitHeal() const;
void SetHitHeal(int32 heal);
void PreventHitHeal() { SetHitHeal(0); }
// returns: true if spell critically hits current HitUnit
bool IsHitCrit() const;
Spell* GetSpell() const { return m_spell; }
// returns current spell hit target aura
Aura* GetHitAura(bool dynObjAura = false) const;