From d8b4bf9b93cfd1cdb0f7792bab58790f0c15f919 Mon Sep 17 00:00:00 2001
From: Joseph Botosh <rumly111@gmail.com>
Date: Fri, 18 Sep 2015 04:39:28 +0300
Subject: add function fishing

---
 npc/001-1/salem.txt          |   1 +
 npc/001-1/wateranimation.txt |   9 ++-
 npc/functions/fishing.txt    | 130 +++++++++++++++++++++++++++++++++++++++++++
 npc/scripts.conf             |   1 +
 4 files changed, 136 insertions(+), 5 deletions(-)
 create mode 100644 npc/functions/fishing.txt

diff --git a/npc/001-1/salem.txt b/npc/001-1/salem.txt
index a9c51450..a201f215 100644
--- a/npc/001-1/salem.txt
+++ b/npc/001-1/salem.txt
@@ -76,6 +76,7 @@
             ArtisQuests_CatchPiou_Difficulcy = 0;
             if (!BuyPiou(@ArtisQuests_PiouPrice))
                 ArtisQuests_PiouDiscount = 0;
+            // else ...
         }
         else
             mesq l("So, where is my piou? You should keep the given promise.");
diff --git a/npc/001-1/wateranimation.txt b/npc/001-1/wateranimation.txt
index c01e3b67..466ba6e3 100644
--- a/npc/001-1/wateranimation.txt
+++ b/npc/001-1/wateranimation.txt
@@ -5,11 +5,10 @@
 //    Water animations, splash, fishes, etc...
 
 001-1,116,123,0	script	#water_animation0	NPC_WATER_SPLASH,{
-    mesn "Narrator";
-    mesq col(l("You see some fish reflecting the sun on the surface of the ocean."), 9);
-    next;
-    closedialog;
-    end;
+    narrator
+        l("You see some fish reflecting the sun on the surface of the ocean.");
+    fishing;
+    close;
 
 OnInit:
     setnpcsex G_OTHER;
diff --git a/npc/functions/fishing.txt b/npc/functions/fishing.txt
new file mode 100644
index 00000000..08d53f82
--- /dev/null
+++ b/npc/functions/fishing.txt
@@ -0,0 +1,130 @@
+// Evol functions.
+// Authors:
+//    Travolta
+// Description:
+//    Fishing functions.
+
+
+function	script	fishing	{
+
+    .@wait_time_min = 5000;
+    .@wait_time_max = 30000;
+    .@pull_rand_max = 800;
+    .@pull_timeout = 1500;
+    .@fish_id = CommonCarp;
+    .@max_wait_times = 3;
+    .@curr_wait_times = 0;
+    .@rare_fish_chance = 2500;
+
+    setarray .@bait_ids[0], SmallTentacles, Bread, Aquada,
+                            UrchinMeat, TortugaTongue,
+                            Tentacles;
+    // if (countitem(FishingRod) < 1)
+    // {
+    //     narrator
+    //         l("You don't have a @@", getitemlink(FishingRod));
+    //     return -1;
+    // }
+
+
+L_ChooseBait:
+    .@sel$ = "";
+    .@cnt = 0;
+
+    for (.@i = 0; .@i < getarraysize(.@bait_ids); .@i++)
+        if (countitem(.@bait_ids[.@i]) > 0)
+        {
+            setarray .@user_items[.@cnt], .@bait_ids[.@i];
+            .@sel$ = .@sel$ + getitemname(.@bait_ids[.@i]) + ":";
+            .@cnt += 1;
+        }
+    .@sel$ = .@sel$ + l("Nothing, I changed my mind.");
+
+    if (!.@cnt)
+    {
+        .@bait_names$ = getitemlink(.@bait_ids[0]);
+        for (.@i = 1; .@i < getarraysize(.@bait_ids); .@i++)
+            .@bait_names$ = .@bait_names$ + ", " + getitemlink(.@bait_ids[.@i]);
+        narrator
+            l("You don't have any food suitable for bait."),
+            l("You need one of these: ") + .@bait_names$;
+            return -2;
+    }
+
+    narrator
+        l("What will be the bait for the fish?");
+    .@idx = select(.@sel$);
+
+    if (.@idx == .@cnt + 1)
+    {
+        narrator l("You take your fishing rod and leave.");
+        return 0;
+    }
+
+    .@bait = .@user_items[.@idx - 1];
+    delitem .@bait, 1;
+
+    narrator
+        l("You use a @@ as a bait.", getitemname(.@bait)),
+        l("You patiently wait...");
+
+L_Wait:
+    sleep2 rand(.@wait_time_min, .@wait_time_max);
+    .@tick = gettimetick(0);
+
+    mes col(l("Splash!"), 9);
+    mes "";
+
+    menuint
+        l("Pull!"), 1,
+        l("Wait..."), 2,
+        l("Give up."), 3;
+
+    switch (@menuret)
+    {
+        case 1:
+            .@timediff = gettimetick(0) - .@tick;
+            .@rnd = rand(.@timediff);
+            if (!rand(.@rare_fish_chance))
+                .@fish_id = GrassCarp;
+            // debugmes "timediff = " + .@timediff;
+            if (.@rnd <= .@pull_rand_max)
+            {
+                getitem .@fish_id, 1;
+                narrator
+                    l("You caught a @@!", getitemname(.@fish_id));
+                return 1;
+            }
+            else
+            {
+                narrator
+                    l("You pulled too late and lost the bait.");
+                goto L_ChooseBait;
+            }
+
+        case 2:
+            .@curr_wait_times += 1;
+
+            if (.@curr_wait_times > .@max_wait_times)
+            {
+                narrator
+                    l("The fish ate all your bait.");
+                goto L_ChooseBait;
+            }
+            else
+            {
+                narrator
+                    l("The fish ate small part of your bait."),
+                    l("But you decide to patiently wait.");
+                goto L_Wait;
+            }
+            break;
+
+        case 3:
+            narrator
+                l("You take your fishing rod and leave.");
+            return 0;
+    }
+
+    return;
+}
diff --git a/npc/scripts.conf b/npc/scripts.conf
index 5c8b9fbc..522874d2 100644
--- a/npc/scripts.conf
+++ b/npc/scripts.conf
@@ -19,6 +19,7 @@ npc: npc/functions/sailordialogue.txt
 npc: npc/functions/savepoint.txt
 npc: npc/functions/shops.txt
 npc: npc/functions/npcmovegraph.txt
+npc: npc/functions/fishing.txt
 
 // Maps specific scripts
 import: npc/_import.txt
-- 
cgit v1.2.3-70-g09d2