summaryrefslogtreecommitdiff
path: root/npc/guild2/agit_main_se.txt
blob: 00fbdbeaaf8f2f4bf4593da0eb71ccc83c673949 (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
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
//===== rAthena Script =======================================
//= War of Emperium SE - Template File
//===== By: ==================================================
//= Euphy
//===== Current Version: =====================================
//= 1.2
//===== Compatible With: =====================================
//= rAthena SVN
//===== Description: =========================================
//= Like agit_main, this file is required
//= for SE castles to function.
//===== Additional Comments: =================================
//= 0.x Previous authors: L0ne_W0lf, Zephyrus, Brian.
//= 1.0 If anything breaks, blame Maki. [Euphy]
//= 1.1 Fixed an incorrect label execution. [Euphy]
//= 1.2 Hopefully fixed a processing error. [Euphy]
//============================================================

// Core, triggers all other events
//============================================================
-	script	Manager#template	-1,{
OnAgitInit2:
OnRecvCastle2:
	if (strnpcinfo(2) == "template") end;
	if (!getcastledata(strnpcinfo(2),1)) {
		donpcevent strnpcinfo(0)+"::OnStart";
		// Monster spawns are identical for all castles.
		monster strnpcinfo(2),0,0,"Evil Druid",1117,10;
		monster strnpcinfo(2),0,0,"Khalitzburg",1132,4;
		monster strnpcinfo(2),0,0,"Abysmal Knight",1219,3;
		monster strnpcinfo(2),0,0,"Executioner",1205,1;
		monster strnpcinfo(2),0,0,"Penomena",1216,10;
		monster strnpcinfo(2),0,0,"Alarm",1193,18;
		monster strnpcinfo(2),0,0,"Clock",1269,9;
		monster strnpcinfo(2),0,0,"Raydric Archer",1276,12;
		monster strnpcinfo(2),0,0,"Wanderer",1208,3;
		monster strnpcinfo(2),0,0,"Alice",1275,1;
		monster strnpcinfo(2),0,0,"Bloody Knight",1268,2;
		monster strnpcinfo(2),0,0,"Dark Lord",1272,2;
		monster strnpcinfo(2),0,0,"Tower Keeper",1270,4;
	}
	if (getcastledata(strnpcinfo(2),9) < 1)
		disablenpc "Kafra Employee#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
	end;

OnAgitStart2:
	if (strnpcinfo(2) == "template") end;
	if (agitcheck2()) {
		maprespawnguildid strnpcinfo(2),getcastledata(strnpcinfo(2),1),2;
		gvgon strnpcinfo(2);
		donpcevent strnpcinfo(0)+"::OnStart";
	}
	else for(set .@i,0; .@i<4; set .@i,.@i+1)
		donpcevent "RL"+.@i+"#"+strnpcinfo(2)+"::OnDisable";
	end;

OnAgitEnd2:
	if (strnpcinfo(2) == "template") end;
	gvgoff strnpcinfo(2);
	if (getcastledata(strnpcinfo(2),1)) {
		set .@str$,substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
		killmonster strnpcinfo(2),"Steward#"+.@str$+"::OnStartArena";
		donpcevent strnpcinfo(0)+"::OnReset";
		donpcevent "Steward#"+.@str$+"::OnStop";
	}
	end;

OnStart:
	// $agit_ar0x[] - $agit_sc0x[]
	// 1st Guardian stone, 2nd Guardian stone, Barrier 1, Barrier 2, Barrier 3, Summon Guardians
	// Settings for all but Summon Guardians: 0 = Okay | 1 = Destroyed | 2 = Repairing
	// Summon Guardians: 0 = Do not Summon | 1 = Summon
	if (getcastledata(strnpcinfo(2),1)) {
		setarray getd("$agit_"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"[0]"),0,0,0,0,0,0;
		donpcevent "df1#"+strnpcinfo(2)+"::OnEnable";
		donpcevent "df2#"+strnpcinfo(2)+"::OnEnable";
		for(set .@i,0; .@i<4; set .@i,.@i+1)
			donpcevent "RL"+.@i+"#"+strnpcinfo(2)+"::OnEnable";
	}
OnEmpSpawn:
	if (compare(strnpcinfo(2),"arug")) {
		if (strnpcinfo(2) == "arug_cas01") setarray .@i[0],87,219;
		else if (strnpcinfo(2) == "arug_cas02") setarray .@i[0],89,256;
		else setarray .@i[0],141,293;	// Castles 3,4,5 are identical.
	}
	else {
		if (strnpcinfo(2) == "schg_cas02") setarray .@i[0],162,193;
		else if (strnpcinfo(2) == "schg_cas03") setarray .@i[0],338,202;
		else setarray .@i[0],120,272;	// Castles 1,4,5 are identical.
	}
	monster strnpcinfo(2),.@i[0],.@i[1],"Emperium",1288,1,"Steward#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"::OnStartArena";
	end;

OnReset:
	set .@str$, substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
	donpcevent "df1#"+strnpcinfo(2)+"::OnEnable";
	donpcevent "df2#"+strnpcinfo(2)+"::OnEnable";
	donpcevent "gard1#"+strnpcinfo(2)+"::OnReset";
	donpcevent "gard2#"+strnpcinfo(2)+"::OnReset";
	donpcevent "1st Guardian Stone#"+.@str$+"::OnDisable";
	donpcevent "2nd Guardian Stone#"+.@str$+"::OnDisable";
	for(set .@i,1; .@i<4; set .@i,.@i+1)
		donpcevent "Control Device0"+.@i+"#"+.@str$+"::OnDisable";
	for(set .@i,0; .@i<4; set .@i,.@i+1)
		donpcevent "RL"+.@i+"#"+strnpcinfo(2)+"::OnDisable";
	if (agitcheck2())
		setarray getd("$agit_"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"[0]"),0,0,1,1,1,0;
	end;

OnChange:
	set .@str$, substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
	setarray getd("$agit_"+.@str$+"[0]"),2,2,1,1,2,0;
	donpcevent strnpcinfo(0)+"::OnEmpSpawn";
	donpcevent "Control Device03#"+.@str$+"::OnEnable";
	donpcevent "1st Guardian Stone#"+.@str$+"::OnEnable";
	donpcevent "2nd Guardian Stone#"+.@str$+"::OnEnable";
	end;

OnClock0001:
	// Spawn Treasure Chests based on castle economy.
	if (strnpcinfo(2) == "template") end;
	if (!getcastledata(strnpcinfo(2),1)) end;
	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnTreasureDied";
	if (getcastledata(strnpcinfo(2),4)) {
		set .@Economy,getcastledata(strnpcinfo(2),2);
		setcastledata strnpcinfo(2),2,.@Economy+getcastledata(strnpcinfo(2),4)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),1),10014));
		if (getcastledata(strnpcinfo(2),2) > 100) setcastledata strnpcinfo(2),2,100;
		setcastledata strnpcinfo(2),4,0;
	}
	if (getcastledata(strnpcinfo(2),5)) {
		set .@Defence,getcastledata(strnpcinfo(2),3);
		setcastledata strnpcinfo(2),3,.@Defence+getcastledata(strnpcinfo(2),5);
		if (getcastledata(strnpcinfo(2),3) > 100) setcastledata strnpcinfo(2),3,100;
		setcastledata strnpcinfo(2),5,0;
	}
	set .@Treasure,getcastledata(strnpcinfo(2),2)/5+4;
	if (!.@Treasure) end;
	freeloop(1);
	if (compare(strnpcinfo(2),"arug")) {
		if (strnpcinfo(2) == "arug_cas01") { 
			set .@treasurebox,1943;
			setarray .@treasurex[0],251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258,251,252,253,254,255,256,257,258;
			setarray .@treasurey[0],369,369,369,369,368,368,368,368,367,367,367,367,366,366,366,366,365,365,365,365,364,364,364,364;
		}
		else if (strnpcinfo(2) == "arug_cas02") { 
			set .@treasurebox,1944;
			setarray .@treasurex[0],382,383,384,385,386,387,384,385,386,387,388,389,382,383,384,385,386,387,384,385,386,387,388,389;
			setarray .@treasurey[0],231,231,231,231,231,231,230,230,230,230,230,230,225,225,225,225,225,225,224,224,224,224,224,224;
		}
		else { 	// Castles 3,4,5 are identical, except 4's treasure.
			set .@treasurebox,(strnpcinfo(2) == "arug_cas04")?1946:1945;
			setarray .@treasurex[0],291,292,293,294,295,296,293,294,295,296,297,298,291,292,293,294,295,296,293,294,295,296,297,298;
			setarray .@treasurey[0],276,276,276,276,276,276,274,274,274,274,274,274,272,272,272,272,272,272,269,269,269,269,269,269;
		}
	}
	else {
		if (strnpcinfo(2) == "schg_cas02") { 
			set .@treasurebox,1939;
			setarray .@treasurex[0],249,250,251,252,253,246,247,248,249,250,250,251,252,253,246,247,248,249,250,249,250,251,252,253;
			setarray .@treasurey[0],378,378,378,378,378,376,376,376,376,376,374,374,374,374,372,372,372,372,372,370,370,370,370,370;
		}
		else if (strnpcinfo(2) == "schg_cas03") { 
			set .@treasurebox,1940;
			setarray .@treasurex[0],189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194,189,190,191,192,193,194;
			setarray .@treasurey[0], 21, 21, 21, 21, 21, 21, 19, 19, 19, 19, 19, 19, 17, 17, 17, 17, 17, 17, 15, 15, 15, 15, 15, 15;
		}
		else {	// Castles 1,4,5 are identical, except treasures.
			if (strnpcinfo(2) == "schg_cas01") set .@treasurebox,1938;
			else if (strnpcinfo(2) == "schg_cas04") set .@treasurebox,1941;
			else set .@treasurebox,1942;
			setarray .@treasurex[0],388,388,388,387,386,385,384,384,384,384,384,384,385,386,387,388,389,390,390,390,389,388,387,386;
			setarray .@treasurey[0],388,389,390,390,390,390,389,388,387,386,385,384,384,384,384,384,384,384,385,386,386,386,386,386;
		}
	}
	for(set .@i,0; .@i<4; set .@i,.@i+1)
		monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";
	for(set .@i,4; .@i<24; set .@i,.@i+1) {
		if (.@Treasure < .@i+1) break;
		monster strnpcinfo(2),.@treasurex[.@i],.@treasurey[.@i],"Treasure Chest",(.@i%2)?.@treasurebox:1324,1,strnpcinfo(0)+"::OnTreasureDied";
	}
	freeloop(0);
	end;

OnTreasureDied:
	end;
}

// Guild Manager
//============================================================
-	script	Steward#template	-1,{
	set .@GID, getcastledata(strnpcinfo(4),1);
	if (!.@GID) {
		mes "[ Steward ]";
		mes "I await for the master";
		mes "whom destiny will choose";
		mes "for me. Do you think you";
		mes "have to courage and strength";
		mes "to conquer this stronghold?";
		close;
	}
	if (getcharid(2) != .@GID || strcharinfo(0) != getguildmaster(.@GID)) {
		mes "[ Steward ]";
		mes "Hmpf. Your threats don't";
		mes "scare me! Guardians, drive";
		mes "this infidel away from here!";
		mes "I will always be loyal to the";
		mes "master of this stronghold,";
		mes "the one and only ^FF0000"+getguildmaster(.@GID)+"^000000.";
		close;
	}
	mes "[ Steward ]";
	mes "Ah, Master ^FF0000"+getguildmaster(.@GID)+"^000000...";
	mes "How shall I serve you today?";
	mes "Was there an aspect of this";
	mes "stronghold's maintenance";
	mes "you wanted to discuss?";
	next;
	switch(select("Stronghold Briefing:Invest in Commercial Growth:Invest in Defense growth:Hire/Fire Storage Staff:Go to Master's room")) {
	case 1:
		mes "[ Steward ]";
		mes "The Commercial Growth";
		mes "Level of the stronghold is ^0000ff"+getcastledata(strnpcinfo(4),2)+".";
		if (getcastledata(strnpcinfo(4),4) > 0) {
			mes "Last time, you invested in";
			mes "Commercial Growth "+getcastledata(strnpcinfo(4),4)+".";
		}
		next;
		mes "[ Steward ]";
		mes "Our stronghold's";
		mes "safeguard level is "+getcastledata(strnpcinfo(4),3)+".";
		if (getcastledata(strnpcinfo(4),5) > 0) {
			mes "Last time, you invested";
			mes "in defense "+getcastledata(strnpcinfo(4),5)+" times.";
		}
		mes " ";
		mes "That is all, master.";
		close;
	case 2:
		set .@Economy,getcastledata(strnpcinfo(4),2);
		setarray .@cost[0],5000,10000,20000,35000,55000,80000,110000,145000,185000,230000,280000,335000,395000,460000,530000,605000,685000,770000,860000,955000;
		set .@j,0;
		for(set .@i,6; .@i<101; set .@i,.@i+5) {
			if (.@Economy < .@i) {
				set .@eco_invest,.@cost[.@j];
				break;
			}
			set .@j, .@j+1;
		}
		// Quadruple the cost of investing if you've already invested once.
		if (getcastledata(strnpcinfo(4),4)) set .@eco_invest,.@eco_invest*4;
		mes "[ Steward ]";
		mes "Raising the stronghold's";
		mes "commercial growth will";
		mes "increase the quantity of";
		mes "goods produced for the guild.";
		mes "Investing in commercial growth";
		mes "will help the guild's future.";
		next;
		mes "[ Steward ]";
		mes "You can make one investment";
		mes "each day, but if you can make";
		mes "two investments if you pay";
		mes "more Zeny: this will speed";
		mes "up commercial development,";
		mes "but can be quite expensive.";
		next;
		if (.@Economy == 100) {
			mes "[ Steward ]";
			mes "However, our stronghold's";
			mes "commerical growth level is";
			mes "at 100%. It's not possible to";
			mes "develop commercial growth";
			mes "any further than that.";
			close;
		}
		if (getcastledata(strnpcinfo(4),4) >= 2) {
			mes "[ Steward ]";
			mes "You've already made two";
			mes "investments today, so you'll";
			mes "have to wait until tomorrow";
			mes "to make another investment.";
			close;
		}
		if (getcastledata(strnpcinfo(4),4) == 0) {
			mes "[ Steward ]";
			mes "You must pay ^FF0000"+.@eco_invest+"^000000 Zeny";
			mes "to make an investment";
			mes "Will you invest in this";
			mes "stronghold's commerical";
			mes "development now?";
		}
		else {
			mes "[ Steward ]";
			mes "You must pay ^FF0000"+.@eco_invest+"^000000";
			mes "more Zeny to make a second";
			mes "investment today. Will you";
			mes "invest one more time?";
		}
		next;
		switch(select("Invest in Commercial Growth:Cancel")) {
		case 1:
			if (getcastledata(strnpcinfo(4),4) >= 2) {
				mes "[ Steward ]";
				mes "You've already made two";
				mes "investments today, so you'll";
				mes "have to wait until tomorrow";
				mes "to make another investment.";
				close;
			}
			if (Zeny < .@eco_invest) {
				mes "[ Steward ]";
				mes "I'm sorry, Master, but";
				mes "you do not have enough";
				mes "Zeny to make an investment";
				mes "for the guild today.";
				close;
			}
			set Zeny, Zeny-.@eco_invest;
			setcastledata strnpcinfo(4),4,getcastledata(strnpcinfo(4),4)+1;
			mes "[ Steward ]";
			mes "A wise use of the guild's";
			mes "funds, Master. We can expect";
			mes "to see the results of this";
			mes "investment by tomorrow.";
			close;
		case 2:
			mes "[ Steward ]";
			mes "As you command, Master.";
			close;
		}
	case 3:
		set .@Defence,getcastledata(strnpcinfo(4),3);
		setarray .@cost[0],10000,20000,40000,70000,110000,160000,220000,290000,370000,460000,560000,670000,790000,920000,1060000,1210000,1370000,1540000,1720000,1910000;
		set .@j,0;
		for(set .@i,6; .@i<101; set .@i,.@i+5) {
			if (.@Defence < .@i) {
				set .@def_invest,.@cost[.@j];
				break;
			}
			set .@j, .@j+1;
		}
		// Quadruple the cost of investing if you've already invested once.
		if (getcastledata(strnpcinfo(4),5)) set .@def_invest,.@def_invest*4;
		mes "[ Steward ]";
		mes "Investing in our stronghold's";
		mes "defense will enhance the";
		mes "durability of our Guardians";
		mes "and the Emperium. We'll need";
		mes "every advantage to protect";
		mes "ourselves from our enemies.";
		next;
		mes "[ Steward ]";
		mes "You can invest in defense";
		mes "once per day, but if you pay";
		mes "more Zeny, you can invest";
		mes "a maximum of two times daily.";
		next;
		mes "[ Steward ]";
		if (getcastledata(strnpcinfo(4),3) == 100) {
			mes "The Defense Level of this";
			mes "stronghold is 100%, and";
			mes "cannot be increased further.";
			close;
		}
		if (getcastledata(strnpcinfo(4),5) >= 2) {
			mes "Master, you've already";
			mes "invested in Defense twice";
			mes "today. You'll need to wait";
			mes "until tomorrow if you really";
			mes "want to increase our defenses.";
			close;
		}
		if (getcastledata(strnpcinfo(4),5) == 0) {
			mes "We need ^FF0000"+.@def_invest+"^000000";
			mes "Zeny to invest in our";
			mes "stronghold's defenses.";
			mes "Will you invest now?";
		}
		else {
			mes "We need ^FF0000"+.@def_invest+"^000000";
			mes "Zeny to invest in our";
			mes "stronghold's defenses";
			mes "a second time today.";
			mes "Will you invest now?";
		}
		next;
		switch(select("Invest in Defense:Cancel")) {
		case 1:
			if (getcastledata(strnpcinfo(4),5) >= 2) {
				mes "[ Steward ]";
				mes "Master, you've already";
				mes "invested in Defense twice";
				mes "today. You'll need to wait";
				mes "until tomorrow if you really";
				mes "want to increase our defenses.";
				close;
			}
			if (Zeny < .@def_invest) {
				mes "[ Steward ]";
				mes "I'm sorry, Master, but";
				mes "you do not have enough";
				mes "Zeny to make an investment";
				mes "for the guild today.";
				close;
			}
			set Zeny, Zeny-.@def_invest;
			setcastledata strnpcinfo(4),5,getcastledata(strnpcinfo(4),5)+1;
			mes "[ Steward ]";
			mes "A wise use of the guild's";
			mes "funds, Master. Increasing";
			mes "the frequency of treasure";
			mes "procured by the guild will";
			mes "definitely help us all.";
			close;
		case 2:
			mes "[ Steward ]";
			mes "As you command, Master.";
			close;
		}
	case 4:
		if (getcastledata(strnpcinfo(4),9) == 1) {
			mes "[ Steward ]";
			mes "Do you wish to dismiss";
			mes "the Kafra Employee that";
			mes "we've hired for the guild?";
			next;
			switch(select("Dismiss:Cancel")) {
			case 1:
				cutin "kafra_01",2;
				mes "[ Hired Kafra Employee ]";
				mes "Master, please reconsider!";
				mes "I've been working very hard";
				mes "for the success of the guild!";
				mes "I'll try harder to serve the";
				mes "guild members of this";
				mes "stronghold, I promise!";
				next;
				switch(select("Dismiss:Cancel")) {
				case 1:
					mes "[ Hired Kafra Employee ]";
					mes "Why?! What have I done";
					mes "to deserve this? Waaah~!";
					next;
					cutin "kafra_01",255;
					break;
				case 2:
					mes "[ Hired Kafra Employee ]";
					mes "Thank you, Master!";
					mes "I'll obey your every";
					mes "command as best I can!";
					mes "You won't regret this!";
					close;
				}
				break;
			case 2:
				mes "[ Steward ]";
				mes "She works very hard,";
				mes "in my opinion. It was in";
				mes "all of our best interests to";
				mes "allow her to stay with us.";
				close;
			}
			disablenpc "Kafra Employee#"+strnpcinfo(2);
			setcastledata strnpcinfo(4),9,0;
			mes "[ Steward ]";
			mes "That Kafra Employee";
			mes "has been dismissed.";
			mes "Were really dissatisfied";
			mes "by the quality of her service?";
			close;
		}
		else {
			mes "[ Steward ]";
			mes "Will you hire a";
			mes "Kafra Employee to serve";
			mes "our stronghold? You must";
			mes "pay ^FF000010,000 Zeny^000000 to hire one.";
			next;
			switch(select("Hire:Cancel")) {
			case 1:
				if (getgdskilllv(.@GID,10001) == 0) {
					mes "[ Steward ]";
					mes "Master, we cannot hire a";
					mes "Kafra Employee because";
					mes "you have not yet attained";
					mes "the ^FF0000Contract with Kafra^000000";
					mes "guild skill.";
					close;
				}
				if (Zeny < 10000) {
					mes "[ Steward ]";
					mes "Master, we cannot hire a";
					mes "Kafra Employee because";
					mes "we do not have enough";
					mes "funds to pay the contract fee.";
					close;
				}
				set Zeny, Zeny-10000;
				enablenpc "Kafra Employee#"+strnpcinfo(2);
				setcastledata strnpcinfo(4),9,1;
				mes "[ Steward ]";
				mes "Very well. We have formed";
				mes "a contract with the Kafra";
				mes "Head Office, and hired a";
				mes "Kafra Employee for our";
				mes "stronghold. Here she is~";
				next;
				cutin "kafra_01",2;
				mes "[ Hired Kafra Employee ]";
				mes "How do you do? I've";
				mes "been dispatched by the";
				mes "Kafra Head Office to";
				mes "serve your guild's needs.";
				mes "I'll do my best to follow";
				mes "your every command, Master.";
				next;
				cutin "kafra_01",255;
				mes "[ Steward ]";
				mes "Our contract will expire";
				mes "after one month, so we must";
				mes "pay additional fees to keep";
				mes "this Kafra Employee in";
				mes "the service of our guild.";
				close;
			case 2:
				mes "[ Steward ]";
				mes "As you command, Master.";
				mes "However, I suggest hiring";
				mes "a Kafra Employee as soon";
				mes "as possible since our guild";
				mes "would greatly benefit from";
				mes "the convenient Kafra services.";
				close;
			}
		}
	case 5:
		mes "[ Steward ]";
		mes "Do you wish to enter the";
		mes "Guild Treasure Room?";
		mes "Only you, the Guild Master,";
		mes "are permitted to enter.";
		next;
		mes "[ Steward ]";
		mes "Please remember to open";
		mes "the Treasure Boxes at the";
		mes "proper time. Otherwise, the";
		mes "treasure may disappear if";
		mes "something unexpected happens.";
		next;
		switch(select("Go to Treasure Room:Cancel")) {
		case 1:
			mes "[ Steward ]";
			mes "Allow me to guide you";
			mes "on the secret path to";
			mes "the Treasure Room.";
			mes "Press the secret switch";
			mes "when you wish to return here.";
			close2;
			if (compare(strnpcinfo(4),"arug")) {
				if (strnpcinfo(4) == "arug_cas01") setarray .@i[0],250,363;
				else if (strnpcinfo(4) == "arug_cas02") setarray .@i[0],382,227;
				else setarray .@i[0],292,266;	// Castles 3,4,5 are identical.
			}
			else {
				if (strnpcinfo(4) == "schg_cas02") setarray .@i[0],249,373;
				else if (strnpcinfo(4) == "schg_cas03") setarray .@i[0],190,16;
				else setarray .@i[0],381,381;	// Castles 1,4,5 are identical.
			}
			warp strnpcinfo(4),.@i[0],.@i[1];
			end;
		case 2:
			mes "[ Steward ]";
			mes "Items in the Treasure Room";
			mes "are produced once each day.";
			mes "Therefore, you must obtain";
			mes "the treasure items everyday.";
			mes "For the sake of the guild,";
			mes "prioritize treasure harvesting!";
			close;
		}
	}

OnStop:
	awake strnpcinfo(0);
	end;

OnStartArena:
	set .@GID,getcharid(2);
	set .@region$, (compare(strnpcinfo(4),"arug"))?"Valfreyja":"Nithafjoll";
	// Lower castle Economy
	set .@Economy,getcastledata(strnpcinfo(4),2)-5;
	if (.@Economy < 0) set .@Economy, 0;
	setcastledata strnpcinfo(4),2,.@Economy;
	// Lower Castle Defence
	set .@Defence,getcastledata(strnpcinfo(4),3)-5;
	if (.@Defence < 0) set .@Defence, 0;
	setcastledata strnpcinfo(4),3,.@Defence;
	// Set new owner
	setcastledata strnpcinfo(4),1,.@GID;
	// Clear castle's data.
	for(set .@i,4; .@i<10; set .@i,.@i+1)
		setcastledata strnpcinfo(4),.@i,0;
	// Disable Kafra
	disablenpc "Kafra Employee#"+strnpcinfo(2);

	announce "The ["+getguildname(.@GID)+"] guild conquered the ["+.@region$+" "+charat(strnpcinfo(2),3)+"] stronghold of "+getcastlename(strnpcinfo(4))+"!",bc_all|bc_woe;
	mapannounce strnpcinfo(4),"The emperium has been shattered!",bc_map,"0x00FF00",FW_NORMAL,20,0,40;
	donpcevent "Manager#"+strnpcinfo(4)+"::OnReset";
	maprespawnguildid strnpcinfo(4),getcastledata(strnpcinfo(4),1),2;
	donpcevent "Manager#"+strnpcinfo(4)+"::OnRecvCastle2";
	donpcevent "::OnRecvCastle"+strnpcinfo(2);
	sleep 10000;
	if (agitcheck2()) {
		donpcevent "Manager#"+strnpcinfo(4)+"::OnChange";
		mapannounce strnpcinfo(4),"Rebuild this stronghold's Guardian Stones and Fortress Gates to secure your guild's new aquisition!",bc_map,"0x00FF00",FW_NORMAL,20,0,40;
	}
	end;
}

// Castle Guardians
//============================================================
-	script	Guardian#template	-1,{
	set .@GID, getcastledata(strnpcinfo(4),1);
	set .@n$, "["+strnpcinfo(1)+"]";
	if (!.@GID) {
		mes .@n$;
		mes "Great job. Now, all you";
		mes "need to do is destroy this";
		mes "Emperium to gain ownership";
		mes "over this stronghold.";
		close;
	}
	if (getcharid(2) == .@GID) {
		if (strcharinfo(0) != getguildmaster(.@GID)) {
			mes .@n$;
			mes "As guardian of this";
			mes "stronghold, I answer only";
			mes "to the master of the guild";
			mes "that controls this place.";
			close;
		}
		else {
			if (!agitcheck2()) {
				mes .@n$;
				mes "I am "+strnpcinfo(1)+", guardian of";
				mes "this stronghold. For now,";
				mes "all is quiet in this place.";
				next;
				switch(select("Converse:Cancel")) {
				case 1:
					mes .@n$;
					mes "Do you have any questions";
					mes "about this stronghold?";
					next;
					switch(select("Guardian Stones:Fortress Gates:Link Flags:Battle Strategy:Cancel")) {
					case 1:
						mes .@n$;
						mes "There is one Emperium";
						mes "and two Guardian Stones in";
						mes "each fortress. These stones";
						mes "are the first line of defense,";
						mes "and must be destroyed before";
						mes "enemies can even enter.";
						next;
						mes .@n$;
						mes "The stones are located in";
						mes "^4D4DFFGate Houses^000000 which must be";
						mes "protected to prevent enemies";
						mes "from reaching the Emperium.";
						mes "Guardian Stones can ^4D4DFFrecall";
						mes "your Guardians^000000 for protection.";
						next;
						mes .@n$;
						mes "Fortresses with higher levels";
						mes "of defense can summon more";
						mes "Guardians: this is why it is";
						mes "so important for guilds to";
						mes "invest in Defense Growth.";
						next;
						mes .@n$;
						mes "Guardian Stones that have";
						mes "been destroyed can be revived";
						mes "after a certain time, but one of^FFFFFF ^000000 the guild members must give";
						mes "me the order. I can also report^FFFFFF ^000000 the status of the Guardian Stones.";
						close;
					case 2:
						mes .@n$;
						mes "^4D4DFFFortress Gates^000000 are the second ^FFFFFF ^000000 line of guild stronghold defense,";
						mes "and are protected by extra barricades activated by the Guardian Stones.";
						mes "These gates are located in three different parts of the fortress.";
						next;
						mes .@n$;
						mes "Barricades are protected by";
						mes "Guardian Stones, and are";
						mes "restored when the Guardian";
						mes "Stones are retrieved. However,";
						mes "it is not as easy to restore";
						mes "destroyed Fortress Gates.";
						next;
						mes .@n$;
						mes "Fortress Gates can only be";
						mes "restored when the ^4D4DFFguild";
						mes "master of a stronghold";
						mes "changes^000000, or if ^4D4DFFrestoration";
						mes "is requested by the guild";
						mes "master of the stronghold^000000.";
						close;
					case 3:
						mes .@n$;
						mes "Strongholds have many";
						mes "Link Flags that allow you";
						mes "to access vital areas within";
						mes "restrictions placed by the";
						mes "Barricades. Usually, ^4D4DFFFlag 1";
						mes "links to the Gate House^000000.";
						next;
						mes .@n$;
						mes "Many flags link directly to";
						mes "the flag near the Emperium.";
						mes "The final numbered flag is";
						mes "linked to the Convenience";
						mes "Facility of the stronghold's";
						mes "owner. Keep this in mind.";
						close;
					case 4:
						mes .@n$;
						mes "Strategy? It would be better";
						mes "to develop your battle plan to";
						mes "exploit your guild's advantages";
						mes "and your enemies' weaknesses.";
						mes "Use the Gate Houses and Barricades, and rebuild as quickly as you can!";
						close;
					case 5:
						mes .@n$;
						mes "You have no questions";
						mes "to ask of me? Well, I'm";
						mes "here to serve your needs.";
						close;
					}
				case 2:
					mes .@n$;
					mes "I'm always here, so";
					mes "feel free to request my";
					mes "assistance whenever";
					mes "the need arises.";
					close;
				}
			}
			else {
				mes .@n$;
				mes "Greetings, "+strcharinfo(0)+".";
				mes "What are your orders?";
				next;
				switch(select("Increase Stronghold Defense:Situational Briefing:Cancel")) {
				case 1:
					if (!getd("$agit_"+strnpcinfo(2)+"[5]")) {
						if (getgdskilllv(.@GID,10002) == 0) {
							mes .@n$;
							mes "I'm sorry, but the Guardian";
							mes "Stones aren't powerful enough";
							mes "to summon Guardians yet. We";
							mes "need to accumulate more";
							mes "knowledge before they can";
							mes "summon any Guardians.";
							close;
						}
						else {
							mes .@n$;
							mes "I shall endeavor to summon";
							mes "a Guardian through a Guardian";
							mes "Stone. However, keep in mind";
							mes "that this will not work if the";
							mes "Guardian Stone is destroyed.";
							setd "$agit_"+strnpcinfo(2)+"[5]",1;
							if (!getd("$agit_"+strnpcinfo(2)+"[0]"))
								donpcevent "gard1#"+strnpcinfo(4)+"::OnEnable";
							if (!getd("$agit_"+strnpcinfo(2)+"[1]"))
								donpcevent "gard2#"+strnpcinfo(4)+"::OnEnable";
							close;
						}
					}
					else {
						mes .@n$;
						mes "You've already commanded";
						mes "me to summon a Guardian";
						mes "to defend the stronghold.";
						close;
					}
				case 2:
					mes .@n$;
					mes "Our defense status is...";
					setarray .@status$[0],"^4D4DFFOperational","^FF0000Destroyed","^008000Repairing";
					mes "1st Guardian Stone: "+.@status$[getd("$agit_"+strnpcinfo(2)+"[0]")]+"^000000";
					mes "2nd Guardian Stone: "+.@status$[getd("$agit_"+strnpcinfo(2)+"[1]")]+"^000000";
					mes "1st Fortress Gate: "+.@status$[getd("$agit_"+strnpcinfo(2)+"[2]")]+"^000000";
					mes "2nd Fortress Gate: "+.@status$[getd("$agit_"+strnpcinfo(2)+"[3]")]+"^000000";
					mes "3rd Fortress Gate: "+.@status$[getd("$agit_"+strnpcinfo(2)+"[4]")]+"^000000";
					close;
				case 3:
					mes .@n$;
					mes "I'll be standing by,";
					mes "awaiting your orders.";
					close;
				}
			}
		}
	}
	else {
		mes .@n$;
		mes "Who are you? Scoundrel!";
		mes "Leave this stronghold now!";
		close;
	}

OnInit:
	setarray getd("$agit_"+strnpcinfo(2)+"[0]"),0,0,0,0,0,0;
	end;
}

// Guild Kafras
//============================================================
-	script	Kafra#template	-1,{
	cutin "kafra_01",2;
	set .@GID, getcastledata(strnpcinfo(4),1);
	if (getcharid(2) == .@GID && getgdskilllv(.@GID,10001)) {
		mes "[Kafra Employee]";
		mes "Welcome, proud member";
		mes "of the ^FF0000"+GetGuildName(.@GID)+"^000000 Guild!";
		mes "The Kafra Corporation is ready";
		mes "to assist you wherever you go!";
		next;
		switch(select("Use Storage:Use Warp Service:Rent Pushcart:Cancel")) {
		case 1:
			if (basicskillcheck() && getskilllv("NV_BASIC") < 6) {
				mes "[Kafra Employee]";
				mes "I'm so sorry, but you must";
				mes "have at least Novice Skill";
				mes "Lv.6 to use the Storage.";
			}
			else openstorage;
			break;
		case 2:
			mes "[Kafra Employee]";
			mes "Please tell me your";
			mes "Warp destination.";
			next;
			switch(select("Rachel -> 200 z:Cancel")) {
			case 1:
				if (Zeny < 200) {
					mes "[Kafra Employee]";
					mes "I'm sorry, but you don't";
					mes "have enough Zeny to pay";
					mes "the warp fee. Would you";
					mes "please check your funds again?";
					close2;
					cutin "kafra_01",255;
					end;
				}
				set Zeny, Zeny-200;
				warp "rachel",115,125;
				end;
			case 2:
				cutin "kafra_01",255;
				break;
			}
			break;
		case 3:
			if (BaseClass != Job_Merchant) {
				mes "[Kafra Employee]";
				mes "I'm sorry, but the Pushcart";
				mes "rental service can only be";
				mes "used by Merchant, Blacksmith,";
				mes "and Alchemist class characters.";
			}
			else if (checkcart() == 1) {
				mes "[Kafra Employee]";
				mes "Hm? You've already";
				mes "rented a Pushcart.";
			}
			else {
				mes "[Kafra Employee]";
				mes "The Pushcart rental fee";
				mes "is 800 Zeny. Would you";
				mes "like to rent a Pushcart?";
				next;
				switch(select("Rent Pushcart:Cancel")) {
				case 1:
					if (Zeny < 800) {
						mes "[Kafra Employee]";
						mes "I'm sorry, but you don't";
						mes "have enough Zeny to rent";
						mes "one of our Pushcarts.";
						close2;
						cutin "kafra_01",255;
						end;
					}
					set Zeny, Zeny-800;
					setcart;
					break;
				case 2:
					break;
				}
			}
			break;
		case 4:
			mes "[Kafra Employee]";
			mes "Thank you for using the";
			mes "Kafra Service. Wherever";
			mes "you go, Kafra will be";
			mes "there to support you!";
			close2;
			cutin "kafra_01",255;
			end;
		}
		close2;
		cutin "kafra_01",255;
		end;
	}
	else {
		mes "[Kafra Employee]";
		mes "I'm sorry, but I've been";
		mes "exclusively contracted";
		mes "to the members of the";
		mes "^FF0000"+getguildname(.@GID)+"^000000 Guild.";
		mes "You'll have to ask another";
		mes "Kafra Employee to help you...";
		close2;
		cutin "kafra_01",255;
		end;
	}
}

// Guardian Stones (2)
//============================================================
-	script	Guardian Stone#template	-1,{
	set .@GID, getcastledata(strnpcinfo(4),1);
	set .@num, atoi(charat(strnpcinfo(1),0));
	set .@var$,"$agit_"+strnpcinfo(2);
	if (getcharid(2) == .@GID) {
		mes "^3355FFYou will need the";
		mes "following materials to";
		mes "rebuild a destroyed";
		mes "Guardian Stone.^000000";
		next;
		mes "1 Oridecon";
		mes "1 Elunium";
		mes "30 Stones";
		mes "5 Blue Gemstones";
		mes "5 Yellow Gemstones";
		mes "5 Red Gemstones";
		next;
		mes "^3355FFDo you want to continue?^000000";
		if(select("No:Continue") == 1) {
			mes "^3355FFWork canceled.^000000";
			close;
		}
		if ((countitem(984) > 0) && (countitem(985) > 0) && (countitem(7049) > 29) && (countitem(717) > 4) && (countitem(715) > 4) && (countitem(716) > 4)) {
			mes "^3355FFArrange Stones, Elunium, and";
			mes "Oridecon, in that order, in the";
			mes "center. Then you must arrange";
			mes "the enchanted Gemstones to";
			mes "rebuild the Guardian Stone.^000000";
			next;
			setarray .@stone$[0],"Elunium","Oridecon","Stones";
			set .@i, select("Elunium:Oridecon:Stone")-1;
			if (.@i == 2) set .@nice,.@nice+10;
			mes "^3355FF"+.@stone$[.@i]+" has been";
			mes "placed in the center.^000000";
			next;
			set .@i, select("Elunium:Oridecon:Stone")-1;
			if (.@i == 0) set .@nice,.@nice+10;
			mes "^3355FFYou have lined the";
			mes "outside of the center";
			mes "with some "+.@stone$[.@i]+".^000000";
			next;
			set .@i, select("Elunium:Oridecon:Stone")-1;
			if (.@i == 1) set .@nice,.@nice+10;
			mes "^3355FFYou covered the";
			mes "rest of the materials";
			mes "with some "+.@stone$[.@i]+".^000000";
			next;
			mes "^3355FFNow you need to arrange";
			mes "the enchanted Gemstones";
			mes "accordingly. You can identify";
			mes "their Magic properties by";
			mes "their casting effect.^000000";
			next;
			setarray .@effect[0],56,54,225;
			setarray .@color$[0],"Red","Yellow","Blue";
			while(1) {
				if (.@roof0 > 7) break;
				set .@i, rand(3);
				specialeffect .@effect[.@i];
				mes "^3355FFThe Gemstones must";
				mes "be arranged in the correct";
				mes "order according to their";
				mes "magic properties and power.^000000";
				next;
				set .@j, select("Red Gemstone:Yellow Gemstone:Blue Gemstone")-1;
				mes "^3355FFYou placed the "+.@color$[.@j]+" Gemstone.^000000";
				if (.@i == .@j) {
					mes "^3355FFHowever, the Guardian Stone";
					mes "Repair System failed because";
					mes "of a magic power conflict.^000000";
					close;
				}
				set .@nice,.@nice+10;
				set .@roof0,.@roof0+1;
				specialeffect EF_STEAL;
				next;
			}
			if (.@nice > 90) {
				if (!getd(.@var$+"["+(.@num-1)+"]")) {
					mes "^3355FFThe Guardian Stone";
					mes "Repair System has";
					mes "already completed.^000000";
					close;
				}
				else {
					if (!agitcheck2()) {
						mes "^3355FFIt is impossible to";
						mes "rebuild the Guardian";
						mes "Stone because the";
						mes "Emperium is not present.^000000";
						close;
					}
					else {
						mes "^3355FFThe Gemstones have been";
						mes "arranged, and the Guardian";
						mes "Stone is successfully repaired.^000000";
						delitem 984,1; //Oridecon
						delitem 985,1; //Elunium
						delitem 7049,30; //Stone
						delitem 717,5; //Blue_Gemstone
						delitem 715,5; //Yellow_Gemstone
						delitem 716,5; //Red_Gemstone
						close2;
						donpcevent "df"+.@num+"#"+strnpcinfo(4)+"::OnEnable";
						specialeffect EF_ICECRASH;
						disablenpc strnpcinfo(0);
						setd .@var$+"["+(.@num-1)+"]",0;
						set .@df_all,getd(.@var$+"[0]")+getd(.@var$+"[1]");
						if (!.@df_all) {
							mapannounce strnpcinfo(4),"Both Guardian Stones have been erected, bolstering this stronghold's defenses!",bc_map,"0x00ff00";
							donpcevent "RL0#"+strnpcinfo(4)+"::OnEnable";
						}
						else mapannounce strnpcinfo(4),"The "+strnpcinfo(1)+" has been repaired successfully.",bc_map,"0x00ff00";
						if (getd(.@var$+"[5]") == 1)
							donpcevent "gard"+.@num+"#"+strnpcinfo(4)+"::OnEnable";
						end;
					}
				}
			}
			else {
				mes "^3355FFAfter all of that work...";
				mes "It looks like you failed";
				mes "to fix the Guardian Stone,";
				mes "and lost some materials.^000000";
				delitem 7049,10; //Stone
				delitem 717,2; //Blue_Gemstone
				delitem 715,2; //Yellow_Gemstone
				delitem 716,2; //Red_Gemstone
				close;
			}
		}
		else {
			mes "^3355FFYou don't have enough";
			mes "materials to repair";
			mes "the Guardian Stone.^000000";
			close;
		}
	}
	end;

OnInit:
OnDisable:
	disablenpc strnpcinfo(0);
	end;

OnEnable:
	enablenpc strnpcinfo(0);
	specialeffect EF_MAPPILLAR2;
	end;
}

// Control Devices (3)
//============================================================
-	script	Control#template	-1,{
	set .@GID, getcastledata(strnpcinfo(4),1);
	set .@num, atoi(charat(strnpcinfo(1),15));
	set .@var$,"$agit_"+strnpcinfo(2);
	if (getcharid(2) == .@GID) {
		if (strcharinfo(0) == getguildmaster(.@GID)) {
			if (getd(.@var$+"["+(.@num+1)+"]") == 2) {
				mes "^3355FFDemolished Fortress";
				mes "Gates can be repaired,";
				mes "but you will need to gather";
				mes "the following materials.^000000";
				next;
				mes "^4D4DFF10 Steel^000000,";
				mes "^4D4DFF30 Trunks^000000,";
				mes "^4D4DFF5 Oridecon^000000, and";
				mes "^4D4DFF10 Emveretarcon^000000.";
				next;
				select("Continue");
				if ((countitem(1019) > 29) && (countitem(999) > 9) && (countitem(1011) > 9) && (countitem(984) > 4)) {
					mes "^3355FFYou will need Trunks to";
					mes "repair the support frame,";
					mes "Oridecon to enhance the";
					mes "gate's endurance, and";
					mes "Emveretarcon to basically";
					mes "hold everything together.^000000";
					next;
					set .@ro_of01,rand(10,15);
					while(1) {
						if (.@ro_of02 == .@ro_of01) break;
						else {
							switch(rand(1,4)) {
							case 1:
								mes "^3355FFThe support frame";
								mes "is badly damaged:";
								mes "fixing this part";
								mes "is a top priority.^000000";
								next;
								switch(select("Trunk:Steel:Emveretarcon:Oridecon")) {
								case 1:
									mes "^3355FFThe frame has been";
									mes "reinforced with wood.^000000";
									set .@rp_temp,.@rp_temp+1;
									set .@ro_of02,.@ro_of02+1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 2:
								mes "^3355FFIt looks like the gate's";
								mes "overall endurance needs to";
								mes "be reinforced with something.^000000";
								next;
								switch(select("Trunk:Steel:Emveretarcon:Oridecon")) {
								case 1:
									mes "^3355FFYou tried using wood";
									mes "to reinforce the gate.^000000";
									set .@ro_of02,.@ro_of02+1;
									next;
									break;
								case 2:
									mes "^3355FFYou tried using steel";
									mes "to reinforce the gate, but";
									mes "it's not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou hammered the";
									mes "oridecon: it looks";
									mes "like this will work.^000000";
									set .@rp_temp,.@rp_temp+1;
									set .@ro_of02,.@ro_of02+1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								}
								break;
							case 3:
								mes "^3355FFThe damage to the gate";
								mes "has caused all these";
								mes "cracks. You'll have to";
								mes "weld them solid somehow.^000000";
								next;
								switch(select("Trunk:Steel:Emveretarcon:Oridecon")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou used steel to weld";
									mes "all the cracks: the gate is";
									mes "is starting to look more solid.^000000";
									set .@rp_temp,.@rp_temp+1;
									set .@ro_of02,.@ro_of02+1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 3:
									mes "^3355FFYou tried using emveretarcon";
									mes "to reinforce the gate, but it's";
									mes "not working well at all.";
									mes "You'll have to start over.^000000";
									close;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
								break;
							case 4:
								mes "^3355FFNow you need to make";
								mes "sure that the gate is held";
								mes "together pretty solidly.^000000";
								next;
								switch(select("Trunk:Steel:Emveretarcon:Oridecon")) {
								case 1:
									mes "^3355FFYou tried using wood to fix";
									mes "this problem, but it seems";
									mes "to have made it worse.";
									mes "You'll have to start all over.^000000";
									close;
								case 2:
									mes "^3355FFYou tried using steel,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								case 3:
									mes "^3355FFYou successfully used";
									mes "the emveretarcon to repair";
									mes "much of the gate's damage.^000000";
									set .@rp_temp,.@rp_temp+1;
									set .@ro_of02,.@ro_of02+1;
									specialeffect2 EF_REPAIRWEAPON;
									next;
									break;
								case 4:
									mes "^3355FFYou tried using oridecon,";
									mes "but it's not working very";
									mes "well. You'll have to try";
									mes "something else.^000000";
									close;
								}
							}
						}
					}
					mes "^3355FFWell, it looks like";
					mes "you're just about done";
					mes "with repairing the gate.^000000";
					next;
					if (!agitcheck2()) {
						mes "^3355FFUnfortunately, the Fortress";
						mes "Gate can't be reconstructed:";
						mes "the Emperium is no longer here.^000000";
						close;
					}
					else {
						if (.@rp_temp == .@ro_of01) {
							mes "^3355FFThe Fortress Gate has";
							mes "been successfully repaired!^000000";
							delitem 1019,30; //Wooden_Block
							delitem 999,10; //Steel
							delitem 1011,10; //Emveretarcon
							delitem 984,5; //Oridecon
							close2;
							donpcevent "RL"+.@num+"#"+strnpcinfo(4)+"::OnEnable";
							disablenpc strnpcinfo(0);
							if (.@num == 1) set .@str$,"1st";
							else if (.@num == 2) set .@str$,"2nd";
							else if (.@num == 3) set .@str$,"3rd";
							mapannounce strnpcinfo(4),"The "+.@str$+" Fortress Gate has been reconstructed!",bc_map,"0x00ff00";
							if (.@num == 1) setd .@var$+"[2]",0;
							else {
								setarray getd(.@var$+"["+.@num+"]"),2,0;
								donpcevent "Control Device0"+(.@num-1)+"#"+strnpcinfo(2)+"::OnEnable";
							}
							end;
						}
						else {
							mes "^3355FFThe wall has been breached,";
							mes "and the attempt to repair the";
							mes "Fortress Gate has failed.";
							mes "You lost some of your";
							mes "repair resources...^000000";
							delitem 984,2; //Oridecon
							delitem 999,4; //Steel
							delitem 1019,14; //Wooden_Block
							delitem 1011,3; //Emveretarcon
							close;
						}
					}
				}
				else {
					mes "^3355FFYou can't attempt to repair";
					mes "the Fortress Gate if you don't";
					mes "have all the needed materials.^000000";
					close;
				}
			}
		}
	}
	end;

OnInit:
OnDisable:
	disablenpc strnpcinfo(0);
	end;

OnEnable:
	enablenpc strnpcinfo(0);
	end;
}

// Guardian Summoners (2)
//============================================================
-	script	gard#template	-1,{
OnEnable:
	// .@x[i],.@y[i]: Normal coordinates, #0-21.
	// .@w[x],.@w[y]: Special coordinates if 'defence' is under 11.
	if (compare(strnpcinfo(2),"arug")) {
		if (strnpcinfo(2) == "arug_cas01") {
			setarray .@w[0],195,250,292,188;
			setarray .x[0],233,252,232,201,224,196,269,252,201,224,222, 294,256,240,246,235,235,246,240,256,254,242;
			setarray .y[0], 83, 81,108,130,168,137, 89, 81,130,168,129, 210,203,133, 92,132,132, 92,133,203, 95,151;
		}
		else if (strnpcinfo(2) == "arug_cas02") {
			setarray .@w[0],20,169,268,169;
			setarray .x[0],104,67,67,113,122,67, 90, 91,122, 20,67, 175,204,211,209,161,186,183,150,161,209,211;
			setarray .y[0], 32,36,85, 87,112,60,167,119,112,169,85,  31, 32, 63, 88, 91,170,121,110, 91, 88, 63;
		}
		else {	// Castles 3,4,5 are identical.
			setarray .@w[0],66,157,211,159;
			setarray .x[0],130,128,128,128,110,91,65, 65,110,128,128, 156,172,154,156,155,187,212,211,155,156,172;
			setarray .y[0], 60, 77, 90,100, 96,53,71,103, 96,100, 77, 101, 95, 90, 77, 60, 54, 67,105, 60, 77, 95;
		}
	}
	else {
		if (strnpcinfo(2) == "schg_cas02") {
			setarray .@w[0],337,95,307,222;
			setarray .x[0],326,337,334,296,285,236,285,296,334,337,334, 359,300,337,317,307,300,337,317,307,359,236;
			setarray .y[0], 83, 95,119, 82, 40, 41, 40, 82,119, 95,119,  85,119,154,183,222,119,154,183,222, 85, 41;
		}
		else if (strnpcinfo(2) == "schg_cas03") {
			setarray .@w[0],306,325,364,305;
			setarray .x[0],323,273,288,306,323,323,273,288,306,273,273, 338,364,365,317,338,338,364,365,317,364,329;
			setarray .y[0],308,309,306,326,308,308,309,306,325,309,309, 309,305,261,318,310,309,305,261,318,305,314;
		}
		else {	// Castles 1,4,5 are identical.
			setarray .@w[0],108,32,128,42,187,15;	// Contains an extra pair, for whatever reason.
			setarray .x[0],111,109,65,110,88,64,47,109,111,112,120, 130,129,151,187,128,152,187,128,130,130,151;
			setarray .y[0], 18, 44,22, 40,20,40,43, 48, 18, 32, 37,  22, 47, 18, 15, 42, 43, 15, 42, 22, 28, 18;
		}
	}
	if (charat(strnpcinfo(1),4) == "2") set .@z,11;
	freeloop(1);
	set .@defence,getcastledata(strnpcinfo(2),3);
	callsub OnSummon,.@z;
	if (.@defence > 70) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),5;
	else if (.@defence > 50) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),4;
	else if (.@defence > 30) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),3;
	else if (.@defence > 10) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),2;
	if (.@w[4] && .@z)
		guardian strnpcinfo(2),.@w[4],.@w[5],"Guardian Soldier",1899,strnpcinfo(0)+"::OnGuardianDied";
	else if (.@defence < 11) {
		set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),2;
		set .@i,(.@z)?2:0;
		guardian strnpcinfo(2),.@w[.@i],.@w[.@i+1],"Guardian Soldier",1899,strnpcinfo(0)+"::OnGuardianDied";
	}
	else for(set .@i,1; .@i<getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)); set .@i,.@i+1)
		callsub OnSummon,.@i+.@z;
	freeloop(0);
	copyarray getd(".x_"+strnpcinfo(2)+"[0]"),.@x[0],22;
	copyarray getd(".y_"+strnpcinfo(2)+"[0]"),.@y[0],22;
	setd ".timer_"+charat(strnpcinfo(1),4)+strnpcinfo(2),4+.@z;
	setarray .count$[5],"1st","2nd","3rd","4th","5th";
	initnpctimer;
	end;

OnTimer300000:
OnTimer900000:
OnTimer1800000:
OnTimer2700000:
OnTimer3600000:
	if (charat(strnpcinfo(1),4) == "2") end;
	set .@var$,".timer_"+charat(strnpcinfo(1),4)+strnpcinfo(2);
	setd .@var$, getd(.@var$)+1;
	set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2))+1;
	callsub OnSummon,getd(.@var$);
	setarray .count$[5],"1st","2nd","3rd","4th","5th";
	mapannounce strnpcinfo(2),"The "+.count$[getd(.@var$)]+" Guardian has been summoned from the Gate House.",bc_map,"0xff4500";
	if (getd(.@var$) == 9) {
		setd .@var$,0;
		stopnpctimer;
	}
	end;

OnTimer600000:
OnTimer1200000:
OnTimer2100000:
OnTimer3000000:
OnTimer3900000:
	if (!(charat(strnpcinfo(1),4) == "2")) end;
	set .@var$,".timer_"+charat(strnpcinfo(1),4)+strnpcinfo(2);
	setd .@var$, getd(.@var$)+1;
	set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2))+1;
	callsub OnSummon,getd(.@var$);
	if (getd(.@var$) == 20) {
		setd .@var$,0;
		stopnpctimer;
	}
	end;

OnSummon:
	guardian strnpcinfo(2),getd(".x_"+strnpcinfo(2)+"["+getarg(0)+"]"),getd(".y_"+strnpcinfo(2)+"["+getarg(0)+"]"),"Guardian Soldier",1899,strnpcinfo(0)+"::OnGuardianDied";
	return;

OnGuardianDied:
	if (charat(strnpcinfo(1),4) == "2") set .@z,11;
	set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2))-1;
	if (getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)) < 2) {
		set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2))+1;
		callsub OnSummon,10+.@z;
	}
	end;

OnReset:
	stopnpctimer;
	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnGuardianDied";
	deletearray getd(".x_"+strnpcinfo(2)+"[0]"),22;
	deletearray getd(".y_"+strnpcinfo(2)+"[0]"),22;
	end;
}

// Guardian Stone Summoners (2)
//============================================================
-	script	df#template	-1,{
OnEnable:
	if (compare(strnpcinfo(2),"arug")) {
		if (strnpcinfo(2) == "arug_cas01") setarray .@i[0],210,234,308,189;
		else if (strnpcinfo(2) == "arug_cas02") setarray .@i[0],33,168,245,168;
		else setarray .@i[0],65,171,212,149;	// Castles 3,4,5 are identical.
	}
	else {
		if (strnpcinfo(2) == "schg_cas02") setarray .@i[0],231,58,335,230;
		else if (strnpcinfo(2) == "schg_cas03") setarray .@i[0],242,309,376,251;
		else setarray .@i[0],27,35,207,75;	// Castles 1,4,5 are identical.
	}
	set .@num, atoi(charat(strnpcinfo(1),2));
	set .@j,(.@num == 1)?0:2;
	guardian strnpcinfo(2),.@i[.@j],.@i[.@j+1],((.@num == 1)?"1st":"2nd")+" Guardian Stone",1906+.@num,strnpcinfo(0)+"::OnGuardianStoneDied";
	end;

OnDisable:
	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnGuardianStoneDied";
	setd "$agit_"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"["+(atoi(charat(strnpcinfo(1),2))-1)+"]",1;
	stopnpctimer;
	end;

OnGuardianStoneDied:
	set .@num, atoi(charat(strnpcinfo(1),2));
	set .@var$,"$agit_"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
	setd .@var$+"["+(.@num-1)+"]",1;
	if (getd(.@var$+"[0]") == 1 || getd(.@var$+"[0]") == 2) set .@destroyed, .@destroyed+1;
	if (getd(.@var$+"[1]") == 1 || getd(.@var$+"[1]") == 2) set .@destroyed, .@destroyed+1;
	if (.@destroyed == 2) {
		mapannounce strnpcinfo(2),"All of the Guardian Stones have been destroyed!",bc_map,"0x00ff00";
		donpcevent "RL0#"+strnpcinfo(2)+"::OnDisable";
	}
	else mapannounce strnpcinfo(2),"The "+((.@num == 1)?"1st":"2nd")+" Guardian Stone has been destroyed!",bc_map,"0x00ff00";
	donpcevent "gard"+.@num+"#"+strnpcinfo(2)+"::OnReset";
	initnpctimer;
	end;

OnTimer300000:
	set .@str$,substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
	donpcevent "1st Guardian Stone#"+.@str$+"::OnEnable";
	setd "$agit_"+.@str$+"["+(atoi(charat(strnpcinfo(1),2))-1)+"]",2;
	stopnpctimer;
	end;
}

// Barrier Summoners (4)
//============================================================
-	script	RL#template	-1,{
OnEnable:
	set .@num, atoi(charat(strnpcinfo(1),2));
	if (.@num == 0) {
		if (compare(strnpcinfo(2),"arug")) {
			if (strnpcinfo(2) == "arug_cas01") {
				setarray .@wall[0],238,74,8,6,0;
				setarray .@x[0],239,241,243,245;
				setarray .@y[0], 73, 73, 73, 73;
			}
			else if (strnpcinfo(2) == "arug_cas02") {
				setarray .@wall[0],136,136,8,6,0;
				setarray .@x[0],137,139,141,143;
				setarray .@y[0],137,137,137,137;
			}
			else {	// Castles 3,4,5 are identical.
				setarray .@wall[0],138,110,8,6,0;
				setarray .@x[0],139,141,143,145;
				setarray .@y[0],111,111,111,111;
			}
		}
		else {
			if (strnpcinfo(2) == "schg_cas02") {
				setarray .@wall[0],290,98,8,0,0;
				setarray .@x[0],289,289,289,289;
				setarray .@y[0], 98,100,102,104;
			}
			else if (strnpcinfo(2) == "schg_cas03") {
				setarray .@wall[0],326,301,6,6,0;
				setarray .@x[0],326,328,330;
				setarray .@y[0],300,300,300;
			}
			else {	// Castles 1,4,5 are identical.
				setarray .@wall[0],114,48,13,6,0;
				setarray .@x[0],115,117,119,121,123,125;
				setarray .@y[0], 49, 49, 49, 49, 49, 49;
			}
		}
	}
	else if (.@num == 1) {
		if (compare(strnpcinfo(2),"arug")) {
			if (strnpcinfo(2) == "arug_cas01") {
				setarray .@wall[0],239,53,8,6,1;
				setarray .@x[0],239,241,243,240,242,244;
				setarray .@y[0], 55, 55, 55, 54, 54, 54;
			}
			else if (strnpcinfo(2) == "arug_cas02") {
				setarray .@wall[0],150,223,12,6,1;
				setarray .@x[0],151,153,155,157,159,161;
				setarray .@y[0],222,222,222,222,222,222;
			}
			else {	// Castles 3,4,5 are identical.
				setarray .@wall[0],139,158,6,6,1;
				setarray .@x[0],140,142,144,139,141,143;
				setarray .@y[0],157,157,157,156,156,156;
			}
		}
		else {
			if (strnpcinfo(2) == "schg_cas02") {
				setarray .@wall[0],279,98,8,0,1;
				setarray .@x[0],280,280,280,281,281,281;
				setarray .@y[0], 98,100,102, 99,101,103;
			}
			else if (strnpcinfo(2) == "schg_cas03") {
				setarray .@wall[0],325,277,8,6,1;
				setarray .@x[0],326,328,330,327,329,331;
				setarray .@y[0],278,278,278,279,279,279;
			}
			else {	// Castles 1,4,5 are identical.
				setarray .@wall[0],114,51,13,6,1;
				setarray .@x[0],115,117,119,121,123,125;
				setarray .@y[0], 50, 50, 50, 50, 50, 50;
			}
		}
	}
	else if (.@num == 2) {
		if (compare(strnpcinfo(2),"arug")) {
			if (strnpcinfo(2) == "arug_cas01") {
				setarray .@wall[0],107,124,6,6,1;
				setarray .@x[0],107,109,111,108,110,112;
				setarray .@y[0],122,122,122,123,123,123;
			}
			else if (strnpcinfo(2) == "arug_cas02") {
				setarray .@wall[0],125,342,8,0,1;
				setarray .@x[0],126,126,126,127,127,127;
				setarray .@y[0],343,345,347,344,346,348;
			}
			else {	// Castles 3,4,5 are identical.
				setarray .@wall[0],138,210,8,6,1;
				setarray .@x[0],140,142,144,139,141,143;
				setarray .@y[0],209,209,209,208,208,208;
			}
		}
		else {
			if (strnpcinfo(2) == "schg_cas02") {
				setarray .@wall[0],230,213,6,0,1;
				setarray .@x[0],231,231,231,232,232,232;
				setarray .@y[0],214,216,218,213,215,217;
			}
			else if (strnpcinfo(2) == "schg_cas03") {
				setarray .@wall[0],200,230,8,0,1;
				setarray .@x[0],201,201,201,202,202,202;
				setarray .@y[0],231,233,235,232,234,236;
			}
			else {	// Castles 1,4,5 are identical.
				setarray .@wall[0],114,154,13,6,1;
				setarray .@x[0],115,117,119,121,123,125;
				setarray .@y[0],153,153,153,153,153,153;
			}
		}
	}
	else {
		if (compare(strnpcinfo(2),"arug")) {
			if (strnpcinfo(2) == "arug_cas01") {
				setarray .@wall[0],84,171,8,6,1;
				setarray .@x[0], 84, 86, 88, 90;
				setarray .@y[0],170,170,170,170;
			}
			else if (strnpcinfo(2) == "arug_cas02") {
				setarray .@wall[0],38,314,12,6,1;
				setarray .@x[0], 40, 42, 44, 46;
				setarray .@y[0],315,315,315,315;
			}
			else {	// Castles 3,4,5 are identical.
				setarray .@wall[0],138,263,8,6,1;
				setarray .@x[0],139,141,143,145;
				setarray .@y[0],262,262,262,262;
			}
		}
		else {
			if (strnpcinfo(2) == "schg_cas02") {
				setarray .@wall[0],160,141,6,6,1;
				setarray .@x[0],160,162,164,166;
				setarray .@y[0],140,140,140,140;
			}
			else if (strnpcinfo(2) == "schg_cas03") {
				setarray .@wall[0],285,198,8,0,1;
				setarray .@x[0],284,284,284,284;
				setarray .@y[0],199,201,203,205;
			}
			else {	// Castles 1,4,5 are identical.
				setarray .@wall[0],116,241,11,6,1;
				setarray .@x[0],116,118,120,122;
				setarray .@y[0],240,240,240,240;
			}
		}
	}
	if (.@num == 3) set getd(".MyMobCount_"+.@num+strnpcinfo(2)),4;
	else if (.@num) set getd(".MyMobCount_"+.@num+strnpcinfo(2)),6;
	setwall strnpcinfo(2),.@wall[0],.@wall[1],.@wall[2],.@wall[3],.@wall[4],substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"_"+strnpcinfo(1);
	set .@j,(getd(".MyMobCount_"+.@num+strnpcinfo(2)))?getd(".MyMobCount_"+.@num+strnpcinfo(2)):getarraysize(.@x);
	for(set .@i,0; .@i<.@j; set .@i,.@i+1)
		guardian strnpcinfo(2),.@x[.@i],.@y[.@i]," ",1905,strnpcinfo(0)+"::OnBarrierDestroyed";
	end;

OnBarrierDestroyed:
	set .@num, atoi(charat(strnpcinfo(1),2));
	if (!.@num) end;
	set getd(".MyMobCount_"+.@num+strnpcinfo(2)),getd(".MyMobCount_"+.@num+strnpcinfo(2))-1;
	if (getd(".MyMobCount_"+.@num+strnpcinfo(2)) == 0) {
		set .@var$,substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
		setd "$agit_"+.@var$+"["+(.@num+1)+"]",1;
		setarray .@count$[0],"1st","2nd","3rd";
		mapannounce strnpcinfo(2),"The "+.@count$[.@num-1]+" Fortress Gate is destroyed.",bc_map,"0x00ff00";
		delwall .@var$+"_"+strnpcinfo(1);
	}
	end;

OnDisable:
	delwall substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"_"+strnpcinfo(1);
	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnBarrierDestroyed";
	end;
}

// Link Flags (function)
//============================================================
function	script	LinkFlag	{
	if (!getcharid(2) || getcharid(2) != getcastledata(strnpcinfo(4),1)) end;
	if (getarg(0) == "Convenience Facility") {
		mes "^3355FFThis is the Stronghold";
		mes "Teleport Service. Would";
		mes "you like to teleport to the";
		mes "Convenience Facility for";
		mes "guild members?^000000";
		if(select("Go to Convenience Facility:Cancel") == 1)
			warp strnpcinfo(4),getarg(1),getarg(2);
		close;
	}
	if (getarg(0) == "Emperium Center") {
		mes "^3355FFThis is the Stronghold";
		mes "Teleport Service. Would";
		mes "you like to teleport to";
		mes "the Emperium Center?^000000";
		if(select("Teleport:Cancel") == 1)
			warp strnpcinfo(4),getarg(1),getarg(2);
		close;
	}
	mes "^3355FFThis is the Stronghold";
	mes "Teleport Service. Please";
	mes "choose a destination";
	mes "within the stronghold.^000000";
	for(set .@i,0; .@i<getargcount(); set .@i,.@i+3)
		set .@menu$, .@menu$+getarg(.@i)+":";
	set .@menu$, .@menu$+"Cancel";
	set .@i, select(.@menu$)-1;
	if (.@i != getargcount()/3)
		warp strnpcinfo(4),getarg(.@i*3+1),getarg(.@i*3+2);
	close;
}

// Return Flags (function)
//============================================================
function	script	ReturnFlag	{
	set .@str$, (compare(strnpcinfo(4),"aru"))?"Arunafeltz":"Schwaltzvalt";
	set .@GID, getcastledata(getarg(0),1);
	if (!.@GID) {
		mes "[ "+.@str$+" Royal Edict ]";
		mes "The Holy Kingdom of";
		mes .@str$+" declares that";
		mes "one has yet to claim lordship";
		mes "over this stronghold. The one";
		mes "that breaks the Emperium will";
		mes "be recognized as its new owner.";
		close;
	}
	if (getcharid(2) == .@GID && getarg(1,0)) {
		mes "[ Ringing Voice ]";
		mes "Courageous one,";
		mes "do you wish to return";
		mes "to your stronghold?";
		next;
		if(select("Return to the Stronghold:Cancel") == 1 && getcharid(2) == getcastledata(getarg(0),1)) {
			if (compare(getarg(0),"arug")) {
				if (getarg(0) == "arug_cas01") setarray .@i[0],67,193;
				else if (getarg(0) == "arug_cas02") setarray .@i[0],43,256;
				else setarray .@i[0],121,318;	// Castles 3,4,5 are identical.
			}
			else {
				if (getarg(0) == "schg_cas02") setarray .@i[0],136,188;
				else if (getarg(0) == "schg_cas03") setarray .@i[0],308,202;
				else setarray .@i[0],120,290;	// Castles 1,4,5 are identical.
			}
			warp getarg(0),.@i[0],.@i[1];
		}
		close;
	}
	mes "[ "+.@str$+" Royal Edict ]";
	mes "The Holy Kingdom of";
	mes .@str$+" decrees that";
	mes "this stronghold is owned";
	mes "by the ^FF0000"+getguildname(.@GID)+"^000000 Guild.";
	next;
	mes "[ "+.@str$+" Royal Edict ]";
	mes "^FF0000"+getguildmaster(.@GID)+"^000000 is";
	mes "Guild Master of ^FF0000"+getguildname(.@GID)+"^000000.";
	mes "Any that object must claim this";
	mes "stronghold through strength of";
	mes "steel and magic during the";
	mes "appointed Guild Siege times.";
	close;
}

// Treasure Room Switches
//============================================================
-	script	Switch#template	-1,{
	mes " ";
	mes "^3355FFWill you pull";
	mes "this small lever?^000000";
	next;
	if(select("Pull Lever:Cancel") == 2) close;
	if (compare(strnpcinfo(4),"arug")) {
		if (strnpcinfo(4) == "arug_cas01") setarray .@i[0],121,357;
		else if (strnpcinfo(4) == "arug_cas02") setarray .@i[0],387,323;
		else setarray .@i[0],321,57;	// Castles 3,4,5 are identical.
	}
	else {
		if (strnpcinfo(4) == "schg_cas02") setarray .@i[0],339,79;
		else if (strnpcinfo(4) == "schg_cas03") setarray .@i[0],57,13;
		else setarray .@i[0],275,244;	// Castles 1,4,5 are identical.
	}
	warp strnpcinfo(4),.@i[0],.@i[1];
	close;
}

// Guild Dungeon Warps
//============================================================
-	script	Sunflower#template	-1,{
	if (getcharid(2) == getcastledata(strnpcinfo(4),1)) {
		mes "- It's an amazingly huge sunflower; as big as a human! ... You feel something mysterious emanating from the flower. -";
		next;
		switch(select("Hold the stem.:Do nothing.")) {
		case 1:
			if (compare(strnpcinfo(4),"arug")) {
				set .@map$,"arug_dun01";
				setarray .@mapx[0],350,350,50, 50,200;
				setarray .@mapy[0],350, 50,50,350,386;
			}
			else {
				set .@map$,"schg_dun01";
				setarray .@mapx[0],262, 94, 79,212,322;
				setarray .@mapy[0],314,284,140, 70,166;
			}
			set .@i, atoi(charat(strnpcinfo(4),9))-1;
			warp .@map$,.@mapx[.@i],.@mapy[.@i];
			close;
		case 2:
			mes "It's too scary to touch unknown things.";
			close;
		}
	}
}