diff options
author | Shauren <shauren.trinity@gmail.com> | 2022-09-05 00:30:17 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-09-05 22:23:03 +0200 |
commit | b2eeca702cc4868ed578f6755ea6b6bce9ba17b8 (patch) | |
tree | 8d984020dd09c455b7740f6beb3ec3bd005dbec8 /src | |
parent | a7b7ad94f8e18a1c4d8bb1d806afec263c6abc7c (diff) |
Core/Spells: Move entering combat for caster and calculating crit chance to separate function called only once for each target instead of doing it once for every effect on every target
(cherry picked from commit f3384fecaa17c2b14bf2089c6813a31f5799a020)
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 39 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.h | 1 |
2 files changed, 29 insertions, 11 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index f92c70e95b0..2987aa544fd 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -8148,6 +8148,9 @@ void Spell::HandleLaunchPhase() PrepareTargetProcessing(); + for (TargetInfo& target : m_UniqueTargetInfo) + PreprocessSpellLaunch(target); + for (SpellEffectInfo const& spellEffectInfo : m_spellInfo->GetEffects()) { float multiplier = 1.0f; @@ -8167,7 +8170,7 @@ void Spell::HandleLaunchPhase() FinishTargetProcessing(); } -void Spell::DoEffectOnLaunchTarget(TargetInfo& targetInfo, float multiplier, SpellEffectInfo const& spellEffectInfo) +void Spell::PreprocessSpellLaunch(TargetInfo& targetInfo) { Unit* targetUnit = m_caster->GetGUID() == targetInfo.TargetGUID ? m_caster->ToUnit() : ObjectAccessor::GetUnit(*m_caster, targetInfo.TargetGUID); if (!targetUnit) @@ -8188,6 +8191,30 @@ void Spell::DoEffectOnLaunchTarget(TargetInfo& targetInfo, float multiplier, Spe if (!unit) return; + float critChance = m_spellValue->CriticalChance; + if (m_originalCaster) + { + if (!critChance) + critChance = m_originalCaster->SpellCritChanceDone(this, nullptr, m_spellSchoolMask, m_attackType); + critChance = unit->SpellCritChanceTaken(m_originalCaster, this, nullptr, m_spellSchoolMask, critChance, m_attackType); + } + + targetInfo.IsCrit = roll_chance_f(critChance); +} + +void Spell::DoEffectOnLaunchTarget(TargetInfo& targetInfo, float multiplier, SpellEffectInfo const& spellEffectInfo) +{ + Unit* unit = nullptr; + // In case spell hit target, do all effect on that target + if (targetInfo.MissCondition == SPELL_MISS_NONE) + unit = m_caster->GetGUID() == targetInfo.TargetGUID ? m_caster->ToUnit() : ObjectAccessor::GetUnit(*m_caster, targetInfo.TargetGUID); + // In case spell reflect from target, do all effect on caster (if hit) + else if (targetInfo.MissCondition == SPELL_MISS_REFLECT && targetInfo.ReflectResult == SPELL_MISS_NONE) + unit = m_caster->ToUnit(); + + if (!unit) + return; + m_damage = 0; m_healing = 0; @@ -8219,16 +8246,6 @@ void Spell::DoEffectOnLaunchTarget(TargetInfo& targetInfo, float multiplier, Spe targetInfo.Damage += m_damage; targetInfo.Healing += m_healing; - - float critChance = m_spellValue->CriticalChance; - if (m_originalCaster) - { - if (!critChance) - critChance = m_originalCaster->SpellCritChanceDone(this, nullptr, m_spellSchoolMask, m_attackType); - critChance = unit->SpellCritChanceTaken(m_originalCaster, this, nullptr, m_spellSchoolMask, critChance, m_attackType); - } - - targetInfo.IsCrit = roll_chance_f(critChance); } SpellCastResult Spell::CanOpenLock(SpellEffectInfo const& effect, uint32 lockId, SkillType& skillId, int32& reqSkillValue, int32& skillValue) diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 0fda5253439..8c06e6c2aca 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -804,6 +804,7 @@ class TC_GAME_API Spell void AddCorpseTarget(Corpse* target, uint32 effectMask); void AddDestTarget(SpellDestination const& dest, uint32 effIndex); + void PreprocessSpellLaunch(TargetInfo& targetInfo); SpellMissInfo PreprocessSpellHit(Unit* unit, TargetInfo& targetInfo); void DoSpellEffectHit(Unit* unit, SpellEffectInfo const& spellEffectInfo, TargetInfo& targetInfo); |