From 3ea7d58ca8b48ed252345fbad73dddbeea1815b4 Mon Sep 17 00:00:00 2001
From: scrawl <scrawl@baseoftrash.de>
Date: Sat, 9 Nov 2013 10:34:46 +0100
Subject: [PATCH 1/2] Advance skill on successfull spell cast

---
 apps/openmw/CMakeLists.txt       | 2 +-
 apps/openmw/mwworld/worldimp.cpp | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt
index f07bbab86b..e2dbf40de4 100644
--- a/apps/openmw/CMakeLists.txt
+++ b/apps/openmw/CMakeLists.txt
@@ -68,7 +68,7 @@ add_openmw_dir (mwclass
 add_openmw_dir (mwmechanics
     mechanicsmanagerimp stat character creaturestats magiceffects movement actors objects
     drawstate spells activespells npcstats aipackage aisequence alchemy aiwander aitravel aifollow
-    aiescort aiactivate repair enchanting pathfinding security
+    aiescort aiactivate repair enchanting pathfinding security spellsuccess
     )
 
 add_openmw_dir (mwbase
diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp
index a91f1e00c3..6c18ec4fd6 100644
--- a/apps/openmw/mwworld/worldimp.cpp
+++ b/apps/openmw/mwworld/worldimp.cpp
@@ -2040,6 +2040,7 @@ namespace MWWorld
                 return;
             }
 
+            actor.getClass().skillUsageSucceeded(actor, MWMechanics::spellSchoolToSkill(MWMechanics::getSpellSchool(selectedSpell, actor)), 0);
 
             actor.getClass().getCreatureStats(actor).getActiveSpells().addSpell(selectedSpell, actor, ESM::RT_Self);
             // TODO: RT_Range, RT_Touch

From 3e58655a902ffe96311d8060ca61d3f1377d5b41 Mon Sep 17 00:00:00 2001
From: scrawl <scrawl@baseoftrash.de>
Date: Sat, 9 Nov 2013 10:49:00 +0100
Subject: [PATCH 2/2] Implemented Fortify/Drain skill magic effects. Scroll of
 icarian flight works!

---
 apps/openmw/mwmechanics/actors.cpp | 15 +++++++++++++++
 apps/openmw/mwmechanics/actors.hpp |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp
index 42851dea39..39276e9645 100644
--- a/apps/openmw/mwmechanics/actors.cpp
+++ b/apps/openmw/mwmechanics/actors.cpp
@@ -47,6 +47,7 @@ namespace MWMechanics
         if(!paused)
         {
             updateDrowning(ptr, duration);
+            calculateNpcStatModifiers(ptr);
             updateEquippedLight(ptr, duration);
         }
     }
@@ -170,6 +171,20 @@ namespace MWMechanics
         }
     }
 
+    void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr)
+    {
+        NpcStats &npcStats = MWWorld::Class::get(ptr).getNpcStats(ptr);
+        const MagicEffects &effects = npcStats.getMagicEffects();
+
+        // skills
+        for(int i = 0;i < ESM::Skill::Length;++i)
+        {
+            Stat<float>& skill = npcStats.getSkill(i);
+            skill.setModifier(effects.get(EffectKey(ESM::MagicEffect::FortifySkill, i)).mMagnitude -
+                             effects.get(EffectKey(ESM::MagicEffect::DrainSkill, i)).mMagnitude);
+        }
+    }
+
     void Actors::updateDrowning(const MWWorld::Ptr& ptr, float duration)
     {
         MWBase::World *world = MWBase::Environment::get().getWorld();
diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp
index a77e52ba30..eeef22635c 100644
--- a/apps/openmw/mwmechanics/actors.hpp
+++ b/apps/openmw/mwmechanics/actors.hpp
@@ -34,11 +34,14 @@ namespace MWMechanics
 
         void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
 
+
+
             void adjustMagicEffects (const MWWorld::Ptr& creature);
 
             void calculateDynamicStats (const MWWorld::Ptr& ptr);
 
             void calculateCreatureStatModifiers (const MWWorld::Ptr& ptr);
+            void calculateNpcStatModifiers (const MWWorld::Ptr& ptr);
 
             void calculateRestoration (const MWWorld::Ptr& ptr, float duration);