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
#!/usr/bin/python
# -*- coding: GBK -*-
#
# @todo: 
#
# @author: Alee
# @date 2017-12-29 ÏÂÎç02:02:23
# @version 1.0
#
# @note: ¹¹½¨¹¤¾ßÐèͬ²½´Ë±í
#
#---------------------------------------------------------------------
import CommFunc
import logging
import ConfigurationReader.ConfigIniReader 
 
 
 
 
# 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[0])
        self.NPCID = CommFunc.ToIntDef(curList[1])
        self.LowLV = CommFunc.ToIntDef(curList[2])
        self.HighestLV = CommFunc.ToIntDef(curList[3])
        self.Defense = CommFunc.ToIntDef(curList[4])
 
        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
            # ×Ö¶ÎÃû 
            if linenum <= 1:
                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
            # .×Ö¶ÎÃû 
            if linenum <= 1:
                continue
            classObj = NPCPoint()
            lineList = line.strip().split('\t')
 
            classObj.ReadFromList(lineList)
            
            self.__NPCPoint[classObj.NPCID] = classObj
        return
    
    
    def GetPoint(self, robot, lv, defense, maxMapID):
        #maxMapID = robot.GetPlayerInfo().GetMaxMapID()
        
        myPoint = None # ×îÊʺϵĵȼ¶¹Ò»úµã
        pointList = []
        
        for point in self.__Table:
            if maxMapID != 0:
                # ´æÔÚÖ¸¶¨µØÍ¼
                if maxMapID != point.MapID:
                    continue
            else:
                if point.MapID/10000 != 1:
                    continue
            
            if point.LowLV  == 0:
                # ·Ç¹Ò»úµã
                continue
            
            pointList.append(point)     # ¼Ç¼±¾µØÍ¼µÄ¿É¹Ò»úµã
            # ÕÒµ½×îÊʺÏ×Ô¼ºµÄµÈ¼¶µã
            if lv >= point.LowLV:
                if myPoint and myPoint.LowLV >= point.LowLV:
                    # ÒѼǼ
                    continue
                myPoint = point
                #print myPoint.LowLV
 
        if not myPoint:
            if not pointList:
                #print "ÓÎÏ·ÖÐûÓÐÊʺϵĹһúµã"
                return myPoint
            
            # ×îµÍµã
            #print "ûÕÒµ½--------È¡×îµÍ"
            return pointList[0]
        
        #print "-----------µ±Ç°µã", myPoint.LowLV
        pIndex = pointList.index(myPoint)
 
        pointLen = len(pointList)
        # ÔÙ¸ù¾Ý·ÀÓùÉÏϵ÷Õû
        if defense >= pointList[min(pointLen-1, pIndex+1)].Defense:
            # ¸ßÒ»µã
            #print "¸ßÒ»µã"
            return pointList[min(pointLen-1, pIndex+1)]
        
        if defense < myPoint.Defense:
            # µÍÒ»µã
            #print "µÍÒ»µã" 
            return pointList[max(0, pIndex-1)]
        
        #print "µ±Ç°µã"
        return myPoint
    
    
    def FindNPC(self, robot):
        # µØÍ¼½âËøÌõ¼þ 1.µÈ¼¶  2.ÈÎÎñ  3.È¡¿É¹Ò»úµÄµØÍ¼µÄµÈ¼¶,ÉÏϵã¸ù¾Ý·ÀÓù²¨¶¯
        lv = robot.GetPlayerInfo().GetPlayerLV()
        defense = robot.GetPlayerInfo().GetDefense()
        
        maxMapID = robot.GetPlayerInfo().GetMaxMapID()
 
        point = self.GetPoint(robot, lv, defense, maxMapID)
        if not point:
            return
        pointNPCID = point.NPCID
            
        npcPoint = self.__NPCPoint.get(pointNPCID, None)
        if not npcPoint:
            logging.info("ÕÒ²»µ½ÈκιһúµãmapID:%s lv:%s defense:%s NPCID:%s"%(maxMapID, lv, defense, pointNPCID))
            return
        
        tjgPoint = [maxMapID, npcPoint.Point, pointNPCID]
        
        logging.debug("¹Ò»úµã------%s"%str(tjgPoint))
        robot.GetPlayerInfo().SetTJGPoint(tjgPoint)
        return
    
    
 
__gMapEventPointReader = None
 
def ReadMapEventPoint( PyBaseRoot):
    config =  ConfigurationReader.ConfigIniReader.GetConfig()
    ServerDBConfigPath = config.GetServerDBConfigPath()    #Êý¾Ý¿â·¾¶
    global __gMapEventPointReader
    if not __gMapEventPointReader:
        __gMapEventPointReader =  MapEventPointMgr()
        __gMapEventPointReader.InitTable(ServerDBConfigPath + r"\PySysDB\tagMapEventPoint.txt")
        __gMapEventPointReader.InitPointType(ServerDBConfigPath + r"\PySysDB\tagMonsterRefreshPoint.txt")
        
def GetMapEventPoint():
    global __gMapEventPointReader
    return __gMapEventPointReader