Added a helper function to handle dynamic stat changes

openmw-35
Internecine 10 years ago
parent edc51ab768
commit a87fe71ddf

@ -580,30 +580,15 @@ namespace MWMechanics
} }
else if (effectId == ESM::MagicEffect::DamageHealth || effectId == ESM::MagicEffect::RestoreHealth) else if (effectId == ESM::MagicEffect::DamageHealth || effectId == ESM::MagicEffect::RestoreHealth)
{ {
MWMechanics::DynamicStat<float> health = target.getClass().getCreatureStats(target).getHealth(); applyDynamicStatsEffect(0, target, magnitude);
if (effectId == ESM::MagicEffect::DamageHealth)
health.setCurrent(health.getCurrent() - magnitude);
else
health.setCurrent(health.getCurrent() + magnitude);
target.getClass().getCreatureStats(target).setHealth(health);
} }
else if (effectId == ESM::MagicEffect::DamageFatigue || effectId == ESM::MagicEffect::RestoreFatigue) else if (effectId == ESM::MagicEffect::DamageFatigue || effectId == ESM::MagicEffect::RestoreFatigue)
{ {
MWMechanics::DynamicStat<float> fatigue = target.getClass().getCreatureStats(target).getFatigue(); applyDynamicStatsEffect(1, target, magnitude);
if (effectId == ESM::MagicEffect::DamageFatigue)
fatigue.setCurrent(fatigue.getCurrent() - magnitude);
else
fatigue.setCurrent(fatigue.getCurrent() + magnitude);
target.getClass().getCreatureStats(target).setHealth(fatigue);
} }
else if (effectId == ESM::MagicEffect::DamageMagicka || effectId == ESM::MagicEffect::RestoreMagicka) else if (effectId == ESM::MagicEffect::DamageMagicka || effectId == ESM::MagicEffect::RestoreMagicka)
{ {
MWMechanics::DynamicStat<float> magicka = target.getClass().getCreatureStats(target).getMagicka(); applyDynamicStatsEffect(2, target, magnitude);
if (effectId == ESM::MagicEffect::DamageMagicka)
magicka.setCurrent(magicka.getCurrent() - magnitude);
else
magicka.setCurrent(magicka.getCurrent() + magnitude);
target.getClass().getCreatureStats(target).setHealth(magicka);
} }
else if (effectId == ESM::MagicEffect::DamageSkill || effectId == ESM::MagicEffect::RestoreSkill) else if (effectId == ESM::MagicEffect::DamageSkill || effectId == ESM::MagicEffect::RestoreSkill)
{ {
@ -666,6 +651,13 @@ namespace MWMechanics
} }
} }
} }
void CastSpell::applyDynamicStatsEffect(int attribute, const MWWorld::Ptr& target, float magnitude)
{
DynamicStat<float> value = target.getClass().getCreatureStats(target).getDynamic(attribute);
value.modify(magnitude);
target.getClass().getCreatureStats(target).setDynamic(attribute, value);
}
bool CastSpell::cast(const std::string &id) bool CastSpell::cast(const std::string &id)
{ {

@ -93,6 +93,8 @@ namespace MWMechanics
/// @note \a caster can be any type of object, or even an empty object. /// @note \a caster can be any type of object, or even an empty object.
void applyInstantEffect (const MWWorld::Ptr& target, const MWWorld::Ptr& caster, const MWMechanics::EffectKey& effect, float magnitude); void applyInstantEffect (const MWWorld::Ptr& target, const MWWorld::Ptr& caster, const MWMechanics::EffectKey& effect, float magnitude);
void applyDynamicStatsEffect (int attribute, const MWWorld::Ptr& target, float magnitude);
}; };
} }

Loading…
Cancel
Save