From 6741fbe7a9ff84f226db2fdbc37c5bdca00af3a1 Mon Sep 17 00:00:00 2001
From: Internecine <qhibkgv@shitmail.org>
Date: Wed, 5 Nov 2014 15:22:44 +1300
Subject: [PATCH] Fixes bug #2031

---
 apps/openmw/mwmechanics/spellcasting.cpp | 30 +++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp
index d33bb6ad1..e124c8b79 100644
--- a/apps/openmw/mwmechanics/spellcasting.cpp
+++ b/apps/openmw/mwmechanics/spellcasting.cpp
@@ -434,7 +434,8 @@ namespace MWMechanics
                 float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * random;
                 magnitude *= magnitudeMult;
 
-                bool hasDuration = !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration);
+                bool hasDuration = !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration) && effectIt->mDuration > 0;
+                std::cout << (hasDuration == true ? "true" : "false") << std::endl;
                 if (target.getClass().isActor() && hasDuration)
                 {
                     ActiveSpells::ActiveEffect effect;
@@ -578,6 +579,33 @@ namespace MWMechanics
                     value.restore(magnitude);
                 target.getClass().getCreatureStats(target).setAttribute(attribute, value);
             }
+            else if (effectId == ESM::MagicEffect::DamageHealth || effectId == ESM::MagicEffect::RestoreHealth)
+            {
+                MWMechanics::DynamicStat<float> health = target.getClass().getCreatureStats(target).getHealth();
+                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)
+            {
+                MWMechanics::DynamicStat<float> fatigue = target.getClass().getCreatureStats(target).getFatigue();
+                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)
+            {
+                MWMechanics::DynamicStat<float> magicka = target.getClass().getCreatureStats(target).getMagicka();
+                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)
             {
                 if (target.getTypeName() != typeid(ESM::NPC).name())