summaryrefslogtreecommitdiff
path: root/npc/functions/fishing.txt
blob: 2f019847ee4a1a1663f2a9c7a82ce1fdd307dea7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Evol functions.
// Authors:
//    omatt
//    Travolta
// Description:
//    Fishing functions.
// Variable
//    .dir
//         DOWN    Never try or pulled too late
//         UP      Bait dropped
//         LEFT    Fish bite bait
//
// player log on .dir is DOWN, start by choose bait menu
// player chooses bait, script addtimer in npc .dir is UP
// if player pulls before signal npc, bait is lost, set .bait to DOWN goto choose bait
// if player pulls after pull delay max, bait is lost, set .bait to DOWN goto choose bait
// npc signal .dir is LEFT
// player pulls between npc signal and pulls delay max, got the fish, set .dir to DOWN goto choose bait

function	script	fishingspot	{

    if (getnpcdir(getarg(0)) != DOWN && @occupy == false)
    {
        npctalkonce l("This fishing spot is already being used!");

        close;
    }

    // Skip the narator when we are in fishing
    if (getnpcdir(getarg(0)) == DOWN)
    {
        narrator 4, l("You see some fish reflecting the sun on the surface of the water.");
    }

    return;
}
function	script	fishing	{

    .@wait_time_min = 4000;
    .@wait_time_max = 18000;
    .@pull_rand_max = 800;
    .@fish_id = CommonCarp;
    .@rare_fish_chance = 25;

    
    if (countitem(FishingRod) < 1)
    {
        narrator
            l("You don't have any @@.", getitemlink(FishingRod));
        return -1;
    }

    switch (getnpcdir(getarg(0)))
    {
        case UP:
            @occupy = false;
            setnpcdir getarg(0), DOWN;

            deltimer getarg(0) + "::OnBiteBait";
            deltimer getarg(0) + "::OnRemoveBait";
            narrator l("You pulled too soon and lost the bait.");

            close;
        case LEFT:
            @occupy = false;
            deltimer getarg(0) + "::OnRemoveBait";

            setnpcdir getarg(0), DOWN;

            getmapxy (.@mapbis$, .@xbis, .@ybis, 0);

            // Leave spot, lost the bait
            if (.@xbis != @x || .@ybis != @y || !compare (@map$, .@mapbis$))
            {
                narrator l("You left your fishing spot!");
                close;
            }

            // RNG to obtain a rare fish
            .@timediff = gettimetick(0) - @tick;
            if (rand(.@rare_fish_chance) == 0)
            {
                .@fish_id = GrassCarp;
            }

            // RNG to obtain a fish
            if (rand(.@timediff) <= .@pull_rand_max)
            {
                narrator l("You caught a @@!", getitemname(.@fish_id));

                inventoryplace .@fish_id, 1;
                getitem .@fish_id, 1;
            }
            else
            {
                narrator l("You pulled too late and lost a @@...", getitemname(.@fish_id));
            }

            close;

        default:
            break;
    }

OnChooseBait:
    if (Fishing_Tick > gettimetick(2) - 20)
    {
        narrator l("This fishing spot has just been used, give it a rest.");
        close;
    }

    setarray .@bait_ids[0], SmallTentacles, Bread, Aquada,
                            UrchinMeat, TortugaTongue,
                            Tentacles;


    .@curr_wait_times = 0;
    .@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 to use as bait."),
            l("You need at least one of these: ") + .@bait_names$;
            return -2;
    }

    narrator 2,
        l("What will be the bait for the fish?");
    .@idx = select(.@sel$);

    if (.@idx == .@cnt + 1)
    {
        narrator 1,
            l("You take your fishing rod and leave.");
        return 0;
    }

    if (@occupy == true)
    {
        narrator 1,
            l("Somebody took your place on this spot!"),
            l("You take your fishing rod and leave.");
        return 0;
    }
    @occupy = true;

    // The player uses this spot, his bait is ready, he just has to wait for the signal.
    closedialog;

    setnpcdir getarg(0), UP;

    Fishing_Tick = gettimetick(2);
    .@bait = .@user_items[.@idx - 1];
    delitem .@bait, 1;

    npctalk3 l("Wait for the bait to sink underwater.");
    getmapxy (@map$, @x, @y, 0);

    .@delay = rand(.@wait_time_min, .@wait_time_max);

    addtimer .@delay, getarg(0) + "::OnBiteBait";
    addtimer (.@delay + 5000), getarg(0) + "::OnRemoveBait";

    close;
}