1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 08:23:53 +00:00

Modify the current magicka and fatigue when the base changes

This commit is contained in:
Chris Robinson 2013-08-27 22:44:52 -07:00
parent 305b5fec0f
commit 92082dae66
2 changed files with 23 additions and 9 deletions

View file

@ -70,22 +70,24 @@ namespace MWMechanics
{ {
CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr); CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr);
int strength = creatureStats.getAttribute(0).getBase(); int strength = creatureStats.getAttribute(ESM::Attribute::Strength).getBase();
int intelligence = creatureStats.getAttribute(1).getBase(); int intelligence = creatureStats.getAttribute(ESM::Attribute::Intelligence).getBase();
int willpower = creatureStats.getAttribute(2).getBase(); int willpower = creatureStats.getAttribute(ESM::Attribute::Willpower).getBase();
int agility = creatureStats.getAttribute(3).getBase(); int agility = creatureStats.getAttribute(ESM::Attribute::Agility).getBase();
int endurance = creatureStats.getAttribute(5).getBase(); int endurance = creatureStats.getAttribute(ESM::Attribute::Endurance).getBase();
double magickaFactor = double magickaFactor =
creatureStats.getMagicEffects().get (EffectKey (ESM::MagicEffect::FortifyMaximumMagicka)).mMagnitude * 0.1 + 0.5; creatureStats.getMagicEffects().get (EffectKey (ESM::MagicEffect::FortifyMaximumMagicka)).mMagnitude * 0.1 + 0.5;
DynamicStat<float> magicka = creatureStats.getMagicka(); DynamicStat<float> magicka = creatureStats.getMagicka();
magicka.setBase (static_cast<int> (intelligence + magickaFactor * intelligence)); float diff = (static_cast<int>(intelligence + magickaFactor*intelligence)) - magicka.getBase();
creatureStats.setMagicka (magicka); magicka.modify(diff);
creatureStats.setMagicka(magicka);
DynamicStat<float> fatigue = creatureStats.getFatigue(); DynamicStat<float> fatigue = creatureStats.getFatigue();
fatigue.setBase (strength+willpower+agility+endurance); diff = (strength+willpower+agility+endurance) - fatigue.getBase();
creatureStats.setFatigue (fatigue); fatigue.modify(diff);
creatureStats.setFatigue(fatigue);
} }
void Actors::calculateRestoration (const MWWorld::Ptr& ptr, float duration) void Actors::calculateRestoration (const MWWorld::Ptr& ptr, float duration)

View file

@ -42,6 +42,18 @@ namespace MWMechanics
mBase = mModified = value; mBase = mModified = value;
} }
void modify(const T& diff)
{
mBase += diff;
if(mBase >= static_cast<T>(0))
mModified += diff;
else
{
mModified += diff - mBase;
mBase = static_cast<T>(0);
}
}
/// Set base and adjust modified accordingly. /// Set base and adjust modified accordingly.
void setBase (const T& value) void setBase (const T& value)
{ {