From 5d6b6243092503622e552d082e2e40223f209344 Mon Sep 17 00:00:00 2001
From: Jesusaves <cpntb1@ymail.com>
Date: Mon, 15 Apr 2019 10:56:44 -0300
Subject: Alpha: Guild Alchemy

---
 npc/functions/craft/alchemy.txt |  2 +-
 npc/guilds/logs.txt             | 70 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/npc/functions/craft/alchemy.txt b/npc/functions/craft/alchemy.txt
index 227e9e546..b76db43fd 100644
--- a/npc/functions/craft/alchemy.txt
+++ b/npc/functions/craft/alchemy.txt
@@ -16,7 +16,7 @@ function	script	AlchemySystem	{
     if (.scope == CRAFT_PLAYER)
         copyarray(.knowledge,RECIPES_ALCHEMY,getarraysize(RECIPES_ALCHEMY));
     else if (.scope == CRAFT_GUILD)
-        copyarray(.knowledge,$@RECIPES_ALCHEMY[getcharid(2)],getarraysize($@RECIPES_ALCHEMY[getcharid(2)]));
+        copyarray(.knowledge,$RECIPES_ALCHEMY[getcharid(2)],getarraysize($RECIPES_ALCHEMY[getcharid(2)]));
     .success=false;
 
     setskin "craft2";
diff --git a/npc/guilds/logs.txt b/npc/guilds/logs.txt
index fcd555f99..a41a377c5 100644
--- a/npc/guilds/logs.txt
+++ b/npc/guilds/logs.txt
@@ -5,8 +5,19 @@
 //  Guild Facility - Contains recipe list
 
 guilds,47,39,0	script	Guild Logs	NPC_NO_SPRITE,{
+    function showRecipe;
+    function calcRecipe;
     .@gid=getcharid(2);
-    mesc l("Your guild doesn't know any recipes."), 1;
+
+    mes ".:: " + l("Alchemy Recipes") + " ::.";
+    showRecipe(CraftPiberriesInfusion, PiberriesInfusion,
+               5, Piberries, 1, Curshroom);
+    showRecipe(CraftSacredManaPot, SacredManaPot,
+               1, GoldenApple, 15, CelestiaTea);
+    showRecipe(CraftSacredLifePot, SacredLifePot,
+               1, GoldenApple, 1, ElixirOfLife);
+
+
     if (getguildrole(.@gid, getcharid(3)) > GPOS_VICELEADER)
         close;
     do
@@ -14,6 +25,7 @@ guilds,47,39,0	script	Guild Logs	NPC_NO_SPRITE,{
         select
             l("Do nothing"),
             rif(strcharinfo(0) == getguildmaster(.@gid), l("Raise max members"));
+            l("Learn Alchemy Recipes");
         mes "";
 
         switch (@menu) {
@@ -41,11 +53,67 @@ guilds,47,39,0	script	Guild Logs	NPC_NO_SPRITE,{
                     break;
                 }
                 break;
+            case 3:
+                mes ".:: " + l("Alchemy Recipes") + " ::.";
+                deletearray(@tmp_alcrep_id);
+                deletearray(@tmp_alcrep_glv);
+                deletearray(@tmp_alcrep_ggp);
+                deletearray(@tmp_alcrep_txt$);
+
+                // Setup
+                if (!showRecipe(CraftPiberriesInfusion, 0, 0, 0, 0, 0, true))
+                calcRecipe(CraftPiberriesInfusion, 3, 10000, l("Piberries Infusion"));
+                if (!showRecipe(CraftSacredManaPot, 0, 0, 0, 0, 0, true))
+                calcRecipe(CraftSacredManaPot, 5, 100000, l("Sacred Mana Potion"));
+                if (!showRecipe(CraftSacredLifePot, 0, 0, 0, 0, 0, true))
+                calcRecipe(CraftSacredLifePot, 5, 100000, l("Sacred Life Potion"));
+
+                // Select
+                select (@tmp_alcrep_txt$+":Nothing");
+                if (@tmp_alcrep_glv[@menu] == 0)
+                    break;
+                if (getguildlvl(.@gid) < @tmp_alcrep_glv[@menu]) {
+                    mesc l("Insufficient Guild Level!"), 1;
+                    break;
+                }
+                if ($GUILD_BANK[.@gid] < @tmp_alcrep_ggp[@menu]) {
+                    mesc l("Insufficient Guild Money! (Guild has: @@ GP)", format_number($GUILD_BANK[.@gid])), 1;
+                    break;
+                }
+                // All fine, proceed
+                $GUILD_BANK[.@gid] -= @tmp_alcrep_ggp[@menu];
+                $RECIPES_ALCHEMY[getcharid(2)]=$RECIPES_ALCHEMY[getcharid(2)]|@tmp_alcrep_id[@menu];
+                mesc l("Skill learnt!"), 2;
+                next;
+                break;
         }
 
     } while (@menu != 1);
     close;
 
+// showRecipe (Craft, Bonus, Req1No, Req1Id, Req2No, Req2Id, DisplayText)
+function showRecipe {
+    if ($RECIPES_ALCHEMY[getcharid(2)] & getarg(0)) {
+        if (getarg(6,1)) {
+            mesn l("Craft @@", getitemlink(getarg(1)));
+            mesc l("* @@ @@", getarg(2), getitemlink(getarg(3)));
+            mesc l("* @@ @@", getarg(4), getitemlink(getarg(5)));
+            mes "";
+        }
+        return 1;
+    }
+    return 0;
+}
+
+// calcRecipe (CraftID, GLV, GGP, TXT)
+function calcRecipe {
+    array_push(@tmp_alcrep_id, getarg(0));
+    array_push(@tmp_alcrep_glv, getarg(1));
+    array_push(@tmp_alcrep_ggp, getarg(2));
+    array_push(@tmp_alcrep_txt$, getarg(3) + " - GLV "+getarg(1)+", "+getarg(2)+" GP");
+    return;
+}
+
 OnInit:
     .distance=2;
     end;
-- 
cgit v1.2.3-70-g09d2