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