Modify the current magicka and fatigue when the base changes

pull/51/head
Chris Robinson 12 years ago
parent 305b5fec0f
commit 92082dae66

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

@ -42,6 +42,18 @@ namespace MWMechanics
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.
void setBase (const T& value)
{

Loading…
Cancel
Save