mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-05 18:49:40 +00:00
Absorb spells per effect
This commit is contained in:
parent
b9dc05a158
commit
f902efbfcc
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())
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue