Skip to content

Commit bac679d

Browse files
committed
Merge branch 'absorb47' into 'openmw-47'
Absorb spells per effect See merge request OpenMW/openmw!1274
2 parents b9dc05a + f902efb commit bac679d

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

apps/openmw/mwmechanics/spellabsorption.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,27 @@ namespace MWMechanics
4444
}
4545
};
4646

47-
bool absorbSpell (const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target)
47+
int getAbsorbChance(const MWWorld::Ptr& caster, const MWWorld::Ptr& target)
4848
{
49-
if (spellId.empty() || target.isEmpty() || caster == target || !target.getClass().isActor())
50-
return false;
49+
if(target.isEmpty() || caster == target || !target.getClass().isActor())
50+
return 0;
5151

5252
CreatureStats& stats = target.getClass().getCreatureStats(target);
5353
if (stats.getMagicEffects().get(ESM::MagicEffect::SpellAbsorption).getMagnitude() <= 0.f)
54-
return false;
54+
return 0;
5555

5656
GetAbsorptionProbability check;
5757
stats.getActiveSpells().visitEffectSources(check);
5858
stats.getSpells().visitEffectSources(check);
5959
if (target.getClass().hasInventoryStore(target))
6060
target.getClass().getInventoryStore(target).visitEffectSources(check);
6161

62-
int chance = check.mProbability * 100;
63-
if (Misc::Rng::roll0to99() >= chance)
64-
return false;
62+
return check.mProbability * 100;
63+
}
64+
65+
void absorbSpell (const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target)
66+
{
67+
CreatureStats& stats = target.getClass().getCreatureStats(target);
6568

6669
const auto& esmStore = MWBase::Environment::get().getWorld()->getStore();
6770
const ESM::Static* absorbStatic = esmStore.get<ESM::Static>().find("VFX_Absorb");
@@ -85,7 +88,6 @@ namespace MWMechanics
8588
DynamicStat<float> magicka = stats.getMagicka();
8689
magicka.setCurrent(magicka.getCurrent() + spellCost);
8790
stats.setMagicka(magicka);
88-
return true;
8991
}
9092

9193
}

apps/openmw/mwmechanics/spellabsorption.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ namespace MWWorld
1010

1111
namespace MWMechanics
1212
{
13-
// Try to absorb a spell based on the magnitude of every Spell Absorption effect source on the target.
14-
bool absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target);
13+
void absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target);
14+
// Calculate the chance to absorb a spell based on the magnitude of every Spell Absorption effect source on the target.
15+
int getAbsorbChance(const MWWorld::Ptr& caster, const MWWorld::Ptr& target);
1516
}
1617

1718
#endif

apps/openmw/mwmechanics/spellcasting.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ namespace MWMechanics
119119
// throughout the iteration of this spell's
120120
// effects, we display a "can't re-cast" message
121121

122-
// Try absorbing the spell. Some handling must still happen for absorbed effects.
123-
bool absorbed = absorbSpell(mId, caster, target);
122+
int absorbChance = getAbsorbChance(caster, target);
124123

125124
int currentEffectIndex = 0;
126125
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (effects.mList.begin());
@@ -142,6 +141,13 @@ namespace MWMechanics
142141
}
143142
canCastAnEffect = true;
144143

144+
// Try absorbing the effect
145+
if(absorbChance && Misc::Rng::roll0to99() < absorbChance)
146+
{
147+
absorbSpell(mId, caster, target);
148+
continue;
149+
}
150+
145151
if (!checkEffectTarget(effectIt->mEffectID, target, caster, castByPlayer))
146152
continue;
147153

@@ -155,10 +161,6 @@ namespace MWMechanics
155161
if (target.getClass().isActor() && target != caster && !caster.isEmpty() && isHarmful)
156162
target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true);
157163

158-
// Avoid proceeding further for absorbed spells.
159-
if (absorbed)
160-
continue;
161-
162164
// Reflect harmful effects
163165
if (!reflected && reflectEffect(*effectIt, magicEffect, caster, target, reflectedEffects))
164166
continue;

0 commit comments

Comments
 (0)