| #!/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  |