Skip to content

Commit

Permalink
Spell: Abstract m_usableWhileStunned
Browse files Browse the repository at this point in the history
Also rolls into it m_guaranteed crit
  • Loading branch information
killerwife committed Jan 13, 2024
1 parent 86c2d76 commit 600d418
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/game/Spells/Spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 600d418

Please sign in to comment.