aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2022-09-05 00:30:17 +0200
committerShauren <shauren.trinity@gmail.com>2022-09-05 00:30:17 +0200
commitf3384fecaa17c2b14bf2089c6813a31f5799a020 (patch)
tree82ff30a68288e2d2d0bda30225ce98ee91f77332 /src
parente2840a3f817ccdda416605d45f83a6c13121f435 (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
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Spells/Spell.cpp39
-rw-r--r--src/server/game/Spells/Spell.h1
2 files changed, 29 insertions, 11 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 4a07cde7670..1cdcd9128e6 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -7584,6 +7584,9 @@ void Spell::HandleLaunchPhase()
TakeAmmo();
}
+ for (TargetInfo& target : m_UniqueTargetInfo)
+ PreprocessSpellLaunch(target);
+
for (SpellEffectInfo const& spellEffectInfo : m_spellInfo->GetEffects())
{
float multiplier = 1.0f;
@@ -7603,7 +7606,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)
@@ -7624,6 +7627,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(m_spellInfo, m_spellSchoolMask, m_attackType);
+ critChance = unit->SpellCritChanceTaken(m_originalCaster, m_spellInfo, 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;
@@ -7655,16 +7682,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(m_spellInfo, m_spellSchoolMask, m_attackType);
- critChance = unit->SpellCritChanceTaken(m_originalCaster, m_spellInfo, m_spellSchoolMask, critChance, m_attackType);
- }
-
- targetInfo.IsCrit = roll_chance_f(critChance);
}
SpellCastResult Spell::CanOpenLock(SpellEffectInfo const& spellEffectInfo, 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 c8668dd791e..f71c8829164 100644
--- a/src/server/game/Spells/Spell.h
+++ b/src/server/game/Spells/Spell.h
@@ -625,6 +625,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, bool scaleAura, TargetInfo& targetInfo);
void DoSpellEffectHit(Unit* unit, SpellEffectInfo const& spellEffectInfo, TargetInfo& targetInfo);