From db020f7cccf3894ace14558b4c737ccc9f16886d Mon Sep 17 00:00:00 2001
From: Jesusaves <cpntb1@ymail.com>
Date: Fri, 24 May 2019 15:40:24 -0300
Subject: mlearn() skill, meant to reduce the maintenance cost on Magic
 Schools.

---
 npc/003-0/wizard.txt   | 31 ++++++-------------------------
 npc/functions/util.txt | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/npc/003-0/wizard.txt b/npc/003-0/wizard.txt
index 7283e0e2f..0d15e6f48 100644
--- a/npc/003-0/wizard.txt
+++ b/npc/003-0/wizard.txt
@@ -101,31 +101,12 @@ L_Member:
             //mesc l("Useful in PvP when your enemy have equipped a @@", getitemlink(AstralCube));
             mes "";
             mesn;
-            mesq l("This useful skill will only require:");
-            mesc l("@@/@@ @@", countitem(Acorn),            (getskilllv(MG_NAPALMBEAT)+1)*60, getitemlink(Acorn));
-            mesc l("@@/@@ @@", countitem(Bread),            (getskilllv(MG_NAPALMBEAT)+1)*30, getitemlink(Bread));
-            mesc l("@@/@@ @@", countitem(SmallMushroom),    (getskilllv(MG_NAPALMBEAT)+1)*20, getitemlink(SmallMushroom));
-            mesc l("@@/@@ @@", countitem(PinkBlobime),      (getskilllv(MG_NAPALMBEAT)+1)*20,  getitemlink(PinkBlobime));
-            mesc l("@@/@@ @@", countitem(RedApple),         (getskilllv(MG_NAPALMBEAT)+1)*15,  getitemlink(RedApple));
-            next;
-            if (askyesno() == ASK_YES) {
-                if (
-                    countitem(Acorn)         < (getskilllv(MG_NAPALMBEAT)+1)*60 ||
-                    countitem(Bread)         < (getskilllv(MG_NAPALMBEAT)+1)*30 ||
-                    countitem(SmallMushroom) < (getskilllv(MG_NAPALMBEAT)+1)*20 ||
-                    countitem(PinkBlobime)   < (getskilllv(MG_NAPALMBEAT)+1)*20 ||
-                    countitem(RedApple)      < (getskilllv(MG_NAPALMBEAT)+1)*15) goto L_Missing;
-
-                delitem Acorn,          (getskilllv(MG_NAPALMBEAT)+1)*60;
-                delitem Bread,          (getskilllv(MG_NAPALMBEAT)+1)*30;
-                delitem SmallMushroom,  (getskilllv(MG_NAPALMBEAT)+1)*20;
-                delitem PinkBlobime,    (getskilllv(MG_NAPALMBEAT)+1)*20;
-                delitem RedApple,       (getskilllv(MG_NAPALMBEAT)+1)*15;
-
-                sk_lvup(MG_NAPALMBEAT);
-
-                next;
-            }
+            if (!mlearn(Acorn, 60,
+                        Bread, 30,
+                        SmallMushroom, 20,
+                        PinkBlobime, 20,
+                        RedApple, 15))
+                goto L_Missing;
             break;
         // Magic Bolts
         case 3:
diff --git a/npc/functions/util.txt b/npc/functions/util.txt
index 644954942..c83f040b0 100644
--- a/npc/functions/util.txt
+++ b/npc/functions/util.txt
@@ -603,6 +603,45 @@ function	script	sk_intcost	{
     return 0;
 }
 
+// Magic School Learning Interface
+// mlearn( skill, {item 1, amount 1}, {item 2, amount 2}... )
+// returns false if cheater
+function	script	mlearn	{
+    if (getargcount() < 2 || getargcount() % 2 != 1)
+        return Exception("Faulty learning skill command invoked - error");
+
+    .@sk=getarg(0);
+
+    // List required ingredients
+    mesq l("This useful skill will only require:");
+    for (.@i=1;.@i < getargcount(); .@i++) {
+        mesc l("@@/@@ @@", countitem(getarg(.@i)),            (getskilllv(.@sk)+1)*getarg(.@i+1), getitemlink(getarg(.@i)));
+        .@i++;
+    }
+    // getarg(.@i)
+    next;
+    if (askyesno() == ASK_NO)
+        return true;
+
+    // Count items
+    for (.@i=1;.@i < getargcount(); .@i++) {
+        if (countitem(getarg(.@i))         < (getskilllv(.@sk)+1)*getarg(.@i+1))
+            return false;
+        .@i++;
+    }
+
+    // Delete Items
+    for (.@i=1;.@i < getargcount(); .@i++) {
+        delitem getarg(.@i),          (getskilllv(.@sk)+1)*getarg(.@i+1);
+        .@i++;
+    }
+
+    sk_lvup(.@sk);
+    next;
+
+    return true;
+}
+
 // Returns a value defining your current magic control (affects success ratio, higher is better)
 // A value of '5' means perfect control, and a value of '0' means overwhelm.
 // abizit()
-- 
cgit v1.2.3-70-g09d2