mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-24 14:41:34 +00:00
Support for temporary stunted magicka effects
This commit is contained in:
parent
fcdb0c16bf
commit
f5eacfcf63
1 changed files with 59 additions and 12 deletions
|
@ -130,23 +130,45 @@ void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float
|
||||||
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr);
|
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr);
|
||||||
const MWWorld::Store<ESM::GameSetting>& settings = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
const MWWorld::Store<ESM::GameSetting>& settings = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
||||||
|
|
||||||
bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;
|
|
||||||
int endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified ();
|
int endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified ();
|
||||||
|
|
||||||
health = 0.1f * endurance;
|
health = 0.1f * endurance;
|
||||||
|
|
||||||
magicka = 0;
|
|
||||||
if (!stunted)
|
|
||||||
{
|
|
||||||
float fRestMagicMult = settings.find("fRestMagicMult")->mValue.getFloat ();
|
float fRestMagicMult = settings.find("fRestMagicMult")->mValue.getFloat ();
|
||||||
magicka = fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified();
|
magicka = fRestMagicMult * stats.getAttribute(ESM::Attribute::Intelligence).getModified();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
|
class GetStuntedMagickaDuration : public MWMechanics::EffectSourceVisitor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float mRemainingTime;
|
||||||
|
|
||||||
|
GetStuntedMagickaDuration(const MWWorld::Ptr& actor)
|
||||||
|
: mRemainingTime(0.f){}
|
||||||
|
|
||||||
|
virtual void visit (MWMechanics::EffectKey key,
|
||||||
|
const std::string& sourceName, const std::string& sourceId, int casterActorId,
|
||||||
|
float magnitude, float remainingTime = -1, float totalTime = -1)
|
||||||
|
{
|
||||||
|
if (mRemainingTime == -1) return;
|
||||||
|
|
||||||
|
if (key.mId == ESM::MagicEffect::StuntedMagicka)
|
||||||
|
{
|
||||||
|
if (totalTime == -1)
|
||||||
|
{
|
||||||
|
mRemainingTime = -1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remainingTime > mRemainingTime)
|
||||||
|
mRemainingTime = remainingTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class SoulTrap : public MWMechanics::EffectSourceVisitor
|
class SoulTrap : public MWMechanics::EffectSourceVisitor
|
||||||
{
|
{
|
||||||
MWWorld::Ptr mCreature;
|
MWWorld::Ptr mCreature;
|
||||||
|
@ -585,10 +607,34 @@ namespace MWMechanics
|
||||||
stat.setCurrent(stat.getCurrent() + health * hours);
|
stat.setCurrent(stat.getCurrent() + health * hours);
|
||||||
stats.setHealth(stat);
|
stats.setHealth(stat);
|
||||||
|
|
||||||
|
double restoreHours = hours;
|
||||||
|
bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;
|
||||||
|
if (stunted)
|
||||||
|
{
|
||||||
|
// Stunted Magicka effect should be taken into account.
|
||||||
|
GetStuntedMagickaDuration visitor(ptr);
|
||||||
|
stats.getActiveSpells().visitEffectSources(visitor);
|
||||||
|
stats.getSpells().visitEffectSources(visitor);
|
||||||
|
if (ptr.getClass().hasInventoryStore(ptr))
|
||||||
|
ptr.getClass().getInventoryStore(ptr).visitEffectSources(visitor);
|
||||||
|
|
||||||
|
// Take a maximum remaining duration of Stunted Magicka effects (-1 is a constant one) in game hours.
|
||||||
|
if (visitor.mRemainingTime > 0)
|
||||||
|
{
|
||||||
|
double timeScale = MWBase::Environment::get().getWorld()->getTimeScaleFactor();
|
||||||
|
restoreHours = std::max(0.0, hours - visitor.mRemainingTime * timeScale / 3600.f);
|
||||||
|
}
|
||||||
|
else if (visitor.mRemainingTime == -1)
|
||||||
|
restoreHours = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restoreHours > 0)
|
||||||
|
{
|
||||||
stat = stats.getMagicka();
|
stat = stats.getMagicka();
|
||||||
stat.setCurrent(stat.getCurrent() + magicka * hours);
|
stat.setCurrent(stat.getCurrent() + magicka * restoreHours);
|
||||||
stats.setMagicka(stat);
|
stats.setMagicka(stat);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Current fatigue can be above base value due to a fortify effect.
|
// Current fatigue can be above base value due to a fortify effect.
|
||||||
// In that case stop here and don't try to restore.
|
// In that case stop here and don't try to restore.
|
||||||
|
@ -1809,11 +1855,12 @@ namespace MWMechanics
|
||||||
getRestorationPerHourOfSleep(ptr, healthPerHour, magickaPerHour);
|
getRestorationPerHourOfSleep(ptr, healthPerHour, magickaPerHour);
|
||||||
|
|
||||||
CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
|
CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
|
||||||
|
bool stunted = stats.getMagicEffects ().get(ESM::MagicEffect::StuntedMagicka).getMagnitude() > 0;
|
||||||
|
|
||||||
float healthHours = healthPerHour > 0
|
float healthHours = healthPerHour > 0
|
||||||
? (stats.getHealth().getModified() - stats.getHealth().getCurrent()) / healthPerHour
|
? (stats.getHealth().getModified() - stats.getHealth().getCurrent()) / healthPerHour
|
||||||
: 1.0f;
|
: 1.0f;
|
||||||
float magickaHours = magickaPerHour > 0
|
float magickaHours = magickaPerHour > 0 && !stunted
|
||||||
? (stats.getMagicka().getModified() - stats.getMagicka().getCurrent()) / magickaPerHour
|
? (stats.getMagicka().getModified() - stats.getMagicka().getCurrent()) / magickaPerHour
|
||||||
: 1.0f;
|
: 1.0f;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue