summaryrefslogtreecommitdiff
path: root/npc/099-5/boss.txt
blob: 01ea29f7227b97a70e2bda383e1109c5dba65fb5 (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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
// Evol script
// Author:
//      Jesusalva
// Description:
//      099-5 FINAL EXAM
//      The epic final showdown of The Mana World: Legacy
/////////////////////////////////////////////////////////////////////////////////
// $@DD5_STATUS     - Status of the battle
//      0 - Idle
//      1 - Timer running
//      2 - Started, first cutscene
//      3 - First Stage
//      4 - Started, second cutscene
//      5 - Second Stage
//      6 - Started, third cutscene
//      7 - Third Stage
//      8 - Epilogue running
//      9 - Epilogue OK
///////////////////////////////////////////////////////////////////
// $@DD5_HP         - Real HitPoints bar of the NPC
//      int
// $@DD5_PTS        - Total participation points distributed
//      int
// $@DD5_BEGIN      - Time where the battle begun
//      time
// $@DD5_MOBC       - Amount of monsters to spawn
//      int
// $@DD5MB_WEAK, $@DD5MB_AVERAGE, $@DD5MB_STRONG, $@DD5MB_BOSSLV
//      int array   - Contains lists of monsters to be used
///////////////////////////////////////////////////////////////////
// $@DD5_PRIMARY
//      int         - 3x the challengers in boss room
// $@DD5_SUPPORT
//      int         - 3x the challengers in waiting room
// $@DD5_TOTALPC
//      int         - Primary + Support, used to ramp up difficulty
///////////////////////////////////////////////////////////////////
// $@DD5_RAIN       - Is Xakelbael in rain?
//      bool
// $@DD5_ATK        - Are attacks allowed?
//      bool
// $@DD5_DEFCON     - Defensive mode of Zax De'Kagen
//      0 - Defenseless (#------- TRANSPARENT)
//      1 - Invencible (except to shearing) (#CC79A7 PURPLE)
//      2 - All damage is halved (#E69F00 ORANGE)
//      3 - Immune to potion'ed attackers (#D55E00 BROWN)
//      4 - Vulnerable only when wet (#56B4E9 CYAN)
//      5 - Vulnerable only to melee (#999999 GRAY)
//      6 - Vulnerable to Bone Knife/Bone Arrow (#FFFFFF W.@hitE)
//      7 - Regenerate from melee (#009E7E GREEN)
//      8 - Requires 10 GP per Damage (#F0E442 YELLOW)
//      9 - (#0072B2 BLUE)
// @dd5_dmg
//      int         - Calculated damage
// @dd5_shear
//      bool        - Damage is from shearing skill (FIXME)
///////////////////////////////////////////////////////////////////
// $@DD5_TALLY_     - Max Individual Score at tally time
// $@DD5_TALLY$     - Player with highest tally
// Tally is conducted at first epilogue scene
// Reward is handed out at last epilogue scene
// If player leaves in-between, reward will be forsaken
// Players who already got the reward (#DD5_TALLY = True)
// will not participate on the tally sequence.
// Tally will not be conducted on Vanilla mode.
///////////////////////////////////////////////////////////////////
// mapmask
//     1            - Show tiles
//     128          - Epilogue Mode
//     256          - DEFCON 1 INVENCIBLE
//     512          - DEFCON 2 DOUBLE DEFENSE
//     1024         - DEFCON 3 POTION IMMUNITY
//     2048         - DEFCON 4 WATER VULNERABLE
//     4096         - DEFCON 5 RANGED INVULNERABILITY
//     8192         - DEFCON 6 BONE VULNERABLE
//     16384        - DEFCON 7 MELEE REGEN
//     32768        - DEFCON 8 GP COST
// NOTE: Personal score overflows at 214,000 points

099-5	mapflag	nosave	099-4,50,49
//099-5	mapflag	resave	009-1,52,40
099-4	mapflag	nosave	009-1,52,40
//099-4	mapflag	resave	009-1,52,40

099-6	mapflag	nosave	099-7,95,52
//099-6	mapflag	resave	099-7,95,52
099-3	mapflag	nosave	099-7,95,52
//099-3	mapflag	resave	099-7,95,52
099-2	mapflag	nosave	099-7,95,52
//099-2	mapflag	resave	099-7,95,52
099-1	mapflag	nosave	099-7,95,52
//099-1	mapflag	resave	099-7,95,52

/* The Dooomsday Mapzone inheirs MMO and allows @storage */
099-6	mapflag	zone	Doomsday
099-5	mapflag	zone	Doomsday
099-4	mapflag	zone	Doomsday
099-3	mapflag	zone	Doomsday
099-2	mapflag	zone	Doomsday
099-1	mapflag	zone	Doomsday

099-5,0,0,0	script	#TMWFinalExam	NPC32767,{
    // Main script
    end;

OnZax:
    debugmes "OnZax";
    callfunc "FinalExamAttack", "Zax";
    end;

OnXak:
    debugmes "OnXak";
    callfunc "FinalExamAttack", "Xak";
    end;

OnAbort:
    stopnpctimer;
    $@DD5_STATUS = 0;
    $@DD5_HP = 0;
    $@DD5_PTS = 0;
    $@DD5_BEGIN = 0;
    $@DD5_MOBC = 0;
    $@DD5_PRIMARY = 0;
    $@DD5_SUPPORT = 0;
    $@DD5_TOTALPC = 0;
    $@DD5_RAIN = 0;
    $@DD5_DEFCON = 0;
    $@DD5_TALLY_ = 0;
    $@DD5_TALLY$ = "";
    $@DD5_ATK=false;
    killmonster "099-5", "all";
    killmonster "099-4", "all";
    setmapmask "099-4", 1;
    setmapmask "099-5", 1;
    setnpcdisplay "Zax De'Kagen#0", NPC432;
    disablenpc "Gema III";
    disablenpc "Flying Ship";
    disablenpc "Jande#0";
    disablenpc "Tal#0";
    disablenpc "Anon";
    disablenpc "Zax De'Kagen#0";
    disablenpc "Xakelbael the Dark#0";
    donpcevent "Zax De'Kagen#0::OnAbort";
    end;

OnMTChallenge:
    @dd5_score = 0;
    @dd5_timer = gettimetick(0);
    getexp 40000, 0;
    BOSS_POINTS = BOSS_POINTS + 5;
    message strcharinfo(0), l("This battle experience distribution is different, and death is final. Be careful!");
    // Give everyone some participation points simply for continued survival
    @dd5_score = 1200;
    $@DD5_PTS = $@DD5_PTS+1200;
    end;

OnMTWarpTo0:
    message strcharinfo(0), l("Your party was defeated.");
    warp "009-1", 54, 40;
    end;

OnMTDispose:
    warp "009-1", 54, 40;
    end;

OnMTReward50:
    @dd5_share = 10000*@dd5_score/$@DD5_PTS;
    if (!@dd5_share)
        end;
    getexp @dd5_share*50, @dd5_share;
    Zeny = Zeny + @dd5_share;
    BOSS_POINTS = BOSS_POINTS + @dd5_share/200;
    message strcharinfo(0), "Gained "+(@dd5_share/200)+" boss points!";
    goto OnMTMusicOff;

OnMTReward40:
    @dd5_share = 10000*@dd5_score/$@DD5_PTS;
    if (!@dd5_share)
        end;
    getexp @dd5_share*10, @dd5_share/10;
    Zeny = Zeny + @dd5_share/10;
    BOSS_POINTS = BOSS_POINTS + @dd5_share/400;
    message strcharinfo(0), "Gained "+(@dd5_share/400)+" boss points!";
    goto OnMTMusicOff;

OnMTReward51:
    @dd5_share = 10000*@dd5_score/$@DD5_PTS;
    if (!@dd5_share)
        end;
    getexp @dd5_share*100, @dd5_share*3/2;
    Zeny = Zeny + (@dd5_share*2);
    BOSS_POINTS = BOSS_POINTS + @dd5_share/100;
    message strcharinfo(0), "Gained "+(@dd5_share/100)+" boss points!";
    goto OnMTMusicOff;

OnMTReward41:
    @dd5_share = 10000*@dd5_score/$@DD5_PTS;
    if (!@dd5_share)
        end;
    getexp @dd5_share*20, @dd5_share/5;
    Zeny = Zeny + @dd5_share/5;
    BOSS_POINTS = BOSS_POINTS + @dd5_share/200;
    message strcharinfo(0), "Gained "+(@dd5_share/200)+" boss points!";
    goto OnMTMusicOff;

OnMTReward52:
    @dd5_share = 10000*@dd5_score/$@DD5_PTS;
    if (!@dd5_share)
        end;
    getexp @dd5_share*250, @dd5_share*5/2;
    Zeny = Zeny + (@dd5_share*5);
    BOSS_POINTS = BOSS_POINTS + @dd5_share/50;
    message strcharinfo(0), "Gained "+(@dd5_share/50)+" boss points!";
    changemusic "099-5","ghoulish-fun.ogg";
    mapmask 1; // Reset map mask for you

    // Dispose dead bodies (BUG, should not happen)
    if (ispcdead())
        goto OnMTDispose;

    // Tally rewards
    if (getq(Quest_Doomsday) < 3)
        goto OnTally;
    goto OnEpilogue1;

OnMTReward42:
    @dd5_share = 10000*@dd5_score/$@DD5_PTS;
    if (!@dd5_share)
        end;
    getexp @dd5_share*50, @dd5_share;
    Zeny = Zeny + @dd5_share;
    BOSS_POINTS = BOSS_POINTS + @dd5_share/100;
    message strcharinfo(0), "Gained "+(@dd5_share/100)+" boss points!";
    changemusic "099-4","ghoulish-fun.ogg";

    // Warp to 099-5 or dispose dead bodies
    if (ispcdead())
        goto OnMTDispose;
    warp "099-5", rand(53, 59), rand(37, 41);

    // Tally rewards
    // FIXME TODO Use a bitwise to save space? See above
    if (getq(Quest_Doomsday) < 3)
        goto OnTally;
    goto OnEpilogue1;

OnTally:
    compareandsetq Quest_Doomsday, 1, 2;
    if (@dd5_score > $@DD5_TALLY_)
        goto OnTallyOK;
    goto OnEpilogue1;

OnTallyOK:
    $@DD5_TALLY_ = @dd5_score;
    $@DD5_TALLY$ = strcharinfo(0);
    goto OnEpilogue1;

OnMTFourthFall:
    misceffect 52, strcharinfo(0); // FIXME
    addtimer 3000, "#TMWFinalExam::OnFourthFall";
    end;

OnFourthFall:
    //debugmes "FOURTH FALL";
    // NOTE: Fourth Fall DOES NOT affects the SCs given by Kirin
    // aka. SC_INCMHPRATE and SC_INCMSPRATE

    // High Damage
    if (sc_check(SC_ATTHASTE_POTION1))
        heal -300, -100;

    if (sc_check(SC_PLUSATTACKPOWER))
        heal -300, -100;

    // Medium Damage
    if (sc_check(SC_INCDEFRATE))
        heal -250, -50;

    if (sc_check(SC_PHYSICAL_SHIELD))
        heal -250, -50;

    if (sc_check(SC_MDEFSET))
        heal -250, -50;

    // Low Damage
    if (sc_check(SC_S_LIFEPOTION))
        heal -125, -25;

    if (sc_check(SC_SLOWPOISON))
        heal -125, -25;

    //debugmes "FOURTH WALL WAS BROKEN";
    misceffect 52, strcharinfo(0); // FIXME
    end;

OnMTBlissOblivion:
    misceffect 51, strcharinfo(0);
    misceffect 52, strcharinfo(0); // FIXME
    // Poison
    sc_start SC_POISON, 1, 80;
    // Adjust Map Mask
    // WARNING: FIXME - Removes weather effects
    if ($@DD5_DEFCON == 0)
        setmapmask "099-5", 1;
    if ($@DD5_DEFCON == 1)
        setmapmask "099-5", 1 | 256;
    if ($@DD5_DEFCON == 2)
        setmapmask "099-5", 1 | 512;
    if ($@DD5_DEFCON == 3)
        setmapmask "099-5", 1 | 1024;
    if ($@DD5_DEFCON == 4)
        setmapmask "099-5", 1 | 2048;
    if ($@DD5_DEFCON == 5)
        setmapmask "099-5", 1 | 4096;
    if ($@DD5_DEFCON == 6)
        setmapmask "099-5", 1 | 8192;
    if ($@DD5_DEFCON == 7)
        setmapmask "099-5", 1 | 16384;
    if ($@DD5_DEFCON == 8)
        setmapmask "099-5", 1 | 32768;
    end;

OnBlissOblivion:
    killmonster "099-5", "all";
    killmonster "099-4", "all";
    spawndummy("099-5", 50, 49, Kage, "Zax De'Kagen", "#TMWFinalExam::OnZax");
    $@DD5_DEFCON = rand(0, 8);
    // Keep a few tricks under the sleeve initially
    if ($@DD5_HP > 100000 && $@DD5_DEFCON < 4)
        $@DD5_DEFCON = rand(4, 8);
    // Re-rolls: Start avoiding initial movements
    if ($@DD5_HP < 50000 && $@DD5_DEFCON > 3 && $@DD5_DEFCON < 7)
        $@DD5_DEFCON = rand(0, 8);
    // If hurt badly, use invencible a bit more often (shearing is annoying)
    if ($@DD5_HP < 10000 && $@DD5_DEFCON > 2)
        $@DD5_DEFCON = rand(0, 8);
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTBlissOblivion";
    setnpctimer 119000;
    end;

OnMTWarning:
    misceffect 54, strcharinfo(0);
    end;

OnMTMusicOn:
    changemusic "099-5","Dramatic.ogg";
    end;

OnMTMusicOff:
    changemusic "099-5","ghoulish-fun.ogg";
    end;

OnWarn0:
    announce "Doomsday : The Final Showdown will start shortly! Make way to the Master Chamber at once!", 0;
    $@DD5_STATUS = 1;
    $@DD5_PTS = 0;
    // FIXME DEBUG DEBUG DEBUG FIXME
    if (debug || $@GM_OVERRIDE)
        addnpctimer 15000, "#TMWFinalExam::OnBegin";
    else
        addnpctimer 90000, "#TMWFinalExam::OnWarn1";
    end;
OnWarn1:
    announce "Doomsday : Doors to Zax De'Kagen domains will seal shut in ##1##B5 minutes##b##0, so prepare yourselves!", 0;
    addnpctimer 120000, "#TMWFinalExam::OnWarn2";
    end;
OnWarn2:
    announce "Doomsday : Doors to Zax De'Kagen domains will seal shut in ##1##B3 minutes##b##0, so prepare yourselves!", 0;
    addnpctimer 120000, "#TMWFinalExam::OnWarn3";
    end;
OnWarn3:
    announce "Doomsday : Doors to Zax De'Kagen domains will seal shut in ##1##B1 minute##b##0, last call for challengers!", 0;
    addnpctimer 60000, "#TMWFinalExam::OnBegin";
    end;
OnBegin:
    announce "Doomsday : Final Showdown: BEGIN!", 0;
    $@DD5_STATUS = 2;
    $@DD5_BEGIN = gettimetick(2);
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTChallenge";
    addnpctimer 2000, "#TMWFinalExam::OnPrologue1";
    donpcevent "#099-2_Prestart::OnJanitor";
    end;

OnPrologue1:
    // set the sprite (implies enablenpc)
    // FIXME - Can we still use mobid here? Also: fakenpcname() deprecated!
    enablenpc "Zax De'Kagen#0";
    setnpcdisplay "Zax De'Kagen#0", NPC432;
    mapannounce "099-5", "Zax De'Kagen : What is that, a bunch of Talpans in my domains?" , 0;
    mapannounce "099-4", "Zax De'Kagen : What is that, a bunch of Talpans in my domains?" , 0;
    npctalk "What is that, a bunch of Talpans in my domains?", "Zax De'Kagen#0";
    addnpctimer 5000, "#TMWFinalExam::OnPrologue2";
    end;

OnPrologue2:
    mapannounce "099-5", "Zax De'Kagen : Don't make me laugh. Do you really think you have what it takes to stop ME?!" , 0;
    mapannounce "099-4", "Zax De'Kagen : Don't make me laugh. Do you really think you have what it takes to stop ME?!" , 0;
    npctalk "Don't make me laugh. Do you really think you have what it takes to stop ME?!", "Zax De'Kagen#0";
    addnpctimer 10000, "#TMWFinalExam::OnPrologue3";
    end;

OnPrologue3:
    mapannounce "099-5", "Zax De'Kagen : Hmpf! We will see about that. Therefore..." , 0;
    mapannounce "099-4", "Zax De'Kagen : Hmpf! We will see about that. Therefore..." , 0;
    npctalk "Hmpf! We will see about that. Therefore...", "Zax De'Kagen#0";
    addnpctimer 5000, "#TMWFinalExam::OnPrologue4";
    end;

OnPrologue4:
    mapannounce "099-5", "Zax De'Kagen : Catch me if you can!" , 0;
    mapannounce "099-4", "Zax De'Kagen : Catch me if you can!" , 0;
    npctalk "Catch me if you can!", "Zax De'Kagen#0";
    spawndummy("099-5", 50, 49, Kage, "Zax De'Kagen", "#TMWFinalExam::OnZax");
    $@DD5_ATK=true;
    $@DD5_STATUS = 3;
    $@DD5_HP = 20000+(getmapusers("099-5")*100);
    $@DD5_PRIMARY = 5+getmapusers("099-5");
    $@DD5_SUPPORT = 3+getmapusers("099-4");
    $@DD5_TOTALPC = $@DD5_PRIMARY+$@DD5_SUPPORT;
    // Spawn first assault
    areamonster "099-5", 43, 44, 56, 55, "", any_of($@DD5MB_AVERAGE), $@DD5_TOTALPC, "#TMWFinalExam::OnKillAverage";
    areamonster "099-5", 20, 20, 75, 75, "", any_of($@DD5MB_AVERAGE), $@DD5_PRIMARY, "#TMWFinalExam::OnKillAverage";
    areamonster "099-4", 20, 20, 75, 75, "", any_of($@DD5MB_AVERAGE), $@DD5_SUPPORT, "#TMWFinalExam::OnKillAverage";
    areamonster "099-5", 20, 20, 75, 75, "", VoidFlower, $@DD5_TOTALPC, "#TMWFinalExam::OnKillAverage";
    // Begin timers!
    initnpctimer;
    donpcevent "Zax De'Kagen#0::OnEnable";
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTMusicOn";
    areatimer 0, "099-4", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTMusicOn";
    end;

OnWarmedUp0:
    stopnpctimer;
    $@DD5_STATUS = 4;
    $@DD5_HP = 0;
    killmonster "099-5", "all";
    killmonster "099-4", "all";
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTReward50";
    areatimer 0, "099-4", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTReward40";

    mapannounce "099-5", "Zax De'Kagen : Hahaha! Not bad, not bad at all!" , 0;
    mapannounce "099-4", "Zax De'Kagen : Hahaha! Not bad, not bad at all!" , 0;
    npctalk "Hahaha! Not bad, not bad at all!", "Zax De'Kagen#0";

    addnpctimer 5000, "#TMWFinalExam::OnWarmedUp1";
    donpcevent "Zax De'Kagen#0::OnDisable";
    end;

OnWarmedUp1:
    mapannounce "099-5", "Zax De'Kagen : However..." , 0;
    mapannounce "099-4", "Zax De'Kagen : However..." , 0;
    npctalk "However...", "Zax De'Kagen#0";

    addnpctimer 5000, "#TMWFinalExam::OnWarmedUp2";
    end;

OnWarmedUp2:
    mapannounce "099-5", "Zax De'Kagen : This was only warm up!" , 0;
    mapannounce "099-4", "Zax De'Kagen : This was only warm up!" , 0;
    npctalk "This was only warm up!", "Zax De'Kagen#0";

    addnpctimer 10000, "#TMWFinalExam::OnWarmedUp3";
    end;

OnWarmedUp3:
    mapannounce "099-5", "Zax De'Kagen : Look and behold, the form I took on this rewrite..." , 0;
    mapannounce "099-4", "Zax De'Kagen : Look and behold, the form I took on this rewrite..." , 0;
    npctalk "Look and behold, the form I took on this rewrite...", "Zax De'Kagen#0";

    addnpctimer 10000, "#TMWFinalExam::OnWarmedUp4";
    end;

OnWarmedUp4:
    mapannounce "099-5", "Zax De'Kagen : The name which I am known is..." , 0;
    mapannounce "099-4", "Zax De'Kagen : The name which I am known is..." , 0;
    npctalk "The name which I am known is...", "Zax De'Kagen#0";

    addnpctimer 10000, "#TMWFinalExam::OnWarmedUp5";
    end;

OnWarmedUp5:
    disablenpc "Zax De'Kagen#0";
    enablenpc "Xakelbael the Dark#0";
    // FIXME
    //fakenpcname "Xakelbael the Dark#0", "Xakelbael the Dark#0", 1161;
    mapannounce "099-5", "Xakelbael the Dark : ...Xakelbael the Dark! PERISH!" , 0;
    mapannounce "099-4", "Xakelbael the Dark : ...Xakelbael the Dark! PERISH!" , 0;
    npctalk "...Xakelbael the Dark! PERISH!", "Xakelbael the Dark#0";

    addnpctimer 3000, "#TMWFinalExam::OnWarmedUp6";
    end;

OnWarmedUp6:
    $@DD5_STATUS = 5;
    $@DD5_HP = 40000+(getmapusers("099-5")*100);
    $@DD5_PRIMARY = 1+getmapusers("099-5")*15/10;
    $@DD5_SUPPORT = 1+getmapusers("099-4")*15/10;
    $@DD5_TOTALPC = $@DD5_PRIMARY+$@DD5_SUPPORT;
    spawndummy("099-5", 50, 49, Xakelbael, "Xakelbael the Dark", "#TMWFinalExam::OnXak");
    disablenpc "Xakelbael the Dark#0";
    $@DD5_ATK=true;
    // Spawn second wave
    areamonster "099-5", 20, 20, 75, 75, "", any_of($@DD5MB_AVERAGE), $@DD5_PRIMARY, "#TMWFinalExam::OnKillAverage";
    areamonster "099-4", 20, 20, 75, 75, "", any_of($@DD5MB_AVERAGE), $@DD5_SUPPORT, "#TMWFinalExam::OnKillAverage";
    // Begin timers
    initnpctimer;
    donpcevent "Xakelbael the Dark#0::OnEnable";
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTMusicOn";
    areatimer 0, "099-4", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTMusicOn";
    end;

OnShowdown0:
    stopnpctimer;
    $@DD5_STATUS = 6;
    $@DD5_HP = 0;
    killmonster "099-5", "all";
    killmonster "099-4", "all";
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTReward51";
    areatimer 0, "099-4", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTReward41";
    disablenpc "Xakelbael the Dark#0";
    enablenpc "Zax De'Kagen#0";
    setnpcdisplay "Zax De'Kagen#0", NPC432;

    mapannounce "099-5", "Zax De'Kagen : Hah...! That was a good workout!" , 0;
    mapannounce "099-4", "Zax De'Kagen : Hah...! That was a good workout!" , 0;
    npctalk2 "Zax De'Kagen#0", "Hah...! That was a good workout!";

    addnpctimer 5000, "#TMWFinalExam::OnShowdown1";
    donpcevent "Xakelbael the Dark#0::OnDisable";
    end;

OnShowdown1:
    mapannounce "099-5", "Zax De'Kagen : It was totally worth it! I was incredibly bored!" , 0;
    mapannounce "099-4", "Zax De'Kagen : It was totally worth it! I was incredibly bored!" , 0;
    npctalk2 "Zax De'Kagen#0", "It was totally worth it! I was incredibly bored!";

    addnpctimer 5000, "#TMWFinalExam::OnShowdown2";
    end;

OnShowdown2:
    .@DD5_TPASSED = (gettimetick(2)-$@DD5_BEGIN);
    .@DD5_TSPENT$ = $@DD5_TPASSED/60+" minute(s) and "+$@DD5_TPASSED%60+" second(s)";
    // FIXME: Use FuzzyTime()
    mapannounce "099-5", "Zax De'Kagen : Well, we still have time! Only "+.@DD5_TSPENT$+" passed!" , 0;
    mapannounce "099-4", "Zax De'Kagen : Well, we still have time! Only "+.@DD5_TSPENT$+" passed!" , 0;
    npctalk2 "Zax De'Kagen#0", "Well, we still have time! Only "+.@DD5_TSPENT$+" passed!";

    .@DD5_TPASSED = 0;
    .@DD5_TSPENT$ = "";
    addnpctimer 10000, "#TMWFinalExam::OnShowdown3";
    end;

OnShowdown3:
    setnpcdisplay "Zax De'Kagen#0", NPC434;
    mapannounce "099-5", "Zax De'Kagen : I will now acknowledge your strength and fight for realz." , 0;
    mapannounce "099-4", "Zax De'Kagen : I will now acknowledge your strength and fight for realz." , 0;
    npctalk2 "Zax De'Kagen#0", "I will now acknowledge your strength and fight for realz.";

    addnpctimer 10000, "#TMWFinalExam::OnShowdown4";
    end;

OnShowdown4:
    mapannounce "099-5", "Zax De'Kagen : Don't blame me if you die!" , 0;
    mapannounce "099-4", "Zax De'Kagen : Don't blame me if you die!" , 0;
    npctalk2 "Zax De'Kagen#0", "Don't blame me if you die!";

    addnpctimer 10000, "#TMWFinalExam::OnShowdown5";
    end;

OnShowdown5:
    mapannounce "099-5", "Zax De'Kagen : Do your best to entretain me!" , 0;
    mapannounce "099-4", "Zax De'Kagen : Do your best to entretain me!" , 0;
    npctalk2 "Zax De'Kagen#0", "Do your best to entretain me!";

    addnpctimer 3000, "#TMWFinalExam::OnShowdown6";
    end;

OnShowdown6:
    $@DD5_STATUS = 7;
    $@DD5_HP = 115000+(getmapusers("099-5")*100);
    $@DD5_PRIMARY = 3+getmapusers("099-5")*15/10;
    $@DD5_SUPPORT = 3+getmapusers("099-4")*15/10;
    $@DD5_TOTALPC = $@DD5_PRIMARY+$@DD5_SUPPORT-2;
    $@DD5_ATK=true;
    spawndummy("099-5", 50, 49, Kage, "Zax De'Kagen", "#TMWFinalExam::OnZax");
    areamonster "099-5", 20, 20, 75, 75, "", any_of($@DD5MB_WEAK), $@DD5_PRIMARY, "#TMWFinalExam::OnKillWeak";
    initnpctimer;
    $@DD5_DEFCON = rand(4, 8);
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTBlissOblivion";
    donpcevent "Zax De'Kagen#0::OnFinal";
    end;

OnEpilogue0:
    stopnpctimer;
    $@DD5_STATUS = 8;
    $@DD5_HP = 0;
    killmonster "099-5", "all";
    killmonster "099-4", "all";
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTReward52";
    areatimer 0, "099-4", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTReward42";
    enablenpc "Flying Ship";

    $@DD5_TPASSED = (gettimetick(2)-$@DD5_BEGIN);
    $@DD5_TSPENT$ = $@DD5_TPASSED/60+" minute(s) and "+$@DD5_TPASSED%60+" second(s)";
    set $@DD5_TPASSED2, 2100+$@DD5_TPASSED; // 35 minutes, The Big Bad, Watchmen
    $@DD5_TSPENT2$ = $@DD5_TPASSED2/60+" minute(s)";
    $@DD5_PRIMARY = 0;
    $@DD5_SUPPORT = 0;
    donpcevent "Zax De'Kagen#0::OnDisable";
    end;

OnEpilogue1:
    @dd5_illegalexit = 1;
    addtimer 10, "#TMWFinalExam::OnIllegalExit1";

    mes "[Zax De'Kagen]";
    mes l("Thanks for the %s of fun you gave me!", $@DD5_TSPENT$);
    next;
    if (debug) goto L_Epilogue1Part22;
    mes "[Zax De'Kagen]";
    mes l("This was not in the plan, but was fun nonetheless. Worth the detour.");
    next;
    mes "[Zax De'Kagen]";
    mes l("However, now I need to go. Unlike you, I do not want to be late.");
    next;
    menu
        l("We just killed you?"),     L_Epilogue1Part1,
        l("Late? What do you mean?"), L_Epilogue1Part1;

L_Epilogue1Part1:
    mes "[Zax De'Kagen]";
    mes l("You know villains never lie. Did you notice how I did not attack any of you directly?");
    next;
    mes "[Zax De'Kagen]";
    mes l("I already finished my plans %s ago, otherwise I would not be bothering myself with you.", $@DD5_TSPENT2$);
    next;
    mes "[Zax De'Kagen]";
    mes l("I hope you did not expected to kill me. Wait. You actually did?!");
    next;
    mes "[Zax De'Kagen]";
    mes l("HAHAHAHAHAHAHAHA!!");
    next;
    mes "[Zax De'Kagen]";
    mes l("Thanks for this, I don't recall laughing so hard the past five years.");
    next;
    mes "[Zax De'Kagen]";
    mes l("Tell me... Enumerate me... Which beings on The Mana World remains dead after being killed?");
    next;
    mes "[Zax De'Kagen]";
    mes l("Think a bit! Monsters respawn... Adventurers appear near the Soul Menhir...");
    next;
    mes "[Zax De'Kagen]";
    mes l("...Or used to, at least; I don't know why that's not true anymore... anyway...");
    next;
    mes "[Zax De'Kagen]";
    mes l("Did you really thought you could simply defeat me in combat and expect this to solve all your problems?");
    next;
    menu
        l("I did"),    L_Epilogue1Part21,
        l("I didn't"), L_Epilogue1Part22;

L_Epilogue1Part21:
    mes "[Zax De'Kagen]";
    mes l("HAHAHAHAHAHAHAHA!!");
    next;
    goto L_Epilogue1Part2;
L_Epilogue1Part22:
    mes "[Zax De'Kagen]";
    mes l("So I assume you thought in a way to seal me? Not that it matters anymore.");
    next;
    goto L_Epilogue1Part2;

L_Epilogue1Part2:
    mes "[Zax De'Kagen]";
    mes l("I'm not even close to fainting yet.");
    next;
    mes "[Zax De'Kagen]";
    mes l("Besides, only a handful of mana beings know how to erase something of existence.");
    next;
    mes "[Zax De'Kagen]";
    mes l("Anyway, just look! My ride arrived.");
    next;

    @dd5_illegalexit = 0;
    if (getmapname() == "099-5")
        goto OnEpilogue1b;

    // What. How? Force script to explode.
    Hp = 0;
    heal -99999, -99999;
    end;

OnIllegalExit1:
    if (@dd5_illegalexit)
        goto OnEpilogue1;
    end;


OnEpilogue1b:
    $@DD5_SUPPORT = 0;
    // Would this timer ever run if player is on dialog?
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnEpilogue1c";
    close;

OnEpilogue1c:
    if ($@DD5_PRIMARY)
        end;
    if (!@dd5_illegalexit)
        $@DD5_SUPPORT = $@DD5_SUPPORT+1;
    addtimer 50, "#TMWFinalExam::OnEpilogue1d";
    end;

OnEpilogue1d:
    if ($@DD5_PRIMARY)
        end;
    if ($@DD5_SUPPORT >= getmapusers("099-5"))
        goto OnEpilogue1e;
    $@DD5_SUPPORT = 0;
    end;

OnEpilogue1e:
    $@DD5_PRIMARY = 1;
    $@DD5_SUPPORT = 0;
    addnpctimer 300, "#TMWFinalExam::OnEpilogue2";
    close;

OnEpilogue2:
    mapannounce "099-5", "Zax De'Kagen : Now that I know where Nu'Rem is burried, nothing can stop me." , 0;
    npctalk2 "Zax De'Kagen#0", "Now that I know where Nu'Rem is burried, nothing can stop me.";

    // FIXME DEBUG DEBUG DEBUG FIXME
    if (debug)
        addnpctimer 2000, "#TMWFinalExam::OnEpilogue5";
    else
        addnpctimer 5000, "#TMWFinalExam::OnEpilogue3";
    end;

OnEpilogue3:
    mapannounce "099-5", "Zax De'Kagen : Good bye, mortal adventurers." , 0;
    npctalk2 "Zax De'Kagen#0", "Good bye, mortal adventurers.";

    addnpctimer 5000, "#TMWFinalExam::OnEpilogue4";
    end;

OnEpilogue4:
    mapannounce "099-5", "Zax De'Kagen : Heh, not like I wasn't one too, back then..." , 0;
    npctalk2 "Zax De'Kagen#0", "Heh, not like I wasn't one too, back then...";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue5";
    end;

OnEpilogue5:
    setnpcdisplay "Zax De'Kagen#0", NPC432;
    disablenpc "Zax De'Kagen#0";
    disablenpc "Flying Ship";

    addnpctimer 10000, "#TMWFinalExam::OnEpilogue6";
    end;

OnEpilogue6:
    enablenpc "Gema III";
    enablenpc "Jande#0";
    enablenpc "Tal#0";
    enablenpc "Anon";
    mapannounce "099-5", "Jande : With Zax gone, I could finally arrive here." , 0;
    npctalk2 "Jande#0", "With Zax gone, I could finally arrive here.";

    // FIXME DEBUG DEBUG DEBUG FIXME
    if (debug)
        addnpctimer 2000, "#TMWFinalExam::OnEpilogue15";
    else
        addnpctimer 5000, "#TMWFinalExam::OnEpilogue7";
    end;

OnEpilogue7:
    mapannounce "099-5", "Tal : I believe some introductions are in order. I am Tal, the Great Dragon of Water." , 0;
    npctalk2 "Tal#0", "Tal : I believe some introductions are in order. I am Tal, the Great Dragon of Water.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue8";
    end;

OnEpilogue8:
    mapannounce "099-5", "Tal : I also consider myself the creator of the Tritan race. Jande called me to help." , 0;
    npctalk2 "Tal#0", "Tal : I also consider myself the creator of the Tritan race. Jande called me to help.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue9";
    end;

OnEpilogue9:
    mapannounce "099-5", "Tal : While I do not like this idea myself, we have an enemy in common." , 0;
    npctalk2 "Tal#0", "Tal : While I do not like this idea myself, we have an enemy in common.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue10";
    end;

OnEpilogue10:
    mapannounce "099-5", "Anon : We prepared another ship, Gema III. This ship will bring you to the damned island." , 0;
    npctalk2 "Anon", "We prepared another ship, Gema III. This ship will bring you to the damned island.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue11";
    end;

OnEpilogue11:
    mapannounce "099-5", "Anon : Be careful, though. It is the final resting place of the Great Dragon of Air." , 0;
    npctalk2 "Anon", "Be careful, though. It is the final resting place of the Great Dragon of Air.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue12";
    end;

OnEpilogue12:
    mapannounce "099-5", "Anon : There is no telling on the horrors you'll find there." , 0;
    npctalk2 "Anon", "There is no telling on the horrors you'll find there.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue13";
    end;

OnEpilogue13:
    mapannounce "099-5", "Jande : A ship is not so fast as a flying one, but I am sure you can make in time." , 0;
    npctalk2 "Jande#0", "A ship is not so fast a flying one, but I am sure you can make in time.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue14";
    end;

OnEpilogue14:
    mapannounce "099-5", "Jande : Whatever happens, DO NOT let Zax De'Kagen reach the great dragon body. Remember: Zax is wounded!" , 0;
    npctalk2 "Jande#0", "Whatever happens, DO NOT let Zax De'Kagen reach the great dragon body. Remember: Zax is wounded!";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue15";
    end;

OnEpilogue15:
    $@DD5_STATUS = 9;
    mapannounce "099-5", "##1(Talk to Gema III to embark)" , 0;
    npctalk "Gema III", "##1(Talk to Gema III to embark)";
    // FIXME DEBUG DEBUG DEBUG FIXME
    if (debug)
        addnpctimer 2000, "#TMWFinalExam::OnEpilogue25";
    else
        addnpctimer 30000, "#TMWFinalExam::OnEpilogue16";
    end;


OnEpilogue16:
    npctalk2 "Jande#0", "(*whisper* Tal, do you think they'll make it?)";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue17";
    end;
OnEpilogue17:
    npctalk2 "Tal#0", "Tal : (*whisper* I would be surprised if they survived the trip alone.)";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue18";
    end;
OnEpilogue18:
    npctalk2 "Jande#0", "(*whisper* For now, let's hope for the best. I don't want another rewrite...)";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue19";
    end;
OnEpilogue19:
    npctalk2 "Tal#0", "Tal : (*whisper* You worry too much. Di'Tal already put measures in place.)";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue20";
    end;
OnEpilogue20:
    npctalk2 "Tal#0", "Tal : (*whisper* The same incident from years ago will not repeat itself.)";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue21";
    end;
OnEpilogue21:
    npctalk2 "Tal#0", "Tal : (*whisper* Besides, shall they fail - they won't remember any of this.)";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue22";
    end;
OnEpilogue22:
    npctalk2 "Jande#0", "(*whisper* We will have a good room to maneuver undercover, then.)";
    addnpctimer 15000, "#TMWFinalExam::OnEpilogue23";
    end;

OnEpilogue23:
    npctalk2 "Anon", "What are you waiting for? You're running against the clock.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue24";
    end;
OnEpilogue24:
    npctalk2 "Anon", "You know Jande and Tal cannot get close to that... that thing.";
    addnpctimer 5000, "#TMWFinalExam::OnEpilogue25";
    end;
OnEpilogue25:
    npctalk2 "Anon", "We will do what we can to support you from sidelines. Now go!";
    end;

S_DD5PrimarySpawn:
    // Receives: $@DD5_MOBC
    $@DD5_TMP = rand(270) / 100;
    if ($@DD5_TMP == 0)
        goto L_DD5PSN;
    if ($@DD5_TMP == 1)
        goto L_DD5PSR;
    if ($@DD5_TMP == 2)
        goto L_DD5PSP;
    goto L_DD5PSResume;

L_DD5PSN:
    callfunc "DD5SpawnNoob";
    goto L_DD5PSResume;

L_DD5PSR:
    callfunc "DD5SpawnRegular";
    goto L_DD5PSResume;

L_DD5PSP:
    callfunc "DD5SpawnPro";
    goto L_DD5PSResume;

L_DD5PSResume:
    if ($@DD5_MOBC)
        goto S_DD5PrimarySpawn;
    $@DD5_TMP = 0;
    return;

OnTimer40000:
    // Imperial Chamber
    areamonster "099-5", 43, 44, 56, 55, "", any_of($@DD5MB_WEAK), $@DD5_PRIMARY/2, "#TMWFinalExam::OnKillWeak";
    // Map
    $@DD5_MOBC = $@DD5_TOTALPC/2+1;
    callsub S_DD5PrimarySpawn;
    // Prologue mobs
    if ($@DD5_STATUS == 3)
        areamonster "099-5", 20, 20, 75, 75, "", VoidFlower, $@DD5_TOTALPC, "#TMWFinalExam::OnKillAverage";
    end;

OnTimer75000:
    // Imperial Chamber
    areamonster "099-5", 43, 44, 56, 55, "", any_of($@DD5MB_AVERAGE), $@DD5_PRIMARY/6+1, "#TMWFinalExam::OnKillAverage";
    // Map
    $@DD5_MOBC = $@DD5_TOTALPC/3+1;
    callsub S_DD5PrimarySpawn;
    // Prologue mobs
    if ($@DD5_STATUS == 3)
        areamonster "099-5", 20, 20, 75, 75, "", VoidFlower, $@DD5_TOTALPC, "#TMWFinalExam::OnKillAverage";
    end;

OnTimer104000:
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTWarning";
    end;

OnTimer120000:
    // Imperial Chamber
    areamonster "099-5", 43, 44, 56, 55, "", any_of($@DD5MB_STRONG), max(3, 1+$@DD5_PRIMARY/5), "#TMWFinalExam::OnKillStrong";
    areamonster "099-5", 43, 44, 56, 55, "", any_of($@DD5MB_BOSSLV), $@DD5_STATUS/2, "#TMWFinalExam::OnKillStrong";
    // Map
    $@DD5_MOBC = $@DD5_TOTALPC/3+1;
    callsub S_DD5PrimarySpawn;
    // Prologue mobs
    if ($@DD5_STATUS == 3)
        areamonster "099-5", 20, 20, 75, 75, "", VoidFlower, $@DD5_TOTALPC, "#TMWFinalExam::OnKillAverage";
    // Boss regeneration, which may overflow into infinity.
    // A regular tick takes 7s - so ~13 cycles of regen
    // It'll regen STATUS Hp per tick, so: 39, 65 and 91 HP every 90s
    // Which is a ridiculously low amount, so I buffed it in 3
    // A base healing of 3 HP per tick - So 117, 195 and 273 HP (still low)
    $@DD5_HP = $@DD5_HP+((13*$@DD5_STATUS)*3);
    initnpctimer;
    end;

OnKillWeak:
    if (!playerattached()) end;
    @dd5_score = @dd5_score+1;
    $@DD5_PTS = $@DD5_PTS+1;
    end;

OnKillAverage:
    if (!playerattached()) end;
    @dd5_score = @dd5_score+10;
    $@DD5_PTS = $@DD5_PTS+10;
    end;

OnKillStrong:
    if (!playerattached()) end;
    @dd5_score = @dd5_score+25;
    $@DD5_PTS = $@DD5_PTS+25;
    end;

OnInit:
    setarray $@DD5MB_WEAK, VoidBat, VoidMaggot, VoidBat, VoidMaggot, VoidBat, VoidMaggot, VoidMouboo;
    setarray $@DD5MB_AVERAGE, VoidScorpion, VoidShroom, VoidScorpion, VoidShroom, VoidScorpion, VoidShroom, VoidSoldier, VoidMouboo;
    setarray $@DD5MB_STRONG, VoidArchant, VoidSlime, VoidSnake, VoidArchant, VoidSlime, VoidSnake, VoidArchant, VoidSlime, VoidSnake;
    setarray $@DD5MB_BOSSLV, Flashmob, Koyntety, Tengu, Sasquatch, ManaSlayer, Enchanter, DoomGolem, Tengu;
    // In theory, pattern ID must be between 1~9
    // To set $@p1$~$@p9$ with the PERL expression
    // But as we're only using $@p0$ (full string)
    // the value itself is meaningless
    .pid=getnpcid();
    debugmes "Doomsday: Pattern %d", .pid;
    //I'm not going to learn PERL just for that
    defpattern(.pid, "^(.*)$", "OnTalkNearby");
    activatepset(.pid);
    end;

OnTalkNearby:
    // not very obvious stuff by gumi, $@p0$ contains the whole string
    // so we must cut it. Could use $@p1$ if perl was proper but... meh.
    .@no_nick$ = strip(substr($@p0$, getstrlen(strcharinfo(PC_NAME)) + 3, getstrlen($@p0$) - 1));
    .@message$ = strtoupper(.@no_nick$);
    // Only react if the message is what we want to hear
    if (.@message$ != "MITEYO")
        end;
    if ($@DD5_HP < 1)
        end;
    message strcharinfo(0), "Estimated boss HP: "+($@DD5_HP+rand(-100, 100));
    end;
}

function	script	DD5SpawnNoob	{
    areamonster "099-4", 20, 20, 75, 75, "", any_of($@DD5MB_WEAK), any(1,2), "#TMWFinalExam::OnKillWeak";
    areamonster "099-5", 20, 20, 75, 75, "", any_of($@DD5MB_WEAK), any(2,3), "#TMWFinalExam::OnKillWeak";
    $@DD5_MOBC = $@DD5_MOBC-1;
    return;
}
function	script	DD5SpawnRegular	{
    if (rand(6) % 2 == 0)
        areamonster "099-4", 20, 20, 75, 75, "", any_of($@DD5MB_AVERAGE), 1, "#TMWFinalExam::OnKillAverage";
    areamonster "099-5", 20, 20, 75, 75, "", any_of($@DD5MB_AVERAGE), any(1, 2), "#TMWFinalExam::OnKillAverage";
    $@DD5_MOBC = $@DD5_MOBC-1;
    return;
}
function	script	DD5SpawnPro	{
    if (rand(6) % 2 == 0)
        areamonster "099-4", 20, 20, 75, 75, "", any_of($@DD5MB_STRONG), 1, "#TMWFinalExam::OnKillStrong";
    areamonster "099-5", 20, 20, 75, 75, "", any_of($@DD5MB_STRONG), 1, "#TMWFinalExam::OnKillStrong";
    $@DD5_MOBC = $@DD5_MOBC-1;
    return;
}

function	script	DD5RainCheck	{
    $@DD5_RAIN="#WeatherCore"::weather(MASK_RAIN, "099-5");

    // Not in rain - nullify damage
    if (!($@DD5_RAIN))
        @dd5_dmg = 0;
    return;
}

function	script	DD5DEFCONCheck	{
    .@atkrange=readparam2(UDT_ATKRANGE);
    // Shearing magic is active? FIXME
    if (@chipchipspell[2] > 0)
        goto L_Shear;
    goto L_Loop;

L_Shear:
    @dd5_shear = 1;
    //addtimer 0, "shear::OnDischarge"; // FIXME
    goto L_Loop;

L_Loop:
    if ($@DD5_DEFCON == 0)
        goto L_DEFCON0;
    if ($@DD5_DEFCON == 1)
        goto L_DEFCON1;
    if ($@DD5_DEFCON == 2)
        goto L_DEFCON2;
    if ($@DD5_DEFCON == 3)
        goto L_DEFCON3;
    if ($@DD5_DEFCON == 4)
        goto L_DEFCON4;
    if ($@DD5_DEFCON == 5)
        goto L_DEFCON5;
    if ($@DD5_DEFCON == 6)
        goto L_DEFCON6;
    if ($@DD5_DEFCON == 7)
        goto L_DEFCON7;
    if ($@DD5_DEFCON == 8)
        goto L_DEFCON8;
    debugmes "ERROR INVALID DEFCON: "+$@DD5_DEFCON;
    goto L_Return;

L_DEFCON0:
    goto L_Return;

L_DEFCON1:
    // FIXME
    if (@dd5_shear)
        goto L_Return;
    @dd5_dmg = 0;
    goto L_Return;

L_DEFCON2:
    @dd5_dmg = @dd5_dmg/2;
    goto L_Return;

L_DEFCON3:
    if (sc_check(SC_ATTHASTE_POTION1))
        @dd5_dmg = 0;
    if (sc_check(SC_PLUSATTACKPOWER))
        @dd5_dmg = 0;
    goto L_Return;

L_DEFCON4:
    callfunc "DD5RainCheck";
    goto L_Return;

L_DEFCON5:
    if (.@atkrange > 2)
        @dd5_dmg = 0;
    goto L_Return;

L_DEFCON6:
    // Shearing is immune to DEFCON 6
    if (@dd5_shear)
        goto L_Return;
    // Not using the allowed equips
    if (!isequippedcnt(BoneArrows, BoneKnife, BoneDarts))
        @dd5_dmg = 0;
    // Lame check for bows because I'm lazy
    if (isequipped(BoneArrows) && .@atkrange < 4)
        @dd5_dmg = 0;
    goto L_Return;

L_DEFCON7:
    if (.@atkrange < 3)
        @dd5_dmg = 0-(@dd5_dmg);
    goto L_Return;

L_DEFCON8:
    if (Zeny < @dd5_dmg*5)
        @dd5_dmg = 0;
    Zeny = Zeny-(@dd5_dmg*5);
    goto L_Return;

L_Return:
    @dd5_shear = 0;
    return;
}

function	script	FinalExamAttack	{
    // Failsafe
    if ($@DD5_STATUS != 3 && $@DD5_STATUS != 5 && $@DD5_STATUS != 7)
        return;

    if (!$@DD5_ATK)
        return;

    if (!playerattached())
        goto L_Return;

    // CD Initial failsafe
    if (!@dd5_timer)
        @dd5_timer = 1-2147483647-1;

    // CD Failsafe
    if (@dd5_timer > 1 && gettimetick(0) < 1)
        @dd5_timer = gettimetick(0);

    // Cooldown
    if (gettimetick(0) < @dd5_timer)
        goto L_Return;

    // Set variables
    .@atkrange=readparam2(UDT_ATKRANGE);
    .@crit=readparam2(UDT_CRIT);
    .@hit=readparam2(UDT_HIT);

    // Verify range
    if (!(isin("099-5", 50-.@atkrange, 49-.@atkrange, 50+.@atkrange, 49+.@atkrange)))
        goto L_Return;

    // Assign attack speed delay - 300ms with pots, 600ms without
    @dd5_timer = if_then_else(sc_check(SC_ATTHASTE_POTION1), gettimetick(0)+300, gettimetick(0)+600);

    // Calculate .@hit and .@crit rate
    @dd5_crit = (rand(10000) < .@crit);
    if (.@hit < rand(350) && !@dd5_crit)
        goto L_Miss;

    // Calculate damage
    @dd5_dmg = rand2(readparam2(UDT_ATKMIN), readparam2(UDT_ATKMAX)+1);

    // Strength Potion - DMG +50%
    if (sc_check(SC_PLUSATTACKPOWER))
        @dd5_dmg = @dd5_dmg*15/10;

    // Boss defense
    @dd5_dmg = @dd5_dmg*(11-$@DD5_STATUS)/9;

    // Consider criticals (no defense disregard, though)
    if (@dd5_crit)
        @dd5_dmg = @dd5_dmg*2;

    // Adjust to Stages
    if ($@DD5_STATUS == 5)
        goto L_Rainy;
    if ($@DD5_STATUS == 7)
        goto L_Defcon;
    goto L_Damage;

L_Rainy:
    callfunc "DD5RainCheck";
    if (!($@DD5_RAIN))
        goto L_Miss;
    goto L_Damage;

L_Defcon:
    callfunc "DD5DEFCONCheck";
    if (@dd5_dmg == 0)
        goto L_Miss;
    if (@dd5_dmg < 1)
        goto L_Absorb;
    goto L_Damage;

L_Absorb:
    // Ops! Zax appreciates the heal!
    $@DD5_HP = $@DD5_HP-@dd5_dmg;
    message strcharinfo(0), "Battle : Absorbed +"+@dd5_dmg+" HP";
    goto L_Return;

L_Damage:
    // Apply the damage!
    $@DD5_HP = $@DD5_HP-@dd5_dmg;
    @dd5_score = @dd5_score+min(25, @dd5_dmg/50);
    $@DD5_PTS = $@DD5_PTS+min(25, @dd5_dmg/50);
    message strcharinfo(0), "Battle : Damage -"+@dd5_dmg+" HP";

    // Fire events if HP < 0
    if ($@DD5_HP <= 0)
        goto L_Slain;
    goto L_Return;

L_Miss:
    message strcharinfo(0), "Battle : Miss";
    goto L_Return;

L_Slain:
    @dd5_score = @dd5_score+100;
    $@DD5_PTS = $@DD5_PTS+100;
    BOSS_POINTS = BOSS_POINTS + ($@DD5_STATUS * 5);
    if ($@DD5_STATUS == 3)
        donpcevent "#TMWFinalExam::OnWarmedUp0";
    if ($@DD5_STATUS == 5)
        donpcevent "#TMWFinalExam::OnShowdown0";
    if ($@DD5_STATUS == 7)
        donpcevent "#TMWFinalExam::OnEpilogue0";
    message strcharinfo(0), l("You gained %d Boss Points!", ($@DD5_STATUS * 5));
    $@DD5_ATK=false;
    return;

L_Return:
    .@s$=getarg(0);
    .@n$=(.@s$ == "Zax" ? "Zax De'Kagen" : "Xakelbael the Dark");
    .@id=(.@s$ == "Zax" ? Kage : Xakelbael);
    spawndummy("099-5", 50, 49, .@id, .@n$, "#TMWFinalExam::On"+.@s$);
    return;
}

099-5,52,35,0	script	Jande#0	NPC426,{
    message strcharinfo(0), "Jande : What are you waiting for?"; // npctalk3 ?
    end;
OnInit:
    disablenpc strnpcinfo(0);
    end;
}

099-5,47,34,0	script	Tal#0	NPC427,{
    message strcharinfo(0), "Tal : What are you waiting for?";
    end;
OnInit:
    disablenpc strnpcinfo(0);
    end;
}

099-5,49,35,0	script	Anon	NPC425,{
    message strcharinfo(0), "Anon : What are you waiting for?";
    end;
OnInit:
    disablenpc strnpcinfo(0);
    end;
}

099-5,51,33,0	script	Flying Ship	NPC428,{
    message strcharinfo(0), l("WHAT. IN. NAME. OF. JANDE. IS. THAT. THING?!");
    end;
OnInit:
    disablenpc strnpcinfo(0);
    end;
}

099-5,51,33,0	script	Gema III	NPC395,{
    if ($@DD5_STATUS != 9)
        goto L_TooEarly;
    if (@dd5_cutscene)
        end;
    mesc l("Embark on Gema III in pursuit?");
    mes l("You may be unable to return here!");
    next;
    menu
        l("Yes"),L_Yes,
        l("No"),L_No;

L_No:
    closeclientdialog;
    close;

L_Yes:
    @dd5_cutscene = 1;
    // Stop rendering the map and Embark - Player effect only
    mapmask 1 | 128;
    changemusic "099-5","epilogue.ogg";
    if (debug)
        addtimer 5000, "Gema III::OnDebugPrompt";
    if (!debug)
        addtimer 300, "Gema III::OnStart";
    closeclientdialog;
    close;

OnStart:
    selfeffect 53;
    message strcharinfo(0), l("But it might be too late.");
    addtimer 2300, "Gema III::OnFPS01";
    end;

OnFPS01:
    message strcharinfo(0), l("Brave adventurers from all around the world,");
    addtimer 2500, "Gema III::OnFPS02";
    end;

OnFPS02:
    message strcharinfo(0), l("Marches toward that unknown island,");
    addtimer 2100, "Gema III::OnFPS03";
    end;

OnFPS03:
    message strcharinfo(0), l("Said to have the key to stop Zax De'Kagen's ambitions.");
    addtimer 4300, "Gema III::OnFPS04";
    end;

OnFPS04:
    message strcharinfo(0), l("Unbeknownst to them, Zax already made his move.");
    addtimer 3200, "Gema III::OnFPS05";
    end;

OnFPS05:
    message strcharinfo(0), l("Before anyone can even reach him, he executes the plan,");
    addtimer 3600, "Gema III::OnFPS06";
    end;

OnFPS06:
    message strcharinfo(0), l("Carefully written for over a decade.");
    addtimer 3100, "Gema III::OnFPS07";
    end;

OnFPS07:
    message strcharinfo(0), l("Using Nu'Rem's body as a catalyst,");
    addtimer 2000, "Gema III::OnFPS08";
    end;

OnFPS08:
    message strcharinfo(0), l("The Ether Spirit of Air is finally compromised.");
    addtimer 2900, "Gema III::OnFPS09";
    end;

OnFPS09:
    message strcharinfo(0), l("Half from the Etheral Powers of Air,");
    addtimer 2300, "Gema III::OnFPS10";
    end;

OnFPS10:
    message strcharinfo(0), l("Are absorbed by The Mana Seal.");
    addtimer 2100, "Gema III::OnFPS11";
    end;

OnFPS11:
    message strcharinfo(0), l("The other half collides with the Earth Spirit,");
    addtimer 2400, "Gema III::OnFPS12";
    end;

OnFPS12:
    message strcharinfo(0), l("And a new element is born.");
    addtimer 2200, "Gema III::OnFPS13";
    end;

OnFPS13:
    message strcharinfo(0), l("History begins to rewrite itself,");
    addtimer 2200, "Gema III::OnFPS14";
    end;

OnFPS14:
    message strcharinfo(0), l("Who's Zax? Something is not right.");
    addtimer 3600, "Gema III::OnFPS15";
    end;

OnFPS15:
    message strcharinfo(0), l("But what will be of our brave adventurers,");
    addtimer 3400, "Gema III::OnFPS16";
    end;

OnFPS16:
    message strcharinfo(0), l("lost midst all this cataclysm?");
    addtimer 2800, "Gema III::OnFPS17";
    end;

OnFPS17:
    message strcharinfo(0), l("Will they reach Nu'Rem's grave?");
    addtimer 2400, "Gema III::OnFPS18";
    end;

OnFPS18:
    message strcharinfo(0), l("Will they put a stop to Zax's evil ambitions?");
    addtimer 3000, "Gema III::OnFPS19";
    end;

OnFPS19:
    message strcharinfo(0), l("Follow their journey, and take back the world, in");
    addtimer 3600, "Gema III::OnFPS20";
    end;

OnFPS20:
    message strcharinfo(0), col(b(l("THE MANA WORLD: REVOLT")), 2);
    //if (debug)
        addtimer 5000, "Gema III::OnDebugPrompt";
    //if (!debug)
    //    addtimer 5000, "Gema III::OnPrompt";
    end;

OnPrompt:
    mes ".:: THE MANA WORLD - REVOLT ::.";
    mes "";
    mes "Server Name: ##BThe Mana World##b";
    mes "Server Address: ##Bserver.themanaworld.org##b";
    mes "Server Port: ##BXXXX##b";
    mes "Server Type: ##BEvol2##b";
    mes "Server Description: ##BMain Server for The Mana World##b";
    mes "";
    mes "##BCOMING SOON##b";
    mes "##BMONTH DAY, 18:00 UTC##b";
    next;
    mes "##BPre-register##b here:";
    mes "[@@https://vault.themanaworld.org/|@@]";
    mes "Max. 1 account per player.";
    next;
    goto L_MissionComplete;

OnDebugPrompt:
    mes ".:: THE MANA WORLD - REVOLT ::.";
    mes "";
    mes "##BCOMING SOON##b";
    mes "";
    mes "Thanks for playing!";
    mes "Stay tuned for updates!";
    mes "";
    mes "-- The Mana World Team";
    next;
    goto L_MissionComplete;

L_MissionComplete:
    @dd5_cutscene = 0;
    warp "009-1", 52, 40;
    getexp 1000000, 0;
    if (strcharinfo(0) == $@DD5_TALLY$)
        goto L_Winner;
    close;

L_Winner:
    getitem SaviorArmor, 1;
    $@DD5_TALLY$ = "";
    setq Quest_Doomsday, 3;
    getvaultexp(250); // This is TMW's main quest, worth 50% of the EXP bar
    mesc l("You were the MVP with %s points!", fnum($@DD5_TALLY_)), 2;
    close;

L_TooEarly:
    mesn strcharinfo(0);
    mes l("It is Gema III! How did they manage to bring the ship here?!");
    close;

OnInit:
    disablenpc "Gema III";
    end;
}
099-5,50,49,0	script	Xakelbael the Dark#0	NPC433,{
    end;
OnInit:
    disablenpc "Xakelbael the Dark#0";
    end;

OnTimer50000:
    areatimer 0, "099-5", 20, 20, 75, 75, 10, "#TMWFinalExam::OnMTFourthFall";
    initnpctimer;
    npctalk "Fourth Fall!";
    end;
OnEnable:
    initnpctimer;
    end;
OnDisable:
    stopnpctimer;
    end;
}

099-5,50,49,0	script	Zax De'Kagen#0	NPC432,{
    end;
OnInit:
    disablenpc "Zax De'Kagen#0";
    end;

OnTimer18000:
    if ($@DD5_STATUS != 3)
        end;
    $@DD5_ATK=true;
    killmonster("099-5", "#TMWFinalExam::OnZax");
    spawndummy("099-5", 50, 49, Kage, strnpcinfo(1), "#TMWFinalExam::OnZax");
    end;
OnTimer24000:
    if ($@DD5_STATUS != 3)
        end;
    initnpctimer;
    $@DD5_ATK=false;
    killmonster("099-5", "#TMWFinalExam::OnZax");
    end;
OnTimer90000:
    if ($@DD5_STATUS != 7)
        end;
    initnpctimer;
    npctalk "Bliss Of Oblivion!";
    donpcevent "#TMWFinalExam::OnBlissOblivion";
    end;

OnAdjustPotion:
    if ($@DD5_STATUS != 7)
        end;
    setnpctimer max(0, min(75000, getnpctimer(0)-rand(5000, 15000)));
    // If it is me testing then it forwards >.>
    if (debug && strcharinfo(0) == "Jesusalva")
        setnpctimer 75000;
    end;

OnEnable:
    disablenpc "Zax De'Kagen#0";
    initnpctimer;
    end;
OnDisable:
    enablenpc strnpcinfo(0); // FIXME
    stopnpctimer;
    end;
OnFinal:
    initnpctimer;
    end;
OnAbort:
    stopnpctimer;
    areatimer 0, "099-4", 20, 20, 75, 75, 1000, "#TMWFinalExam::OnMTWarpTo0";
    donpcevent "Xakelbael the Dark#0::OnDisable";
    end;
}