diff options
author | psi29a <psi29a@gmail.com> | 2021-10-10 16:17:03 +0000 |
---|---|---|
committer | psi29a <psi29a@gmail.com> | 2021-10-10 16:17:03 +0000 |
commit | bac679d5f5a252e479a576855c8b00bad9b67d6a (patch) | |
tree | eb91864e82c63286ec8c019ccefe282afc515937 | |
parent | b9dc05a158eeb5e59f8f92e2d628466894d40907 (diff) | |
parent | f902efbfcca6226c12c8295ed3dd2798ecbd2fbb (diff) |
Merge branch 'absorb47' into 'openmw-47'openmw-0.47.0
Absorb spells per effect
See merge request OpenMW/openmw!1274
-rw-r--r-- | apps/openmw/mwmechanics/spellabsorption.cpp | 18 | ||||
-rw-r--r-- | apps/openmw/mwmechanics/spellabsorption.hpp | 5 | ||||
-rw-r--r-- | apps/openmw/mwmechanics/spellcasting.cpp | 14 |
3 files changed, 21 insertions, 16 deletions
diff --git a/apps/openmw/mwmechanics/spellabsorption.cpp b/apps/openmw/mwmechanics/spellabsorption.cpp index bab290fdab..1a2dfe65a9 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<ESM::Static>().find("VFX_Absorb"); @@ -85,7 +88,6 @@ namespace MWMechanics DynamicStat<float> 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 0fe501df91..5537483a48 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 5a367b5020..0011515baf 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<ESM::ENAMstruct>::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; |