summaryrefslogtreecommitdiff
path: root/npc/042-10/ctrl.txt
blob: d1abd258561ba459b0aeb4dbf6587f804facd7b1 (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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
// TMW 2 Script
// Author:
//  Jesusalva
//  Micksha
// Description:
//  Controls the great hall

// None of the exits work
042-10,86,139,0	script	#KDoor04210a	NPC_HIDDEN,3,0,{
    end;

OnTouch:
    .@g=getcharid(2);
    if (.@g < 1) percentheal -100, -100;
    dispbottom l("OH NOES! The ceiling seems to have collapsed. I hope we got the key, or the quest is over for us!");
    end;
}

042-10,149,136,0	duplicate(#KDoor04210a)	#KDoor04210b	NPC_HIDDEN,0,0
042-10,21,139,0	duplicate(#KDoor04210a)	#KDoor04210c	NPC_HIDDEN,2,0
042-10,20,80,0	duplicate(#KDoor04210a)	#KDoor04210d	NPC_HIDDEN,0,6


// Boss Room control
042-10,142,20,0	script	#KDoor04210e	NPC_HIDDEN,4,0,{
    end;

OnTouch:
    .@g=getcharid(2);
    if (.@g < 1) percentheal -100, -100;
    if (!($KAMELOT_QUEST[.@g] & 8) || !($KAMELOT_QUEST[.@g] & 16) || !($KAMELOT_QUEST[.@g] & 32)) goto L_NoAccess;
    warp "042-11@"+.@g, 41, 56;
    // TODO Fire Events
    end;

L_NoAccess:
    dispbottom l("A powerful door is sealed shut. It has no keyhole, but I'm sure it can be opened somewhere else on these caves.");
    //dispbottom l("This door is locked, if we only had a %s...", getitemlink(KamelotKey));
    end;
}

// Boss Room Warning
042-10,150,25,0	script	Warning#Kamelot	NPC_HIDDEN,{
    mesc ".:: "+l("DANGER!")+" ::.", 1;
    mes "";
    mesc l("I've sealed a massive amount of dark magic here."), 1;
    mesc l("Do not break my seal to prevent the curse from reaching Kamelot."), 1;
    mes "";
    mes l("-- Merlin");
    end;
OnInit:
    .distance=4;
    end;
}

// Magic Seal Main
042-10,135,42,0	script	#KamelotSeal	NPC_HIDDEN,0,4,{
    end;

OnTouch:
    .@g=getcharid(2);
    if (.@g < 1) percentheal -100, -100;
    if (!($KAMELOT_QUEST[.@g] & 16) && !($KAMELOT_QUEST[.@g] & 8)) goto L_NoAccessBlock;
    if (!($KAMELOT_QUEST[.@g] & 16) || !($KAMELOT_QUEST[.@g] & 8)) goto L_NoAccess;
    // You can pass freely, so we do nothing
    end;

L_NoAccess:
    slide 127, 36;
    percentheal -5, -5;
    dispbottom l("A powerful magic barrier repeals you!");
    dispbottom l("It's weaker than before, probably only one is working right now.");
    end;

L_NoAccessBlock:
    slide 127, 36;
    percentheal -10, -10;
    dispbottom l("A powerful magic barrier repeals you!");
    dispbottom l("We need to find what powers these two seals and disable it.");
    end;
}

////////////////////////////////////////////////////////////////////
// TODO: Catazuli info monument
// KatazuliInfo( )
function	script	KatazuliInfo	{
    mes ".:: Magical Seal ::.";
    mes "";
    mes l("The Magical Seal which protects the final room is too strong.");
    mes l("However, by casting %s here, we'll be able to weaken the seal!", b("katazuli"));
    next;
    mes l("To cast, one must sit on the circle and say the chant on general chat.");
    mes l("The chant must be exact, without any prefix or suffix.");
    next;
    mes l("While breaking the seal, monsters will spawn. They may drop %s.", getitemlink(DarkPetal));
    mes l("Drop these near the circle to make the breaking faster.");
    next;
    mes l("Multiple players may conduct Katazuli at once. If you move or stand, the spell may be aborted.");
    mes l("Remember: Taking damage will make you stand!");
    next;
    mes l("After casting %s, you must wait %d seconds before casting it again.", b("katazuli"), b("60"));
    mes l("However, as long as you remain seated and immobile, the spell will slowly destroy the seal.");
    next;
    mesc l("Caution"), 1;
    mes l("The seals slowly grow stronger as time passes!");
    mes l("Once broken, they'll lose the link to the magical seal.");
    mes l("Even if they recover their strength, because the connection was severed, the barrier will not power up again.");
    return;
}

// KatazuliCore( Begin, ID )
function	script	KatazuliCore	{
    // Basic checks
    // Not sitting - Do nothing and cancel
    if (!issit())
        end;

    // Not sitting on the circle - Again, do nothing
    getmapxy(.@m$, .@x, .@y, 0);
    if (.@x != .x || .@y != .y)
        end;

    // Initialize local variables
    .@start=getarg(0);
    .@id=getarg(1);

    // User cooldown
    if (.@start && @katazuli >= gettimetick(2))
        end;
    if (!.@start && @katazuli <= gettimetick(2))
        end;

    // All checks passed: KATAZULI
    specialeffect FX_MGSHIELD, AREA, getcharid(3); // Temporary FX

    // Consume Dark Petals nearby
    .@cat=getareadropitem(getmap(), .x-3, .y-3, .x+3, .y+3, DarkPetal, true);

    // Your own power boost
    .@cat+=1;

    // Power the circle
    .@power=getd("$@GTEMP_"+.@id+"_"+.@m$)+.@cat;
    setd("$@GTEMP_"+.@id+"_"+.@m$, .@power);

    // Inform new status
    if (.@power < 5 && .@start)
        unittalk(getcharid(3), "This circle is nearly at full power! We need to shut down it!", true);
    else if (.@power < 100)
        unittalk(getcharid(3), "There is still too much power! Please drop "+getitemlink(DarkPetal)+" nearby!", true);
    else if (.@power < 200)
        unittalk(getcharid(3), "At this rate, we will do it! Keep going! Please drop "+getitemlink(DarkPetal)+" nearby!", true);
    else if (.@power < 300)
        unittalk(getcharid(3), "Guys I'm close to shut it down! Please drop "+getitemlink(DarkPetal)+" nearby!", true);

    // Debug Information
    if (is_staff() && $@GM_OVERRIDE)
        dispbottom l("[DEBUG] Current Power: %d", .@power);

    // Circle was shut down (give rewards if appropriate)
    if (.@power >= 300) {
        if ($KAMELOT_QUEST[.@g] & .@id) end;
        $KAMELOT_QUEST[.@g]=$KAMELOT_QUEST[.@g]|.@id;
        unittalk(getcharid(3), "We did it! The seal is now broken!", true);
        // Player Reward for completing this stage
        getitem GuildCoin, 1;
        getexp $KAMELOT_MX[.@g]*50, $KAMELOT_MX[.@g]*10;
        // Guild Reward for completing this stage
        .@ggp=1200+$KAMELOT_MX[.@g]*10;
        .@gxp=$KAMELOT_MX[.@g]*25;
        $GUILD_BANK[.@g]+=.@ggp;
        guildgetexp(.@gxp); // 25xp per player average level (max 2500/3750)
        // Announce
        mapannounce getmap(), strcharinfo(0)+" has broken a magic seal!", 0;
        // Guild Master Notification
        .@gm$=getguildmaster(.@g);
        if (!getcharid(3, .@gm$)) return;
        .@gma=getcharid(3, .@gm$);
        .@gmb=getcharid(0, .@gm$);
        if (!isloggedin(.@gma, .@gmb)) return;
        message .@gm$, strcharinfo(0)+" broke a magic seal: Guild GP +"+.@ggp+" Guild XP +"+.@gxp;
        end;
    }

    // TODO: Spawn monsters, drop Dark Petal
    // (Probably spawn Dark Rose Field)

    // Set cooldown on start
    if (.@start) {
        dispbottom l("Please wait 60 seconds to cast again.");
        @katazuli=gettimetick(2)+60;
    }
    return;
}


////////////////////////
// The first Katazuli
042-10,128,85,0	script	#Katazuli01	NPC_SUMMONING_CIRC,0,0,{
    mes "Read tutorial?";
    select l("No"), l("Yes");
    if (@menu == 2)
        KatazuliInfo();
    dispbottom l("This is probably related to the magic barrier.");
    close;

OnInit:
    .kataId=8;
    .distance=3;
    .pid=getnpcid();
    debugmes "Pattern %d", .pid;
    //defpattern(.pid, "^([Kk][Aa][Tt][Aa][Zz][Uu][Ll][Ii])$", "OnTalkNearby");
    defpattern(.pid, "^(.*)$", "OnTalkNearby");
    activatepset(.pid);
    end;

OnTouch:
    npctalkonce l("You must %s and chant %s to begin channeling.", b(l("sit")), b(l("katazuli")));
    end;

OnTalkNearby:
    // not very obvious stuff by gumi
    .@no_nick$ = strip(substr($@p0$, getstrlen(strcharinfo(PC_NAME)) + 3, getstrlen($@p0$) - 1));
    .@message$ = strtoupper(.@no_nick$);

    // It is with us!
    if (.@message$ == "KATAZULI") {
        KatazuliCore(true, .kataId);
        addtimer 6000, instance_npcname(.name$)+"::OnKatazuli";
    }
    end;

OnKatazuli:
    KatazuliCore(false, .kataId);
    addtimer 6000, instance_npcname(.name$)+"::OnKatazuli";
    end;

OnInstanceInit:
    initnpctimer;
    end;

// Every minute, recover some energy
OnTimer60000:
    .@id=.kataId;
    .@m$=instance_mapname("042-10");
    .@power=min(0, getd("$@GTEMP_"+.@id+"_"+.@m$)-rand2(5));
    setd("$@GTEMP_"+.@id+"_"+.@m$, .@power);
    initnpctimer;
    end;
}


////////////////////////
// The second Katazuli
042-10,32,108,0	script	#Katazuli02	NPC_SUMMONING_CIRC,0,0,{
    mes "Read tutorial?";
    select l("No"), l("Yes");
    if (@menu == 2)
        KatazuliInfo();
    dispbottom l("This is probably related to the magic barrier.");
    close;

OnInit:
    .kataId=16;
    .distance=3;
    .pid=getnpcid();
    debugmes "Pattern %d", .pid;
    //defpattern(.pid, "^([Kk][Aa][Tt][Aa][Zz][Uu][Ll][Ii])$", "OnTalkNearby");
    defpattern(.pid, "^(.*)$", "OnTalkNearby");
    activatepset(.pid);
    end;

OnTouch:
    npctalkonce l("You must %s and chant %s to begin channeling.", b(l("sit")), b(l("katazuli")));
    end;

OnTalkNearby:
    // not very obvious stuff by gumi
    .@no_nick$ = strip(substr($@p0$, getstrlen(strcharinfo(PC_NAME)) + 3, getstrlen($@p0$) - 1));
    .@message$ = strtoupper(.@no_nick$);

    // It is with us!
    if (.@message$ == "KATAZULI") {
        KatazuliCore(true, .kataId);
        addtimer 6000, instance_npcname(.name$)+"::OnKatazuli";
    }
    end;

OnKatazuli:
    KatazuliCore(false, .kataId);
    addtimer 6000, instance_npcname(.name$)+"::OnKatazuli";
    end;

OnInstanceInit:
    initnpctimer;
    end;

// Every minute, recover some energy
OnTimer60000:
    .@id=.kataId;
    .@m$=instance_mapname("042-10");
    .@power=min(0, getd("$@GTEMP_"+.@id+"_"+.@m$)-rand2(5));
    setd("$@GTEMP_"+.@id+"_"+.@m$, .@power);
    initnpctimer;
    end;
}

////////////////////////////////////////////////////////////////////
// KamelotSwitch( "_SWITCH ID" )
function	script	KamelotSwitch	{
    // Extract ID
    .@n$=getarg(0, "_0");
    explode(.@ni$, .@n$, "_");
    .@id=atoi(.@ni$[1]);
    if (.@id <= 0) Exception("Unparseable switch: "+.@n$, RB_DEFAULT|RB_ISFATAL);

    .@g=getcharid(2);
    if (!($KAMELOT_KEYMASK[.@g] & $KAMELOT_KEY[.@g])) end; // Don't care
    .@st=($KAMELOT_PASSMASK[.@g] & .@id);
    mes l("Status: %s", (.@st ? col(l("Active"),2) : col(l("Inactive"),1) ));
    if (!countitem(KamelotKey))
        close;
    mes "Change switch status?";
    next;
    if (askyesno() == ASK_YES) {
        $KAMELOT_PASSMASK[.@g]=$KAMELOT_PASSMASK[.@g]^.@id;
        // The meaning of st is now mixed
        if (.@st)
            setnpcdisplay instance_npcname(.name$), NPC_SWITCH_OFFLINE;
        else
            setnpcdisplay instance_npcname(.name$), NPC_SWITCH_ONLINE;
    }
    // Check password and delete key
    if ($KAMELOT_PASSMASK[.@g] == $KAMELOT_PASSCODE[.@g]) {
        delitem KamelotKey, 1;
        $KAMELOT_QUEST[.@g]=$KAMELOT_QUEST[.@g]|32;
        mesc l("Your hear a clink, and the key breaks."), 2;
        // Player Reward for completing this stage
        getitem GuildCoin, 1;
        getexp $KAMELOT_MX[.@g]*50, $KAMELOT_MX[.@g]*10;
        // Guild Reward for completing this stage
        .@ggp=1200+$KAMELOT_MX[.@g]*10;
        .@gxp=$KAMELOT_MX[.@g]*25;
        $GUILD_BANK[.@g]+=.@ggp;
        guildgetexp(.@gxp); // 25xp per player average level (max 2500/3750)
        // Announce
        mapannounce getmap(), strcharinfo(0)+" has opened the gate!", 0;
        // Guild Master Notification
        .@gm$=getguildmaster(.@g);
        if (!getcharid(3, .@gm$)) return;
        .@gma=getcharid(3, .@gm$);
        .@gmb=getcharid(0, .@gm$);
        if (!isloggedin(.@gma, .@gmb)) return;
        message .@gm$, strcharinfo(0)+" opened the gate: Guild GP +"+.@ggp+" Guild XP +"+.@gxp;

    }
    return;
}

// Switches hints
// TODO: NPC_PAPER_NOTE sprite
042-10,97,126,0	script	#K4210Note01	NPC_SWORDS_SIGN,{
    .@g=getcharid(2);
    if (!($KAMELOT_KEYMASK[.@g] & $KAMELOT_KEY[.@g])) end; // Don't care
    if ($KAMELOT_PASSCODE[.@g] & 1)
        dispbottom l("There is power on the north");
    else
        dispbottom l("The north sleeps.");
    end;

OnInit:
    .distance=4;
    end;
}
042-10,139,98,0	script	#K4210Note02	NPC_SWORDS_SIGN,{
    .@g=getcharid(2);
    if (!($KAMELOT_KEYMASK[.@g] & $KAMELOT_KEY[.@g])) end; // Don't care
    if ($KAMELOT_PASSCODE[.@g] & 2)
        dispbottom l("There is power on the south");
    else
        dispbottom l("The south sleeps.");
    end;

OnInit:
    .distance=4;
    end;
}
042-10,127,45,0	script	#K4210Note04	NPC_SWORDS_SIGN,{
    .@g=getcharid(2);
    if (!($KAMELOT_KEYMASK[.@g] & $KAMELOT_KEY[.@g])) end; // Don't care
    if ($KAMELOT_PASSCODE[.@g] & 1)
        dispbottom l("There is power on the west");
    else
        dispbottom l("The west sleeps.");
    end;

OnInit:
    .distance=4;
    end;
}
042-10,33,133,0	script	#K4210Note08	NPC_SWORDS_SIGN,{
    .@g=getcharid(2);
    if (!($KAMELOT_KEYMASK[.@g] & $KAMELOT_KEY[.@g])) end; // Don't care
    if ($KAMELOT_PASSCODE[.@g] & 8)
        dispbottom l("There is power on the east");
    else
        dispbottom l("The east sleeps.");
    end;

OnInit:
    .distance=4;
    end;
}
042-10,38,39,0	script	#K4210Note16	NPC_SWORDS_SIGN,{
    .@g=getcharid(2);
    if (!($KAMELOT_KEYMASK[.@g] & $KAMELOT_KEY[.@g])) end; // Don't care
    if ($KAMELOT_PASSCODE[.@g] & 16)
        dispbottom l("There is power on the maze");
    else
        dispbottom l("The maze sleeps.");
    end;

OnInit:
    .distance=4;
    end;
}

// The "_" is used on explode
042-10,89,28,0	script	#K4210Switch_1	NPC_SWITCH_OFFLINE,{
    KamelotSwitch(strnpcinfo(0, "_0"));
    close;

OnInit:
    .distance=2;
    end;
}

// Other switches
042-10,80,115,0	duplicate(#K4210Switch_1)	#K4210Switch_2	NPC_HIDDEN,0,0 // S
042-10,63,76,0	duplicate(#K4210Switch_1)	#K4210Switch_4	NPC_HIDDEN,0,0 // W
042-10,100,79,0	duplicate(#K4210Switch_1)	#K4210Switch_8	NPC_HIDDEN,0,0 // E
042-10,82,64,0	duplicate(#K4210Switch_1)	#K4210Switch_16	NPC_HIDDEN,0,0 // C


///////////////////////////////////////////////////////////////////
// THIS CONTROLS EVERYTHING ELSE ON THIS ROOM
// TODO: Spawn monsters
042-10,0,0,0	script	#Kamelot4210	NPC_HIDDEN,{
    end;

OnKillMob:
    if (!playerattached())
        goto OnRespawn;
    // Handle Dark Petal
    // TODO: How MX/PC should affect drop rates?
    // I imagine a higher MX will increase DR.... (Right now, level 100 = +10% DR)
    .@r=rand2(1000);
    if (.@r < 100+$KAMELOT_MX[.@g]) {
        getmapxy(.@m$, .@x, .@y, 0);
        makeitem(DarkPetal, 1, .@m$, rand2(.@x-1, .@x+1), rand2(.@y-1, .@y+1));
    }

    // Maybe a reward is due
    .@g=getcharid(2);
    if (.@g < 1) percentheal -100, -100;
    getexp $KAMELOT_MX[.@g]*10, $KAMELOT_MX[.@g]*5;
    .@delay=max(5000, 30000-$KAMELOT_PC[.@g]*1250);
    // FALLTHROUGH

OnRespawn:
    .@delay=(.@delay ? .@delay : 5000);
    sleep(.@delay);
    // Yes, we just hope it works out of box
    explode(.@map$, .map$, "@");
    .@g=atoi(.@map$[1]);
    if (.@g < 1) {
        debugmes "[ERROR] [KAMELOT] Unable to respawn for Kamelot %s", .map$;
        .@g=0;
    }
    KamelotCaveSpawn(1, 20, 20, 160, 140, $KAMELOT_MX[.@g]+10);
    end;

OnInstanceInit:
    explode(.@map$, .map$, "@");
    .@g=atoi(.@map$[1]);
    if (.@g < 1) {
        debugmes "[ERROR] [KAMELOT] Unable to spawn for Kamelot %s", .map$;
        .@g=0;
    }
    .@pc=$KAMELOT_PC[.@g]+1;
    .@avg=$KAMELOT_MX[.@g]+15; // Monsters will be at least 15 levels stronger
    .@m$="042-10"; // or .@map$[0]

    // Spawns
    KamelotCaveSpawn(.@pc*15/10, 60, 24, 115, 85, .@avg, .@m$); // Central Chambers (150% of player population)

    // Fill the whole cave with at least, 1 per 1000 tiles
    // There are 16800 tiles, so = 18 guards should do the trick
    KamelotCaveSpawn(18, 20, 20, 160, 140, .@avg, .@m$);
    end;
}