From 600d418f144af64783cabd55171c56aab8cd6493 Mon Sep 17 00:00:00 2001 From: killerwife Date: Fri, 12 Jan 2024 14:14:56 +0100 Subject: [PATCH] Spell: Abstract m_usableWhileStunned Also rolls into it m_guaranteed crit --- src/game/Spells/Spell.cpp | 12 ++++++------ src/game/Spells/Spell.h | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index 62f5e0c766..85fd9f26ae 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -444,6 +444,8 @@ Spell::Spell(WorldObject* caster, SpellEntry const* info, uint32 triggeredFlags, m_updated = false; m_duration = 0; m_maxRange = 0.f; + m_guaranteedCrit = false; + m_usableWhileStunned = m_spellInfo->HasAttribute(SPELL_ATTR_EX5_ALLOW_WHILE_STUNNED); m_needAliveTargetMask = 0; @@ -1649,6 +1651,7 @@ void Spell::HandleImmediateEffectExecution(TargetInfo* target) m_damage = 0; m_absorb = 0; m_healing = 0; // healing maybe not needed at this point + m_guaranteedCrit = false; // keep damage amount for reflected spells if (missInfo == SPELL_MISS_NONE || (missInfo == SPELL_MISS_REFLECT && target->reflectResult == SPELL_MISS_NONE)) @@ -1664,7 +1667,7 @@ void Spell::HandleImmediateEffectExecution(TargetInfo* target) target->HitInfo = 0; target->effectMaskProcessed = mask; if (m_damage > 0 || m_healing > 0) - target->isCrit = Unit::RollSpellCritOutcome(affectiveCaster, unit, m_spellSchoolMask, m_spellInfo); + target->isCrit = m_guaranteedCrit ? true : Unit::RollSpellCritOutcome(affectiveCaster, unit, m_spellSchoolMask, m_spellInfo); } bool Spell::CanSpellDiminish() const @@ -6288,10 +6291,7 @@ SpellCastResult Spell::CheckCasterAuras(uint32& param1) const return SPELL_CAST_OK; // these attributes only show the spell as usable on the client when it has related aura applied - // still they need to be checked against certain mechanics - - // SPELL_ATTR5_USABLE_WHILE_STUNNED by default only MECHANIC_STUN (ie no sleep, knockout, freeze, etc.) - bool usableWhileStunned = m_spellInfo->HasAttribute(SPELL_ATTR_EX5_ALLOW_WHILE_STUNNED); + // still they need to be checked against certain mechanics // SPELL_ATTR5_USABLE_WHILE_FEARED by default only fear (ie no horror) bool usableWhileFeared = m_spellInfo->HasAttribute(SPELL_ATTR_EX5_ALLOW_WHILE_FLEEING); @@ -6352,7 +6352,7 @@ SpellCastResult Spell::CheckCasterAuras(uint32& param1) const return SPELL_CAST_OK; }; - if (unitflag & UNIT_FLAG_STUNNED && !usableWhileStunned && !CheckSpellCancelsStun(param1)) + if (unitflag & UNIT_FLAG_STUNNED && !m_usableWhileStunned && !CheckSpellCancelsStun(param1)) result = SPELL_FAILED_STUNNED; else if (unitflag & UNIT_FLAG_SILENCED && m_spellInfo->PreventionType == SPELL_PREVENTION_TYPE_SILENCE && !CheckSpellCancelsSilence(param1)) result = SPELL_FAILED_SILENCED; diff --git a/src/game/Spells/Spell.h b/src/game/Spells/Spell.h index 3baece0342..3ae4e8129a 100644 --- a/src/game/Spells/Spell.h +++ b/src/game/Spells/Spell.h @@ -776,6 +776,7 @@ class Spell uint32 GetDamage() { return damage; } void SetDamage(uint32 newDamage) { damage = newDamage; } SpellSchoolMask GetSchoolMask() { return m_spellSchoolMask; } + void SetGuaranteedCrit() { m_guaranteedCrit = true; } // OnInit use only void SetEffectSkipMask(uint32 mask) { m_effectSkipMask = mask; } // OnHit use only @@ -810,6 +811,7 @@ class Spell void SetOverridenSpeed(float newSpeed); void SetIgnoreRoot(bool state) { m_ignoreRoot = state; } void SetDamageDoneModifier(float mod, SpellEffectIndex effIdx); + void SetUsableWhileStunned(bool state) { m_usableWhileStunned = state; } protected: void SendLoot(ObjectGuid guid, LootType loottype, LockType lockType); bool IgnoreItemRequirements() const; // some item use spells have unexpected reagent data @@ -875,6 +877,8 @@ class Spell int32 m_healing; // Healing in effects count here int32 m_healingPerEffect[MAX_EFFECT_INDEX]; int32 m_healthLeech; // Health leech in effects for all targets count here + bool m_guaranteedCrit; // Used in effect handlers to guarantee crit + bool m_usableWhileStunned; //****************************************** // Spell trigger system