summaryrefslogtreecommitdiff
path: root/npc/items/shovel.txt
blob: fef4c24f17386b58c3504237cfad26a82d6f4040 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// Evol scripts.
// Author:
//    Travolta
// Description:
//    NPC to use shovel (dig, bury etc)

-	script	Shovel	-1,{

    function CheckDigLocation {
        getmapxy(.@map$, .@x, .@y, 0);

        if (getunits(BL_NPC, .@units, 1, .@map$, .@x - 1, .@y, .@x + 1, .@y + 1))
        {
            dispbottom(l("You cannot bury under a NPC!"));
            return false;
        }

        // TODO: we should have a way to check for GROUNDTOP collisions too

        for (.@i = 0; .@i < getarraysize(.WorldDigRect_Map$); .@i++)
        {
            if (!strcmp(.WorldDigRect_Map$[.@i], .@map$) &&
                .WorldDigRect_x1[.@i] <= .@x &&
                .WorldDigRect_x2[.@i] >= .@x &&
                .WorldDigRect_y1[.@i] <= .@y &&
                .WorldDigRect_y2[.@i] >= .@y)
            {
                return true;
            }
        }

        dispbottom(l("You can't use the shovel here."));
        return false;
    }

    function AddDigRect {
        if (getargcount() < 5)
        {
            consolemes(CONSOLEMES_ERROR, "usage: AddDigRect(map$,x1,y1,x2,y2)");
            return 0;
        }
        .@map$ = str(getarg(0));
        .@x1 = getarg(1);
        .@y1 = getarg(2);
        .@x2 = getarg(3);
        .@y2 = getarg(4);
        .@size = getarraysize(.WorldDigRect_Map$);
        .WorldDigRect_Map$[.@size] = .@map$;
        .WorldDigRect_x1[.@size] = .@x1;
        .WorldDigRect_y1[.@size] = .@y1;
        .WorldDigRect_x2[.@size] = .@x2;
        .WorldDigRect_y2[.@size] = .@y2;
        return 1;
    }

    function PlayerIsTired {
        if (is_evtc())
            return false; // event coordinators are never tired

        .@tick = gettimetick(1);
        .@playertick = .PlayerTiredTime - readparam(bStr);
        if (@ShovelLastUsed + max(4, .@playertick) > .@tick)
        {
            narrator S_FIRST_BLANK_LINE,
                lg("You are exhausted, you should rest a bit.");
            return true;
        }
        @ShovelLastUsed = .@tick;
        return false;
    }

    function Dig {
        getmapxy(.@map$, .@x, .@y, 0);
        for (.@i = 0; .@i < getarraysize($WorldBuriedTreasures_id); .@i++)
        {
            if (!strcmp($WorldBuriedTreasures_map$[.@i], .@map$) &&
                $WorldBuriedTreasures_x[.@i] == .@x &&
                $WorldBuriedTreasures_y[.@i] == .@y)
            {
                .@id = $WorldBuriedTreasures_id[.@i];
                .@amount = $WorldBuriedTreasures_amount[.@i];
                deletearray $WorldBuriedTreasures_id[.@i], 1;
                deletearray $WorldBuriedTreasures_amount[.@i], 1;
                deletearray $WorldBuriedTreasures_map$[.@i], 1;
                deletearray $WorldBuriedTreasures_x[.@i], 1;
                deletearray $WorldBuriedTreasures_y[.@i], 1;
                getitem .@id, .@amount;
                narrator S_FIRST_BLANK_LINE,
                    l("You found something!"),
                    l("It's @@ @@.", .@amount, getitemname(.@id));
                return 1;
            }
        }
        narrator S_FIRST_BLANK_LINE, l("Sadly, you found nothing but dirt.");
        return 0;
    }

    function Bury {
        narrator(S_FIRST_BLANK_LINE | S_LAST_NEXT,
            l("What would you like to bury?"));

        mes("##B" + l("Drag and drop an item from your inventory.") + "##b");
        .@id = requestitem();

        // You cannot bury: Items you don't have, your shovel, Bound Items, and items which are not dropped by any mobs.
        // The "item not dropped by any mob" is temporary, and should be replaced by "items with trade restrictions" later. [JESUS]
        // event coordinators can always bury
        if (!is_evtc() && (.@id < 1 || countitem(.@id) < 1 ||
            compare(getitemname(.@id), "shovel") || checkbound(.@id) ||
            !getiteminfo(.@id, ITEMINFO_MAXCHANCE)))
        {
            mesc(l("You cannot bury this item!"));
            return false;
        }

        .@amount = 1;
        if (countitem(.@id) > 1)
        {
            narrator S_FIRST_BLANK_LINE | S_LAST_BLANK_LINE, l("Amount?");
            input .@amount, 1, countitem(.@id);
        }

        getmapxy(.@map$, .@x, .@y, 0);

        delitem .@id, .@amount;
        .@wtc = getarraysize($WorldBuriedTreasures_id);
        $WorldBuriedTreasures_id[.@wtc] = .@id;
        $WorldBuriedTreasures_amount[.@wtc] = .@amount;
        $WorldBuriedTreasures_map$[.@wtc] = .@map$;
        $WorldBuriedTreasures_x[.@wtc] = .@x;
        $WorldBuriedTreasures_y[.@wtc] = .@y;
        narrator S_FIRST_BLANK_LINE, l("You buried @@ @@.", .@amount, getitemname(.@id));

        return true;
    }

    function ShovelQuests {
        getmapxy(.@map$, .@x, .@y, 0);
        for (.@i = 0; .@i < getarraysize(ShovelQuests_func$); .@i++)
        {
            if (!strcmp(ShovelQuests_map$[.@i], .@map$) &&
                ShovelQuests_x[.@i] == .@x &&
                ShovelQuests_y[.@i] == .@y)
            {
                .@func$ = ShovelQuests_func$[.@i];
                deletearray ShovelQuests_func$[.@i], 1;
                deletearray ShovelQuests_map$[.@i], 1;
                deletearray ShovelQuests_x[.@i], 1;
                deletearray ShovelQuests_y[.@i], 1;
                callfunc(.@func$);
                return 1;
            }
        }
        return 0;
    }

OnUse:
    if (!CheckDigLocation())
        end;

    narrator S_LAST_BLANK_LINE,
        l("You hold the shovel in your hands."),
        l("What are you going to do?");

    .@action = select(
        l("Dig."),
        l("Bury."),
        l("Nothing."));

    switch(.@action)
    {
        case 1:
            if (PlayerIsTired())
                close;
            if (!ShovelQuests())
                Dig();
            break;
        case 2:
            if (PlayerIsTired())
                close;
            Bury();
            break;
        case 3:
            narrator S_FIRST_BLANK_LINE, l("You hide your shovel.");
            break;
    }
    close;

OnHour00:
    if (playerattached())
       @ShovelLastUsed = 0;
    end;

OnInit:
    .PlayerTiredTime = 20;
    AddDigRect("001-1", 172, 26, 200, 48);
    end;

}

function	script	shovel_addquest	{
    if (getargcount() < 4)
    {
        consolemes(CONSOLEMES_ERROR, "usage: shovel_addquest(map$,x,y,func$)");
        return 0;
    }
    .@map$ = str(getarg(0));
    .@x = getarg(1);
    .@y = getarg(2);
    .@func$ = str(getarg(3));
    .@size = getarraysize(ShovelQuests_func$);
    ShovelQuests_func$[.@size] = .@func$;
    ShovelQuests_map$[.@size] = .@map$;
    ShovelQuests_x[.@size] = .@x;
    ShovelQuests_y[.@size] = .@y;
    return 1;
}

function	script	shovel_adddigrect	{
    if (getargcount() < 5)
    {
        consolemes(CONSOLEMES_ERROR, "usage: shovel_adddigrect(map$,x1,y1,x2,y2)");
        return 0;
    }
    .@map$ = str(getarg(0));
    .@x1 = getarg(1);
    .@y1 = getarg(2);
    .@x2 = getarg(3);
    .@y2 = getarg(4);
    .@size = getarraysize(getvariableofnpc(.WorldDigRect_Map$, strnpcinfo(3)));
    set getvariableofnpc(.WorldDigRect_Map$[.@size], strnpcinfo(3)), .@map$;
    set getvariableofnpc(.WorldDigRect_x1[.@size], strnpcinfo(3)), .@x1;
    set getvariableofnpc(.WorldDigRect_y1[.@size], strnpcinfo(3)), .@y1;
    set getvariableofnpc(.WorldDigRect_x2[.@size], strnpcinfo(3)), .@x2;
    set getvariableofnpc(.WorldDigRect_y2[.@size], strnpcinfo(3)), .@y2;
    return 1;
}