summaryrefslogtreecommitdiff
path: root/world/map/npc/annuals/halloween/trick_or_treat.txt
blob: 10265382ca792a5d126cf37a0478ac03d61401a0 (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// Halloween Annual
// Authors: alastrim, enchilado, o11c, wushin
// See config
function|script|TrickOrTreat
{
    callfunc "HalloweenCheckOld";
    if ($@halloween_time)
        goto L_Halloween;
    goto L_QuickReturn;

L_Halloween:
    if ((gettimetick(2)-TUT_var < $@halloween_min_age) || (BaseLevel < $@halloween_min_level)) //player must be created at least 1 weeks ago
        goto L_QuickReturn;
    menu
        "Trick or Treat", L_HWQuest,
        "[Go to normal NPC dialog]", L_QuickReturn;

L_HWQuest:
    set @mask, getequipid(equip_head);
    goto L_Begin;

L_Begin:
    set @karma, (HALLOWEENTIME & 65535);
    if (@mask > 0)
        goto L_WearingMask;
    goto L_NoMask;

L_WearingMask:
    // set the scare factor of the equipped mask
    set @mask_index, 0;
    set @scare_factor, 1;
    goto L_MaskLoop;

L_MaskLoop:
    if ($@halloween_mask_IDs[@mask_index] == @mask)
        goto L_FoundMask;
    set @mask_index, @mask_index + 1;
    if ($@halloween_mask_IDs[@mask_index])
        goto L_MaskLoop;
    // not a mask in the list
    set @mask, 0;
    goto L_MaskDone;

L_FoundMask:
    set @scare_factor, $@halloween_scare_factors[@mask_index];
    if (@mask != 616)
        goto L_MaskDone;
    mes "\"Aaargh... Gross! This is sick! I can't even look at your face...\"";
    goto L_MaskDone;

L_MaskDone:
    set @mask_index, 0;
    // check if the mask is in the memory
    set @loop, 0;
    // Note: we don't handle remembered faces until they get their candy
    if (!@mask)
        goto L_MaskMemoryNo;
    // check if the mask is remembered
    goto L_MaskMemoryCheck;

L_MaskMemoryCheck:
    set @tmp, $@halloween_maskmemory[8 * @halloween_npc_id + @loop];
    if (!@tmp)
        goto L_MaskMemoryNo;
    if (@tmp == @mask)
        goto L_MaskMemoryYes;
    set @loop, @loop + 1;
    if (@loop != $@halloween_memory_count)
        goto L_MaskMemoryCheck;
    goto L_MaskMemoryNo;

L_MaskMemoryYes:
    // not necessarily true
    mes "\"I remember you, " + getitemlink(getequipid(equip_head)) + " person. No more treats for you!\"";
    goto L_Close;

L_MaskMemoryNo:
    // player will probably get treats
    set @loop, 0;
    set @sweets_types, 0;
    goto L_Count_Sweets;

L_Count_Sweets:
    if ($@halloween_sweets[@loop] == 0)
        goto L_Check_Inventory;
    if (countitem($@halloween_sweets[@loop]))
        set @sweets_types, @sweets_types + 1;
    set @loop, @loop + 1;
    goto L_Count_Sweets;

L_Check_Inventory:
    getinventorylist;
    if (@inventorylist_count + (@loop - @halloween_invy) > 100)
        goto L_Full_Inventory;
    if (@mask)
        goto L_Check_Karma;
    // check if the player's face is remembered
    if (HALLOWEENTIME & (1 << (31 - @halloween_npc_id)))
        goto L_Remember_Face;
    goto L_Tricking_Trick_or_Treat;

L_Check_Karma:
    // NPC Cheater detection starts after max NPCs hit
    if (rand($@halloween_num_npcs, 65535) <= @karma)
        goto L_Cheater;
    // NPC Cheater detection engages at 48 Trick or Treats
    if (@karma >= 48)
        goto L_Cheater;
    if (HALLOWEENTIME & $@halloween_got_big_reward)
        goto L_Tricking_Trick_or_Treat;
    // assert: @karma < $@halloween_num_npcs
    if (rand($@halloween_num_npcs - @karma))
        goto L_Tricking_Trick_or_Treat;
    mes "\"All this candy isn't healthy, here take this to have a break from it.\"";
    getitem $@halloween_big_reward[rand(getarraysize($@halloween_big_reward))], 1;
    set HALLOWEENTIME, HALLOWEENTIME | $@halloween_got_big_reward;
    // you get the big reward first, then the main treats
    // otherwise it would be too complicated, and/or possibly unfair
    goto L_Tricking_Trick_or_Treat;

L_Cheater:
    mes "\"I recognize you despite your mask, you have been taking sweets you do not deserve.\"";
    if (@karma != 65535)
        set HALLOWEENTIME, HALLOWEENTIME + 1;
    goto L_Close;

L_Remember_Face:
    // mes "You've been here before; I remember your face";
    mes "\"I remember your face, " + strcharinfo(0) + ". No more treats for you!\"";
    goto L_Close;

L_Tricking_Trick_or_Treat:
    // moved above
    mes $@halloween_npc_names$[@halloween_npc_id];
    mes $@halloween_greetings$[@halloween_npc_id];
    next;
    // TODO: should we randomize these? (in a subsequent commit)
    menu
        $@halloween_trick_notscary$[@halloween_npc_id], L_Tricking_Notscary,
        $@halloween_trick_scary$[@halloween_npc_id], L_Tricking_Scary,
        $@halloween_trick_veryscary$[@halloween_npc_id], L_Tricking_Veryscary;

L_Tricking_Notscary:
    mes $@halloween_npc_names$[@halloween_npc_id];
    mes $@halloween_react_notscary$[@halloween_npc_id];
    goto L_Tricking_Reward;

L_Tricking_Scary:
    mes $@halloween_npc_names$[@halloween_npc_id];
    mes $@halloween_react_scary$[@halloween_npc_id];
    set @scare_factor, @scare_factor * 2;
    goto L_Tricking_Reward;

L_Tricking_Veryscary:
    mes $@halloween_npc_names$[@halloween_npc_id];
    mes $@halloween_react_veryscary$[@halloween_npc_id];
    set @scare_factor, @scare_factor * 3;
    goto L_Tricking_Reward;

L_Tricking_Reward:
    next;
    if (@karma >= 16)
        set @scare_factor, rand(@scare_factor / 2, @scare_factor);
    if (@karma >= 24)
        set @scare_factor, rand(@scare_factor / 3, @scare_factor);
    if (@scare_factor < 1)
        set @scare_factor, 1;
    goto L_Tricking_Reward_Loop;

L_Tricking_Reward_Loop:
    set @random, rand($@halloween_sweets_num);
    setarray @getitem_ids, $@halloween_sweets[@random];
    setarray @getitem_counts, 1;
    callfunc "CheckInventory";
    if (@check_fail)
        set @scare_factor, 0;
    if (!@scare_factor)
        goto L_Tricking_End;
    // NOTE: it gives out one piece at a time, but can loop several times
    getitem $@halloween_sweets[@random], 1;
    set @scare_factor, @scare_factor - 1;
    goto L_Tricking_Reward_Loop;

L_SetRememberFace:
    set HALLOWEENTIME, HALLOWEENTIME | (1 << (31 - @halloween_npc_id));
    goto L_Close;

L_Tricking_End:
    mes $@halloween_npc_names$[@halloween_npc_id];
    mes "\"That should be enough sweets for you. Thanks for participating!\"";
    if (!@mask)
        goto L_SetRememberFace;
    // add the player's mask to the list
    set @loop, 7;
    goto L_SetRememberMask;

L_SetRememberMask:
    set $@halloween_maskmemory[8 * @halloween_npc_id + @loop], $@halloween_maskmemory[8 * @halloween_npc_id + @loop - 1];
    set @loop, @loop - 1;
    if (@loop)
        goto L_SetRememberMask;
    set $@halloween_maskmemory[8 * @halloween_npc_id], @mask;
    set HALLOWEENTIME, HALLOWEENTIME + 1;
    goto L_Close;

L_Full_Inventory:
    mes $@halloween_npc_names$[@halloween_npc_id];
    mes "\"You are trying to collect candy but you have no space to carry all the kinds of stuff that I have to offer! Please, save room for more stuff and come back.\"";
    goto L_Close;

L_NoMask:
    mes $@halloween_npc_names$[@halloween_npc_id];
    mes "\"Hey " + strcharinfo(0) + ", are you trying to scare me with your face? Interesting! hahaha...\"";
    goto L_Close;

L_Close:
    set @tmp, 0;
    set @mask, 0;
    set @karma, 0;
    set @loop, 0;
    set @menu, 0;
    set @halloween_npc_id, 0;
    return;

L_QuickReturn:
    set @halloween_npc_id, 0;
    return;
}
function|script|TrickOrTreatTally
{
    set @npc_loop, 0;
    set @npc_tally, 0;
    goto L_LoopCheck;

L_LoopCheck:
    if (HALLOWEENTIME & (1 << (31 - @npc_loop)))
        set @npc_tally, (@npc_tally + 1);
    goto L_IncLoop;

L_IncLoop:
    set @npc_loop, (@npc_loop + 1);
    if (@npc_loop >= 15)
        goto L_Return;
    goto L_LoopCheck;

L_Return:
    return;
}
// Checks for an expired event key
// Each new annual event needs a new key
// or it will allow completion from last year
function|script|HalloweenCheckOld
{
    if(HALLOWEENYEAR == $HALLOWEEN_TIME_KEY[5])
        goto L_Return;
    goto L_OldMatch;

L_OldMatch:
    set HALLOWEENTIME, 0;
    set HALLOWEENYEAR, $HALLOWEEN_TIME_KEY[5];
    goto L_Return;

L_Return:
    return;
}
function|script|HalloweenTree
{
    mes "[Confused Tree]";
    if ((HALLOWEENTIME & 65535) > ($@halloween_num_npcs * 3))
        mes "\"Whoa slow down greedy, leave some candy for the reset of us!\"";
    if ((HALLOWEENTIME & 65535) > $@halloween_num_npcs)
        mes "\"I see you have ben enjoying trick or treating, I hope you don't get a stomach ache.\"";
    if ((HALLOWEENTIME & 65535) <= $@halloween_num_npcs)
        mes "\"I love halloween, wearing masks and going trick or treating is so much fun.\"";
    goto L_StartMenu;

L_StartMenu:
    menu
        "Whats Halloween?", L_Explain,
        "Me too!", L_CheckDressed,
        "Meh, I like Christmas Better.", L_XmasBetter;

L_Explain:
    mes "\"I've convinced some people throughout the world to help with trick or treating.\"";
    next;
    set @npc_check_loop, 0;
    goto L_NpcCheckLoop;

L_NpcCheckLoop:
    mes $@halloween_npc_names$[@npc_check_loop];
    next;
    goto L_NpcCheckInc;

L_NpcCheckInc:
    set @npc_check_loop, (@npc_check_loop + 1);
    if (@npc_check_loop >= getarraysize($@halloween_npc_names$))
        goto L_ContinueExplain;
    goto L_NpcCheckLoop;

L_ContinueExplain:
    mes "\"Find each person and put on a mask then try to scare them.\"";
    next;
    mes "\"The scarier you are, the more treats you will be awarded.\"";
    next;
    mes "\"If you are really scary you could get a rare reward.\"";
    next;
    goto L_StartMenu;

L_CheckDressed:
    set @head, getequipid(equip_head);
    set @chest, getequipid(equip_torso);
    set @leg, getequipid(equip_legs);
    set @random_mes$, "\" I like your costume.\"";
    if ((@head <= 0) && (@chest <= 0) && (@leg <= 0))
        set @random_mes$, "\"Birthday Suit, always a classic.\"";
    if ((@head == 615) && (@chest == 870))
        set @random_mes$, "\"How embrassing... we are wearing the same costume.\"";
    if ((@head == 617) || (@head == 622) || (@head == 621))
        set @random_mes$, "\"Yar, matey I see that.\"";
    if ((@head == 633) || (@head == 1205) || (@chest == 1183) || (@chest == 1184) || (@chest == 1185) || (@chest == 1186) || (@chest == 1187))
        set @random_mes$, "\"Your sense of humor offends me, it's way to early for that.\"";
    mes @random_mes$;
    goto L_Return;

L_XmasBetter:
    mes "\"Bah, Humbug, Show your Halloween spirit! OOooooOooo\"";
    misceffect 302, strcharinfo(0);
    goto L_Return;

L_Return:
    return;
}