From af2ea477d5efac748ed5c8dd3a943b46a1aaf160 Mon Sep 17 00:00:00 2001 From: capostrophic Date: Thu, 9 Jan 2020 13:39:12 +0300 Subject: [PATCH] Don't use loops to detect absorb effects --- apps/openmw/mwmechanics/spellcasting.cpp | 40 ++++++++++-------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 5d3b83a62..0b7c27b86 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -554,16 +554,11 @@ namespace MWMechanics // Avoid applying absorb effects if the caster is the target // We still need the spell to be added - if (caster == target) + if (caster == target + && effectIt->mEffectID >= ESM::MagicEffect::AbsorbAttribute + && effectIt->mEffectID <= ESM::MagicEffect::AbsorbSkill) { - for (int i=0; i<5; ++i) - { - if (effectIt->mEffectID == ESM::MagicEffect::AbsorbAttribute+i) - { - effect.mMagnitude = 0; - break; - } - } + effect.mMagnitude = 0; } bool hasDuration = !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration); @@ -614,22 +609,19 @@ namespace MWMechanics // magnitude, since we're transferring stats from the target to the caster if (!caster.isEmpty() && caster != target && caster.getClass().isActor()) { - for (int i=0; i<5; ++i) + if (effectIt->mEffectID >= ESM::MagicEffect::AbsorbAttribute && + effectIt->mEffectID <= ESM::MagicEffect::AbsorbSkill) { - if (effectIt->mEffectID == ESM::MagicEffect::AbsorbAttribute+i) - { - std::vector absorbEffects; - ActiveSpells::ActiveEffect effect_ = effect; - effect_.mMagnitude *= -1; - absorbEffects.push_back(effect_); - if (reflected && Settings::Manager::getBool("classic reflected absorb spells behavior", "Game")) - target.getClass().getCreatureStats(target).getActiveSpells().addSpell("", true, - absorbEffects, mSourceName, caster.getClass().getCreatureStats(caster).getActorId()); - else - caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell("", true, - absorbEffects, mSourceName, target.getClass().getCreatureStats(target).getActorId()); - break; - } + std::vector absorbEffects; + ActiveSpells::ActiveEffect effect_ = effect; + effect_.mMagnitude *= -1; + absorbEffects.push_back(effect_); + if (reflected && Settings::Manager::getBool("classic reflected absorb spells behavior", "Game")) + target.getClass().getCreatureStats(target).getActiveSpells().addSpell("", true, + absorbEffects, mSourceName, caster.getClass().getCreatureStats(caster).getActorId()); + else + caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell("", true, + absorbEffects, mSourceName, target.getClass().getCreatureStats(target).getActorId()); } } }