hzr
2025-04-21 2d9d117228fd281aeeb0f3c173f538744f8dffd7
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package NPCAI.AIType_21
#
# @todo:¸±±¾»î¶¯»úÆ÷ÈË
# @author hxp
# @date 2018-12-06
# @version 1.0
#
# ÏêϸÃèÊö: ¸±±¾»î¶¯»úÆ÷ÈË
#
#-------------------------------------------------------------------------------
#"""Version = 2018-12-06 20:00"""
#-------------------------------------------------------------------------------
 
import ChConfig
import AICommon
import NPCCommon
import BaseAttack
import IpyGameDataPY
import IPY_GameWorld
import GameWorld
import FBCommon
import GameObj
 
import random
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
## ³õʼ»¯
#  @param curNPC µ±Ç°npc
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def DoInit(curNPC):
    curNPC.GetNPCAngry().Init(ChConfig.Def_SuperFBBossAngryCount)
    return
 
def OnNPCReborn(curNPC):
    curNPC.SetIsNeedProcess(True)
    return
 
## Ö´ÐÐAI
#  @param curNPC µ±Ç°npc
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def ProcessAI(curNPC, tick):
    npcControl = NPCCommon.NPCControl(curNPC)
    if curNPC.GetCurAction() == IPY_GameWorld.laNPCDie or not curNPC.IsAlive():
        return
    
    #Ë¢ÐÂ×Ô¼ºµÄbuff
    npcControl.RefreshBuffState(tick)
    if GameObj.GetHP(curNPC) == 0:
        # BUFFË¢ÐÂÖпÉÄܻᵼÖÂNPCËÀÍö
        return
    
    #Ë¢ÐÂ×Ô¼º³ðºÞ¶ÈÁбí
    npcControl.RefreshAngryList(tick)
    curNPCAngry = npcControl.GetMaxAngryTag()
    
    #³ðºÞ¶ÈÁбíÖеÄÈËΪ¿Õ
    if curNPCAngry == None:
        if curNPC.GetSpeed() != 0:
            __RobotMove(curNPC)
        return
    
    #³ðºÞ¶ÔÏóÀàÐÍ,³ðºÞ¶ÔÏóID
    curNPCAngryType = curNPCAngry.GetObjType()
    curNPCAngryID = curNPCAngry.GetObjID()
    
    #Ö´Ðй¥»÷Âß¼­
    __NPCFight(curNPC, curNPCAngryID, curNPCAngryType, tick)
    return
 
def __RobotMove(curNPC):
    if curNPC.GetCurAction() == IPY_GameWorld.laNPCMove:
        #GameWorld.DebugLog("ÒÆ¶¯Öв»´¦Àí£¡(%s,%s)" % (curNPC.GetPosX(), curNPC.GetPosY()))
        return
    mapID = GameWorld.GetMap().GetMapID()
    lineID = FBCommon.GetFBPropertyMark()
    dataMapID = FBCommon.GetRecordMapID(mapID)
    fbRandMovePosDict = IpyGameDataPY.GetFuncEvalCfg("AI198Point", 2, {})
    if str(dataMapID) in fbRandMovePosDict:
        __RobotMove2(curNPC, fbRandMovePosDict[str(dataMapID)])
        return
    posKey = "%d%02d" % (mapID, lineID)
    fbMovePosDict = IpyGameDataPY.GetFuncCfg("AI198Point", 1)
    if posKey not in fbMovePosDict:
        posKey = "%d%02d" % (mapID, 0)
        if posKey not in fbMovePosDict:
            return
        
    posList = fbMovePosDict[posKey]
    Key_PosIndex = "RobotMovePosIndex" # NPCÉÏ´ÎÒÆ¶¯µÄ×ø±êË÷Òý£¬´æÖµ+1
    posIndex =  curNPC.GetDictByKey(Key_PosIndex) - 1
    if posIndex < 0:
        # »¹Ã»ÓÐ×ß¹ýµãµÄ£¬Ñ°ÕÒËùÓеãÖÐ×î½üµÄµã
        posIndex = random.randint(0, len(posList) - 1)
    else:
        tagPosX, tagPosY = posList[posIndex]
        tagDist = GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), tagPosX, tagPosY)
        if tagDist < 2:
            posIndex += 1
            
    if posIndex < 0 or posIndex >= len(posList):
        posIndex = random.randint(0, len(posList) - 1)
        
    curNPC.SetDict(Key_PosIndex, posIndex + 1)
    tagPosX, tagPosY = posList[posIndex]
    curNPC.Move(tagPosX, tagPosY)
    return
 
def __RobotMove2(curNPC, randPosList):
    ''' ¸ù¾Ý¶àÌõ·¾¶Ëæ»úÒÆ¶¯£¬²»Í¬Â·¾¶¼äÈç¹û´æÔÚ½»²æµã£¬ÄÇô¿ÉÄÜËæ»ú¸Ä±ä·¾¶
    @param randPosList: [[[·¾¶Aµã1x,y],[·¾¶Aµã2x,y],...], [[·¾¶Bµã1x,y],[·¾¶Bµã2x,y],...], ...]
    '''
    if not randPosList:
        return
    
    #objID = curNPC.GetID()
    #npcID = curNPC.GetNPCID()
    RobotMoveIndexInfo = "RobotMoveIndexInfo" # ÉÏ´ÎÒÆ¶¯Ä¿±ê×ø±êµãË÷ÒýÐÅÏ¢  i * 100 + j
    RobotMovePosInfo = "RobotMovePosInfo" # ÉÏ´ÎÒÆ¶¯Ä¿±ê×ø±êµã posX * 10000 + posY
    indexInfo =  curNPC.GetDictByKey(RobotMoveIndexInfo)
    posInfo =  curNPC.GetDictByKey(RobotMovePosInfo)
    tagI, tagJ = indexInfo / 100, indexInfo % 100
    tagPosX, tagPosY = posInfo / 10000, posInfo % 10000
    curPosX, curPosY = curNPC.GetPosX(), curNPC.GetPosY()
    
    
    resetPosPath = True # ÖØÖÃ×ø±ê·¾¶£¬ÎªTrueÊ±ÖØÐÂËÑË÷·¾¶
    # ÒѾ­ÓÐÄ¿±êµã
    if tagPosX and tagPosY:
        # ÀíÂÛÉÏÅäÖÃÃ»ÖØ¶Á
        if tagI < len(randPosList) and type(randPosList[tagI]) in [list, tuple] and tagJ < len(randPosList[tagI]) \
            and randPosList[tagI][tagJ] == [tagPosX, tagPosY]:
            resetPosPath = False
            
    #GameWorld.DebugLog("__RobotMove2: objID=%s,npcID=%s,curPos(%s,%s),tagPos(%s,%s),tagIndex(%s,%s)" 
    #                   % (objID, npcID, curPosX, curPosY, tagPosX, tagPosY, tagI, tagJ))
    #GameWorld.DebugLog("    resetPosPath=%s,randPosList=%s" % (resetPosPath, randPosList))
    
    # ÖØÖ÷¾¶£¬ÏÈ×ßÏò×î½üµÄµã
    if resetPosPath:
        nearestDist = 99999999
        for i, pathList in enumerate(randPosList):
            for j, pos in enumerate(pathList):
                posX, posY = pos
                tagDist = GameWorld.GetDist(curPosX, curPosY, posX, posY)
                if tagDist < nearestDist:
                    nearestDist = tagDist
                    tagI, tagJ = i, j
                    tagPosX, tagPosY = posX, posY
        #GameWorld.DebugLog("    nearestDist=%s" % nearestDist)
    else:
        tagDist = GameWorld.GetDist(curPosX, curPosY, tagPosX, tagPosY)
        #GameWorld.DebugLog("    tagDist=%s" % (tagDist))
        # ¿ìµ½´ïÄ¿±êµãÁË£¬Ô¤ÏÈѰÕÒϸöµã
        if tagDist < 2:
            nearPosIndexList = __getNearPosIndexList(randPosList, tagI, tagJ)
            #GameWorld.DebugLog("    nearPosIndexList=%s" % nearPosIndexList)
            if nearPosIndexList:
                tagI, tagJ = random.choice(nearPosIndexList)
                tagPosX, tagPosY = randPosList[tagI][tagJ]
            
    #GameWorld.DebugLog("    tagPos(%s,%s),tagIndex(%s,%s)" % (tagPosX, tagPosY, tagI, tagJ))
    curNPC.SetDict(RobotMoveIndexInfo, tagI * 100 + tagJ)
    curNPC.SetDict(RobotMovePosInfo, tagPosX * 10000 + tagPosY)
    curNPC.Move(tagPosX, tagPosY)
    return
 
def __getNearPosIndexList(randPosList, tagI, tagJ):
    ## »ñÈ¡¶àÌõ·¾¶ÉÏÏàÁڵĵã
    pathPosList = randPosList[tagI]
    if not pathPosList or len(pathPosList) <= 1:
        return
    
    tagPosX, tagPosY = randPosList[tagI][tagJ]
    nearPosIndexList = __getNearIndexByPath(pathPosList, tagI, tagJ)
    # ¼ì²éÆäËû·¾¶½»²æµã
    for i, pathList in enumerate(randPosList):
        if i == tagI:
            # ±¾Â·¾¶²»´¦Àí
            continue
        for j, pos in enumerate(pathList):
            posX, posY = pos
            if posX == tagPosX and posY == tagPosY:
                for ni, nj in __getNearIndexByPath(pathList, i, j):
                    if [ni, nj] not in nearPosIndexList:
                        nearPosIndexList.append([ni, nj])
    return nearPosIndexList
 
def __getNearIndexByPath(pathPosList, tagI, tagJ):
    ## »ñȡijÌõ·¾¶ÉϵÄÏàÁÚµãË÷ÒýÐÅÏ¢
    nearPosIndexList = []
    # Æðʼµã »ò ×îÖÕµã
    if tagJ == 0 or tagJ == len(pathPosList) - 1:
        # Æðµã=ÖÕµã
        if pathPosList[0] == pathPosList[-1]:
            nearPosIndexList.append([tagI, 1])
            nearPosIndexList.append([tagI, -2])
        # Æðµã
        elif tagJ == 0:
            nearPosIndexList.append([tagI, 1])
        else:
            nearPosIndexList.append([tagI, -2])
            
    # Öмäµã£¬È¡Ç°ºóÁ½µã
    else:
        nearPosIndexList.append([tagI, tagJ - 1])
        nearPosIndexList.append([tagI, tagJ + 1])
    return nearPosIndexList
 
#---------------------------------------------------------------------
## npc¹¥»÷Âß¼­
#  @param curNPC µ±Ç°npc
#  @param tagID curNPCAngryID
#  @param tagType curNPCAngryType 
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __NPCFight(curNPC, tagID, tagType, tick):
    #ÉèÖýøÈëÕ½¶·×´Ì¬
    NPCCommon.SetNPCInBattleState(curNPC)
    npcControl = NPCCommon.NPCControl(curNPC)
    
    #¿ªÊ¼¹¥»÷
    curTag = GameWorld.GetObj(tagID, tagType)
    
    if curTag == None or GameObj.GetHP(curTag) <= 0:
        return
    
    tagDist = GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), curTag.GetPosX(), curTag.GetPosY())
    
    #---ÓÅÏÈÊͷż¼ÄÜ---
    if AICommon.DoAutoUseSkill(curNPC, curTag, tagDist, tick):
        return
    
    #---ÊÍ·ÅÆÕͨ¹¥»÷---
    
    if curNPC.GetSpeed() == 0:
        # ²»¿ÉÒÆ¶¯NPC
        if tagDist > curNPC.GetAtkDist():
            return
        
        if tick - curNPC.GetAttackTick() < curNPC.GetAtkInterval():
            #¹¥»÷¼ä¸ôûÓе½, ·µ»Ø
            return
        
        #ÆÕͨ¹¥»÷
        BaseAttack.Attack(curNPC, curTag, None, tick)
        return
    
    #³¬¹ý¹¥»÷¾àÀë,ÒÆ¶¯¹ýÈ¥
    if tagDist > curNPC.GetAtkDist():
 
        destDist = GameWorld.GetDist(curNPC.GetDestPosX() , curNPC.GetDestPosY(), curTag.GetPosX(), curTag.GetPosY())
        if destDist <= curNPC.GetAtkDist() and curNPC.GetCurAction() == IPY_GameWorld.laNPCMove:
            # Ä¿±êÔÚÒÆ¶¯µÄ¹¥»÷·¶Î§ÄÚ£¬²»¸Ä±äÄ¿±êµã
            return
        npcControl.MoveToObj_Detel(curTag)
        return
    else:
        curNPC.StopMove()
        
    if tick - curNPC.GetAttackTick() < curNPC.GetAtkInterval():
        #¹¥»÷¼ä¸ôûÓе½, ·µ»Ø
        return
    
    if npcControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):
        #ÐÞÕýÕâ¸öNPCµÄÕ¾Á¢Î»ÖÃ
        return
    
    #ÆÕͨ¹¥»÷
    BaseAttack.Attack(curNPC, curTag, None, tick)
    return
 
## NPCËÀÍö
#  @param curNPC µ±Ç°npc
#  @param hurtType É˺¦ÕßµÄobjÀàÐÍ
#  @param hurtID É˺¦ÕßµÄobjID
#  @return None
def OnDie(curNPC, hurtType, hurtID):
    AICommon.DoNPCUseSkillOnDie(curNPC)
    return