From bfd598b64021ce2d5e4afe369e8cdd82ddd6d418 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 9 Mar 2022 17:39:49 -0500 Subject: [PATCH] Core/Scripts: Expose IsCrit to hit hooks for spell scripts Port From (https://github.com/TrinityCore/TrinityCore/commit/2cc652b305f31ebcc71680f314792d0d09c43bfe) --- Source/Game/Scripting/SpellScript.cs | 24 ++++++++++++++++++++++++ Source/Game/Spells/Spell.cs | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Source/Game/Scripting/SpellScript.cs b/Source/Game/Scripting/SpellScript.cs index fa9147c74..31fd13676 100644 --- a/Source/Game/Scripting/SpellScript.cs +++ b/Source/Game/Scripting/SpellScript.cs @@ -797,6 +797,29 @@ namespace Game.Scripting } void PreventHitHeal() { SetHitHeal(0); } public Spell GetSpell() { return m_spell; } + + /// + /// + /// + /// true if spell critically hits current HitUnit + public bool IsHitCrit() + { + if (!IsInTargetHook()) + { + Log.outError(LogFilter.Scripts, $"Script: `{m_scriptName}` Spell: `{m_scriptSpellId}`: function SpellScript::IsHitCrit was called, but function has no effect in current hook!"); + return false; + } + + Unit hitUnit = GetHitUnit(); + if (hitUnit != null) + { + var targetInfo = m_spell.m_UniqueTargetInfo.Find(targetInfo => targetInfo.TargetGUID == hitUnit.GetGUID()); + Cypher.Assert(targetInfo != null); + return targetInfo.IsCrit; + } + return false; + } + // returns current spell hit target aura public Aura GetHitAura(bool dynObjAura = false) { @@ -815,6 +838,7 @@ namespace Game.Scripting return aura; } + // prevents applying aura on current spell hit target public void PreventHitAura() { diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index bf39d0d5b..dd29d1384 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -7802,7 +7802,7 @@ namespace Game.Spells // Spell target subsystem // ***************************************** // Targets store structures and data - List m_UniqueTargetInfo = new(); + public List m_UniqueTargetInfo = new(); uint m_channelTargetEffectMask; // Mask req. alive targets List m_UniqueGOTargetInfo = new();