hxp
3 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
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
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#
#---------------------------------------------------------------------
##@package QuestManager
#Íæ¼ÒÈÎÎñ¹ÜÀíÆ÷
#
# @author eggxp
# @date 2010-4-26ÏÂÎç02:07:26
# @version 2.8
 
#---------------------------------------------------------------------
"""Version = 2015-03-31 02:50"""
#---------------------------------------------------------------------
import IPY_GameWorld
import GameWorld
import ChConfig
import os
import QuestCommon
import SubjectLib
import zipfile
import ReadChConfig
#import traceback
#import EventShell
#---------------------------------------------------------------------
ZipFile = None
ZipFileTree = None
 
#---------------------------------------------------------------------
##»ñÈ¡ZIPÊý¾Ý
# @param ÎÞ
# @return ·µ»ØÖµ, ZIPÊý¾Ý
# @remarks »ñÈ¡ZIPÊý¾Ý
def __GetZipFile():
    return ZipFile
 
#---------------------------------------------------------------------
##»ñÈ¡ZIPÊý¾ÝÊ÷
# @param ÎÞ
# @return ·µ»ØÖµ, ZIPÊý¾ÝÊ÷
# @remarks »ñÈ¡ZIPÊý¾ÝÊ÷
def __GetZipFileTree():
    return ZipFileTree
 
## ZIPÊý¾ÝÀàÐÍÈÝÆ÷
#
#  PyClassÀàµÄÏêϸ˵Ã÷.
class ZipFileType:
    ## ÈÝÆ÷Êý¾Ý°üº¬, FileName = '', FileType = 0, SubDir = {}
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ÈÝÆ÷Êý¾Ý°üº¬, FileName = '', FileType = 0, SubDir = {}
    def __init__(self):
        self.FileName = ''
        self.FileType = 0        #0: File    1: Dir
        self.SubDir = {}
 
#---------------------------------------------------------------------
##»ñµÃÎļþÊ÷
# @param curZipFile ZIPÎļþ°ü
# @return ·µ»ØÖµ, ÎļþÊ÷
# @remarks »ñµÃÎļþÊ÷
def __GetFileTree(curZipFile):
    fileDict = ZipFileType()
    nameList = curZipFile.namelist()
    for name in nameList:
        name = name.upper()
        curFileSplit = name.split('/')
        fileSplitLen = len(curFileSplit)
        
        fileName = curFileSplit[fileSplitLen-1]
        if fileName == '':
            #No File
            #print name
            continue
        
        del curFileSplit[fileSplitLen-1]
        curEnterDir = fileDict
        for dir in curFileSplit:
            if curEnterDir.SubDir.has_key(dir) == False:
                curZipFileType = ZipFileType()
                curZipFileType.FileName = dir
                curZipFileType.FileType = 1
                curEnterDir.SubDir[dir] = curZipFileType
            
            curEnterDir = curEnterDir.SubDir[dir]
 
        curFile = ZipFileType()
        curFile.FileName = fileName
        curFile.FileType = 0
        curFile.SubDir = None
        curEnterDir.SubDir[fileName] = curFile
        
    return fileDict
 
#---------------------------------------------------------------------
##»ñµÃÎļþ½Úµã
# @param inputDir ÊäÈë·¾¶
# @return ·µ»ØÖµ, Îļþ½Úµã
# @remarks »ñµÃÎļþ½Úµã
def __GetZipFileNode(inputDir):
    curFileDir = inputDir.split('\\')
    lencurFileDir = len(curFileDir)
    if lencurFileDir == 0:
        return
    
    fileTree = __GetZipFileTree()
    curFileNode = fileTree
    
    if curFileDir[lencurFileDir - 1].strip() == '':
        del curFileDir[lencurFileDir - 1]
    
    for file in curFileDir:
        if not curFileNode.SubDir.has_key(file):
            return 
        curFileNode = curFileNode.SubDir[file]
    
    return curFileNode
 
#---------------------------------------------------------------------
##ÅжÏ·¾¶ÊÇ·ñÊÇĿ¼
# @param inputDir ÊäÈë·¾¶
# @return ·µ»ØÖµÕæ, ÊÇĿ¼
# @remarks ÅжÏ·¾¶ÊÇ·ñÊÇĿ¼
def ZipFile_IsDir(inputDir):
    inputDir = inputDir.upper()
    result = __GetZipFileNode(inputDir)
    if result == None:
        return False
    
    if result.FileType != 1:
        return False
    
    return True
 
#---------------------------------------------------------------------
##ÅжÏ·¾¶ÊÇ·ñÊÇÎļþ
# @param inputDir ÊäÈë·¾¶
# @return ·µ»ØÖµÕæ, ÊÇÎļþ
# @remarks ÅжÏ·¾¶ÊÇ·ñÊÇÎļþ
def ZipFile_IsFile(inputDir):
    inputDir = inputDir.upper()
    result = __GetZipFileNode(inputDir)
    if result == None:
        return False
    
    if result.FileType != 0:
        return False
    
    return True
 
#---------------------------------------------------------------------
##»ñȡĿ¼Áбí
# @param inputDir ÊäÈë·¾¶
# @return ·µ»ØÖµ, Ä¿Â¼Áбí
# @remarks »ñȡĿ¼Áбí
def ZipFile_ListDir(inputDir):
    inputDir = inputDir.upper()
    resultNode = __GetZipFileNode(inputDir)
    curDir = []
    if resultNode == None:
        return curDir
    for key in resultNode.SubDir.keys():
        if resultNode.SubDir[key].FileType != 1:
            continue
        curDir.append(resultNode.SubDir[key].FileName)
    return curDir
 
#---------------------------------------------------------------------
##»ñÈ¡ÎļþÁбí
# @param inputDir ÊäÈë·¾¶
# @return ·µ»ØÖµ, ÎļþÁбí
# @remarks »ñÈ¡ÎļþÁбí
def ZipFile_ListFile(inputDir):
    inputDir = inputDir.upper()
    resultNode = __GetZipFileNode(inputDir)
    curDir = []
    if resultNode == None:
        return curDir
    for key in resultNode.SubDir.keys():
        if resultNode.SubDir[key].FileType != 0:
            continue
        curDir.append(resultNode.SubDir[key].FileName)
    return curDir
 
#---------------------------------------------------------------------
##»ñÈ¡ÎļþÁбí
# @param result ÎļþÁбí
# @param curNode µ±Ç°½Úµã
# @param fileSource Îļþ·¾¶
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks »ñÈ¡ÎļþÁбí
def __GetZipFileList(result, curNode, fileSource):
    for key in curNode.SubDir.keys():
        curFileName = os.path.join(fileSource, curNode.SubDir[key].FileName)
        if curNode.SubDir[key].FileType != 0:
            __GetZipFileList(result, curNode.SubDir[key], curFileName)
            continue
        result.append(curFileName.lower())
 
#---------------------------------------------------------------------
##»ñȡ·¾¶ÏµÄÎļþÁбí
# @param inputDir ÊäÈëµÄ·¾¶
# @return ·µ»ØÖµ,ÎļþÁбí
# @remarks »ñȡ·¾¶ÏµÄÎļþÁбí
def ZipFile_Walk(inputDir):
    inputDir = inputDir.upper()
    resultNode = __GetZipFileNode(inputDir)
    result = []
    if resultNode == None:
        return result
    __GetZipFileList(result, resultNode, inputDir)
    return result
 
#---------------------------------------------------------------------
##ÎļþÊý¾Ý
# @param inputDir ÊäÈëµÄ·¾¶
# @return ·µ»ØÖµ, ÎļþÊý¾Ý
# @remarks ÎļþÊý¾Ý
def ZipFile_GetData(inputDir):
    inputDir = inputDir.upper()
    zipFile = __GetZipFile()
    inputDir = inputDir.replace('\\', '/')
    #GameWorld.Log('read : %s'%inputDir)
#    try:
    data = zipFile.read(inputDir)
    return data
#    except BaseException:
#        GameWorld.Log("Can't Find Dir : %s"%inputDir)
#        GameWorld.Log(traceback.format_exc())
#        raise ("Read Error")
    
 
#---------------------------------------------------------------------
 
#Ŀ¼
#-QuestData
# -Quests
#  +on_visit
#  +on_kill
 
#ÈÎÎñÊý¾Ý
Quests = {}     #Type = MainQuestData
DefaultTalk = {} #Type = DefaultTalkData        Ä¬È϶Ի°Êý¾Ý Type = IPY_GameWorld.IPY_XMLLoader()
AllQuestsEvents={}   #Type = list()             list type = (missID, MainQuestEventData)     
FunctionNPCTalk = {}    #Type = FunctionNPCTalkData
QuestTrig = {}  #Type = list()          listÖеÄType = QuestTrigData           ÈÎÎñ´¥·¢Êý¾Ý
QuestDescriptions = {}          #Type = QuestDescriptionsData
 
#---------------------------------------------------------------------
##°´°æ±¾»ñµÃÈÎÎñ¶ÁÈ¡µÄÃû×Ö
# @param ÎÞ
# @return ·µ»ØÖµ, ÈÎÎñ°æ±¾Ãû
# @remarks °´°æ±¾»ñµÃÈÎÎñ¶ÁÈ¡µÄÃû×Ö
def GetQuestDataName():
    return "QuestData"
 
#---------------------------------------------------------------------
##»ñÈ¡ÈÎÎñ·¾¶
# @param ÎÞ
# @return ·µ»ØÖµ, ÈÎÎñ·¾¶
# @remarks »ñÈ¡ÈÎÎñ·¾¶
def GetQuestPath():
    return "%s\\Quests"%GetQuestDataName()
 
#Ŀǰ²»ÄÜ×ö»º´æ, Ô­Òò:
#¶Ô»°ÖлáÓÐSetCurrentQuestNode²Ù×÷, Èç¹ûÊÍ·ÅÁË, »áµ¼Ö¿¨×¡
LoadQuestLen = 5000      #×î´ó¶ÁÈ¡µÄxmlÎļþ¸öÊý
FreeQuestCount = 10     #Ò»´ÎÊÍ·Å10¸öxml
 
#---------------------------------------------------------------------
##²éÕÒNPCĬÈ϶Ի°
# @param npcID NPCID
# @return ·µ»ØÖµ, XMLÊý¾Ý
# @remarks ²éÕÒNPCĬÈ϶Ի°
def FindDefaultTalk(npcID):
    global DefaultTalk
    if DefaultTalk.has_key(npcID):
        return DefaultTalk[npcID]
    
    filePath = "%s\\default_talk"%GetQuestDataName()
    #µ¼ÈëÕâ¸öÈÎÎñµÄËùÓÐXMLÊý¾Ý    
    filePath = os.path.join(filePath, '%s.xml'%npcID)
    
    if not ZipFile_IsFile(filePath):
        return
    
    xmlLoader = IPY_GameWorld.IPY_XMLLoader()
    #xmlLoader.LoadFromFile(filePath)
    xmlLoader.LoadFromXML(filePath, ZipFile_GetData(filePath))
    DefaultTalk[npcID] = xmlLoader
    return xmlLoader
 
#---------------------------------------------------------------------
##ÈÎÎñ×ÖµäÅÅÐò¹æÔò
# @param key1 ×Öµä1
# @param key2 ×Öµä2
# @return ·µ»ØÖµ, ÓÅÏȼ¶
# @remarks ÈÎÎñ×ÖµäÅÅÐò¹æÔò
def QuestKeyCmp(key1, key2):
    if key1[1] < key2[1]:
        return 1
    elif key1[1] > key2[1]:
        return -1
    else:
        return 0
 
#---------------------------------------------------------------------
##²éÕÒÈÎÎñÊý¾Ý
# @param questID ÈÎÎñID
# @return ·µ»ØÖµ, ÈÎÎñÊý¾Ý
# @remarks ²éÕÒÈÎÎñÊý¾Ý
def FindQuest(questID):
    #GameWorld.Log(str(questID))
    global Quests
    if Quests.has_key(questID):
        #ÃüÖÐÁË, °ÑÕâ¸öÈÎÎñÌáǰ
        curQuest = Quests[questID]
        curQuest.UseCount += 1
        return curQuest
    
#    if len(Quests) > LoadQuestLen:
#        #ÊÍ·ÅxmlÎļþ
#        curList = []
#        for key in Quests.keys():
#            curList.append((key, Quests[key].UseCount))
#            
#        curList.sort(QuestKeyCmp)
#        
#        for i in range(0, min(FreeQuestCount, len(curList))):
#            #ɾ³ýǰ10¸ökey
#            Quests.pop(curList[i][0])
        
     
    curQuest = MainQuestData()
    LoadQuest(os.path.join(GetQuestPath(), str(questID)), questID, curQuest)
    if curQuest.ID == 0:
        return None
    
    Quests[questID] = curQuest
    return  curQuest
 
#---------------------------------------------------------------------
##»ñÈ¡ÈÎÎñÊý¾Ý
# @param ÎÞ
# @return ·µ»ØÖµ, ÈÎÎñÊý¾Ý
# @remarks »ñÈ¡ÈÎÎñÊý¾Ý
def GetQuests():
    return Quests
 
#---------------------------------------------------------------------
##»ñÈ¡¹¦ÄÜNPC¶Ô»°Êý¾Ý
# @param ÎÞ
# @return ·µ»ØÖµ, ¶Ô»°Êý¾Ý
# @remarks »ñÈ¡¹¦ÄÜNPC¶Ô»°Êý¾Ý
def GetFunctionNPCTalk():
    return FunctionNPCTalk
 
#---------------------------------------------------------------------
##»ñÈ¡ËùÓÐÈÎÎñÊý¾Ý
# @param ÎÞ
# @return ·µ»ØÖµ, ÈÎÎñÊý¾Ý
# @remarks »ñÈ¡ËùÓÐÈÎÎñÊý¾Ý
def GetAllQuestsEvents():
    return AllQuestsEvents
 
#---------------------------------------------------------------------
##»ñÈ¡NPCĬÈ϶Ի°
# @param ÎÞ
# @return ·µ»ØÖµ, NPCĬÈ϶Ի°
# @remarks »ñÈ¡NPCĬÈ϶Ի°
def GetDefaultTalk():
    return DefaultTalk
 
#---------------------------------------------------------------------
##»ñÈ¡ÈÎÎñÌø×ªÊý¾Ý
# @param ÎÞ
# @return ·µ»ØÖµ, ÈÎÎñÌø×ªÊý¾Ý
# @remarks »ñÈ¡ÈÎÎñÌø×ªÊý¾Ý
def GetQuestTrig():
    return QuestTrig
 
#---------------------------------------------------------------------
##»ñÈ¡ÈÎÎñÃèÊö
# @param ÎÞ
# @return ·µ»ØÖµ, ÈÎÎñÃèÊö
# @remarks »ñÈ¡ÈÎÎñÃèÊö
def GetQuestDescriptions():
    return QuestDescriptions
 
## ÈÎÎñÃèÊöÊý¾ÝÀà
#
#  PyClassÀàµÄÏêϸ˵Ã÷.
class QuestDescriptionsData:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, Code = '', ShowReward = 0
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, Code = '', ShowReward = 0
    def __init__(self):
        self.Code = ''
        self.ShowReward = 0
 
#---------------------------------------------------------------------
## ÈÎÎñË÷ÒýÖеÄÒ»¸öʼþ
#
#  PyClassÀàµÄÏêϸ˵Ã÷.
class MainQuestEventData:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, Type = "",Source = "",FileSource = "",XMLEventLoader = None
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, Type = "",Source = "",FileSource = "",XMLEventLoader = None
    def __init__(self):
        self.XMLEventLoader = None
        self.Type = ""
        self.Source = ""
        self.FileSource = ""
    
    #---------------------------------------------------------------------
    ## ¼ÓÔØXMLÊý¾Ý
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ¼ÓÔØXMLÊý¾Ý
    def GetXMLEventLoader(self):
        if self.XMLEventLoader:
            return self.XMLEventLoader
        
        #GameWorld.Log("¶ÁÈ¡ÈÎÎñ´¥·¢: %s, %s"%(self.Type, self.Source))
        self.XMLEventLoader = IPY_GameWorld.IPY_XMLLoader() 
        #self.XMLEventLoader.LoadFromFile(self.FileSource)
        self.XMLEventLoader.LoadFromXML(self.FileSource, ZipFile_GetData(self.FileSource))
        return self.XMLEventLoader
 
#---------------------------------------------------------------------
## ÈÎÎñµÆµÄ¶¨Òå
#
#  PyClassÀàµÄÏêϸ˵Ã÷.    
class QuestLight:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, NPCID = 0, Type = 0
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, NPCID = 0, Type = 0
    def __init__(self):
        self.NPCID = 0
        self.Type = 0
 
#---------------------------------------------------------------------
## ÈÎÎñÃèÊöÀà
#
#  PyClassÀàµÄÏêϸ˵Ã÷.
class QuestDescription:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, Msg = "", Info = None, Lights = None, Rewards = None, 
    #                        IsRewardNode = 0, MsgNode = None
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, Msg = "", Info = None, Lights = None, Rewards = None, 
    #                                IsRewardNode = 0, MsgNode = None
    def __init__(self):
        self.Msg = ""
        self.Info = list()      #Type = str()
        self.Lights = list()    #Type = QuestLight
        self.Rewards = None     #Type = list , listType = IPY_XMLNode
        self.IsRewardNode = 0   #ÊÇ·ñÊǽ±Àø½Úµã, (ÈÎÎñÏÔʾΪÍê³É״̬)
        self.MsgNode = None
 
#---------------------------------------------------------------------
## ÍÚ±¦µØµã¶¨Òå
#
#  PyClassÀàµÄÏêϸ˵Ã÷.
class TreasurePos:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, MapID = 0, PosX = 0, PosY = 0
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, MapID = 0, PosX = 0, PosY = 0
    def __init__(self):
        self.MapID = 0
        self.PosX = 0
        self.PosY = 0
 
#---------------------------------------------------------------------
## ÍÚ±¦Ê¼þÊý¾Ý
#
#  PyClassÀàµÄÏêϸ˵Ã÷.
class TreasureData:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, Normal = None, Week = None
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, Normal = None, Week = None
    def __init__(self):
        self.Normal = None  #Type = list()     list Type = TreasurePos
        self.Week = None    #Type = dict() key = µÈ¼¶ dictType = dict() key = ÐÇÆÚ    
                            # dict Type = list()   list Type = TreasurePos
 
#---------------------------------------------------------------------
## Ã¿ÈÕÈÎÎñ½±ÀøÊý¾ÝÀà
#
#  PyClassÀàµÄÏêϸ˵Ã÷.  
class DayEventRewardData:
    ## ³õʼ»¯
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯
    def __init__(self):
        self.Exp = 0             #¾­Ñé²ÎÊý
        self.AddExp = 0          #¾­Ñé
        self.Money = 0           #¸øÇ®
        self.Soul = 0            #¸øÄ§»ê
        self.TruckMoney = 0      #æô³µÑº½ð
        self.Item = ""            #ÎïÆ·½±Àø
        self.PlayerFamilyHornor = 0    #¼Ò×å¹±Ï×
        self.PlayerFamilyActiveValue = 0 #¼Ò×å»îÔ¾¶È
        self.FamilyHomeExp = 0      #¼Ò×å¼ÒÔ°¾­Ñé
        self.FamilyMoney = 0     #¼Ò×å×ʽð
        self.FamilyHornor = 0    #¼Ò×åÈÙÓþ
        self.PetExp = 0    # ³èÎï¾­Ñé
        self.Prestige = 0    # ÍþÍû½±Àø
        self.GoldPaper = 0    # °óÓñ/Áéʯ
        
#---------------------------------------------------------------------
## Ã¿ÈÕÈÎÎñ½±ÀøÊý¾ÝÀ༯ºÏ
#
#  PyClassÀàµÄÏêϸ˵Ã÷.  
class AllDayEventRewardData:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, MinLV, MaxLV, MoneyType, Rewards
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, MinLV, MaxLV, MoneyType, Rewards
    def __init__(self):
        self.MinLV = 0
        self.MaxLV = 0
        self.MoneyType = 0
        self.Rewards = {}        #Type = dict{}       ÀàÐÍ: DayEventRewardData
        
#---------------------------------------------------------------------
## ÅÜ»·ÈÎÎñ½±ÀøÊý¾ÝÀà
#
#  PyClassÀàµÄÏêϸ˵Ã÷. 
class RunAroundRewardData(DayEventRewardData):
    ## ³õʼ»¯
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯
    def __init__(self):
        DayEventRewardData.__init__(self)
 
#---------------------------------------------------------------------
## ÅÜ»·ÈÎÎñ½±ÀøÊý¾ÝÀ༯ºÏ
#
#  PyClassÀàµÄÏêϸ˵Ã÷.  
class AllRunAroundRewardData:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬, MinLV, MaxLV, MoneyType, Rewards
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬, MinLV, MaxLV, MoneyType, Rewards
    def __init__(self):
        self.MinLV = 0
        self.MaxLV = 0
        self.MoneyType = 0
        self.Rewards = {}        #Type = dict{}       ÀàÐÍ: RunAroundRewardData
 
#---------------------------------------------------------------------
## ÈÎÎñË÷ÒýÊý¾Ý, ¶ÔÓ¦ÓÚquests.xml
#
#  PyClassÀàµÄÏêϸ˵Ã÷.  
class MainQuestData:
    ## ³õʼ»¯
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯
    def __init__(self):
        self.ID = 0                           #ÈÎÎñID
        self.Name = ""                        #ÈÎÎñÃû³Æ
        self.Type = 0                         #ÈÎÎñÀàÐÍ
        self.QuestDescriptionList = list()    #Type = QuestDescription ÈÎÎñÃèÊö
        self.NPCID = 0                        #ÆðʼNPCID
        self.LV = 0                           #¿É½ÓµÈ¼¶
        self.MapID = 0                        #µØÍ¼ID
        self.DayCurCount = ""                 #µ±Ç°ÈÎÎñ´ÎÊý
        self.DayMaxCount = ""                 #ÿÈÕÈÎÎñ×î´ó´ÎÊý
        self.Day_Count = ""                   #ÿÈÕÈÎÎñµÄÃèÊö
        self.QuestsEvent = {}                 #Type = MainQuestEventData  ÈÎÎñÐÅÏ¢,key = ("on_visit", 1111)
        self.DayEvent = {}                    #Type = dict() Ã¿ÈÕÈÎÎñÐÅÏ¢ DayEventData
        self.Treasure = None                  #Type = ÍÚ±¦µØµã, TreasureDataÀà
        self.DayEventReward = None            #Type = Ã¿ÈÕ½±Àø£¬AllDayEventRewardDataÀà
        self.Invisible = 0                    #²»ÏÔʾÔÚ¿Í»§¶Ë
        self.Code = ""                        
        self.NameCode = ""                    #ÈÎÎñ´úÂë
        self.UseCount = 0                     #ÃüÖдÎÊý
        self.Color_lv = 0                     #ÈÎÎñÑÕÉ«
        self.CanDel = 0                       #ÈÎÎñ¿É·ñɾ³ý
        self.RunAroundReward = None             #ÅÜ»·ÈÎÎñ½±Àø  AllRunAroundRewardData
        self.ResetCurCountDictName = ''               #ÈÎÎñµ±Ç°ÖØÖôÎÊý×ÖµäÃû
        self.ResetMaxCount = 0                #ÈÎÎñÖØÖÃ×î´ó´ÎÊý
 
#---------------------------------------------------------------------
## ¹¦ÄÜNPC¶Ô»°Êý¾Ý
#
#  PyClassÀàµÄÏêϸ˵Ã÷.  
class FunctionNPCTalkData:
    #---------------------------------------------------------------------
    ## ³õʼ»¯, ÈÝÆ÷°üº¬ID, Name, Menus
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬ID, Name, Menus
    def __init__(self):
        self.ID = 0
        self.Name = ""
        self.Menus = list()
 
#---------------------------------------------------------------------
## ¹¦Äܲ˵¥Àà
#
#  PyClassÀàµÄÏêϸ˵Ã÷.  
class FunctionMenu:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬Check, Menu
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬Check, Menu
    def __init__(self):
        self.Check = ""
        self.Menu = ""
        self.Code = ""
        self.CheckArgs = ""
        
#---------------------------------------------------------------------
## ÌØÊâÈÎÎñÊý¾Ý
#
#  PyClassÀàµÄÏêϸ˵Ã÷.  
class SpecialQuestData:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬ID, Type, Name, LV, MapID, NPCID
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬ID, Type, Name, LV, MapID, NPCID
    def __init__(self):
        self.ID = 0
        self.Type = 0
        self.Name = ""
        self.LV = 0
        self.MapID = 0
        self.NPCID = 0
        
#---------------------------------------------------------------------
## ÈÎÎñ°´ÕÕIDɱNPC
#
#  PyClassÀàµÄÏêϸ˵Ã÷£ºÄ¿Ç°ÅÜ»·ºÍÿÈÕÓÃ
class Day_KillNPC_By_ID:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬ID, Count, NPCData
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬ID, Count, NPCData
    def __init__(self):
        self.ID = 0
        self.Count = 0
        self.NPCData = None
        self.MapID = 0 
 
#---------------------------------------------------------------------
## ÈÎÎñ°´Õյȼ¶É±NPC
#
#  PyClassÀàµÄÏêϸ˵Ã÷£ºÄ¿Ç°ÅÜ»·ºÍÿÈÕÓÃ
class Day_KillNPC_By_LV:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬LV, Count, Country
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬LV, Count, Country
    def __init__(self):
        self.LV = 0
        self.Count = 0
        self.Country = 0
 
#---------------------------------------------------------------------
## ÈÎÎñÊÕ¼¯ÎïÆ·
#
#  PyClassÀàµÄÏêϸ˵Ã÷£ºÄ¿Ç°ÅÜ»·ºÍÿÈÕÓÃ
class Day_GetItem_By_ID:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬ID, Count
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬ID, Count
    def __init__(self):
        self.ID = 0
        self.Count = 0
 
#---------------------------------------------------------------------
## ·ÃÎÊNPC
#
#  PyClassÀàµÄÏêϸ˵Ã÷£ºÄ¿Ç°ÅÜ»·ºÍÿÈÕÓÃ
class Day_VisitNPC:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬ID
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬ID
    def __init__(self):
        self.ID = 0
        self.MapID = 0
        self.NPCData = None
 
#---------------------------------------------------------------------
## Ëæ»úÈÎÎñ
#
#  PyClassÀàµÄÏêϸ˵Ã÷£ºÄ¿Ç°ÅÜ»·ÓÃ
class Day_Mission:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬ID
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬ID
    def __init__(self):
        self.ID = 0
 
#---------------------------------------------------------------------
## Ëæ»ú²É¼¯
#
#  PyClassÀàµÄÏêϸ˵Ã÷£ºÄ¿Ç°ÅÜ»·ÓÃ
class Day_CollectNPC:
    ## ³õʼ»¯, ÈÝÆ÷°üº¬ID
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ÈÝÆ÷°üº¬ID
    def __init__(self):
        self.ID = 0
        self.Count = 0
        self.MapID = 0
#---------------------------------------------------------------------
## Ã¿ÈÕʼþÊý¾Ý
#
#  PyClassÀàµÄÏêϸ˵Ã÷.
#===============================================================================
# class DayEventData:
#    ## ³õʼ»¯
#    #  @param self ÀàʵÀý
#    #  @return ·µ»ØÖµÎÞÒâÒå
#    #  @remarks ³õʼ»¯
#    def __init__(self):
#        self.LV = 0
#        self.Day_KillNPC_By_ID_List = list()    #Type = Day_KillNPC_By_ID
#        self.Day_KillNPC_By_LV_List = list()    #Type = Day_KillNPC_By_LV
#        self.Day_GetItem_By_ID = list()         #Type = Day_GetItem_By_ID
#        self.Day_VisitNPCList = list()          #Type = Day_VisitNPC
#        self.Day_MissionList = list()           #Type = Day_Mission
#        self.Day_CollectNPCList = list()           #Type = Day_CollectNPC_By_ID
#===============================================================================
 
#---------------------------------------------------------------------
## ÈÎÎñÌø×ªÀà
#
#  PyClassÀàµÄÏêϸ˵Ã÷.       
class QuestTrigData:
    ## ³õʼ»¯, ID,Next,Continue,CheckJob
    #  @param self ÀàʵÀý
    #  @return ·µ»ØÖµÎÞÒâÒå
    #  @remarks ³õʼ»¯, ID,Next,Continue,CheckJob
    def __init__( self ):
        self.ID = 0
        self.Next = 0
        self.Continue = 0
        self.CheckJob = ''
 
 
 
#---------------------------------------------------------------------
##¼ÓÔØÈÎÎñÊý¾Ý
# @param filePath Îļþ·¾¶
# @param questID ÈÎÎñID
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼ÓÔØÈÎÎñÊý¾Ý
def LoadQuestEvents(filePath, questID):
    #global Quests
    global AllQuestsEvents
    filePath = filePath + "\\"
    
    #GameWorld.Log('LoadQuestEvents filePath = %s'%filePath)
#    questXMLName = '%s.xml'%questID
#    #GameWorld.Log("¶ÁÈ¡ÈÎÎñ: %s"%questXMLName)
#    mainQuest = filePath + questXMLName
#    mainQuestLoader = IPY_GameWorld.IPY_XMLLoader()
#
#    mainQuestLoader.LoadFromFile(mainQuest)
#    #³õʼ»¯ÈÎÎñË÷Òý
#    mainQuestList = mainQuestLoader.GetNodeList()
#    #µ±Ç°ÈÎÎñµÄÈÎÎñÊý¾Ý
    
    #µ¼ÈëÕâ¸öÈÎÎñµÄËùÓÐXMLÊý¾Ý
#    for root, dirs, files in ZipFile_Walk(filePath):
#        for file in files:
#            fileName = os.path.join(root, file)
#            fileName = fileName.replace(filePath, "")
 
    #GameWorld.Log(filePath)
    filePath = filePath.lower()
    for fileName in ZipFile_Walk(filePath):
        fileName = fileName.replace(filePath, "")
        if fileName.find("__init__") >= 0:
            continue
        
        #GameWorld.Log(fileName)
        curFileList = fileName.split(".")
        
        ext = curFileList[1]
        if ext != "xml":
            continue
        fileSplit = fileName.split("\\")
        
        
        if len(fileSplit) <= 1:
            continue
        xmlType = fileSplit[0]
        
        
        xmlSource = fileName.replace("%s\\"%fileSplit[0], "")
        xmlType = xmlType.lower()
        key = (xmlType, xmlSource)
 
        curEvent = MainQuestEventData()
        curEvent.Type = xmlType
        curEvent.Source = xmlSource
        
        #ÕÒµ½²¢ÇÒ¶ÁÈ¡Õâ¸öÎļþ
        curEvent.FileSource = filePath + xmlType + "\\" + xmlSource
        if ChConfig.DelayLoadXML == False:
            curEvent.GetXMLEventLoader()
            #curEvent.XMLEventLoader.LoadFromFile(filePath + xmlType + "\\" + xmlSource)
 
        #°Ñµ±Ç°Ê¼þÌí¼Óµ½ËùÓÐÈÎÎñË÷ÒýÖÐ
        if AllQuestsEvents.has_key(key) != True:
            AllQuestsEvents[key] = list()
        
        #GameWorld.Log(key)
        AllQuestsEvents[key].append((questID, curEvent))
            
    return
 
#---------------------------------------------------------------------
##¼ÓÔØÈÎÎñÊý¾Ý
# @param filePath Îļþ·¾¶
# @param questID ÈÎÎñID
# @param curQuest ÈÎÎñÈÝÆ÷
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼ÓÔØÈÎÎñÊý¾Ý
def LoadQuest(filePath, questID, curQuest):
    curMapID = GameWorld.GetMap().GetMapID()
    #²»¼ÓÔØ²»ÊôÓÚ±¾µØÍ¼µÄXML
    if not CheckMapCanLoadXML( curMapID, questID ):
        #µ÷ÊÔÐÅÏ¢, ÕýʽÉÏÏßɾ³ý
        #GameWorld.Log( 'LoadQuest, ²»¼ÓÔØ²»ÊôÓÚ±¾µØÍ¼µÄXML mapID = %s, questID = %s, filePath = %s'%( curMapID, questID, filePath ) )
        return
    
    #GameWorld.Log(GameWorld.GetScript().OutputTrace())
    #global Quests
    #global AllQuestsEvents
    questXMLName = '%s.xml'%questID
    filePath = filePath + "\\"
    
    mainQuestList = None
    if questID != 0:
        #GameWorld.Log("¶ÁÈ¡ÈÎÎñÏêϸ: %s"%questXMLName)
        mainQuest = filePath + questXMLName
    
        mainQuestLoader = IPY_GameWorld.IPY_XMLLoader()
        
        if not ZipFile_IsFile(mainQuest):
            GameWorld.Log("Zip : %d Ã»ÓÐÈÎÎñÊý¾Ý : %s"%(questID, mainQuest))
            return
        #mainQuestLoader.LoadFromFile(mainQuest)
        mainQuestLoader.LoadFromXML(mainQuest, ZipFile_GetData(mainQuest))
        #³õʼ»¯ÈÎÎñË÷Òý
        mainQuestList = mainQuestLoader.GetNodeList()
#    #µ±Ç°ÈÎÎñµÄÈÎÎñÊý¾Ý
#    curQuest = MainQuestData()
    
    #µ¼ÈëÕâ¸öÈÎÎñµÄËùÓÐXMLÊý¾Ý
#    for root, dirs, files in os.walk(filePath):
#        for file in files:
#            fileName = os.path.join(root, file)
#            fileName = fileName.replace(filePath, "")
 
    filePath = filePath.lower()
    for fileName in ZipFile_Walk(filePath):
        fileName = fileName.replace(filePath, "")
        if fileName.find("__init__") >= 0:
            continue
        
        curFileList = fileName.split(".")
        
        ext = curFileList[1]
        if ext != "xml":
            continue
        fileSplit = fileName.split("\\")
        
        #GameWorld.Log(fileName)
        if len(fileSplit) <= 1:
            continue
        xmlType = fileSplit[0]
        
        
        xmlSource = fileName.replace("%s\\"%fileSplit[0], "")
        key = (xmlType, xmlSource)
        if curQuest.QuestsEvent.has_key(key) != True:
            curEvent = MainQuestEventData()
            curEvent.Type = xmlType
            curEvent.Source = xmlSource
            
            curEvent.FileSource = filePath + xmlType + "\\" + xmlSource
            #ÕÒµ½²¢ÇÒ¶ÁÈ¡Õâ¸öÎļþ
            #curEvent.XMLEventLoader.LoadFromFile(filePath + xmlType + "\\" + xmlSource)
            curQuest.QuestsEvent[(xmlType,xmlSource)] = curEvent
#                
#                #°Ñµ±Ç°Ê¼þÌí¼Óµ½ËùÓÐÈÎÎñË÷ÒýÖÐ
#                if AllQuestsEvents.has_key(key) != True:
#                    AllQuestsEvents[key] = list()
#                try:
#                    AllQuestsEvents[key].append((questID, curEvent))
#                except Exception:
#                    GameWorld.Log("ÈÎÎñ¶ÁÈ¡´íÎó£º%s"%fileName)
#                    raise Exception("ÈÎÎñ¶ÁÈ¡´íÎó£º%s"%fileName)
                
                
    if mainQuestList == None or mainQuestList.IsEmpty():
        #ûÓÐÈÎÎñÊý¾Ý
        if questID != 0:
            GameWorld.Log("%d Ã»ÓÐÈÎÎñÊý¾Ý : %s"%(questID, mainQuest))
        return
    
    questList = mainQuestList.FindNode("quests").ChildNodes()
    
    if questList.GetCount() != 1:
        GameWorld.Log("ÈÎÎñÊý¾Ý²»Îª1")
        return
    
    curQuestLoader = questList.Get(0)
    
    #idStr = curQuestLoader.GetAttribute("id")
    curQuest.ID = questID
    curQuest.Name = curQuestLoader.GetAttribute("name")
    curQuest.NameCode = curQuestLoader.GetAttribute("ms_code")
    curQuest.Code = curQuestLoader.GetAttribute("code")
    curQuest.Type = int(curQuestLoader.GetAttribute("type"))
    curQuest.NPCID = GameWorld.ToIntDef(curQuestLoader.GetAttribute("npc"), 0)
    curQuest.LV = GameWorld.ToIntDef(curQuestLoader.GetAttribute("lv"), 0)
    curQuest.MapID = GameWorld.ToIntDef(curQuestLoader.GetAttribute("map"), 0)
    curQuest.Day_Count = curQuestLoader.GetAttribute("day_count")
    curQuest.Color_lv = GameWorld.ToIntDef(curQuestLoader.GetAttribute("color_lv"), 0)
    curQuest.CanDel = GameWorld.ToIntDef(curQuestLoader.GetAttribute("can_del"), 0)
    
    if curQuest.Day_Count != '':
        #Õâ¸öÈÎÎñÓдÎÊýÌõ¼þ
        curList = curQuest.Day_Count.split('/')
        try:
            curQuest.DayCurCount = QuestCommon.DealWithInPut(curList[0], '!')[0]  #µ±Ç°ÈÎÎñ´ÎÊý
        except BaseException:
            GameWorld.ErrLog("ÈÎÎñ: %s ¸ñʽ´íÎó! curQuest.Day_Count = %s"%(questID, curQuest.Day_Count))
            raise ("DD")
    
        maxCountList = QuestCommon.DealWithInPut(curList[1], '!')
        if len(maxCountList) == 0:
            curQuest.DayMaxCount = curList[1]
        else:
            curQuest.DayMaxCount = maxCountList[0]  #ÿÈÕÈÎÎñ×î´ó´ÎÊý
    
    #---ÈÎÎñ´ÎÊýÖØÖÃ---
    resetCountStr = curQuestLoader.GetAttribute("reset_count")
    if resetCountStr != '':
        #Õâ¸öÈÎÎñÓдÎÊýÌõ¼þ
        curList = resetCountStr.split('/')
        try:
            curQuest.ResetCurCountDictName = QuestCommon.DealWithInPut(curList[0], '!')[0]  #µ±Ç°ÈÎÎñÖØÖôÎÊý
        except BaseException:
            GameWorld.ErrLog("ÈÎÎñ: %s ¸ñʽ´íÎó! curQuest.ResetCurCountDictName = %s"%(questID, 
                                                curQuest.ResetCurCountDictName))
            raise ("DD")
 
        curQuest.ResetMaxCount = int(curList[1])
 
    
    #Õâ¸öÈÎÎñÊÇ·ñ²»ÔÚÈÎÎñÁбíÖÐÏÔʾ
    curQuest.Invisible = GameWorld.ToIntDef(curQuestLoader.GetAttribute("invisible"), 0)
            
    descriptionsNode = curQuestLoader.FindChildNode("descriptions")
    
#    if not Quests.has_key(curQuest.ID) :
#        #Ìí¼ÓÈÎÎñ
#        Quests[curQuest.ID] = curQuest
        
    if descriptionsNode == None or descriptionsNode.IsEmpty():
        return
    
    for i in range(0,descriptionsNode.GetChildCount()):
        questDescription = QuestDescription()
        curDescription = descriptionsNode.GetChild(i)       #description
        
        questDescription.IsRewardNode = GameWorld.ToIntDef(curDescription.GetAttribute("reward"), 0)
 
        curMsg = curDescription.FindChildNode("msg")
        curMissionInfo = curDescription.FindChildNode("mission_info")
        curLight = curDescription.FindChildNode("lights")
        questDescription.Rewards = curDescription.FindChildNode("rewards")
        questDescription.MsgNode = curMsg
        if curMsg != None and (not curMsg.IsEmpty()):
            #questDescription.Msg = curMsg.GetXML()
            questDescription.Msg = curMsg.GetAttribute("code")
            
        if curMissionInfo != None and (not curMissionInfo.IsEmpty()):
            for i in range(0, curMissionInfo.GetChildCount()):
                curNode = curMissionInfo.GetChild(i)
                curContent = curNode.GetAttribute("code")
                #curContent = curNode.GetXML()
                questDescription.Info.append(curContent)
                
#===============================================================================
#        if curLight != None and (not curLight.IsEmpty()):
#            for i in range(0, curLight.GetChildCount()):
#                questLight = QuestLight()
#                curNode = curLight.GetChild(i)
#                #GameWorld.Log("curQuest.ID = %s, NPCID = %s"%(curQuest.ID, curNode.GetAttribute("npcid")))
#                questLight.NPCID = int(curNode.GetAttribute("npcid"))
#                questLight.Type = int(curNode.GetAttribute("type"))
#                questDescription.Lights.append(questLight)
#===============================================================================
        try:
            #¹¹³ÉÈÎÎñÃèÊöÁбí
            curQuest.QuestDescriptionList.append(questDescription)
        except Exception:
            GameWorld.Log("ÈÎÎñ¶ÁÈ¡´íÎó£º%s"%str(curQuest.ID))
            raise Exception("ÈÎÎñÃèÊö´íÎó£º%s"%str(curQuest.ID))
    
    #¶ÁÈ¡ÈÎÎñʼþËæ»úÊý¾Ý
    curQuest.DayEvent = LoadLevityEventData(filePath)
    
    #¶ÁÈ¡ÍÚ±¦µØµã¶¨Òå
    #===========================================================================
    # treasurePath = filePath + "treasure.xml"
    # if ZipFile_IsFile(treasurePath):
    #    try:
    #        curQuest.Treasure = LoadTreasureData(treasurePath)
    #        
    #    except Exception:
    #        GameWorld.Log("¶ÁÈ¡ÍÚ±¦µØµã´íÎó:%s"%treasurePath)
    #        raise Exception("¶ÁÈ¡ÍÚ±¦µØµã´íÎó:%s"%treasurePath)
    #===========================================================================
        
    #¶ÁȡÿÈÕÈÎÎñ½±Àø ÔÝʱ¹Ø±ÕÿÈÕÈÎÎñµÄ½±Àø¼ÓÔØ£¬¿ªÆôÐ迼ÂÇminlvºÍmaxlv´æ´¢µÄ´úÂë²»ÒªÓ°ÏìÐÔÄܺÍÄÚ´æ
    #===========================================================================
    # rewardPath = filePath + "reward.xml"
    # if ZipFile_IsFile(rewardPath):
    #    try:
    #        curQuest.DayEventReward = LoadDayEventRewardData(rewardPath)
    #    except Exception:
    #        GameWorld.Log("¶ÁȡÿÈÕÈÎÎñ½±Àø´íÎó:%s"%rewardPath)
    #        raise Exception("¶ÁȡÿÈÕÈÎÎñ½±Àø´íÎó:%s"%rewardPath)
    #===========================================================================
        
    #¶ÁÈ¡ÅÜ»·ÈÎÎñ½±Àø
    rewardPath = filePath + "run_reward.xml"
    if ZipFile_IsFile(rewardPath):
        try:
            curQuest.RunAroundReward = LoadRunAroundRewardData(rewardPath)
        except Exception:
            GameWorld.Log("¶ÁÈ¡ÅÜ»·ÈÎÎñ½±Àø´íÎó:%s"%rewardPath)
            raise Exception("¶ÁÈ¡ÅÜ»·ÈÎÎñ½±Àø´íÎó:%s"%rewardPath)
 
    return
 
#---------------------------------------------------------------------
##¼ÓÔØËùÓÐÈÎÎñÊý¾Ý
# @param ÎÞ
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼ÓÔØËùÓÐÈÎÎñÊý¾Ý
def LoadQuestData():
    global Quests
    questPath = "%s\\Quests"%GetQuestDataName()
    GameWorld.Log("Quests Initing... path = %s"%questPath)
    
#    LoadQuest(os.path.join(questPath, '0'), 0, MainQuestData())
    if ZipFile_IsDir(questPath)!= True:
        GameWorld.Log("Can't Find Path = %s"%questPath)
        return
    
    dirs = ZipFile_ListDir(questPath)
    #ÈÎÎñ¼ÆÊýÆ÷
    cnt = 0
    #±¾µØÍ¼ID
    curMapID = GameWorld.GetMap().GetMapID()
    
    for curDir in dirs:
        curPath = os.path.join(questPath, curDir)
        #questXMLName = "%s.xml"%curDir
        try:
            questID = GameWorld.ToIntDef(curDir, 0)
            if questID == 0 and curDir != '0':
                GameWorld.Log("questID = 0 : %s, ¸ñʽ²»¶Ô, ²»¶ÁÈ¡´Ëxml"%curDir)
                continue
            
            #²»¼ÓÔØ²»ÊôÓÚ±¾µØÍ¼µÄXML
            if not CheckMapCanLoadXML( curMapID, questID ):
                continue
            
            cnt += 1
            LoadQuestEvents(curPath, questID)
            
        except Exception:
            GameWorld.Log('ÈÎÎñ¶ÁÈ¡´íÎó£º%s'%curPath)
            raise Exception('ÈÎÎñ¶ÁÈ¡´íÎó£º%s'%curPath)
        
    GameWorld.Log("Quests Init OK, Quest = %d"%cnt)        
    return
 
#---------------------------------------------------------------------
##Ö»¼ÓÔØ±¾µØÍ¼µÄXMLÎļþ
# @param curMapID µ±Ç°µØÍ¼ID
# @param questID ÈÎÎñID
# @return ·µ»ØÖµÕæ, ¿ÉÒÔ¼ÓÔØ
# @remarks Ö»¼ÓÔØ±¾µØÍ¼µÄXMLÎļþ
def CheckMapCanLoadXML( curMapID, questID ):
    #Õâ¸öÈÎÎñÊÇÓÃÀ´¼Ç¼ÈÎÎñDZ¹æÔòµÄ, ¶¼Òª¼ÓÔØ
    if questID == ChConfig.Def_MissionID_FirstLogin:
        return True
    
    readDict = ReadChConfig.GetEvalChConfig('MissionAcceptMapID')
    
    accecpMapID = readDict.get( questID )
    #Õâ¸öÈÎÎñÎÞÏÞÖÆ
    if not accecpMapID:
        return True
    
    #È«µØÍ¼¼ÓÔØ
    if -1 in accecpMapID:
        return True
    
    return ( curMapID in accecpMapID ) 
#---------------------------------------------------------------------
##¼ÓÔØ¹¦ÄÜNPCÊý¾Ý
# @param ÎÞ
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼ÓÔØ¹¦ÄÜNPCÊý¾Ý
def LoadFunctionData():
    global FunctionNPCTalk
    #===========================================================
    #³õʼ»¯¹¦ÄÜNPCµÄ¶Ô»°Áбí
    functionPath = "%s\\FunctionNPC.xml"%GetQuestDataName()
    functionLoader = IPY_GameWorld.IPY_XMLLoader()
    #functionLoader.LoadFromFile(functionPath)
    functionLoader.LoadFromXML(functionPath, ZipFile_GetData(functionPath))
    
    functionList = functionLoader.GetNodeList().FindNode("functions").ChildNodes()
    for i in range(0, functionList.GetCount()):
        curFunctionLoader = functionList.Get(i)
        id = int(curFunctionLoader.GetAttribute("id"))
        funcData = FunctionNPCTalkData()
        funcData.ID = id
        funcData.Name = curFunctionLoader.GetAttribute("name")
        for i in range(0, curFunctionLoader.GetChildCount()):
            funcMenu = FunctionMenu()
            curMenu = curFunctionLoader.GetChild(i)
            funcMenu.Menu = curMenu.GetAttribute("menu")
            funcMenu.Code = curMenu.GetAttribute("code")
            funcMenu.Check = curMenu.GetAttribute("check")
            if funcMenu.Check == None:
                continue
            
            funcMenu.CheckArgs = curMenu.GetAttribute("args")
            funcData.Menus.append(funcMenu)
        FunctionNPCTalk[id] = funcData
 
#---------------------------------------------------------------------
##¼ÓÔØ´«Ë͵ãÊý¾Ý
# @param treasurePath Îļþ·¾¶
# @return ·µ»ØÖµ£¬ ÈÝÆ÷ TreasureData()
# @remarks ¼ÓÔØ´«Ë͵ãÊý¾Ý
def LoadTreasureData(treasurePath):
    treasureLoader = IPY_GameWorld.IPY_XMLLoader()
    #treasureLoader.LoadFromFile(treasurePath)
    treasureLoader.LoadFromXML(treasurePath, ZipFile_GetData(treasurePath))
    nodeList = treasureLoader.GetNodeList()
    if nodeList == None or nodeList.IsEmpty():
        return None
    
    #GameWorld.Log("Load Treasure : %s"%treasurePath)
    treasureData = TreasureData()
    treasureList = nodeList.FindNode("treasure").ChildNodes()
    
    #¶ÁÈ¡ÆÕͨÍÚ±¦µØµã
    normalList = treasureList.FindNode("treasure_normal")
    if normalList != None and (not normalList.IsEmpty()):
        treasureNormalList = list()
        for i in range(normalList.GetChildCount()):
            curNode = normalList.GetChild(i)
            treasurePos = TreasurePos()
            treasurePos.MapID = int(curNode.GetAttribute("mapid"))
            treasurePos.PosX = int(curNode.GetAttribute("posx"))
            treasurePos.PosY = int(curNode.GetAttribute("posy"))
            treasureNormalList.append(treasurePos)
        treasureData.Normal = treasureNormalList
    
    weekList = treasureList.FindNode("treasure_weeks")
    if weekList != None and (not weekList.IsEmpty()):
        treasureByLV = dict()
        for i in range(weekList.GetChildCount()):
            curLVData = weekList.GetChild(i)        #treasure_week½Úµã
            
            minLV = GameWorld.ToIntDef(curLVData.GetAttribute("minlv"), 0)
            maxLV = GameWorld.ToIntDef(curLVData.GetAttribute("maxlv"), 0)
            lv = GameWorld.ToIntDef(curLVData.GetAttribute("lv"), 0)
        
            treasureWeekList = dict()
            if curLVData.GetChildCount() == 1:
                #иñʽ:Èç¹û<week>½ÚµãÖ»ÓÐÒ»¸ö, ×Ô¶¯À©³äΪ7¸ö
                curWeekData = curLVData.GetChild(0)
                curPosData = curWeekData.GetChild(0)
                curData = list()
                treasurePos = TreasurePos()
                treasurePos.MapID = int(curPosData.GetAttribute("mapid"))
                treasurePos.PosX = int(curPosData.GetAttribute("posx"))
                treasurePos.PosY = int(curPosData.GetAttribute("posy"))
                curData.append(treasurePos)
                for curDay in range(1, 8):
                    #7Ìì
                    treasureWeekList[curDay] = curData
                    #GameWorld.Log(GameWorld.Log('---curDay---%s'%str(curData)))
                
                treasureByLV[lv] = treasureWeekList
                continue
            
            for i in range(curLVData.GetChildCount()):
                curWeekData = curLVData.GetChild(i)
                curWeek = int(curWeekData.GetAttribute("day"))
                treasureWeekList[curWeek] = list()
                for i in range(curWeekData.GetChildCount()):
                    curPosData = curWeekData.GetChild(i)
                    treasurePos = TreasurePos()
                    treasurePos.MapID = int(curPosData.GetAttribute("mapid"))
                    treasurePos.PosX = int(curPosData.GetAttribute("posx"))
                    treasurePos.PosY = int(curPosData.GetAttribute("posy"))
                    treasureWeekList[curWeek].append(treasurePos)
                    
            if lv != 0:
                treasureByLV[lv] = treasureWeekList
                #GameWorld.Log('---lv---%s'%str(treasureWeekList))
            else:
#                GameWorld.Log(treasurePath)
#                GameWorld.Log('---minLV %s, maxLV %s---%s'%(minLV, maxLV, str(treasureWeekList)))
                for curLV in range(minLV, maxLV):
                    treasureByLV[curLV] = treasureWeekList
                    
                    
        treasureData.Week = treasureByLV
        #GameWorld.Log(str(treasureData.Week))
    return treasureData
 
#---------------------------------------------------------------------
##¼ÓÔØÅÜ»·ÈÎÎñ½±ÀøÊý¾Ý
# @param runAroundRewardPath Îļþ·¾¶
# @return ·µ»ØÖµ, ÈÝÆ÷AllRunAroundRewardData()
# @remarks ¼ÓÔØÅÜ»·ÈÎÎñ½±ÀøÊý¾Ý
def LoadRunAroundRewardData(runAroundRewardPath):
    allRunAround = AllRunAroundRewardData()
    
    dayEventRewardLoader = IPY_GameWorld.IPY_XMLLoader()
    dayEventRewardLoader.LoadFromXML(runAroundRewardPath, ZipFile_GetData(runAroundRewardPath))
    
    nodeList = dayEventRewardLoader.GetNodeList()
    
    if nodeList == None or nodeList.IsEmpty():
        GameWorld.Log("ûÓÐÕâ¸öÎļþ %s"%runAroundRewardPath)
        return None
    rewardsNode = nodeList.FindNode("rewards")
    
    allRunAround.MoneyType = int(rewardsNode.GetAttribute("moneytype"))
    allRunAround.MinLV = 1000
    allRunAround.MaxLV = 0
    runAroundRewardList = rewardsNode.ChildNodes()
    for i in xrange(runAroundRewardList.GetCount()):
        curRunAroundRewardNode = runAroundRewardList.Get(i)
        Exp = GameWorld.ToIntDef(curRunAroundRewardNode.GetAttribute("exp"), 0)
        addExp = GameWorld.ToIntDef(curRunAroundRewardNode.GetAttribute("addexp"), 0)
        Money = GameWorld.ToIntDef(curRunAroundRewardNode.GetAttribute("money"), 0)
        Item = curRunAroundRewardNode.GetAttribute("item")
        minLV = GameWorld.ToIntDef(curRunAroundRewardNode.GetAttribute("minlv"), 0)
        maxLV = GameWorld.ToIntDef(curRunAroundRewardNode.GetAttribute("maxlv"), 0)
        familyHornor = GameWorld.ToIntDef(curRunAroundRewardNode.GetAttribute("familyhornor"), 0)
        goldPaper = GameWorld.ToIntDef(curRunAroundRewardNode.GetAttribute("goldpaper"), 0)
        #¼Ì³ÐÿÈÕ½±Àø£¬²Î¿¼ÉèÖÃ
        dayEventRewardData = RunAroundRewardData()
        dayEventRewardData.Exp = Exp
        dayEventRewardData.AddExp = addExp
        dayEventRewardData.Money = Money
        dayEventRewardData.Item = Item
        dayEventRewardData.PlayerFamilyHornor = familyHornor
        dayEventRewardData.GoldPaper = goldPaper
        allRunAround.Rewards[(minLV, maxLV)] = dayEventRewardData
        if minLV < allRunAround.MinLV:
            allRunAround.MinLV = minLV
        if maxLV > allRunAround.MaxLV:
            allRunAround.MaxLV = maxLV
         
    return allRunAround
 
#---------------------------------------------------------------------
##¼ÓÔØÃ¿ÈÕÈÎÎñ½±ÀøÊý¾Ý
# @param treasurePath Îļþ·¾¶
# @return ·µ»ØÖµ, ÈÝÆ÷AllDayEventRewardData()
# @remarks ¼ÓÔØÃ¿ÈÕÈÎÎñ½±ÀøÊý¾Ý
def LoadDayEventRewardData(dayEventRewardPath):
    allDayEvent = AllDayEventRewardData()
    
    dayEventRewardLoader = IPY_GameWorld.IPY_XMLLoader()
    #dayEventRewardLoader.LoadFromFile(dayEventRewardPath)
    dayEventRewardLoader.LoadFromXML(dayEventRewardPath, ZipFile_GetData(dayEventRewardPath))
    
    nodeList = dayEventRewardLoader.GetNodeList()
    
    if nodeList == None or nodeList.IsEmpty():
        #ûÓÐÕâ¸öÎļþ
        return None
    
    rewardsNode = nodeList.FindNode("rewards")
    
    allDayEvent.MinLV = int(rewardsNode.GetAttribute("minlv"))
    allDayEvent.MaxLV = int(rewardsNode.GetAttribute("maxlv"))
    allDayEvent.MoneyType = int(rewardsNode.GetAttribute("moneytype"))
    
    dayEventRewardList = rewardsNode.ChildNodes()
    for i in range(0, dayEventRewardList.GetCount()):
        curDayEventRewardNode = dayEventRewardList.Get(i)
        lv = int(curDayEventRewardNode.GetAttribute("lv"))
        dayEventRewardData = DayEventRewardData()
        
        dayEventRewardData.Exp = GameWorld.ToIntDef(curDayEventRewardNode.GetAttribute("exp"), 0)
        dayEventRewardData.Money = GameWorld.ToIntDef(curDayEventRewardNode.GetAttribute("money"), 0)
        dayEventRewardData.TruckMoney = GameWorld.ToIntDef(curDayEventRewardNode.\
                                                           GetAttribute("truck_money"), 0)
        dayEventRewardData.Item = curDayEventRewardNode.GetAttribute("item")
        
        #¼Ò×å¹±Ï×
        dayEventRewardData.PlayerFamilyHornor = GameWorld.ToIntDef(curDayEventRewardNode.\
                                                GetAttribute("player_family_hornor"), 0)
        #¼Ò×å»îÔ¾¶È
        dayEventRewardData.PlayerFamilyActiveValue = GameWorld.ToIntDef(curDayEventRewardNode.\
                                                    GetAttribute("player_family_active_value"), 0)
        #¼ÒÔ°¾­Ñé
        dayEventRewardData.FamilyHomeExp = GameWorld.ToIntDef(curDayEventRewardNode.\
                                                    GetAttribute("family_home_exp"), 0)
        #¼Ò×å×ʽð 
        dayEventRewardData.FamilyMoney = GameWorld.ToIntDef(curDayEventRewardNode.\
                                         GetAttribute("family_money"), 0)
        #¼Ò×åÈÙÓþ
        dayEventRewardData.FamilyHornor = GameWorld.ToIntDef(curDayEventRewardNode.\
                                          GetAttribute("family_hornor"), 0)
        #³èÎï¾­Ñé
        dayEventRewardData.PetExp = GameWorld.ToIntDef(curDayEventRewardNode.\
                                    GetAttribute("pet_exp"), 0)
        #ÍþÍû
        dayEventRewardData.Prestige = GameWorld.ToIntDef(curDayEventRewardNode.\
                                      GetAttribute("prestige"), 0)
        
        allDayEvent.Rewards[lv] = dayEventRewardData  
            
    return allDayEvent
 
 
#===============================================================================
## °´ÕÕIDÀ´É±¹Ö
# @param curNode ½Úµã
# @param funcData ÈÎÎñÈÝÆ÷DayEvent
# @return ÎÞ
# @remarks °´ÕÕIDÀ´É±¹Ö
def LoadKillByID(curNode):
    killNPC = Day_KillNPC_By_ID()
    killNPC.ID = int(curNode.GetAttribute("id")) 
    #killNPC.Count = int(curNode.GetAttribute("count"))
    killNPC.NPCData = GameWorld.GetGameData().FindNPCDataByID(killNPC.ID)
    killNPC.MapID = GameWorld.ToIntDef(curNode.GetAttribute("mapid"), 0)
    return killNPC
 
## °´Õյȼ¶À´É±¹Ö
# @param curNode ½Úµã
# @param funcData ÈÎÎñÈÝÆ÷DayEvent
# @return ÎÞ
# @remarks °´Õյȼ¶À´É±¹Ö
def LoadKillByLV(curNode):
    killLV = Day_KillNPC_By_LV()
    killLV.LV = int(curNode.GetAttribute("lv"))
    killLV.Count = int(curNode.GetAttribute("count"))
    killLV.Country = int(curNode.GetAttribute("country"))
    return killLV
 
## °´ÕÕIDÀ´ÊÕ¼¯ÎïÆ·
# @param curNode ½Úµã
# @param funcData ÈÎÎñÈÝÆ÷DayEvent
# @return ÎÞ
# @remarks °´ÕÕIDÀ´ÊÕ¼¯ÎïÆ·
def LoadItemByID(curNode):
    getItem = Day_GetItem_By_ID()
    getItem.ID = int(curNode.GetAttribute("id"))
    getItem.Count = int(curNode.GetAttribute("count"))
    return getItem
 
## Ëæ»ú·ÃÎÊNPCÊý¾Ý
# @param curNode ½Úµã
# @param funcData ÈÎÎñÈÝÆ÷DayEvent
# @return ÎÞ
# @remarks Ëæ»ú·ÃÎÊNPCÊý¾Ý
def LoadVisitNpcByID(curNode):
    visitNPC = Day_VisitNPC()
    visitNPC.ID = int(curNode.GetAttribute("id"))
    visitNPC.MapID = GameWorld.ToIntDef(curNode.GetAttribute("mapid"), 0)
    visitNPC.NPCData = GameWorld.GetGameData().FindNPCDataByID(visitNPC.ID)
    return visitNPC
 
## Ëæ»úÈÎÎñÊý¾Ý
# @param curNode ½Úµã
# @param funcData ÈÎÎñÈÝÆ÷DayEvent
# @return ÎÞ
# @remarks Ëæ»úÈÎÎñÊý¾Ý
def LoadMissionByID(curNode):
    #mission = Day_Mission()
    missionID = int(curNode.GetAttribute("id"))
    rate = int(curNode.GetAttribute("rate"))
 
    return rate, missionID
    
## Ëæ»ú²É¼¯Êý¾Ý
# @param curNode ½Úµã
# @param funcData ÈÎÎñÈÝÆ÷DayEvent
# @return ÎÞ
# @remarks Ëæ»ú²É¼¯Êý¾Ý
def LoadCollectNPCByID(curNode):
    collectNPC = Day_CollectNPC()
    collectNPC.ID = int(curNode.GetAttribute("id"))
    collectNPC.Count = int(curNode.GetAttribute("count"))
    collectNPC.MapID = GameWorld.ToIntDef(curNode.GetAttribute("mapid"), 0)
    
    return collectNPC
 
## ¶Á±í¸ü¸Ä×ÖµäÖµ,´Ëº¯ÊýÍâ²ãÐ迼ÂÇÊÇ·ñ±éÀúµ÷Ó㬠»áÒòÖØ¸´µ¼ÖÂÄÚ´æºÍÐÔÄÜÎÊÌâ
# ²ÎÊý lvInfo ¿ÉÒÔÊÇÊý×ֵȼ¶£¬ºÍÔª×飨×îС£¬×î´óµÈ¼¶£©
# @remarks Ëæ»ú²É¼¯Êý¾Ý
def LoadXMLDict(eventXMLData, lvInfo, curEventNode, loadFunc, dayEventType):
    if dayEventType not in eventXMLData:
        eventXMLData[dayEventType] = {}
    
    if lvInfo not in eventXMLData[dayEventType]:
        eventXMLData[dayEventType][lvInfo] = []
        
    for i in range(0, curEventNode.GetChildCount()):
        curNode = curEventNode.GetChild(i)
        eventXMLData[dayEventType][lvInfo].append(loadFunc(curNode))
 
 
    
#==============================================================================
## Ëæ»úʱ¼ä¶ÁÈ¡Æ÷
# @param eventPath XML·¾¶
# @param funcData ÈÎÎñÈÝÆ÷DayEvent
# @param eventXMLData ÈÎÎñ×ÜÈÝÆ÷
# @param loadFunc º¯ÊýÃû
# @return ÎÞ
# @remarks Ëæ»úʱ¼ä¶ÁÈ¡Æ÷
def LoadEvent(eventPath, eventXMLData, loadFunc, dayEventType):
    eventLoader = IPY_GameWorld.IPY_XMLLoader()
    eventLoader.LoadFromXML(eventPath, ZipFile_GetData(eventPath))
    
    nodeList = eventLoader.GetNodeList()
    
    if nodeList == None or nodeList.IsEmpty():
        #ûÓÐÕâ¸öÎļþ
        return None
 
    #---¶ÁÈ¡½ÚµãÊý¾Ý---
    eventList = nodeList.FindNode("task_event").ChildNodes()
    for i in range(0, eventList.GetCount()):
        curEventNode = eventList.Get(i)
        lv = GameWorld.ToIntDef(curEventNode.GetAttribute("lv"), 0)
 
        if lv != 0:
            LoadXMLDict(eventXMLData, lv, curEventNode, loadFunc, dayEventType)
            continue
        
        #иñʽ: <event minlv="25" maxlv="45">
        minlv = int(curEventNode.GetAttribute("minlv"))
        maxlv = int(curEventNode.GetAttribute("maxlv")) 
 
        LoadXMLDict(eventXMLData, (minlv, maxlv), curEventNode, loadFunc, dayEventType)
 
 
## ¶ÁÈ¡ÈÎÎñʼþ
# @param filePath XML·¾¶
# @return ÎÞ
# @remarks ¶ÁÈ¡ÈÎÎñʼþ
def LoadLevityEventData(filePath):
    eventXMLData = {}
 
    #---¶Áȡɱ¹Ö£¨ID£©ÈÎÎñÊý¾Ý---
    eventPath = filePath + "event_kill_by_id.xml"
    if ZipFile_IsFile(eventPath):
        try:
            LoadEvent(eventPath, eventXMLData, LoadKillByID, QuestCommon.Day_KillNPC_By_ID_List)
        except Exception, e:
            GameWorld.Log("¶ÁÈ¡Ëæ»úÊÕ¼¯É±¹Ö£¨ID£©:%s"%e)
            raise Exception("¶ÁÈ¡Ëæ»úÊÕ¼¯É±¹Ö£¨ID£©:%s"%eventPath) 
 
 
    #---¶Áȡɱ¹Ö£¨LV£©ÈÎÎñÊý¾Ý---
    eventPath = filePath + "event_kill_by_lv.xml"
    if ZipFile_IsFile(eventPath):
        try:
            LoadEvent(eventPath, eventXMLData, LoadKillByLV, QuestCommon.Day_KillNPC_By_LV_List)
        except Exception, e:
            GameWorld.Log("¶ÁÈ¡Ëæ»úÊÕ¼¯É±¹Ö£¨LV£©:%s"%e)
            raise Exception("¶ÁÈ¡Ëæ»úÊÕ¼¯É±¹Ö£¨LV£©:%s"%eventPath) 
        
 
    #---ÊÕ¼¯ÎïÆ·£¨ID£©ÈÎÎñÊý¾Ý---
    eventPath = filePath + "event_item_by_id.xml"
    if ZipFile_IsFile(eventPath):
        try:
            LoadEvent(eventPath, eventXMLData, LoadItemByID, QuestCommon.Day_GetItem_By_ID)
        except Exception, e:
            GameWorld.Log("¶ÁÈ¡Ëæ»úÊÕ¼¯ÎïÆ·£¨ID£©:%s"%e)
            raise Exception("¶ÁÈ¡Ëæ»úÊÕ¼¯ÎïÆ·£¨ID£©:%s"%eventPath)
 
 
    #---·ÃÎÊNPC£¨ID£©ÈÎÎñÊý¾Ý---
    eventPath = filePath + "event_visit_by_id.xml"
    if ZipFile_IsFile(eventPath):
        try:
            LoadEvent(eventPath, eventXMLData, LoadVisitNpcByID, QuestCommon.Day_VisitNPCList)
        except Exception, e:
            GameWorld.Log("¶ÁÈ¡Ëæ»ú·ÃÎÊNPC£¨ID£©:%s"%e)
            raise Exception("¶ÁÈ¡Ëæ»ú·ÃÎÊNPC£¨ID£©:%s"%eventPath) 
        
        
    #---Ëæ»ú½ÓÈÎÎñ£¨ID£©ÈÎÎñÊý¾Ý---
    eventPath = filePath + "event_mission_by_id.xml"
    if ZipFile_IsFile(eventPath):
        try:
            LoadEvent(eventPath, eventXMLData, LoadMissionByID, QuestCommon.Day_MissionList)
        except Exception, e:
            GameWorld.Log("¶ÁÈ¡Ëæ»úÈÎÎñ£¨ID£©:%s"%(e))
            raise Exception("¶ÁÈ¡Ëæ»úÈÎÎñ£¨ID£©:%s"%eventPath) 
        
    #---Ëæ»ú²É¼¯£¨ID£©ÈÎÎñÊý¾Ý---
    eventPath = filePath + "event_collect_by_id.xml"
    if ZipFile_IsFile(eventPath):
        try:
            LoadEvent(eventPath, eventXMLData, LoadCollectNPCByID, QuestCommon.Day_CollectNPCList)
        except Exception, e:
            GameWorld.Log("¶ÁÈ¡Ëæ»ú²É¼¯£¨ID£©:%s"%(e))
            raise Exception("¶ÁÈ¡Ëæ»ú²É¼¯£¨ID£©:%s"%eventPath) 
    
    return eventXMLData
 
 
#def LoadSpecialQuestData():
#    global Special_Quests
#    questPath = ChConfig.GetAppPath() + "QuestData\\"
#    
#    mainQuest = questPath + "special_quests.xml"
#    mainQuestLoader = IPY_GameWorld.IPY_XMLLoader()
#    mainQuestLoader.LoadFromFile(mainQuest)
#                
#                
#    #==============================================
#    #³õʼ»¯ÈÎÎñË÷Òý
#    mainQuestList = mainQuestLoader.GetNodeList()
#    if mainQuestList == None:
#        #ûÓÐÈÎÎñÊý¾Ý
#        return
#    questList = mainQuestList.FindNode("quests").ChildNodes()
#    
#    for i in range(0, questList.GetCount()):
#        curQuestLoader = questList.Get(i)
#        idStr = curQuestLoader.GetAttribute("id")
#        curQuest = SpecialQuestData()
#        curQuest.ID = int(idStr)
#        curQuest.Name = curQuestLoader.GetAttribute("name")
#        curQuest.Type = int(curQuestLoader.GetAttribute("type"))
#        curQuest.LV = int(curQuestLoader.GetAttribute("lv"))
#        curQuest.MapID = int(curQuestLoader.GetAttribute("mapid"))
#        curQuest.NPCID = int(curQuestLoader.GetAttribute("npcid"))
#        Special_Quests[curQuest.ID] = curQuest
#        
#    return
 
#---------------------------------------------------------------------
##¶ÁȡĬÈ϶Ի°Êý¾Ý(Ôݲ»Ê¹ÓÃ)
# @param ÎÞ
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¶ÁȡĬÈ϶Ի°Êý¾Ý(Ôݲ»Ê¹ÓÃ)
def LoadDefaultTalkData():
    #¸ü¸ÄΪ¶¯Ì¬¶ÁÈ¡, ÓÃFindDefaultTalk¶ÁÈ¡
#    global DefaultTalk
#    filePath = ChConfig.GetAppPath() + "QuestDataGb\\default_talk"
#    #µ¼ÈëÕâ¸öÈÎÎñµÄËùÓÐXMLÊý¾Ý
#    files=os.listdir(filePath)
#    for file in files:
#        fileName = file.split(".")[0]
#        if fileName.find("__init__") >= 0:
#            continue
#        ext = file.split(".")[1]
#        if ext != "xml":
#            continue
#        npcID = int(fileName)
#        xmlLoader = IPY_GameWorld.IPY_XMLLoader()
#        xmlLoader.LoadFromFile(filePath+"\\"+file)
#        DefaultTalk[npcID] = xmlLoader
        #GameWorld.Log("¶ÁȡĬÈ϶Ի° : %d"%npcID)
            
    return
 
#---------------------------------------------------------------------
##¼ÓÔØÈÎÎñÌø×ª
# @param ÎÞ
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼ÓÔØÈÎÎñÌø×ª
def LoadQuestTrig():
    global QuestTrig
    filePath = "%s\quest_map.xml"%GetQuestDataName()
    trigLoader = IPY_GameWorld.IPY_XMLLoader()
    #trigLoader.LoadFromFile(filePath)
    trigLoader.LoadFromXML( filePath, ZipFile_GetData( filePath ) )
    questTrig = trigLoader.GetNodeList().FindNode( "quest_trig" )
    
    for i in range( 0, questTrig.GetChildCount() ):
        curTrig = questTrig.GetChild(i)
        
        tridData = QuestTrigData()
        #Ö°ÒµÑéÖ¤ÔÊÐíΪ¿Õ
        tridData.CheckJob = curTrig.GetAttribute( "job" )
        tridData.ID = int( curTrig.GetAttribute( "id" ) )
        tridData.Next = int( curTrig.GetAttribute( "next" ) )
        tridData.Continue = int( curTrig.GetAttribute( "continue" ) )
        
        if not QuestTrig.has_key( tridData.ID ):
            QuestTrig[ tridData.ID ] = list()
        
        QuestTrig[ tridData.ID ].append( tridData )
        
        #GameWorld.Log("add Trig ID = %d"%tridData.ID)
 
#---------------------------------------------------------------------
##¼ÓÔØÈÎÎñ¼òÒªÐÅÏ¢
# @param ÎÞ
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼ÓÔØÈÎÎñ¼òÒªÐÅÏ¢
def LoadMissionDescription():
    global QuestDescriptions
    
    questPath = os.path.join(GetQuestDataName(), "MissionDescription.xml")
    questLoader = IPY_GameWorld.IPY_XMLLoader()
    #questLoader.LoadFromFile(questPath)
    questLoader.LoadFromXML(questPath, ZipFile_GetData(questPath))
    
    questsNode = questLoader.GetNodeList().FindNode('quests') 
    for i in range(questsNode.GetChildCount()):
        questNode = questsNode.GetChild(i)
        msgNode = questNode.FindChildNode('msg')
        code = msgNode.GetAttribute('code')
        questID = int(questNode.GetAttribute('id'))
        curQuestDescriptionsData = QuestDescriptionsData()
        curQuestDescriptionsData.Code = code
        curQuestDescriptionsData.ShowReward = GameWorld.ToIntDef(
                                              questNode.GetAttribute('have_reward'), 0)
        QuestDescriptions[questID] = curQuestDescriptionsData
    return
 
#---------------------------------------------------------------------
##¼ÓÔØÈÎÎñÌâ¿â
# @param ÎÞ
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¼ÓÔØÈÎÎñÌâ¿â
def ReadSubjectLib():
    mapID = GameWorld.GetMap().GetMapID()
    #²»ÐèÒªÖØ¶ÁµÄµØÍ¼
    if mapID not in ChConfig.Def_Subject_Map:
        return
    
    curPath = "%s\\SubjectLib"%GetQuestDataName()
    curPath = curPath.upper()
    
    if not ZipFile_IsDir(curPath):
        GameWorld.Log("·¾¶ = %s , ÎÞ·¨²éÕÒµ½´ðÌâÌâ¿â!"%(curPath))
        return
    
    
    files = ZipFile_ListFile(curPath)
    for file in files:
        file = file.lower()
        ext = os.path.splitext(file)
        postfix = ext[1]
        if postfix != ".txt":
            continue
        
        fileName = ext[0]
        fileData = ZipFile_GetData(os.path.join(curPath, file))
        SubjectLib.ReadSubjectData(fileData, fileName)
    
    return
 
#---------------------------------------------------------------------
##C++´¥·¢, Ö´ÐÐËùÓÐÈÎÎñÂß¼­
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks C++´¥·¢, Ö´ÐÐËùÓÐÈÎÎñÂß¼­
def ReloadQuests(tick):
    global ZipFile
    global ZipFileTree
    global Quests
    global AllQuestsEvents
    
    #Ìí¼Ó¸ß¾«¶È¼ÆÊýÆ÷
    gameWorldMgr = GameWorld.GetGameWorld() 
    saveTick = gameWorldMgr.GetHighResolutionTick()
    
    #---¿ªÊ¼¼ÓÔØ---
    questPath = ChConfig.GetAppPath() + "QuestData.zip"
    ZipFile = zipfile.ZipFile(questPath)
    ZipFileTree = __GetFileTree(ZipFile)
    
    #currentLoader = IPY_GameWorld.IPY_XMLLoader()
    #currentLoader.ClearLoader()
    IPY_GameWorld.ClearXML()
    
    Quests.clear()
    
    AllQuestsEvents.clear()
    
    LoadQuestData()
    
    #¶ÁÈ¡¹¦ÄÜNPCÊý¾Ý
    LoadFunctionData()
    
    #¶ÁȡĬÈ϶Ի°Êý¾Ý
    LoadDefaultTalkData()
    
    #¶ÁÈ¡ÈÎÎñ´¥·¢Êý¾Ý
    LoadQuestTrig()
    
    #¶ÁÈ¡ËùÓеÄÌâ¿â
    #SubjectLib.ReadData()
    
    ReadSubjectLib()
    
    #¶ÁÈ¡ËùÓÐÈÎÎñÈÎÎñÃèÊöÊý¾Ý
    LoadMissionDescription()
    
    #---¼ÓÔØ½áÊø---
    GameWorld.Log('Reload Quests. path = %s, lastTick = %s'%(
                            questPath, gameWorldMgr.GetHighResolutionTick() - saveTick))
    return