#!/usr/bin/python # -*- coding: GBK -*- #--------------------------------------------------------------------- # #--------------------------------------------------------------------- ##@package eggxp # @todo: µØÍ¼×ø±êÂß¼­¿ØÖÆÆ÷ # # @author eggxp # @date 2010-4-27 # @version 1.7 # # @note: # # @change: "2010-05-12 18:30" zhengyang Ìí¼Ó×¢ÊÍ # @change: "2010-06-03 11:30" adaws Ìí¼Óº¯ÊýGetAreaGameObjByType ¸ù¾Ý¸ø¶¨ÖÐÐÄ×ø±ê£¬ # ²éÕÒ·¶Î§ÁÐ±í£¬ºÍ²éÕÒObjµÄÀàÐÍ£¬·µ»ØÖ¸¶¨·¶Î§ÄÚµØÍ¼ÉϵÄÖ¸¶¨objÀàÐ͵ÄobjÁбí # @change: "2010-06-30 16:30" adaws ÐÂÔöº¯Êý »ñµÃµØÍ¼Öиø¶¨×ø±êÖÜΧXX¸ñÄÚûÓÐÕϰ­ÎïµÄµØÍ¼Ò»µã # @change: "2010-08-12 13:30" panwei ÐÞ¸ÄGetAreaGameObjByTypeº¯Êý # @change: "2011-04-30 13:10" zhangd ÐÞ¸ÄGetNearbyPosByDis½Ó¿Ú # @change: "2012-05-22 11:00" jiang Ôö¼Óº¯ÊýGetAreaTypeByMapPos()»ñȡijһµãËùÔÚµÄÇøÓòÀàÐÍ # @change: "2015-09-23 14:30" hxp Ôö¼Óº¯ÊýGetEmptyPlaceInAreaEx»ñȡijµãÖ¸¶¨·¶Î§ÇøÓòÄÚµÄËæ»úµã #--------------------------------------------------------------------- """Version = 2015-09-23 14:30""" #--------------------------------------------------------------------- import GameWorld import random import ChConfig import AttackCommon import IPY_GameWorld #--------------------------------------------------------------------- ######################################################### #PythonµÄpos¶¨Òå ## PythonµÄpos¶¨Òå # # PyClassÀàµÄÏêϸ˵Ã÷. class PYPosition: __PosX = 0 __PosY = 0 ## ³õʼ»¯X£¬Y # @param # @return None # @remarks º¯ÊýÏêϸ˵Ã÷. def __init__(self, posX, posY): #³õʼ»¯ self.__PosX = posX self.__PosY = posY ## ·µ»ØX # @param # @return x # @remarks º¯ÊýÏêϸ˵Ã÷. def GetPosX(self): return self.__PosX ## ·µ»Øy # @param # @return y # @remarks º¯ÊýÏêϸ˵Ã÷. def GetPosY(self): return self.__PosY #--------------------------------------------------------------------- ## ÔÚposX, posY ÖÜΧÕÒµ½Ò»¸öûÓÐÍæ¼ÒµÄµã # @param posX ×ø±êX # @param posY ×ø±êY # @param dist ¾àÀë # @return None # @remarks º¯ÊýÏêϸ˵Ã÷. def GetEmptyPlaceInArea(posX, posY, dist): gameMap = GameWorld.GetMap() for i in range(0, dist*dist): resultX = random.randint(posX-dist, posX+dist) resultY = random.randint(posY-dist, posY+dist) if resultX == posX and resultY == posY: #ÕÒµ½µÄλÖþÍÊÇ×Ô¼ºµÄλÖà continue if gameMap.CanMove(resultX, resultY) != True: continue #¼ì²éÓÐûÓÐÍæ¼ÒÔÚÕâÒ»µãÉÏ mapObj = gameMap.GetPosObj(resultX, resultY) if not mapObj: continue if mapObj.GetObjCount() != 0: #ÓÐÍæ¼ÒÔڴ˵ãÉÏ continue return PYPosition(resultX, resultY) #·µ»Ø×Ô¼º×ø±ê return PYPosition(posX, posY) # Öмäïοգ¨¾Å¸ñ£©µÄËæ»ú·¶Î§µã def GetEmptyPlaceInSurround(posX, posY, dist): gameMap = GameWorld.GetMap() dist = max(dist, 2) for i in range(0, dist*dist): tmpX = random.randint(2, dist) tmpY = random.randint(2, dist) if random.randint(0, 1): resultX = posX + tmpX else: resultX = posX - tmpX if random.randint(0, 1): resultY = posY + tmpY else: resultY = posY - tmpY if gameMap.CanMove(resultX, resultY) != True: continue #¼ì²éÓÐûÓÐÍæ¼ÒÔÚÕâÒ»µãÉÏ mapObj = gameMap.GetPosObj(resultX, resultY) if not mapObj: continue if mapObj.GetObjCount() != 0: #ÓÐÍæ¼ÒÔڴ˵ãÉÏ continue return PYPosition(resultX, resultY) #·µ»Ø×Ô¼º×ø±ê return PYPosition(posX, posY) ## ÔÚposX, posY ÖÜΧÕÒµ½Ò»¸öûÓÐÍæ¼ÒµÄµã # @param posX ×ø±êX # @param posY ×ø±êY # @param minDist ×îС¾àÀë # @param maxDist ×î´ó¾àÀë # @return None # @remarks º¯ÊýÏêϸ˵Ã÷. def GetEmptyPlaceInAreaEx(posX, posY, minDist, maxDist): gameMap = GameWorld.GetMap() for i in range(0, maxDist*maxDist): resultX = random.randint(posX-maxDist, posX+maxDist) resultY = random.randint(posY-maxDist, posY+maxDist) if resultX == posX and resultY == posY: #ÕÒµ½µÄλÖþÍÊÇ×Ô¼ºµÄλÖà continue if gameMap.CanMove(resultX, resultY) != True: continue #ÓëÖÐÐĵãµÄ¾àÀëСÓÚ×îС¾àÀëµ÷¹ý if GameWorld.GetDistEx(posX, posY, resultX, resultY) < minDist: continue #¼ì²éÓÐûÓÐÍæ¼ÒÔÚÕâÒ»µãÉÏ mapObj = gameMap.GetPosObj(resultX, resultY) if not mapObj: continue if mapObj.GetObjCount() != 0: #ÓÐÍæ¼ÒÔڴ˵ãÉÏ continue return PYPosition(resultX, resultY) #·µ»Ø×Ô¼º×ø±ê return PYPosition(posX, posY) #--------------------------------------------------------------------- ## ¸ù¾Ý¸ø¶¨Êý¾Ý,ÐýתÉßÐαéÀú·µ»Ø×ø±ê # @param posX ×ø±êX # @param posY ×ø±êY # @param dist ¾àÀë # @return None # @remarks º¯ÊýÏêϸ˵Ã÷. def GetPosByMatrix(posX , posY , matrix): gameMap = GameWorld.GetMap() for curPos in matrix: resultX = posX + curPos[0] resultY = posY + curPos[1] if not gameMap.CanMove(resultX, resultY): #Íæ¼Ò²»¿ÉÒÆ¶¯Õâ¸öµã continue #¼ì²éÓÐûÓжÔÏóÔÚÕâÒ»µãÉÏ mapObj = gameMap.GetPosObj(resultX, resultY) if not mapObj: continue if mapObj.GetObjCount() != 0: #ÓжÔÏóÔڴ˵ãÉÏ continue return resultX , resultY #ûÓÐÆäËûµã¿ÉÒÔµôÂäÁË return posX , posY #--------------------------------------------------------------------- ## ¸ù¾Ý¸ø¶¨ÖÐÐÄ×ø±ê£¬²éÕÒ·¶Î§ÁÐ±í£¬ºÍ²éÕÒObjµÄÀàÐÍ£¬·µ»ØÖ¸¶¨·¶Î§ÄÚµØÍ¼ÉϵÄÖ¸¶¨objÀàÐ͵ÄobjÁбí # @param centerPosX ÖÐÐÄ×ø±êX # @param centerPosY ÖÐÐÄ×ø±êY # @param areaMatrixList ²éÕÒ·¶Î§ÁÐ±í¾ØÕó[[0,0]] # @param paramTypeList ÀàÐÍÁбí[IPY_GameWorld.gotNPC, IPY_GameWorld.gotPlayer] # @return findObjList ÕÒµ½µÄËùÓеÄobjÁбí # @remarks º¯ÊýÏêϸ˵Ã÷. def GetAreaGameObjByType(centerPosX, centerPosY, areaMatrixList, paramTypeList): gameMap = GameWorld.GetMap() findObjList = [] # ÕÒµ½µÄËùÓеÄobjÁбí #²éÕÒµØÍ¼·¶Î§ÖеÄÿһµã for curAddPosX, curAddPosY in areaMatrixList: curPosX = centerPosX + curAddPosX curPosY = centerPosY + curAddPosY mapObj = gameMap.GetPosObj(curPosX, curPosY) if not mapObj: continue #Ò»µãÖпÉÄÜÓжà¸öobj for i in range(0, mapObj.GetObjCount()): curObj = mapObj.GetObjByIndex(i) #ºÏ·¨ÐÔ¼ì²é if not AttackCommon.CheckObjCanDoLogic(curObj): continue if curObj.GetGameObjType() not in paramTypeList: continue findObjList.append(curObj) return findObjList ## Ëæ»ú»ñµÃµ±Ç°µØÍ¼¸ø¶¨×ø±êµÄx,yÔÚdist·¶Î§ÄڵĿÉÒÔÒÆ¶¯µÄÒ»µã Èç¹ûûÓÐÒ»µã¿ÉÒÔÒÆ¶¯Ôò·µ»Ø 0, 0 # @param posX: ×ø±êX # @param posY: ×ø±êY # @param dist: ÖÜΧµÄ¾àÀë # @return: posX,posY ×ø±ê Èç¹ûûÓÐÕÒµ½·µ»Ø0, 0 # @remarks: Èç¹û·µ»Ø0, 0ÔÚµ÷Óøú¯ÊýµÄÄ£¿éÖÐÐèÒª×öÅж¨£¬Èç¹ûÊÇ0, 0×öÌØÊâ´¦Àí def GetNearbyPosByDis(posX, posY, dist): gameMap = GameWorld.GetMap() for i in range(0, dist*dist): resultX = random.randint(posX-dist, posX+dist) resultY = random.randint(posY-dist, posY+dist) if gameMap.CanMove(resultX, resultY): return (resultX, resultY) if gameMap.CanMove(posX, posY): return (posX, posY) return (0, 0) ## »ñÈ¡µØÍ¼ÉÏijһµãµÄÇøÓòÀàÐÍ # @param posX: ×ø±êX # @param posY: ×ø±êY # @return: ÇøÓòÀàÐÍ def GetAreaTypeByMapPos(posX, posY): curPosObj = GameWorld.GetMap().GetPosObj(posX, posY) if not curPosObj: return IPY_GameWorld.gatNormal areaType = IPY_GameWorld.gatNormal for index in xrange(curPosObj.GetEffectCount()): effectID = curPosObj.GetEffectID(index) if effectID == 0: continue #°²È«Çø, ÓÅÏȼ¶×î¸ß£¬Èç¹ûÓа²È«ÇøÔòÖ±½Ó·µ»Ø°²È«Çø if effectID == ChConfig.Def_AreaType_SkillID_Safe: return IPY_GameWorld.gatSafe if areaType != IPY_GameWorld.gatNormal: continue #×ÔÓÉÇø if effectID == ChConfig.Def_AreaType_SkillID_FreePK: areaType = IPY_GameWorld.gatFreePK #¼Ò×åÇø if effectID == ChConfig.Def_AreaType_SkillID_FamilyPK: areaType = IPY_GameWorld.gatFamilyPK #ÆÕÍ¨Çø return areaType def GetAreaBuffIsExist(posX, posY, findEffectID): ## »ñÈ¡µØÍ¼ÉÏijһµãÊÇ·ñ´æÔÚij¸öbuff curPosObj = GameWorld.GetMap().GetPosObj(posX, posY) if not curPosObj: return False effectCount = curPosObj.GetEffectCount() for index in range(0, effectCount): effectID = curPosObj.GetEffectID(index) if effectID == findEffectID: return True return False