diff --git a/apps/openmw/mwmechanics/spellabsorption.cpp b/apps/openmw/mwmechanics/spellabsorption.cpp index bab290fda..1a2dfe65a 100644 --- a/apps/openmw/mwmechanics/spellabsorption.cpp +++ b/apps/openmw/mwmechanics/spellabsorption.cpp @@ -44,14 +44,14 @@ namespace MWMechanics } }; - bool absorbSpell (const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target) + int getAbsorbChance(const MWWorld::Ptr& caster, const MWWorld::Ptr& target) { - if (spellId.empty() || target.isEmpty() || caster == target || !target.getClass().isActor()) - return false; + if(target.isEmpty() || caster == target || !target.getClass().isActor()) + return 0; CreatureStats& stats = target.getClass().getCreatureStats(target); if (stats.getMagicEffects().get(ESM::MagicEffect::SpellAbsorption).getMagnitude() <= 0.f) - return false; + return 0; GetAbsorptionProbability check; stats.getActiveSpells().visitEffectSources(check); @@ -59,9 +59,12 @@ namespace MWMechanics if (target.getClass().hasInventoryStore(target)) target.getClass().getInventoryStore(target).visitEffectSources(check); - int chance = check.mProbability * 100; - if (Misc::Rng::roll0to99() >= chance) - return false; + return check.mProbability * 100; + } + + void absorbSpell (const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target) + { + CreatureStats& stats = target.getClass().getCreatureStats(target); const auto& esmStore = MWBase::Environment::get().getWorld()->getStore(); const ESM::Static* absorbStatic = esmStore.get().find("VFX_Absorb"); @@ -85,7 +88,6 @@ namespace MWMechanics DynamicStat magicka = stats.getMagicka(); magicka.setCurrent(magicka.getCurrent() + spellCost); stats.setMagicka(magicka); - return true; } } diff --git a/apps/openmw/mwmechanics/spellabsorption.hpp b/apps/openmw/mwmechanics/spellabsorption.hpp index 0fe501df9..5537483a4 100644 --- a/apps/openmw/mwmechanics/spellabsorption.hpp +++ b/apps/openmw/mwmechanics/spellabsorption.hpp @@ -10,8 +10,9 @@ namespace MWWorld namespace MWMechanics { - // Try to absorb a spell based on the magnitude of every Spell Absorption effect source on the target. - bool absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target); + void absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target); + // Calculate the chance to absorb a spell based on the magnitude of every Spell Absorption effect source on the target. + int getAbsorbChance(const MWWorld::Ptr& caster, const MWWorld::Ptr& target); } #endif diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index 5a367b502..0011515ba 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -119,8 +119,7 @@ namespace MWMechanics // throughout the iteration of this spell's // effects, we display a "can't re-cast" message - // Try absorbing the spell. Some handling must still happen for absorbed effects. - bool absorbed = absorbSpell(mId, caster, target); + int absorbChance = getAbsorbChance(caster, target); int currentEffectIndex = 0; for (std::vector::const_iterator effectIt (effects.mList.begin()); @@ -142,6 +141,13 @@ namespace MWMechanics } canCastAnEffect = true; + // Try absorbing the effect + if(absorbChance && Misc::Rng::roll0to99() < absorbChance) + { + absorbSpell(mId, caster, target); + continue; + } + if (!checkEffectTarget(effectIt->mEffectID, target, caster, castByPlayer)) continue; @@ -155,10 +161,6 @@ namespace MWMechanics if (target.getClass().isActor() && target != caster && !caster.isEmpty() && isHarmful) target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true); - // Avoid proceeding further for absorbed spells. - if (absorbed) - continue; - // Reflect harmful effects if (!reflected && reflectEffect(*effectIt, magicEffect, caster, target, reflectedEffects)) continue;