From 9abe7f8ad6795720f39303e54b4839ef1d6677f4 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 7 Sep 2022 13:30:27 -0400 Subject: [PATCH] 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 Port From (https://github.com/TrinityCore/TrinityCore/commit/b2eeca702cc4868ed578f6755ea6b6bce9ba17b8) --- Source/Game/Spells/Spell.cs | 39 ++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index db9c0a477..bd280358b 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -7181,6 +7181,9 @@ namespace Game.Spells PrepareTargetProcessing(); + foreach (TargetInfo target in m_UniqueTargetInfo) + PreprocessSpellLaunch(target); + foreach (var spellEffectInfo in m_spellInfo.GetEffects()) { float multiplier = 1.0f; @@ -7200,7 +7203,7 @@ namespace Game.Spells FinishTargetProcessing(); } - void DoEffectOnLaunchTarget(TargetInfo targetInfo, float multiplier, SpellEffectInfo spellEffectInfo) + void PreprocessSpellLaunch(TargetInfo targetInfo) { Unit targetUnit = m_caster.GetGUID() == targetInfo.TargetGUID ? m_caster.ToUnit() : Global.ObjAccessor.GetUnit(m_caster, targetInfo.TargetGUID); if (targetUnit == null) @@ -7220,6 +7223,30 @@ namespace Game.Spells if (unit == null) return; + float critChance = m_spellValue.CriticalChance; + if (m_originalCaster) + { + if (critChance == 0) + critChance = m_originalCaster.SpellCritChanceDone(this, null, m_spellSchoolMask, m_attackType); + critChance = unit.SpellCritChanceTaken(m_originalCaster, this, null, m_spellSchoolMask, critChance, m_attackType); + } + + targetInfo.IsCrit = RandomHelper.randChance(critChance); + } + + void DoEffectOnLaunchTarget(TargetInfo targetInfo, float multiplier, SpellEffectInfo spellEffectInfo) + { + Unit unit = null; + // In case spell hit target, do all effect on that target + if (targetInfo.MissCondition == SpellMissInfo.None) + unit = m_caster.GetGUID() == targetInfo.TargetGUID ? m_caster.ToUnit() : Global.ObjAccessor.GetUnit(m_caster, targetInfo.TargetGUID); + // In case spell reflect from target, do all effect on caster (if hit) + else if (targetInfo.MissCondition == SpellMissInfo.Reflect && targetInfo.ReflectResult == SpellMissInfo.None) + unit = m_caster.ToUnit(); + + if (!unit) + return; + m_damage = 0; m_healing = 0; @@ -7252,16 +7279,6 @@ namespace Game.Spells targetInfo.Damage += m_damage; targetInfo.Healing += m_healing; - - float critChance = m_spellValue.CriticalChance; - if (m_originalCaster != null) - { - if (critChance == 0) - critChance = m_originalCaster.SpellCritChanceDone(this, null, m_spellSchoolMask, m_attackType); - critChance = unit.SpellCritChanceTaken(m_originalCaster, this, null, m_spellSchoolMask, critChance, m_attackType); - } - - targetInfo.IsCrit = RandomHelper.randChance(critChance); } SpellCastResult CanOpenLock(SpellEffectInfo effect, uint lockId, ref SkillType skillId, ref int reqSkillValue, ref int skillValue)