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
#!/usr/bin/python
# -*- coding: GBK -*-
#
# @todo: 
#
# @author: Alee
# @date 2017-12-29 ÏÂÎç02:02:23
# @version 1.0
#
# @note: ¹¹½¨¹¤¾ßÐèͬ²½´Ë±í
#
#---------------------------------------------------------------------
import CommFunc
import logging
# 1. ¹¹½¨±í
 
        
class MapEventPoint():
    def __init__(self):
        self.MapID = 0
        self.NPCID = 0    
        self.LowLV = 0    
        self.HighestLV = 0    
        self.Defense = 0    
        
        
    def ReadFromList(self, curList):
        self.MapID = CommFunc.ToIntDef(curList[1])
        self.NPCID = CommFunc.ToIntDef(curList[2])
        self.LowLV = CommFunc.ToIntDef(curList[7])
        self.HighestLV = CommFunc.ToIntDef(curList[8])
        self.Defense = CommFunc.ToIntDef(curList[9])
        
        return
 
class NPCPoint():
    def __init__(self):
        self.NPCID = 0
        self.MapID = 0
        self.Point = None
        return
 
    def ReadFromList(self, curList):
        self.NPCID = CommFunc.ToIntDef(curList[0])
        self.MapID = CommFunc.ToIntDef(curList[1])
        self.Point = eval(curList[2])
        
class MapEventPointMgr():
    def __init__(self):
        self.__Table = []
        self.__NPCPoint = {}
        
    def InitTable(self, tablePath):
        fileIO = open(tablePath, "r")
        lines = fileIO.readlines()
        
        linenum = 0
        for line in lines:
            linenum += 1
            # 1.×Ö¶ÎÀàÐÍ 2.×Ö¶ÎÃû 3.×ֶα¸×¢
            if linenum <= 3:
                continue
            classObj = MapEventPoint()
            lineList = line.split('\t')
            classObj.ReadFromList(lineList)
            
            # Åųý·ÇÍÑ»ú¹ÒµØÍ¼
            if classObj.MapID / 10000 != 1:
                continue
            self.__Table.append(classObj)
            
 
            
    def InitPointType(self, tablePath):
        fileIO = open(tablePath, "r")
        lines = fileIO.readlines()
        
        linenum = 0
        for line in lines:
            linenum += 1
            # 1.×Ö¶ÎÀàÐÍ 2.×Ö¶ÎÃû 3.×ֶα¸×¢
            if linenum <= 3:
                continue
            classObj = NPCPoint()
            lineList = line.strip().split('\t')
 
            classObj.ReadFromList(lineList)
            
            self.__NPCPoint[classObj.NPCID] = classObj
        
        return
    
    
    def FindNPC(self, robot):
        lv = robot.GetPlayerInfo().GetPlayerLV()
        
        # ÒÔ·ÀÓùΪµÚÒ»Ìõ¼þ£¬È¡µ±Ç°µØÍ¼¹ÖÎïµÈ¼¶ÔÚÍæ¼ÒµÈ¼¶ÉÏÏÂ20¼¶µÄµØ·½
        # ÒԵȼ¶HighestLVΪ±ê׼ȡ×î¸ß
        maxlv = 0
        pointNPCID = 0
        for point in self.__Table:
            if lv < point.LowLV:
                continue
            if point.MapID/10000 != 1:
                continue
            
            # È¡×î¸ßµÄ
            if maxlv < point.LowLV:
                maxlv = point.LowLV
                pointNPCID = point.NPCID
 
        npcPoint = self.__NPCPoint.get(pointNPCID, None)
        if not npcPoint:
            return
        
        tjgPoint = [npcPoint.MapID, npcPoint.Point, npcPoint.NPCID]
        
        logging.debug("¹Ò»úµã------%s"%str(tjgPoint))
        robot.GetPlayerInfo().SetTJGPoint(tjgPoint)
        return
    
    
 
__gMapEventPointReader = None
 
def ReadMapEventPoint( PyBaseRoot):
    global __gMapEventPointReader
    if not __gMapEventPointReader:
        __gMapEventPointReader =  MapEventPointMgr()
        __gMapEventPointReader.InitTable(PyBaseRoot + "Data\\MapEventPoint.txt")
        __gMapEventPointReader.InitPointType(PyBaseRoot + "Data\\MonsterRefreshPoint.txt")
        
def GetMapEventPoint():
    global __gMapEventPointReader
    return __gMapEventPointReader