mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-10 07:21:35 +00:00
Merge branch 'absorb47' into 'openmw-47'
Absorb spells per effect See merge request OpenMW/openmw!1274
This commit is contained in:
commit
bac679d5f5
3 changed files with 21 additions and 16 deletions
|
@ -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())
|
if(target.isEmpty() || caster == target || !target.getClass().isActor())
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
CreatureStats& stats = target.getClass().getCreatureStats(target);
|
CreatureStats& stats = target.getClass().getCreatureStats(target);
|
||||||
if (stats.getMagicEffects().get(ESM::MagicEffect::SpellAbsorption).getMagnitude() <= 0.f)
|
if (stats.getMagicEffects().get(ESM::MagicEffect::SpellAbsorption).getMagnitude() <= 0.f)
|
||||||
return false;
|
return 0;
|
||||||
|
|
||||||
GetAbsorptionProbability check;
|
GetAbsorptionProbability check;
|
||||||
stats.getActiveSpells().visitEffectSources(check);
|
stats.getActiveSpells().visitEffectSources(check);
|
||||||
|
@ -59,9 +59,12 @@ namespace MWMechanics
|
||||||
if (target.getClass().hasInventoryStore(target))
|
if (target.getClass().hasInventoryStore(target))
|
||||||
target.getClass().getInventoryStore(target).visitEffectSources(check);
|
target.getClass().getInventoryStore(target).visitEffectSources(check);
|
||||||
|
|
||||||
int chance = check.mProbability * 100;
|
return check.mProbability * 100;
|
||||||
if (Misc::Rng::roll0to99() >= chance)
|
}
|
||||||
return false;
|
|
||||||
|
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 auto& esmStore = MWBase::Environment::get().getWorld()->getStore();
|
||||||
const ESM::Static* absorbStatic = esmStore.get<ESM::Static>().find("VFX_Absorb");
|
const ESM::Static* absorbStatic = esmStore.get<ESM::Static>().find("VFX_Absorb");
|
||||||
|
@ -85,7 +88,6 @@ namespace MWMechanics
|
||||||
DynamicStat<float> magicka = stats.getMagicka();
|
DynamicStat<float> magicka = stats.getMagicka();
|
||||||
magicka.setCurrent(magicka.getCurrent() + spellCost);
|
magicka.setCurrent(magicka.getCurrent() + spellCost);
|
||||||
stats.setMagicka(magicka);
|
stats.setMagicka(magicka);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@ namespace MWWorld
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
// Try to absorb a spell based on the magnitude of every Spell Absorption effect source on the target.
|
void absorbSpell(const std::string& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target);
|
||||||
bool 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
|
#endif
|
||||||
|
|
|
@ -119,8 +119,7 @@ namespace MWMechanics
|
||||||
// throughout the iteration of this spell's
|
// throughout the iteration of this spell's
|
||||||
// effects, we display a "can't re-cast" message
|
// effects, we display a "can't re-cast" message
|
||||||
|
|
||||||
// Try absorbing the spell. Some handling must still happen for absorbed effects.
|
int absorbChance = getAbsorbChance(caster, target);
|
||||||
bool absorbed = absorbSpell(mId, caster, target);
|
|
||||||
|
|
||||||
int currentEffectIndex = 0;
|
int currentEffectIndex = 0;
|
||||||
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (effects.mList.begin());
|
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (effects.mList.begin());
|
||||||
|
@ -142,6 +141,13 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
canCastAnEffect = true;
|
canCastAnEffect = true;
|
||||||
|
|
||||||
|
// Try absorbing the effect
|
||||||
|
if(absorbChance && Misc::Rng::roll0to99() < absorbChance)
|
||||||
|
{
|
||||||
|
absorbSpell(mId, caster, target);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!checkEffectTarget(effectIt->mEffectID, target, caster, castByPlayer))
|
if (!checkEffectTarget(effectIt->mEffectID, target, caster, castByPlayer))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -155,10 +161,6 @@ namespace MWMechanics
|
||||||
if (target.getClass().isActor() && target != caster && !caster.isEmpty() && isHarmful)
|
if (target.getClass().isActor() && target != caster && !caster.isEmpty() && isHarmful)
|
||||||
target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true);
|
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
|
// Reflect harmful effects
|
||||||
if (!reflected && reflectEffect(*effectIt, magicEffect, caster, target, reflectedEffects))
|
if (!reflected && reflectEffect(*effectIt, magicEffect, caster, target, reflectedEffects))
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue