summaryrefslogtreecommitdiff
path: root/npc/re/woe-fe/invest_main.txt
blob: 0097b1b3cd95ab67dae326ef062b9037d3c54e03 (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
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
//================= Hercules Script =======================================
//=       _   _                     _
//=      | | | |                   | |
//=      | |_| | ___ _ __ ___ _   _| | ___  ___
//=      |  _  |/ _ \ '__/ __| | | | |/ _ \/ __|
//=      | | | |  __/ | | (__| |_| | |  __/\__ \
//=      \_| |_/\___|_|  \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2013-2015  Hercules Dev Team
//= Copyright (C)  Euphy
//=
//= Hercules is free software: you can redistribute it and/or modify
//= it under the terms of the GNU General Public License as published by
//= the Free Software Foundation, either version 3 of the License, or
//= (at your option) any later version.
//=
//= This program is distributed in the hope that it will be useful,
//= but WITHOUT ANY WARRANTY; without even the implied warranty of
//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//= GNU General Public License for more details.
//=
//= You should have received a copy of the GNU General Public License
//= along with this program.  If not, see <http://www.gnu.org/licenses/>.
//=========================================================================
//= Hall of Abyss - Core Scripts
//================= Description ===========================================
//= Expansion for War of Emperium FE.
//= Invest in each realm to unlock new maps:
//= - Guild Dungeon F2, total 20,000,000z.
//= - Hall of Abyss, total 70,000,000z.
//================= Current Version =======================================
//= 1.1
//================= Variables Used ========================================
//= Note: an asterisk (*) represents any realm (prt, pay, gef, alde).
//= $2011_agit_invest
//= - 0: Inactive.
//= - 1: Investment in progress.
//= - 2: Investment results calculating.
//= - 4: Investment calculations complete (only when at least one $*_invest_result is 3).
//= - 11-21: Tie, revote required.
//=
//= $agit_result_notice
//= - 0: Inactive.
//= - 1-12: Interim statements (displaying $@vfund_*x) available.
//=
//= $agit_result_timer
//= - 0: Inactive.
//= - 0-59: Time elapsed during investment (in hours).
//=
//= $agit_revoting_timer
//= - 0: Inactive.
//= - 0-29: Time elapsed during revote (in minutes).
//= - 30: Revote closed.
//= - 31: Revote results calculating.
//=
//= $*_invest_result
//= - 0: No data.
//= - 1: Realm not connected.
//= - 2: Guild Dungeon F2 open.
//= - 3: Abyss Gate (Hall of Abyss and Gulid Dungeon F2) open.
//=
//= $fund_*[01-05]
//= - Investment units per guild castle.
//= $fund_*_extra
//= - Investment units per realm.
//=
//= $@vfund_*[01-05]
//= $@vfund_*_extra
//= -- Investment units, used in interim statements only.
//=========================================================================

//== Investment Functions & Controller =====================
// Note: The times in this section are almost entirely custom.
-	script	#invest_timer	FAKE_NPC,{
OnClock0000:	// Open investments on Wed (1 hour after WoE)
	if (gettime(GETTIME_WEEKDAY) == WEDNESDAY && !agitcheck()) {
		$2011_agit_invest = 1;
		donpcevent "#fund_master::OnInvest_start";
	}
	end;
OnClock1200:	// Close investments on Fri (60 hours after investments open)
	if (gettime(GETTIME_WEEKDAY) == FRIDAY && !agitcheck()) {
		$2011_agit_invest = 2;
		donpcevent "#fund_master::OnInvest_stop";
	}
	end;
OnClock1235:	// Open dungeons on Fri (at least 31 minutes after investments close)
	if (gettime(GETTIME_WEEKDAY) == FRIDAY && !agitcheck())
		donpcevent "#fund_master::OnResult";
	end;
OnClock2000:	// Close dungeons on Tues (1 hour before WoE)
	if (gettime(GETTIME_WEEKDAY) == TUESDAY)
		donpcevent "#fund_master::OnReset";
	end;
}

function	script	F_Invest_Status	{
	.@day = gettime(GETTIME_WEEKDAY);
	.@hour = gettime(GETTIME_HOUR);
	.@minute = gettime(GETTIME_MINUTE);

	// Inactive.
	if (agitcheck())
		return 0;

	// Open for investments.
	if (.@day >= 3 && (.@day < 5 || (.@day == 5 && .@hour <= 12)))
		return 1;

	// Investments closed, calculating results.
	if (.@day == 5 && .@hour == 12 && .@minute < 35)
		return 2;

	// Calculations complete, dungeons open.
	if ((.@day == 5 && (.@hour > 12 || (.@hour == 12 && .@minute >= 35))) || .@day > 5 ||
	    .@day < 2 || (.@day == 2 && .@hour < 20))
		return 3;

	// Dungeons closed.
	return 0;
}

//callfunc "F_Invest_Abyss","<variable>","<NPC name>"{,"<addon message>"};
function	script	F_Invest_Abyss	{
	mes "There are 2 ways to invest, by Zeny or the Investment Certificate given out by the Cat Paw Merchant Guild.";
	mes "Which way would you like to make your investment?";
	next;
	switch(select("Invest with Zeny.", "Invest with Investment Certificates.", "Cancel")) {
	case 1:
		mes getarg(1);
		mes "So you've decided to invest in Zeny.";
		mes "Minimum investment unit is ^4d4dff10,000 Zeny^000000.";
		mes "You can invest a maximum of 50 units which is ^4d4dff500,000 Zeny^000000.";
		next;
		switch(select("1 unit 10,000 Zeny", "10 units 100,000 Zeny", "50 units 500,000 Zeny", "Another amount", "Cancel")) {
		case 1:
			.@units = 1;
			break;
		case 2:
			.@units = 10;
			break;
		case 3:
			.@units = 50;
			break;
		case 4:
			mes getarg(1);
			mes "Please enter the amount you want to invest.";
			mes "Please choose between 1 to 200.";
			mes "Please enter 0 to cancel.";
			next;
			input .@units;
			if (.@units < 0 || .@units > 200) {
				mes getarg(1);
				mes "You've exceeded the amount per investment.";
				mes "Please try again.";
				close;
			} else if (.@units == 0) {
				mes getarg(1);
				mes "Canceled.";
				close;
			} else
				break;
		case 5:
			mes getarg(1);
			mes "Canceled.";
			close;
		}
		.@zeny = .@units * 10000;
		if (Zeny < .@zeny) {
			mes getarg(1);
			mes "You do not have enough money.";
			close;
		}
		mes getarg(1);
		mes "You've invested "+.@units+" unit"+((.@units == 1)?"":"s")+" "+((.@units < 100)?.@units:insertchar(""+.@units,",",1))+"0,000 Zeny"+getarg(2,"")+".";
		mes "Not much but this is a small gift. You can exchange it with items in Malangdo.";
		Zeny -= .@zeny;
		setd getarg(0), getd(getarg(0)) + .@units;
		getitem Thanks_Invest_Ticket,.@units;
		close;
	case 2:
		mes getarg(1);
		mes "Wow, you've brought Investment Certificates.";
		mes "How many certificates will you submit?";
		next;
		switch(select("1 Investment Certificate", "5 Investment Certificates", "Another amount", "Cancel")) {
		case 1:
			.@tickets = 1;
			break;
		case 2:
			.@tickets = 5;
			break;
		case 3:
			mes getarg(1);
			mes "Please enter the number of Investment Certificates you want to submit.";
			mes "Please choose between 1 to 20.";
			mes "Please enter 0 to cancel.";
			next;
			input .@tickets;
			if (.@tickets < 0 || .@tickets > 20) {
				mes getarg(1);
				mes "You've exceeded the amount per investment.";
				mes "Please try again.";
				close;
			} else if (.@tickets == 0) {
				mes getarg(1);
				mes "Canceled.";
				close;
			} else
				break;
		case 4:
			mes getarg(1);
			mes "Canceled.";
			close;
		}
		if (countitem(Cats_Invest_Certif) < .@tickets) {
			mes getarg(1);
			mes "Looks like you have fewer Investment Certificates than you want to submit.";
			close;
		}
		.@units = .@tickets * 10;
		mes getarg(1);
		mes .@tickets+" Investment Certificate"+((.@tickets == 1)?" is":"s are")+" the same as an investment of "+.@units+" units ("+((.@units < 100)?.@units:insertchar(""+.@units,",",1))+"0,000z)"+getarg(2,"")+".";
		mes "Not much but this is a small gift. You can exchange it with items in Malangdo.";
		delitem Cats_Invest_Certif,.@tickets;
		setd getarg(0), getd(getarg(0)) + .@units;
		getitem Thanks_Invest_Ticket,.@units;
		close;
	case 3:
		mes getarg(1);
		mes "Canceled.";
		close;
	}
}

//== Script Core ===========================================
prt_gld,1,1,0	script	#fund_master	CLEAR_NPC,{
	end;
OnInit:
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 1) {
		$2011_agit_invest = 1;
		end;
	}
	if ((.@invest_status == 2 && $2011_agit_invest == 1) ||
	    (.@invest_status == 3 && ($2011_agit_invest == 1 || $2011_agit_invest == 2))) {
		donpcevent "#fund_master::OnCalculate";
		end;
	}
	end;
OnCalculate_Election:
	.@force_vote = 1;
OnCalculate:
	setarray .@cas$[0],"prt","pay","gef","alde";
	for(.@i = 0; .@i<4; ++.@i) {
		// All funds per realm are summed.
		.@funds[.@i] = getd("$fund_"+.@cas$[.@i]+"01")+getd("$fund_"+.@cas$[.@i]+"02")+getd("$fund_"+.@cas$[.@i]+"03")+getd("$fund_"+.@cas$[.@i]+"04")+getd("$fund_"+.@cas$[.@i]+"05")+getd("$fund_"+.@cas$[.@i]+"_extra");

		// 70,000,000z opens Hall of Abyss and F2.
		if (.@funds[.@i] >= 7000) {
			setd "$"+.@cas$[.@i]+"_invest_result",3;
			.@total_7000 = 1;
		}
		// 20,000,000z opens F2 and a chance for Hall of Abyss.
		else if (.@funds[.@i] >= 2000) {
			setd "$"+.@cas$[.@i]+"_invest_result",2;
			.@total_2000 = 1;
		}
		// Anything below that opens nothing.
		else
			setd "$"+.@cas$[.@i]+"_invest_result",1;
	}
	// No further actions if 20,000,000z isn't reached.
	if (!.@total_2000)
		end;
	// No further actions if any realm hits 70,000,000z.
	if (.@total_7000) {
		$2011_agit_invest = 4;
		end;
	}
	// Otherwise, highest investment above 20,000,000z opens Hall of Abyss.
	.@max = .@funds[0];
	for(.@i = 1; .@i<4; ++.@i) {
		if (.@funds[.@i] > .@max) {
			.@max = .@funds[.@i];
			.@ele = .@i;
			deletearray .@rand$[0], getarraysize(.@rand$);
		} else if (.@funds[.@i] == .@max && .@funds[.@i] >= 2000) {
			if (!getarraysize(.@rand$))
				.@rand$[0] = .@cas$[.@ele];
			.@rand$[getarraysize(.@rand$)] = .@cas$[.@i];
		}
	}
	if (.@max < 2000)
		end;
	if (getarraysize(.@rand$)) {

		// Tie: declare a random winner.
		if (!.@force_vote) {
			.@i = rand(getarraysize(.@rand$));
			setd "$"+.@rand$[.@i]+"_invest_result",3;
			$2011_agit_invest = 4;
			end;
		}

		// Tie: initiate a 30-minute election.
		.@str$ = implode(.@rand$,"|");
		for(.@i = 0; .@i<4; ++.@i) {
			if (compare(.@str$,.@cas$[.@i]))
				.@election = .@election | (1<<.@i);
		}
		switch(.@election) {
			case 3:  $2011_agit_invest = 11; break; //Prontera|Payon
			case 9:  $2011_agit_invest = 12; break; //Prontera|Al De Baran
			case 5:  $2011_agit_invest = 13; break; //Prontera|Geffen
			case 10: $2011_agit_invest = 14; break; //Al De Baran|Payon
			case 6:  $2011_agit_invest = 15; break; //Geffen|Payon
			case 12: $2011_agit_invest = 16; break; //Al De Baran|Geffen
			case 11: $2011_agit_invest = 17; break; //Prontera|Payon|Al De Baran
			case 7:  $2011_agit_invest = 18; break; //Prontera|Payon|Geffen
			case 13: $2011_agit_invest = 19; break; //Prontera|Al De Baran|Geffen
			case 14: $2011_agit_invest = 20; break; //Al De Baran|Payon|Geffen
			case 15: $2011_agit_invest = 21; break; //Prontera|Payon|Al De Baran|Geffen
		}
		if ($2011_agit_invest >= 11)
			donpcevent "Revoting Manager#Invest1::OnStart";
		end;
	} else {
		setd "$"+.@cas$[.@ele]+"_invest_result",3;
		$2011_agit_invest = 4;
		end;
	}
	end;
OnInvest_start:
	announce "From now on, we are going to start the investments to connect the 'Abyss Gate' in the WOE areas: Valkyrie Realm, Greenwood Lake, Luina, Britoniah.",bc_all,0xFF0000; //FW_NORMAL 10
	$fund_prt01 = 0;
	$fund_prt02 = 0;
	$fund_prt03 = 0;
	$fund_prt04 = 0;
	$fund_prt05 = 0;
	$fund_pay01 = 0;
	$fund_pay02 = 0;
	$fund_pay03 = 0;
	$fund_pay04 = 0;
	$fund_pay05 = 0;
	$fund_gef01 = 0;
	$fund_gef02 = 0;
	$fund_gef03 = 0;
	$fund_gef04 = 0;
	$fund_gef05 = 0;
	$fund_alde01 = 0;
	$fund_alde02 = 0;
	$fund_alde03 = 0;
	$fund_alde04 = 0;
	$fund_alde05 = 0;
	donpcevent "Investment_total#fund00::OnEnable";
	end;
OnInvest_stop:
	announce "We've finished the investments to connect the 'Abyss Gate'.",bc_all,0xFF0000; //FW_NORMAL 10
	donpcevent "Investment_total#fund00::OnReset";
	donpcevent "#fund_master::OnCalculate_Election";
	end;
OnResult:
	announce "We've got the results of the investments for the 'Abyss Gate'. You can check through the Investment Status Board in each WOE area.",bc_all,0xFF0000; //FW_NORMAL 10
	if ($2011_agit_invest == 4) {
		$fund_prt01 = 0;
		$fund_prt02 = 0;
		$fund_prt03 = 0;
		$fund_prt04 = 0;
		$fund_prt05 = 0;
		$fund_prt_extra = 0;
		$fund_pay01 = 0;
		$fund_pay02 = 0;
		$fund_pay03 = 0;
		$fund_pay04 = 0;
		$fund_pay05 = 0;
		$fund_pay_extra = 0;
		$fund_gef01 = 0;
		$fund_gef02 = 0;
		$fund_gef03 = 0;
		$fund_gef04 = 0;
		$fund_gef05 = 0;
		$fund_gef_extra = 0;
		$fund_alde01 = 0;
		$fund_alde02 = 0;
		$fund_alde03 = 0;
		$fund_alde04 = 0;
		$fund_alde05 = 0;
		$fund_alde_extra = 0;
	} else if ($2011_agit_invest == 2)
		donpcevent "#fund_master::OnCalculate";
	end;
OnReset:
	$2011_agit_invest = 0;
	donpcevent "Investment_total#fund00::OnReset";
	end;
}

prt_gld,2,2,0	script	Investment_total#fund00	CLEAR_NPC,{
	callfunc "F_GM_NPC";
	mes "Is this not working properly?";
	next;
	if (callfunc("F_GM_NPC",1854,0) == 1) {
		mes "If you think the investment timer is dead, please adjust the timer.";
		next;
		switch(select("Turn on the timer", "Cancel")) {
		case 1:
			donpcevent "Investment_total#fund00::OnTimerReset";
			mes "You've turned on the timer.";
			close;
		case 2:
			mes "Canceled.";
			close;
		}
	} else {
		mes "I don't need to adjust anything now.";
		close;
	}

OnInit:
	if (callfunc("F_Invest_Status") == 1) {
		initnpctimer;
		donpcevent "Investment_total#fund00::OnVarInit";
	} else {
		$agit_result_timer = 0;
		$agit_result_notice = 0;
	}
	end;
OnVarInit:
	setarray .@cas$[0],"prt","pay","gef","alde";
	for(.@i = 0; .@i<4; ++.@i) {
		setd "$@vfund_"+.@cas$[.@i]+"01", getd("$fund_"+.@cas$[.@i]+"01");
		setd "$@vfund_"+.@cas$[.@i]+"02", getd("$fund_"+.@cas$[.@i]+"02");
		setd "$@vfund_"+.@cas$[.@i]+"03", getd("$fund_"+.@cas$[.@i]+"03");
		setd "$@vfund_"+.@cas$[.@i]+"04", getd("$fund_"+.@cas$[.@i]+"04");
		setd "$@vfund_"+.@cas$[.@i]+"05", getd("$fund_"+.@cas$[.@i]+"05");
		setd "$@vfund_"+.@cas$[.@i]+"_extra", getd("$fund_"+.@cas$[.@i]+"_extra");
	}
	end;
OnEnable:
	$agit_result_timer = 0;
	$agit_result_notice = 0;
	initnpctimer;
	end;
OnReset:
	$agit_result_timer = 0;
	$agit_result_notice = 0;
	stopnpctimer;
	end;
OnTimerReset:
	initnpctimer;
	end;
OnTimer3600000:
	if (callfunc("F_Invest_Status") == 1) {
		if ($agit_result_timer < 59) {
			$agit_result_timer = $agit_result_timer+1;

			// Trigger on multiples of 5 up to 55, and 58.
			if ($agit_result_timer % 10 == 5 || $agit_result_timer % 10 == 0 || $agit_result_timer == 58) {
				$agit_result_notice = $agit_result_notice+1;
				donpcevent "Investment_total#fund00::OnVarInit";
				announce "No. "+$agit_result_notice+" Interim statement is now available. You can check through the Investment Status Board in each WOE area.",bc_all,0xFF0000; //FW_NORMAL 10
			}

			donpcevent "Investment_total#fund00::OnTimerReset";
		} else
			stopnpctimer;
		end;
	} else {
		donpcevent "Investment_total#fund00::OnReset";
		end;
	}
}

prt_gld,164,98,3	script	Revoting Manager#Invest1	4_M_BOSSCAT,{
	mes "[Revoting Manager]";
	mes "We are not accepting additional votes.";
	mes "Please wait for our results announcement.";
	close;
OnInit:
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 2 && $2011_agit_invest >= 11 && $agit_revoting_timer < 30) {
		donpcevent "Revoting Manager#Invest2::OnEnable";
		initnpctimer;
	} else if (.@invest_status == 3 && $2011_agit_invest >= 11)
		donpcevent "Revoting Manager#Invest1::OnCalculate";
	donpcevent "Revoting Manager#Invest1::OnDisable";
	end;
OnCalculate:
	switch($2011_agit_invest) {
		case 11: setarray .@cas$[0],"prt","pay"; break;
		case 12: setarray .@cas$[0],"prt","alde"; break;
		case 13: setarray .@cas$[0],"prt","gef"; break;
		case 14: setarray .@cas$[0],"alde","pay"; break;
		case 15: setarray .@cas$[0],"gef","pay"; break;
		case 16: setarray .@cas$[0],"alde","gef"; break;
		case 17: setarray .@cas$[0],"prt","pay","alde"; break;
		case 18: setarray .@cas$[0],"prt","pay","gef"; break;
		case 19: setarray .@cas$[0],"prt","alde","gef"; break;
		case 20: setarray .@cas$[0],"alde","pay","gef"; break;
		case 21: setarray .@cas$[0],"prt","pay","alde","gef"; break;
		default: end;
	}
	.@max = getd("$fund_"+.@cas$[0]+"_extra");
	for(.@i = 1; .@i<getarraysize(.@cas$); ++.@i) {
		.@funds = getd("$fund_"+.@cas$[.@i]+"_extra");
		if (.@funds > .@max) {
			.@max = .@funds;
			.@ele = .@i;
			deletearray .@rand$[0], getarraysize(.@rand$);
		} else if (.@funds == .@max) {
			if (!getarraysize(.@rand$))
				.@rand$[0] = .@cas$[.@ele];
			.@rand$[getarraysize(.@rand$)] = .@cas$[.@i];
		}
	}
	if (getarraysize(.@rand$)) {
		.@i = rand(getarraysize(.@rand$));
		setd "$"+.@rand$[.@i]+"_invest_result",3;
	} else
		setd "$"+.@cas$[.@ele]+"_invest_result",3;
	$2011_agit_invest = 4;
	$agit_revoting_timer = 0;
	end;
OnEnable:
	enablenpc "Revoting Manager#Invest1";
	end;
OnDisable:
	disablenpc "Revoting Manager#Invest1";
	end;
OnStart:
	initnpctimer;
	donpcevent "Revoting Manager#Invest2::OnNotice_on";
	end;
OnEnd:
	stopnpctimer;
	disablenpc "Revoting Manager#Invest1";
	end;
OnTimerReset:
	initnpctimer;
	end;
OnTimer60000:
	.@revote = $agit_revoting_timer;
	if (.@revote < 30) {
		$agit_revoting_timer = $agit_revoting_timer+1;
		donpcevent "Revoting Manager#Invest1::OnTimerReset";
	} else if (.@revote == 30) {
		announce "Cat Paw Merchant Guild: Now we are going to close the additional vote. We will announce the results soon.",bc_all,0xFF0000; //FW_NORMAL 10
		donpcevent "Revoting Manager#Invest2::OnDisable";
		donpcevent "Revoting Manager#Invest1::OnEnable";
		$agit_revoting_timer = $agit_revoting_timer+1;
		donpcevent "Revoting Manager#Invest1::OnTimerReset";
	} else if (.@revote == 31) {
		donpcevent "Revoting Manager#Invest1::OnCalculate";
		donpcevent "Revoting Manager#Invest1::OnDisable";
		stopnpctimer;
		end;
	} else {
		donpcevent "Revoting Manager#Invest1::OnDisable";
		stopnpctimer;
	}
	end;
}

prt_gld,164,98,3	script	Revoting Manager#Invest2	4_M_BOSSCAT,{
	.@invest = $2011_agit_invest;
	if (.@invest < 11) {
		mes "[Revoting Manager]";
		mes "No! This is not the time to take a revote.";
		close2;
		disablenpc "Revoting Manager#Invest2";
		end;
	}
	.@playtime = questprogress(7349,PLAYTIME);
	if (.@playtime == 1) {
		mes "[Revoting Manager]";
		mes "You've already participated in the vote.";
		mes "Please relax and wait for the results.";
		close;
	} else if (.@playtime == 2)
		erasequest 7349;
	mes "[Revoting Manager]";
	mes "Would you like to participate in the vote for choosing where to connect the 'Abyss Gate'?";
	next;
	if(select("Participate in the vote.", "Skip for now.") == 2) {
		mes "[Revoting Manager]";
		mes "You've canceled the vote.";
		close;
	}
	mes "[Revoting Manager]";
	mes "You can vote once and won't need to invest for your choice.";
	mes "Plesae choose one WOE area.";
	next;

	// Create menu.
	explode(.@candidates$, callsub(OnGetCandidates, .@invest),"|");
	for(.@i = 0; .@i<getarraysize(.@candidates$); ++.@i) {
		if (.@candidates$[.@i] == "alde")
			.@menu$[.@i] = "Luina";
		else if (.@candidates$[.@i] == "gef")
			.@menu$[.@i] = "Britoniah";
		else if (.@candidates$[.@i] == "pay")
			.@menu$[.@i] = "Greenwood Lake";
		else if (.@candidates$[.@i] == "prt")
			.@menu$[.@i] = "Valkyrie Realm";
	}
	.@vote = select(implode(.@menu$,":"))-1;

	mes "[Revoting Manager]";
	mes "You've voted for "+.@menu$[.@vote]+".";
	mes "Thanks for voting.";
	setquest 7349;
	setd "$fund_"+.@candidates$[.@vote]+"_extra", getd("$fund_"+.@candidates$[.@vote]+"_extra") + 1;
	close;
OnGetCandidates:
	switch(getarg(0)) {
		case 11: return "prt|pay";
		case 12: return "prt|alde";
		case 13: return "prt|gef";
		case 14: return "alde|pay";
		case 15: return "gef|pay";
		case 16: return "alde|gef";
		case 17: return "prt|pay|alde";
		case 18: return "prt|pay|gef";
		case 19: return "prt|alde|gef";
		case 20: return "alde|pay|gef";
		case 21: return "prt|pay|alde|gef";
	}
	return "";
OnInit:
	disablenpc "Revoting Manager#Invest2";
	end;
OnEnable:
	enablenpc "Revoting Manager#Invest2";
	end;
OnDisable:
	disablenpc "Revoting Manager#Invest2";
	stopnpctimer;
	end;
OnNotice_on:
	initnpctimer;
	end;
OnTimer5000:
	announce "Cat Paw Merchant Guild: As no WOE area has reached the maximum investment level to connect the 'Abyss Gate'...",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer8000:
	announce "Cat Paw Merchant Guild: We were about to connect the 'Abyss Gate' to the WOE area which invested most.",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer11000:
	announce "Cat Paw Merchant Guild: However, there were areas which invested the same amount. So we will put them to a vote.",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer14000:
	announce "Cat Paw Merchant Guild: Additional votes will be available for 30 minutes. You can vote in Valkyrie Realm.",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer20000:
	explode(.@candidates$, callsub(OnGetCandidates, $2011_agit_invest),"|");
	for(.@i = 0; .@i<getarraysize(.@candidates$); ++.@i) {
		if (.@candidates$[.@i] == "alde")
			.@choices$[.@i] = "Luina";
		else if (.@candidates$[.@i] == "gef")
			.@choices$[.@i] = "Britoniah";
		else if (.@candidates$[.@i] == "pay")
			.@choices$[.@i] = "Greenwood Lake";
		else if (.@candidates$[.@i] == "prt")
			.@choices$[.@i] = "Valkyrie Realm";
	}
	announce "Cat Paw Merchant Guild: The candidates for the additional vote are... "+implode(.@choices$," vs. ")+".",bc_all,0xFF0000; //FW_NORMAL 10
	$fund_prt_extra = 0;
	$fund_pay_extra = 0;
	$fund_gef_extra = 0;
	$fund_alde_extra = 0;
	$agit_revoting_timer = 0;
	donpcevent "Revoting Manager#Invest2::OnEnable";
	stopnpctimer;
	end;
}

/*
prtg_cas01,2,2,0	script	Abrai	1_M_JOBTESTER,{
	mes "I should quit my steward job.";
	close;
OnAgitInvest:
	switch(callfunc("F_Invest_Status")) {
	case 0:
		$2011_agit_invest = 0;
		donpcevent "#fund_master::OnReset";
		break;
	case 1:
		$2011_agit_invest = 1;
		donpcevent "#fund_master::OnInvest_start";
		break;
	case 2:
		$2011_agit_invest = 2;
		donpcevent "#fund_master::OnInvest_stop";
		break;
	case 3:
		donpcevent "#fund_master::OnResult";
		break;
	}
	end;
}
*/

//== Realms - Merchant Guilds, Gate Managers, Status Boards =
-	script	Cat Paw Merchant Guild	FAKE_NPC,{

	if (compare(strnpcinfo(4),"alde")) {
		.@npc$ = "alde";
		.@name$ = "Megrez";
		.@realm$ = "Luina";
		.@intro$ = "Luina Branch Manager in Al De Baran";
	} else if (compare(strnpcinfo(4),"gef")) {
		.@npc$ = "gef";
		.@name$ = "Meraq";
		.@realm$ = "Britoniah";
		.@intro$ = "Britoniah Branch Manager";
	} else if (compare(strnpcinfo(4),"pay")) {
		.@npc$ = "pay";
		.@name$ = "Phecda";
		.@realm$ = "Greenwood Lake";
		.@intro$ = "Payon Greenwood Lake Branch Manager";
	} else if (compare(strnpcinfo(4),"prt")) {
		.@npc$ = "prt";
		.@name$ = "Dubae";
		.@realm$ = "Valkyrie Realm";
		.@intro$ = "Prontera Valkyrie Realm Branch Manager";
	}
	.@n$ = "["+.@name$+"]";

	mes .@n$;
	mes "I'm "+.@name$+", the "+.@intro$+" of the Cat Paw Merchant Guild.";
	mes "I consult about investments for the Abyss Gate development.";
	mes "How may I help you?";
	next;
	switch(select("What is the Abyss Gate?", "Investing in the gate development?", "I want to invest in this area.", "Cancel")) {
	case 1:
		mes .@n$;
		mes "It is only called the Abyss Gate for convenience but it's simply a ^4d4dffgap to another dimension^000000.";
		next;
		mes .@n$;
		mes "More of these gaps are found here and there after Morocc created the Crack of Dimension.";
		mes "I personally think that the Abyss Gate found recently is part of the past or even from the future.";
		next;
		mes .@n$;
		mes "It is said that the Abyss Gate forcefully connects to another dimension beyond our world.";
		mes "Probably because there are those that follow the Emperium's power.";
		next;
		mes .@n$;
		mes "There are a total of 4 Abyss Gates found so far. They all connect to the Agit region overflowing with the Emperium's force.";
		next;
		mes .@n$;
		mes "We named each by dimension beyond the gap.";
		mes "^4d4dffWay of the Warrior, Hill of the Dead, Winds of the Ancient, and the Hero's Tears.^000000";
		mes "And all these four gaps are called the ^4d4dffAbyss Gate^000000.";
		next;
		mes .@n$;
		mes "The gap may lead to the past, future or even an unknown world.";
		mes "The power the Abyss Gate holds is both fearful but sweet";
		next;
		mes .@n$;
		mes "Are you also interested in exploring the Abyss Gate?";
		mes "Ha ha. You'll need to go through several steps before exploring.";
		next;
		mes .@n$;
		mes "If you are interested,";
		mes "will you take the time to sit down and talk about investing in maintaining the Abyss Gate?";
		close;
	case 2:
		mes .@n$;
		mes "Are you curious about investing in the Gate development?";
		mes "What do you want to know about?";
		next;
		switch(select("About the Gate?", "About investments?", "How to invest?", "Benefits from investing?")) {
		case 1:
			mes .@n$;
			mes "The Gate is what it is named after, a door.";
			mes "A dimensional passageway that connects here to there.";
			next;
			mes .@n$;
			mes "The Abyss Gate was created as a very unstable path from beyond the dimensional gap,";
			mes "therefore traveling through the Gate will need an artificial dimension connection.";
			next;
			mes .@n$;
			mes "Humans are far from having the advanced technology that's needed";
			mes "but our Cat Paw Merchant Guild holds the high technology to use the Crack of Dimension.";
			next;
			mes .@n$;
			mes "So we made a proposal.";
			mes "With the promise of support the Cat Paw Merchant Guild and paying for the immense expense for maintaining the connection with the Gate,";
			mes "we will make the connection to the Crack of Dimension.";
			next;
			mes .@n$;
			mes "Of course working on the Crack of Dimension is no easy job and it does come with risks.";
			mes "There are cases where people go missing from traveling between.";
			next;
			mes .@n$;
			mes "The best maintaining duration is about 4 days";
			mes "You invest in us and we create the door that connects to the dimensional gap.";
			next;
			mes .@n$;
			mes "Doesn't this sound like the perfect win-win proposal?";
			close;
		case 2:
			mes .@n$;
			mes "Forcing through the unstable dimensional gap and creating a passageway is very dangerous.";
			mes "Not to mention the huge resources needed.";
			next;
			mes .@n$;
			mes "If you take care of the charges and also the danger pay by investing in the Cat Paw Merchant Guild,";
			mes "we'll create and maintain the gate regardless of the risks.";
			next;
			mes .@n$;
			mes "But then of course the money involved for the gate costs will be extreme.";
			mes "It will be easy if you can find investors to share the amount.";
			next;
			mes .@n$;
			mes "There is a basic charge to start connecting the gate.";
			mes "Results depend on the how much investment money is collected.";
			next;
			mes .@n$;
			mes "The Abyss Gate exists in each Agit region.";
			mes "Can you imagine how much money and sacrifice our guild will have to go through to develop in all areas?";
			next;
			mes .@n$;
			mes "This explains the regional competition in investments.";
			mes "If not enough gate maintenance costs are collected then it is obvious the region with the most investments will receive the benefits";
			next;
			mes .@n$;
			mes "If ^4d4dffthe Abyss Gate is successfully connected then the dungeon of the hideout area";
			mes "will be open to others instead of being guild exclusive^000000 which will be very attractive for investment.";
			next;
			mes .@n$;
			mes "But then again, this is only for when the gate is connected.";
			close;
		case 3:
			mes .@n$;
			mes "It's simple.";
			mes "Visit the branch manager of the ^4d4dffregion you want to invest in during the investment duration^000000 and make your investment.";
			next;
			mes .@n$;
			mes "We usually receive ^4d4dffthe common currency here, Zeny^000000.";
			mes "But since we're talking about supporting our Cat Paw Merchant Guild, you can also invest with items in demand in Malangdo.";
			next;
			mes .@n$;
			mes "Provide the items in need to Namis in Malangdo who is in charge of general affairs in our guild.";
			mes "Bring back your Investment Certificate to add it to the investment tribute.";
			next;
			mes .@n$;
			mes "You must visit and invest at the region you want in order for your investment to be counted as a tribute.";
			close;
		case 4:
			mes .@n$;
			mes "The Abyss Gate is basically contracting and connecting with the castle that owns the Agit;";
			mes "therefore, we will provide all we have once the costs for connecting and maintaining the gate are sufficient.";
			next;
			mes .@n$;
			mes "In terms of the minimum and maximum costs for the whole work,";
			mes "if the collected investment ^4d4dffexceeds the minimum costs^000000, we can connect you to the ^4d4dffdeepest layer of an unknown guild dungeon^000000.";
			next;
			mes .@n$;
			mes "If investments exceed the maximum costs, that region will be connected to the";
			mes "^4d4dffAbyss Gate^000000 regardless of the investment rank which includes the deepest layer of the guild dungeon.";
			next;
			mes .@n$;
			mes "^ff0000If there is no Agit region that reached the maximum investment, then the region with the";
			mes "highest investment participation will get the Abyss Gate connected with the investment collected from all regions.^000000";
			next;
			mes .@n$;
			mes "Once the Abyss Gate is connected, the deepest layer (2F) of the guild dungeon";
			mes "will be open to all adventurers that participated in the regional investment.";
			next;
			mes .@n$;
			mes "Visits to the dungeon will be counted for the next investment for the Agit region";
			mes "so being in good terms with the guild that claims the Agit castle will be a bonus.";
			next;
			mes .@n$;
			mes "By the way, it isn't easy to maintain the connection with the Abyss Gate and investments and reconnection is needed weekly";
			mes "so please continue your support and investment if you want the power of the unknown.";
			close;
		}
	case 3:
		if (checkweight(Knife,1) == 0 || MaxWeight - Weight < 1000) {
			mes "- Currently you're carrying -";
			mes "- too many items with you. -";
			mes "- Please try again after you -";
			mes "- lose some weight. -";
			close;
		}
		if (countitem(Thanks_Invest_Ticket) >= 4800) {
			mes .@n$;
			mes "You have too many Thank You Tickets to receive any more.";
			mes "Cannot give you any more tickets. Please use your ticket and come back.";
			mes "The ticket can be exchanged with various items in Malangdo.";
			close;
		}
		if (callfunc("F_Invest_Status") != 1) {
			mes .@n$;
			mes "We do not receive investments now.";
			mes "Please come back during the investment duration.";
			close;
		}
		.@guild = getcharid(2);
		for(.@i = 1; .@i<=5; ++.@i) {
			.@castle_name$[.@i] = getcastlename(.@npc$+"g_cas0"+.@i);
			.@owner_id[.@i] = getcastledata(.@npc$+"g_cas0"+.@i,1);
			.@owner_name$[.@i] = getguildname(.@owner_id[.@i]);
			if (.@guild == .@owner_id[.@i]) {
				.@menu$ = .@menu$+.@castle_name$[.@i]+" ["+.@owner_name$[.@i]+"] Guild:";
				.@castles_owned = .@castles_owned | (1<<.@i);
			} else
				.@menu$ = .@menu$+"^aaaaaaNot the guild that claimed "+.@castle_name$[.@i]+"^000000:";
		}
		mes .@n$;
		mes "Would you like to invest in the ^4d4dff"+.@realm$+"^000000 region?";
		mes "If there is a castle occupied already, you will invest in the castle and the guild that is occupying it.";
		next;
		if (.@castles_owned) {
			.@i = select(.@menu$+"Cancel");
			if (.@i == 6) {
				mes .@n$;
				mes "Canceled.";
				close;
			}
			if (.@guild != .@owner_id[.@i]) {
				mes .@n$;
				mes "The guild that is occupying "+.@castle_name$[.@i]+" is "+.@owner_name$[.@i]+".";
				mes "Doesn't look like your guild.";
				close;
			}
			mes .@n$;
			mes "Invest under "+.@castle_name$[.@i]+"'s"+.@owner_name$[.@i]+" guild name.";
			callfunc "F_Invest_Abyss","$fund_"+.@npc$+"0"+.@i,.@n$;
			end;
		} else {
			mes .@n$;
			callfunc "F_Invest_Abyss","$fund_"+.@npc$+"_extra",.@n$," for "+.@realm$;
			end;
		}
	case 4:
		mes .@n$;
		mes "Is that so?";
		mes "Please come back whenever you are interested in investing in the Abyss Gate development.";
		close;
	}
}

-	script	Gate Manager#realm	FAKE_NPC,{

	if (compare(strnpcinfo(4),"alde")) {
		.@npc$ = "alde";
		.@name$ = "Alkor";
		.@gate$ = "Hero's Tears";
		.@realm$ = "Luina";
	} else if (compare(strnpcinfo(4),"gef")) {
		.@npc$ = "gef";
		.@name$ = "Mizar";
		.@gate$ = "Hill of the Dead";
		.@realm$ = "Britoniah";
	} else if (compare(strnpcinfo(4),"pay")) {
		.@npc$ = "pay";
		.@name$ = "Alkaid";
		.@gate$ = "Winds of the Ancient";
		.@realm$ = "Greenwood Lake";
	} else if (compare(strnpcinfo(4),"prt")) {
		.@npc$ = "prt";
		.@name$ = "Arios";
		.@gate$ = "Way of the Warrior";
		.@realm$ = "Valkyrie Realm";
	}
	.@n$ = "["+.@name$+"]";

	if (callfunc("F_Invest_Status") != 3) {
		mes .@n$;
		mes "There are currently no connected dungeon gates.";
		close;
	}
	.@status = getd("$"+.@npc$+"_invest_result");
	if (.@status == 3) {
		mes .@n$;
		mes "We've successfully connected the Abyss Gate ["+.@gate$+"] with the help from your investment.";
		mes "The Agit dungeon will be open to everyone with a small entrance fee in "+.@realm$+".";
		next;
		mes .@n$;
		mes "Please visit as often as possible since the entrance fee is saved as an investment for the region.";
		mes "Do you want to enter the Agit dungeon?";
		next;
		.@i = select(.@realm$+" Dungeon 1F - 10000z", ""+.@realm$+" Dungeon 2F - 10000z", "Cancel");
		if (.@i == 3) {
			mes .@n$;
			mes "Canceled.";
			close;
		}
		if (Zeny < 10000) {
			mes .@n$;
			mes "I'm collecting a small entrance fee.";
			mes "Your contribution will be saved for the next investment.";
			mes "Entrance fee is 10000z.";
			close;
		}
		mes .@n$;
		mes "I'm sending you to the "+.@realm$+" Agit Dungeon "+.@i+"F.";
		Zeny -= 10000;
		setd "$fund_"+.@npc$+"_extra", getd("$fund_"+.@npc$+"_extra") + 1;
		close2;
		if (compare(strnpcinfo(2),"alde"))
			warp "gld_dun02"+((.@i == 2)?"_2":""),32,122;
		else if (compare(strnpcinfo(2),"gef"))
			warp "gld_dun04"+((.@i == 2)?"_2":""),39,258;
		else if (compare(strnpcinfo(2),"pay"))
			warp "gld_dun01"+((.@i == 2)?"_2":""),186,165;
		else if (compare(strnpcinfo(2),"prt"))
			warp "gld_dun03"+((.@i == 2)?"_2":""),164,268;
		end;
	} else if (.@status == 2) {
		mes .@n$;
		mes "The "+.@realm$+" Agit Dungeon 2F is now available but since it is not connected with the Abyss Gate,";
		mes "the Agit dungeon is only accessible to the Agit guild.";
		close;
	} else {
		mes .@n$;
		mes .@realm$+" was not chosen to be connected with a gate this time.";
		mes "Please wait for the next investment duration.";
		close;
	}
	end;
}

-	script	Investment Status Board	FAKE_NPC,{
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 1) {
		if (compare(strnpcinfo(4),"alde")) {
			.@npc$ = "alde";
			.@realm$ = "Luina";
		} else if (compare(strnpcinfo(4),"gef")) {
			.@npc$ = "gef";
			.@realm$ = "Britoniah";
		} else if (compare(strnpcinfo(4),"pay")) {
			.@npc$ = "pay";
			.@realm$ = "Greenwood Lake";
		} else if (compare(strnpcinfo(4),"prt")) {
			.@npc$ = "prt";
			.@realm$ = "Valkyrie Realm";
		}
		.@notice = $agit_result_notice;
		if (.@notice < 1 || .@notice > 12) {
			mes "There are currently no investment sums available.";
			close;
		} else if (.@notice == 1)
			.@str$ = "1st";
		else if (.@notice == 2)
			.@str$ = "2nd";
		else if (.@notice == 3)
			.@str$ = "3rd";
		else
			.@str$ = .@notice+"th";
		mes .@str$+" total (unit in 10,000z)";
		for(.@i = 1; .@i<=5; ++.@i) {
			.@map$ = .@npc$+"g_cas0"+.@i;
			.@fund[.@i] = getd("$@vfund_"+.@npc$+"0"+.@i);
			mes getcastlename(.@map$)+" "+getguildname(getcastledata(.@map$,1))+" Guild: "+.@fund[.@i];
		}
		.@fund[0] = getd("$@vfund_"+.@npc$+"_extra");
		mes .@realm$+" normal: "+.@fund[0];
		mes .@realm$+" Investment Grand Total: "+(.@fund[0]+.@fund[1]+.@fund[2]+.@fund[3]+.@fund[4]+.@fund[5]);
		close;
	} else if (.@invest_status == 2) {
		mes "!- Notice -!";
		mes "No sums are available because the total investment amount is currently being calculated.";
		mes "Please wait for the announcement of the results.";
		close;
	} else if (.@invest_status == 3) {
		setarray .@invest_result[0], $prt_invest_result,$pay_invest_result,$gef_invest_result,$alde_invest_result;
		setarray .@invest_region$[0],  "Valkyrie Realm",  "Greenwood Lake",       "Britoniah",            "Luina";
		mes "!- Investment Results of All Agit Regions -!";
		for(.@i = 0; .@i<4; ++.@i) {
			if (.@invest_result[.@i] == 1)
				mes "^aaaaaa["+.@invest_region$[.@i]+"] below minimum^000000";
			else if (.@invest_result[.@i] == 2) {
				mes "["+.@invest_region$[.@i]+"] minimum achieved";
				mes "-> Guild Dungeon Deepest Layer (2F) available";
			} else if (.@invest_result[.@i] == 3) {
				mes "^4d4dff["+.@invest_region$[.@i]+"] maximum achieved^000000";
				mes "-> Abyss Gate available";
			} else
				mes "No data for ["+.@invest_region$[.@i]+"].";
		}
		close;
	} else {
		mes "!- Notice -!";
		mes "No investment information will be announced now.";
		close;
	}
}

//== Inside Castles - Gate Managers ========================
-	script	Gate Manager#castle	FAKE_NPC,{

	.@id = atoi(charat(strnpcinfo(2),getstrlen(strnpcinfo(2))-1));
	if (compare(strnpcinfo(2),"alde")) {
		.@npc$ = "alde";
		.@realm$ = "Luina";
	} else if (compare(strnpcinfo(2),"gef")) {
		.@npc$ = "gef";
		.@realm$ = "Britoniah";
	} else if (compare(strnpcinfo(2),"pay")) {
		.@npc$ = "pay";
		.@realm$ = "Greenwood Lake";
	} else if (compare(strnpcinfo(2),"prt")) {
		.@npc$ = "prt";
		.@realm$ = "Valkyrie Realm";
	}

	.@GID = getcastledata(strnpcinfo(4),1);
	if (getcharid(2) != .@GID) {
		mes "[Gate Manager]";
		mes "You don't seem to be the member of guild owning this castle.";
		mes "If you need any help, please visit any of our guild members at "+.@realm$+" Square.";
		close;
	}
	mes "[Gate Manager]";
	mes "Hello, I am the Gate Manager from Cat Paw Merchant Guild warp department.";
	mes "How may I help you today?";
	next;
	switch(select("Invest for gate connection", "Deepest Layer Dungeon Access", "Abyss Gate Access", "Cancel")) {
	case 1:
		if (checkweight(Knife,1) == 0 || MaxWeight - Weight < 1000) {
			mes "[Gate Manager]";
			mes "You have too many items to receive the Thank You Ticket as a small gift for your investment.";
			mes "Please come back after making room in your inventory.";
			close;
		}
		if (countitem(Thanks_Invest_Ticket) >= 4800) {
			mes "[Gate Manager]";
			mes "You have too many Thank You Tickets to receive any more.";
			mes "Cannot give you any more tickets. Please use your ticket and come back.";
			mes "The ticket can be exchanged with various items in Malangdo.";
			close;
		}
		if (callfunc("F_Invest_Status") != 1) {
			mes "[Gate Manager]";
			mes "We do not receive investments now.";
			mes "Please come back during the investment duration.";
			close;
		}
		if (getcharid(2) != .@GID) {
			mes "[Gate Manager]";
			mes "You don't seem to be the member of the guild owning this castle.";
			mes "Please use the normal investment from "+.@realm$+" Square.";
			close;
		}
		mes "[Gate Manager]";
		mes "Proceed investing under your guild name.";
		callfunc "F_Invest_Abyss","$fund_"+.@npc$+"0"+.@id,"[Gate Manager]";
		end;
	case 2:
		callsub L_Enter,1,.@realm$,.@npc$;
		mes "[Gate Manager]";
		mes "You are interested in exploring the "+.@realm$+" Guild Dungeon Deepest Layer (2F).";
		mes "Let me guide you. Good luck.";
		close2;
		if (compare(strnpcinfo(2),"alde")) {
			switch(.@id) {
				case 1: warp "gld_dun02_2",32,122; end;
				case 2: warp "gld_dun02_2",79,30; end;
				case 3: warp "gld_dun02_2",165,38; end;
				case 4: warp "gld_dun02_2",160,148; end;
				case 5: warp "gld_dun02_2",103,169; end;
			}
		} else if (compare(strnpcinfo(2),"gef")) {
			switch(.@id) {
				case 1: warp "gld_dun04_2",39,258; end;
				case 2: warp "gld_dun04_2",125,270; end;
				case 3: warp "gld_dun04_2",268,251; end;
				case 4: warp "gld_dun04_2",268,108; end;
				case 5: warp "gld_dun04_2",230,35; end;
			}
		} else if (compare(strnpcinfo(2),"pay")) {
			switch(.@id) {
				case 1: warp "gld_dun01_2",186,165; end;
				case 2: warp "gld_dun01_2",54,165; end;
				case 3: warp "gld_dun01_2",54,39; end;
				case 4: warp "gld_dun01_2",186,39; end;
				case 5: warp "gld_dun01_2",223,202; end;
			}
		} else if (compare(strnpcinfo(2),"prt")) {
			switch(.@id) {
				case 1: warp "gld_dun03_2",28,251; end;
				case 2: warp "gld_dun03_2",164,268; end;
				case 3: warp "gld_dun03_2",164,179; end;
				case 4: warp "gld_dun03_2",268,203; end;
				case 5: warp "gld_dun03_2",199,28; end;
			}
		}
		end;
	case 3:
		callsub L_Enter,2,.@realm$,.@npc$;
		mes "[Gate Manager]";
		mes "Let me guide you to the Abyss Gap connected with "+.@realm$+", the Abyss Gate 'Way of the Warrior'.";
		close2;
		if (compare(strnpcinfo(2),"alde")) {
			switch(.@id) {
				case 1: warp "gld2_ald",175,41; end;
				case 2: warp "gld2_ald",77,64; end;
				case 3: warp "gld2_ald",46,127; end;
				case 4: warp "gld2_ald",104,246; end;
				case 5: warp "gld2_ald",241,156; end;
			}
		} else if (compare(strnpcinfo(2),"gef")) {
			switch(.@id) {
				case 1: warp "gld2_gef",28,199; end;
				case 2: warp "gld2_gef",217,46; end;
				case 3: warp "gld2_gef",171,195; end;
				case 4: warp "gld2_gef",30,67; end;
				case 5: warp "gld2_gef",115,40; end;
			}
		} else if (compare(strnpcinfo(2),"pay")) {
			switch(.@id) {
				case 1: warp "gld2_pay",33,112; end;
				case 2: warp "gld2_pay",119,27; end;
				case 3: warp "gld2_pay",205,111; end;
				case 4: warp "gld2_pay",175,221; end;
				case 5: warp "gld2_pay",61,221; end;
			}
		} else if (compare(strnpcinfo(2),"prt")) {
			switch(.@id) {
				case 1: warp "gld2_prt",10,27; end;
				case 2: warp "gld2_prt",14,247; end;
				case 3: warp "gld2_prt",259,236; end;
				case 4: warp "gld2_prt",226,25; end;
				case 5: warp "gld2_prt",97,11; end;
			}
		}
		end;
	case 4:
		mes "[Gate Manager]";
		mes "Canceled.";
		close;
	}
	end;

L_Enter:
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 3) {
		.@status = getd("$"+getarg(2)+"_invest_result");
		if ((getarg(0) == 1 && .@status == 2) || .@status == 3)
			return;
		else {
			mes "[Gate Manager]";
			mes getarg(1)+" was not chosen to be connected with a gate this time.";
			mes "Please wait for the next investment duration.";
			close;
		}
	} else if (.@invest_status < 3) {
		mes "[Gate Manager]";
		mes "There are currently no connected dungeon gates.";
		mes "A gate will be connected as soon as the investment results are available.";
		mes "Please wait.";
		close;
	} else {
		mes "[Gate Manager]";
		mes "The gate will disappear soon.";
		mes "The dungeon is no longer accessible.";
		mes "Please try again next time.";
		close;
	}
}

//== Item Investments ======================================
malangdo,218,126,4	script	Cat Paw Merchants Notice	4_BOARD3,{
	mes "<< Cat Paw Merchants Notice >>";
	mes "'^C379CEInvest Unused Items for Prizes!^000000'";
	next;
	switch(select("Read Notice", "Check Event 1", "Check Event 2")) {
	case 1:
		mes "- Notice -";
		mes "Hello all Cat Paw Merchants customers! With your love, we Cat Paw Merchants are growing every day. All executives and staff members promise to do our best to further our frontier and development.";
		next;
		mes "- Event Notice! -";
		mes " An Event called '^C379CEInvest Unused Items for Prizes!^000000' is under way, where you could exchange unused items in your storage for Investment Certificate of the Cat Paw Merchants.";
		next;
		mes "Exchangeable items will be announced on a separate sheet. Thank you for your time.";
		mes "- From all the employees of Cat Paw Merchants -";
		next;
		mes "There is a small warning at the bottom.";
		mes " ";
		mes "^FF0000This event could be changed or repealed due to the Merchants' situation.^000000";
		close;
	case 2:
		mes "'^C379CEInvest Unused Items for Prizes!^000000'";
		mes "There are details of Event 1.";
		next;
		setarray .@event1$[0],
			"Wings of the Insect Queen","Crown of the Fly King","I hear Dragon Scales are tough 01","The Meaning of the Mother's Nightmare",
			"To refine ore","Hekekek Orcs, Orcs!!","Study of Yin-Yang","Secrets of the Pyramid King","Tick-tock the time goes",
			"Planting trees on Mellow Island","Ancient language research","Weapons made of sharp teeth","Toy boss doll 01",
			"A tiger is just a cat after all","The shattered spear and shield?","Toy boss doll 02","Best in summer! Cold scales",
			"Piece of Thanatos' armor","I hear Dragon Scales are tough 02","The identity of the creepy eye","If only I could see!";
		.@menu$ = "Quit:"+implode(.@event1$[0],":");
		while(1) {
			.@i = select(.@menu$)-1;
			switch(.@i) {
				case 0: close;
				case 1: .@str$ = "2 Pieces of Queen's Wing"; break;
				case 2: .@str$ = "2 Broken Crowns"; break;
				case 3: .@str$ = "2 Fire Dragon Scales"; break;
				case 4: .@str$ = "3 Mother's Nightmares"; break;
				case 5: .@str$ = "5 Gemstones"; break;
				case 6: .@str$ = "5 Heroic Emblems"; break;
				case 7: .@str$ = "3 Taeguk Plates"; break;
				case 8: .@str$ = "3 Broken Pharaoh Symbols and 3 Tutankhamen's Masks"; break;
				case 9: .@str$ = "2 Pocket Watches"; break;
				case 10: .@str$ = "3 Young Twigs"; break;
				case 11: .@str$ = "5 Rossata Pieces"; break;
				case 12: .@str$ = "5 Fangs of Garm"; break;
				case 13: .@str$ = "3 Baphomet Dolls"; break;
				case 14: .@str$ = "1 Tiger's Footskin and 5 Tiger Skins"; break;
				case 15: .@str$ = "3 Broken Shield Pieces and 3 Shining Spear Blades"; break;
				case 16: .@str$ = "3 Osiris Dolls"; break;
				case 17: .@str$ = "1 Ice Scale"; break;
				case 18: .@str$ = "1 Skeletal Armor Piece"; break;
				case 19: .@str$ = "1 Darkred Scale Piece"; break;
				case 20: .@str$ = "2 Wills of Red Darkness"; break;
				case 21: .@str$ = "2 Foolishness of the Blind"; break;
			}
			mes "["+.@event1$[.@i-1]+"]";
			mes .@str$+" for one Cat Paw Merchants Investment Certificate.";
			next;
		}
	case 3:
		mes "Look out for the next '^C379CEInvest Unused Items for Prizes!^000000' Event 2!! Coming up real soon!";
		close;
	}
}

malangdo,218,123,1	script	Namis#invest	4_CAT_SAILOR2,4,4,{
	if (checkweight(Knife,1) == 0 || MaxWeight - Weight < 1000) {
		mes "- Currently you're carrying -";
		mes "- too many items with you. -";
		mes "- Please try again after you -";
		mes "- lose some weight. -";
		close;
	}
	emotion e_omg;
	emotion e_an;
	emotion e_ag;
	mes "[Namis]";
	mes "Purr-Purr-Purrr-Purrrr-Pur~ Meow!!";
	mes "Wh-- What? How rude. You scared me.";
	next;
	switch(select("What do you need? I'll invest!", "What's the purpose of this event?", "Were you asleep?")) {
	case 1:
		break;
	case 2:
		mes "[Namis]";
		mes "So, another pushover in contract with the Cat Paw Merchants?";
		next;
		select("Huh? What! You calling me a pushover?");
		mes "[Namis]";
		mes "I'll say this just once, so you listen good!";
		mes "We, the Cat Paw Merchants have planned an event for loyal workers like yourself.";
		next;
		mes "[Namis]";
		mes "Run along to your storage and bring back rotting antiques to us and we'll exchange them for the oh-so valuable 'Cat Paw Merchants Investment Certificate'.";
		next;
		mes "[Namis]";
		mes "It will be wise for you to do so because the Cat Paw Merchants are doing this at a loss!";
		next;
		mes "[Namis]";
		mes "Details are on the notice.";
		close;
	case 3:
		mes "[Namis]";
		mes "Hick- Slurp-";
		mes "Remember, human! There's no other cat who works as hard as I do.";
		close;
	}
	mes "[Namis]";
	mes "You must be here to participate in the '^C379CEInvest Unused Items for Prizes!^000000' event of the Cat Paw Merchants.";
	next;
	mes "[Namis]";
	mes "So, which event do you wish to participate in?";
	next;
	switch(select("Not interested", "Event 1 Items", "Event 2 Items")) {
	case 1:
		mes "[Namis]";
		mes "Don't you mess with a busy cat!";
		close;
	case 2:
		mes "[Namis]";
		mes "So you're in for Event 1.";
		mes "Choose from the shown list.";
		next;
		setarray .@event1$[0],
			"Wings of the Insect Queen","Crown of the Fly King","I hear Dragon Scales are tough 01","The Meaning of the Mother's Nightmare",
			"To refine ore","Hekekek Orcs, Orcs!!","Study of Yin-Yang","Secrets of the Pyramid King","Tick-tock the time goes",
			"Planting trees on Mellow Island","Ancient language research","Weapons made of sharp teeth","Toy boss doll 01",
			"A tiger is just a cat after all","The shattered spear and shield?","Toy boss doll 02","Best in summer! Cold scales",
			"Piece of Thanatos' armor","I hear Dragon Scales are tough 02","The identity of the creepy eye","If only I could see!";
		.@i = select(implode(.@event1$[0],":"))-1;
		switch(.@i+1) {
			case 1: callsub L_Check,"2 Pieces of Queen's Wing",6326,2,"Wings of the Insect Queen? What a pitiful name. I would've given some cool names!",.@event1$[.@i];
			case 2: callsub L_Check,"2 Broken Crowns",7754,2,"For crying out loud! Those cats working on these events must be playing around. Can't they think of a better name?",.@event1$[.@i];
			case 3: callsub L_Check,"2 Fire Dragon Scales",7451,2,"Dragon scales? Well... I guess they are tough. But what are they going to use them for?",.@event1$[.@i];
			case 4: callsub L_Check,"3 Mother's Nightmares",7020,3,"Even though I don't have the authority to find out, I wonder what they're doing with the collected items?",.@event1$[.@i];
			case 5: callsub L_Check,"5 Gemstones",7300,5,"Something useful for a change. The ore will end up as nice pieces of jewelry.",.@event1$[.@i];
			case 6: callsub L_Check,"5 Heroic Emblems",968,5,"Good, good. This is the kind of name I wanted!",.@event1$[.@i];
			case 7: callsub L_Check,"3 Taeguk Plates",7169,3,"Taking in something like this, maybe they're up to something dangerous.",.@event1$[.@i];
			case 8: callsub L_Check,"3 Broken Pharaoh Symbols and 3 Tutankhamen's Masks",7113,3,"I hear the pyramids are in Morroc, but I've never been there. Some humans call it Morco.",.@event1$[.@i],7114,3;
			case 9: callsub L_Check,"2 Pocket Watches",7513,2,"Those lazy merchants, why do they need pocket watches they don't even use?",.@event1$[.@i];
			case 10: callsub L_Check,"3 Young Twigs",7018,3,"Mellow Island has a climate like with where we cats used to live. But the trees die out sometimes due to it being an island.",.@event1$[.@i];
			case 11: callsub L_Check,"5 Rossata Pieces",7211,5,"I guess they collect these because humans have them, but what's the use of researching ancient languages?",.@event1$[.@i];
			case 12: callsub L_Check,"5 Fangs of Garm",7036,5,"Weak humans need sharp weapons, but cats already have nice and sharp claws, so why are we collecting these!!",.@event1$[.@i];
			case 13: callsub L_Check,"3 Baphomet Dolls",750,3,"Baphomet dolls are great for playing around with.",.@event1$[.@i];
			case 14: callsub L_Check,"1 Tiger's Footskin and 5 Tiger Skins",1030,1,"Did you know that tigers are cats too? Therefore, cats are better than tigers.",.@event1$[.@i],1029,5;
			case 15: callsub L_Check,"3 Broken Shield Pieces and 3 Shining Spear Blades",7108,3,"I don't know what they want with these.",.@event1$[.@i],7109,3;
			case 16: callsub L_Check,"3 Osiris Dolls",751,3,"Shame~ I never got to play with an Osiris doll.",.@event1$[.@i];
			case 17: callsub L_Check,"1 Ice Scale",7562,1,"Mellow Island is a fabulous place to live. But the ships are too hot.",.@event1$[.@i];
			case 18: callsub L_Check,"1 Skeletal Armor Piece",7450,1,"Ewww... Why would they collect something so creepy?",.@event1$[.@i];
			case 19: callsub L_Check,"1 Darkred Scale Piece",6091,1,"Dragon scales? Well... I guess they are tough. But what are they going to use them for?",.@event1$[.@i];
			case 20: callsub L_Check,"2 Wills of Red Darkness",7566,2,"Interesting! Does it scream or something when I poke it in the eye?",.@event1$[.@i];
			case 21: callsub L_Check,"2 Foolishness of the Blind",7021,2,"This blind man is foolish in not knowing that gathering 300 cats cures blindness...",.@event1$[.@i];
		}
	case 3:
		mes "[Namis]";
		mes "Participate in Event 2?";
		mes "It is not yet in motion. Wait for it!";
		close;
	}
	end;
L_Check:
	.@args = getargcount();
	if (.@args > 5) {
		if (countitem(getarg(5)) < getarg(6))
			.@items = 1; //incomplete
		else
			.@items = 2; //complete
	}
	if (countitem(getarg(1)) < getarg(2) || .@items == 1) {
		mes "[Namis]";
		mes "You don't have the items?";
		mes getarg(0)+" exchange for one Cat Paw Merchants Investment Certificate.";
		next;
		mes "[Namis]";
		mes "Don't bother me and look up the details on the board over there!";
		close;
	}
	mes "[Namis]";
	mes "'^8E5601"+getarg(4)+" Event^000000'";
	mes "Seems to be the right items.";
	mes getarg(3);
	mes "Oh! Almost forgot. Will you invest?";
	next;
	if(select("Invest", "Don't Invest") == 2) {
		mes "[Namis]";
		mes "Don't you mess with a busy cat!";
		close;
	}
	delitem getarg(1),getarg(2);
	if (.@items == 2)
		delitem getarg(5),getarg(6);
	getitem Cats_Invest_Certif,1;
	mes "[Namis]";
	mes "Here's your Certificate. Always be grateful to the Merchants for these events!";
	close;
OnTouch:
	if (rand(2))
		emotion e_yawn;
	else
		specialeffect EF_SLEEPATTACK;
	end;
}

//== Investment Rewards ====================================
malangdo,215,119,4	script	Thanks Ticket Machine	2_VENDING_MACHINE1,{
	if (MaxWeight - Weight < 4500 || checkweight(Knife,1) == 0) {
		mes "- Currently you're carrying -";
		mes "- too many items with you. -";
		mes "- Please try again after you -";
		mes "- lose some weight. -";
		close;
	}
	mes "[Vending Machine Notice]";
	mes "^6815EA1. Don't kick the machine please. @_@";
	mes "2. You can only insert Invest Thanks Ticket.";
	mes "3. About the Jelly Box, if you open it, it gives you a random item.";
	mes "4. Hope you enjoy~^000000";
	mes "- Mr. Cat, the Machine Owner -";
	next;
	switch(select("Finish", "Purchase", "Red Paw Jelly Bag (5 Tickets)", "Black Paw Jelly Bag (50 Tickets)")) {
	case 1:
		close;
	case 2:
		mes "The Vending Machine is selling items in the following list.";
		next;
		switch(select("Finish", "1 Siege Arrow Quiver A (2 Tickets)", "1 Siege Arrow Quiver S (2 Tickets)", "30 White Potion (12 Tickets)", "30 White Slim Potion (14 Tickets)", "10 Dark Water (20 Tickets)", "20 Siege_Violet_Potion (30 Tickets)", "10 Coldproof Potion (30 Tickets)", "10 Thunderproof Potion (30 Tickets)", "10 Earthproof Potion (30 Tickets)", "10 Fireproof Potion (30 Tickets)", "10 Elemental Converter[Fire] (30 Tickets)")) {
			case 1: close;
			case 2: callsub L_Purchase,2,12678,1; //Siege_Arrow_Quiver_A
			case 3: callsub L_Purchase,2,12677,1; //Siege_Arrow_Quiver_S
			case 4: callsub L_Purchase,12,504,30; //White_Potion
			case 5: callsub L_Purchase,14,547,30; //White_Slim_Potion
			case 6: callsub L_Purchase,20,12020,10; //Water_Of_Darkness
			case 7: callsub L_Purchase,30,11547,20; //Woe_Violet_Potion
			case 8: callsub L_Purchase,30,12119,10; //Resist_Water
			case 9: callsub L_Purchase,30,12121,10; //Resist_Wind
			case 10: callsub L_Purchase,30,12120,10; //Resist_Earth
			case 11: callsub L_Purchase,30,12118,10; //Resist_Fire
			case 12: callsub L_Purchase,30,12114,10,"Elemental Converter[Fire]"; //Elemental_Fire
			case 13: callsub L_Purchase,30,12115,10,"Elemental Converter[Water]"; //Elemental_Water
			case 14: callsub L_Purchase,30,12117,10,"Elemental Converter[Wind]"; //Elemental_Wind
			case 15: callsub L_Purchase,30,12116,10,"Elemental Converter[Earth]"; //Elemental_Earth
		}
		end;
	case 3:
		mes "Red Paw Jelly Bag Button chosen. Need to insert 5 ^FF0000Invest Thanks Ticket^000000 and a random item will appear.";
		next;
		if (countitem(Thanks_Invest_Ticket) < 5) {
			mes "You don't have enough ^FF0000Invest Thanks Ticket^000000 to proceed.";
			close;
		}
		delitem Thanks_Invest_Ticket,5;
		.@i = rand(1,10000);
		     if (.@i <= 100) callsub L_Bag,12531,1; //White_Potion_Box
		else if (.@i <= 200) callsub L_Bag,12549,1; //White_Slim_Pot_Box2
		else if (.@i <= 250) callsub L_Bag,11549,10; //Woe_Blue_Potion
		else if (.@i <= 660) callsub L_Bag,617,1; //Old_Violet_Box
		else if (.@i <= 710) callsub L_Bag,12532,1; //Royal_Jelly_Box2
		else if (.@i <= 760) callsub L_Bag,12533,1; //Blue_Herb_Box2
		else if (.@i <= 810) callsub L_Bag,505,5; //Blue_Potion
		else if (.@i <= 1110) callsub L_Bag,644,1; //Gift_Box
		else if (.@i <= 1120) callsub L_Bag,607,1; //Yggdrasilberry
		else if (.@i <= 1130) callsub L_Bag,608,2; //Seed_Of_Yggdrasil
		else if (.@i <= 1140) callsub L_Bag,12292,5; //Unripe_Fruit
		else if (.@i <= 1150) callsub L_Bag,12293,5; //Dried_Yggdrasilberry
		else if (.@i <= 1250) callsub L_Bag,12679,1; //Sg_White_Potion_Box
		else if (.@i <= 1471) callsub L_Bag,603,1; //Old_Blue_Box
		else if (.@i <= 1571) callsub L_Bag,12550,1,"Poison Bottle Box(30)"; //Poison_Bottle_Box2
		else if (.@i <= 1671) callsub L_Bag,12020,10; //Water_Of_Darkness
		else if (.@i <= 1871) callsub L_Bag,12030,5; //Box_Of_Grudge
		else if (.@i <= 2071) callsub L_Bag,12031,5; //Sleepy_Box
		else if (.@i <= 2371) callsub L_Bag,12033,2; //Box_Of_Sunlight
		else if (.@i <= 2571) callsub L_Bag,12114,5,"Elemental Converter[Fire]"; //Elemental_Fire
		else if (.@i <= 2771) callsub L_Bag,12115,5,"Elemental Converter[Water]"; //Elemental_Water
		else if (.@i <= 2971) callsub L_Bag,12117,5,"Elemental Converter[Wind]"; //Elemental_Wind
		else if (.@i <= 3171) callsub L_Bag,12116,5,"Elemental Converter[Earth]"; //Elemental_Earth
		else if (.@i <= 3271) callsub L_Bag,12680,1; //Sg_Blue_Potion_Box
		else if (.@i <= 3471) callsub L_Bag,12118,5; //Resist_Fire
		else if (.@i <= 3671) callsub L_Bag,12119,5; //Resist_Water
		else if (.@i <= 3871) callsub L_Bag,12121,5; //Resist_Wind
		else if (.@i <= 4071) callsub L_Bag,12120,5; //Resist_Earth
		else if (.@i <= 4271) callsub L_Bag,929,20; //Immortal_Heart
		else if (.@i <= 4471) callsub L_Bag,1059,20; //Transparent_Cloth
		else if (.@i <= 4671) callsub L_Bag,905,20; //Stem
		else if (.@i <= 4871) callsub L_Bag,606,10; //Aloebera
		else if (.@i <= 5071) callsub L_Bag,609,10; //Amulet
		else if (.@i <= 5271) callsub L_Bag,710,2; //Illusion_Flower
		else if (.@i <= 5471) callsub L_Bag,576,20; //Prickly_Fruit
		else if (.@i <= 5671) callsub L_Bag,621,10; //Bitter_Herb
		else if (.@i <= 5871) callsub L_Bag,709,10; //Izidor
		else if (.@i <= 6071) callsub L_Bag,605,10; //Anodyne
		else if (.@i <= 6171) callsub L_Bag,11548,10; //Woe_White_Potion
		else if (.@i <= 6371) callsub L_Bag,706,10; //Four_Leaf_Clover
		else if (.@i <= 6571) callsub L_Bag,521,10; //Leaflet_Of_Aloe
		else if (.@i <= 6771) callsub L_Bag,707,10; //Singing_Plant
		else if (.@i <= 6971) callsub L_Bag,610,10; //Leaf_Of_Yggdrasil
		else if (.@i <= 7021) callsub L_Bag,12676,1; //Sg_Violet_Potion_Box
		else if (.@i <= 7171) callsub L_Bag,6249,10; //Savage_Meat
		else if (.@i <= 7321) callsub L_Bag,6252,10; //Wolf_Blood
		else if (.@i <= 7471) callsub L_Bag,6254,10; //Beef_Head_Meat
		else if (.@i <= 7621) callsub L_Bag,6253,10; //Cold_Ice
		else if (.@i <= 7771) callsub L_Bag,6256,10; //Ice_Fragment
		else if (.@i <= 7921) callsub L_Bag,6257,10; //Ice_Crystal
		else if (.@i <= 8071) callsub L_Bag,6260,10; //Petti_Tail
		else if (.@i <= 8309) callsub L_Bag,7932,20; //Poison_Herb_Nerium
		else if (.@i <= 8547) callsub L_Bag,7933,20; //Poison_Herb_Rantana
		else if (.@i <= 8785) callsub L_Bag,7934,20; //Poison_Herb_Makulata
		else if (.@i <= 9023) callsub L_Bag,7935,20; //Poison_Herb_Seratum
		else if (.@i <= 9261) callsub L_Bag,7936,20; //Poison_Herb_Scopolia
		else if (.@i <= 9499) callsub L_Bag,7937,20; //Poison_Herb_Amoena
		else if (.@i <= 9699) callsub L_Bag,6217,20; //Mandragora_Flowerpot
		else callsub L_Bag,12016,10; //Speed_Up_Potion
		end;
	case 4:
		mes "Black Paw Jelly Bag Button chosen. Need to insert 50 ^FF0000Invest Thanks Ticket^000000 and a random item will appear.";
		next;
		if (countitem(Thanks_Invest_Ticket) < 50) {
			mes "You don't have enough ^FF0000Invest Thanks Ticket^000000 to proceed.";
			close;
		}
		delitem Thanks_Invest_Ticket,50;
		.@i = rand(1,10000);
		     if (.@i <= 100) callsub L_Bag,12531,1; //White_Potion_Box
		else if (.@i <= 200) callsub L_Bag,12549,1; //White_Slim_Pot_Box2
		else if (.@i <= 250) callsub L_Bag,11549,20; //Woe_Blue_Potion
		else if (.@i <= 450) callsub L_Bag,617,1; //Old_Violet_Box
		else if (.@i <= 500) callsub L_Bag,12532,1; //Royal_Jelly_Box2
		else if (.@i <= 550) callsub L_Bag,12533,1; //Blue_Herb_Box2
		else if (.@i <= 600) callsub L_Bag,505,10; //Blue_Potion
		else if (.@i <= 800) callsub L_Bag,644,1; //Gift_Box
		else if (.@i <= 810) callsub L_Bag,607,2; //Yggdrasilberry
		else if (.@i <= 820) callsub L_Bag,608,3; //Seed_Of_Yggdrasil
		else if (.@i <= 830) callsub L_Bag,12292,10; //Unripe_Fruit
		else if (.@i <= 840) callsub L_Bag,12293,10; //Dried_Yggdrasilberry
		else if (.@i <= 940) callsub L_Bag,12679,1; //Sg_White_Potion_Box
		else if (.@i <= 1140) callsub L_Bag,603,1; //Old_Blue_Box
		else if (.@i <= 1240) callsub L_Bag,12550,1,"Poison Bottle Box(30)"; //Poison_Bottle_Box2
		else if (.@i <= 1340) callsub L_Bag,12020,20; //Water_Of_Darkness
		else if (.@i <= 1440) callsub L_Bag,12030,10; //Box_Of_Grudge
		else if (.@i <= 1540) callsub L_Bag,12031,10; //Sleepy_Box
		else if (.@i <= 1690) callsub L_Bag,12033,4; //Box_Of_Sunlight
		else if (.@i <= 1790) callsub L_Bag,12114,10,"Elemental Converter[Fire]"; //Elemental_Fire
		else if (.@i <= 1890) callsub L_Bag,12115,10,"Elemental Converter[Water]"; //Elemental_Water
		else if (.@i <= 1990) callsub L_Bag,12117,10,"Elemental Converter[Wind]"; //Elemental_Wind
		else if (.@i <= 2090) callsub L_Bag,12116,10,"Elemental Converter[Earth]"; //Elemental_Earth
		else if (.@i <= 2190) callsub L_Bag,12680,1; //Sg_Blue_Potion_Box
		else if (.@i <= 2290) callsub L_Bag,12118,10; //Resist_Fire
		else if (.@i <= 2390) callsub L_Bag,12119,10; //Resist_Water
		else if (.@i <= 2490) callsub L_Bag,12121,10; //Resist_Wind
		else if (.@i <= 2590) callsub L_Bag,12120,10; //Resist_Earth
		else if (.@i <= 2690) callsub L_Bag,929,40; //Immortal_Heart
		else if (.@i <= 2790) callsub L_Bag,1059,40; //Transparent_Cloth
		else if (.@i <= 2890) callsub L_Bag,905,40; //Stem
		else if (.@i <= 2990) callsub L_Bag,606,20; //Aloebera
		else if (.@i <= 3090) callsub L_Bag,609,20; //Amulet
		else if (.@i <= 3190) callsub L_Bag,710,4; //Illusion_Flower
		else if (.@i <= 3290) callsub L_Bag,576,40; //Prickly_Fruit
		else if (.@i <= 3390) callsub L_Bag,621,20; //Bitter_Herb
		else if (.@i <= 3490) callsub L_Bag,709,20; //Izidor
		else if (.@i <= 3590) callsub L_Bag,605,20; //Anodyne
		else if (.@i <= 3690) callsub L_Bag,11548,20; //Woe_White_Potion
		else if (.@i <= 3790) callsub L_Bag,706,20; //Four_Leaf_Clover
		else if (.@i <= 3890) callsub L_Bag,521,20; //Leaflet_Of_Aloe
		else if (.@i <= 3990) callsub L_Bag,707,20; //Singing_Plant
		else if (.@i <= 4090) callsub L_Bag,610,20; //Leaf_Of_Yggdrasil
		else if (.@i <= 4140) callsub L_Bag,12676,1; //Sg_Violet_Potion_Box
		else if (.@i <= 4240) callsub L_Bag,6249,20; //Savage_Meat
		else if (.@i <= 4340) callsub L_Bag,6252,20; //Wolf_Blood
		else if (.@i <= 4440) callsub L_Bag,6254,20; //Beef_Head_Meat
		else if (.@i <= 4540) callsub L_Bag,6253,20; //Cold_Ice
		else if (.@i <= 4640) callsub L_Bag,6256,20; //Ice_Fragment
		else if (.@i <= 4740) callsub L_Bag,6257,20; //Ice_Crystal
		else if (.@i <= 4840) callsub L_Bag,6260,20; //Petti_Tail
		else if (.@i <= 4940) callsub L_Bag,7932,40; //Poison_Herb_Nerium
		else if (.@i <= 5040) callsub L_Bag,7933,40; //Poison_Herb_Rantana
		else if (.@i <= 5140) callsub L_Bag,7934,40; //Poison_Herb_Makulata
		else if (.@i <= 5240) callsub L_Bag,7935,40; //Poison_Herb_Seratum
		else if (.@i <= 5340) callsub L_Bag,7936,40; //Poison_Herb_Scopolia
		else if (.@i <= 5440) callsub L_Bag,7937,40; //Poison_Herb_Amoena
		else if (.@i <= 5540) callsub L_Bag,6217,40; //Mandragora_Flowerpot
		else if (.@i <= 6000) callsub L_Bag,12016,20; //Speed_Up_Potion
		else if (.@i <= 6500) callsub L_Bag,2483,1; //Siege_Greave
		else if (.@i <= 7000) callsub L_Bag,2484,1; //Siege_Boots
		else if (.@i <= 7500) callsub L_Bag,2485,1; //Siege_Shoes
		else if (.@i <= 8000) callsub L_Bag,2586,1; //Siege_Manteau
		else if (.@i <= 8500) callsub L_Bag,2587,1; //Siege_Muffler
		else if (.@i <= 9000) callsub L_Bag,15046,1; //Siege_Plate
		else if (.@i <= 9500) callsub L_Bag,15047,1; //Siege_Suits
		else callsub L_Bag,15048,1; //Siege_Robe
		end;
	}
	end;

//callsub L_Purchase,<ticket cost>,<reward ID>,<reward amount>{,<reward name>};
L_Purchase:
	if (countitem(Thanks_Invest_Ticket) < getarg(0)) {
		mes "You don't have enough ^FF0000Invest Thanks Ticket^000000 to proceed.";
		close;
	}
	delitem Thanks_Invest_Ticket,getarg(0);
	getitem getarg(1),getarg(2);
	mes "- Done! -";
	next;
	mes "The item ^0000FF"+((getargcount() > 3)?getarg(3,""):getitemname(getarg(1)))+"^000000 has been obtained.";
	close;

//callsub L_Bag,<reward ID>,<reward amount>{,<reward name>};
L_Bag:
	getitem getarg(0),getarg(1);
	mes "- Done! -";
	next;
	mes "The item ^0000FF"+((getargcount() > 2)?getarg(2,""):getitemname(getarg(0)))+"^000000 has been obtained.";
	close;
}