Implement damage tick effects

This commit is contained in:
scrawl 2013-11-16 03:16:21 +01:00
parent b1a29eb27e
commit bb43ec9b35
3 changed files with 25 additions and 7 deletions

View file

@ -269,6 +269,14 @@ namespace MWMechanics
if (effectIt->mRange != range)
continue;
const ESM::MagicEffect *magicEffect =
MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find (
effectIt->mEffectID);
if (caster.getRefData().getHandle() == "player" && actor != caster
&& magicEffect->mData.mFlags & ESM::MagicEffect::Harmful)
MWBase::Environment::get().getWindowManager()->setEnemy(actor);
// Try resisting effect in case its harmful
const ESM::Spell *spell =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (id);
@ -287,10 +295,6 @@ namespace MWMechanics
// TODO: For Area effects, launch a growing particle effect that applies the effect to more actors as it hits them. Best managed in World.
const ESM::MagicEffect *magicEffect =
MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find (
effectIt->mEffectID);
// Only the sound of the first effect plays
if (first)
{

View file

@ -29,7 +29,7 @@ namespace MWMechanics
// magic effects
adjustMagicEffects (ptr);
calculateDynamicStats (ptr);
calculateCreatureStatModifiers (ptr);
calculateCreatureStatModifiers (ptr, duration);
if(!MWBase::Environment::get().getWindowManager()->isGuiMode())
{
@ -145,7 +145,7 @@ namespace MWMechanics
stats.setFatigue (fatigue);
}
void Actors::calculateCreatureStatModifiers (const MWWorld::Ptr& ptr)
void Actors::calculateCreatureStatModifiers (const MWWorld::Ptr& ptr, float duration)
{
CreatureStats &creatureStats = MWWorld::Class::get(ptr).getCreatureStats(ptr);
const MagicEffects &effects = creatureStats.getMagicEffects();
@ -167,10 +167,24 @@ namespace MWMechanics
stat.setModifier(effects.get(EffectKey(ESM::MagicEffect::FortifyHealth+i)).mMagnitude -
effects.get(EffectKey(ESM::MagicEffect::DrainHealth+i)).mMagnitude);
float damage = creatureStats.getMagicEffects().get(EffectKey(ESM::MagicEffect::DamageHealth)).mMagnitude;
stat.setCurrent(stat.getCurrent() - damage * duration);
creatureStats.setDynamic(i, stat);
}
// Apply damage ticks
int damageEffects[] = {
ESM::MagicEffect::FireDamage, ESM::MagicEffect::ShockDamage, ESM::MagicEffect::FrostDamage, ESM::MagicEffect::Poison
};
for (unsigned int i=0; i<sizeof(damageEffects)/sizeof(int); ++i)
{
float magnitude = creatureStats.getMagicEffects().get(EffectKey(damageEffects[i])).mMagnitude;
DynamicStat<float> health = creatureStats.getHealth();
health.setCurrent(health.getCurrent() - magnitude * duration);
creatureStats.setHealth(health);
}
}
void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr)

View file

@ -40,7 +40,7 @@ namespace MWMechanics
void calculateDynamicStats (const MWWorld::Ptr& ptr);
void calculateCreatureStatModifiers (const MWWorld::Ptr& ptr);
void calculateCreatureStatModifiers (const MWWorld::Ptr& ptr, float duration);
void calculateNpcStatModifiers (const MWWorld::Ptr& ptr);
void calculateRestoration (const MWWorld::Ptr& ptr, float duration);