hxp
4 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
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
#!/usr/bin/python
# -*- coding: GBK -*-
#
#
##@package AIType_104
# @todo: ³èÎïAI
#
# @author chenxuewei
# @date 2010-06-26
# @version 2.2
#
# @change: "2010-06-28 20:56" panwei ³èÎï¿ÕÏÐʱ°´±í¸ñÊýÖµ»ØÑª
# @change: "2010-07-02 13:40" chenxuewei ³èÎï¸úËæÖ÷È˹¥»÷£¬ÔÚ¹¥»÷ǰÇå¿ÕÆä×ÔÉíËùÓгðºÞÖµ¡£
# @change: "2010-07-13 19:30" panwei Ð޸ijèÎïAI
# @change: "2010-07-14 18:10" panwei Ð޸ijèÎïAI
# @change: "2010-07-29 17:00" panwei ³èÎïÑéÖ¤Âß¼­Ìáµ½Èë¿Ú´¦
 
# @change: "2010-08-04 15:20" panwei ³èÎïÐÂÔö×Ô¶¯Êͷż¼ÄÜÂß¼­
# @change: "2010-09-02 16:15" panwei ³èÎïÒÆ¶¯·½Ê½ÐÞ¸Ä
# @change: "2010-09-09 13:50" panwei ³èÎïÍ£Ö¹½ÃÕý×ø±êº¯ÊýÐÞ¸Ä
# @change: "2010-09-26 16:45" panwei ³èÎïÒÆ¶¯Âß¼­Åж¨ÐÞ¸Ä
# @change: "2010-10-21 17:45" Alee ³èÎïÌí¼ÓAIģʽ£¬¸úËæAI
# @change: "2011-07-01 12:40" Alee ·À³ÁÃÔÏÞÖÆ
# @change: "2017-02-15 10:00" xdh ºÍÖ÷ÈËÔÚͬһ¸öλÖÃʱ£¬³èÎïÅÜ¿ª
#------------------------------------------------------------------------------ 
"""Version = 2017-02-15 10:00"""
#---------------------------------------------------------------------
#µ¼Èë
import IPY_GameWorld
import GameWorld
import NPCCommon
import BaseAttack
import ChConfig
import AICommon
import SkillShell
import SkillCommon
import PetControl
import GameMap
import GameObj
#---------------------------------------------------------------------
## ³õʼ»¯
#  @param rolePet ³èÎïʵÀý
#  @return None
#  @remarks ³õʼ»¯
def DoInit(rolePet):
    rolePet.GetNPCAngry().Init(ChConfig.Def_Pet_Angry_Count)
    return
#---------------------------------------------------------------------
## Ö´ÐÐAI
#  @param rolePet ³èÎïʵÀý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks Ö´ÐÐAI
def ProcessAI(rolePet, tick):
    #---²éÕÒ³èÎïÖ÷ÈË---
    curPlayer = NPCCommon.GetSummonNPCOwner(IPY_GameWorld.gotPlayer, rolePet)
 
    if curPlayer == None:
        GameWorld.ErrLog('³èÎï = %sÎÞ·¨²éÕÒÖ÷ÈË, AIÖ´ÐÐʧ°Ü'%(rolePet.GetID()))
        return
    
    #---ˢгèÎïµÄBuff---
    rolePetControl = NPCCommon.NPCControl(rolePet)
    rolePetControl.RefreshBuffState(tick)
    if GameObj.GetHP(rolePet) == 0 :
        # BUFFË¢ÐÂÖпÉÄܻᵼÖÂNPCËÀÍö
        return
    
    #---³èÎïÒÆ¶¯ÖÐ---
    if rolePet.GetCurAction() == IPY_GameWorld.laNPCMove and \
        __SummonOutRefreshArea(curPlayer, rolePet, rolePetControl):
        return
    
    #---AIģʽÊÇ Õ½¶·Ä£Ê½---
    if rolePet.GetAIMode() == IPY_GameWorld.pamAttack:
        
        #·À³ÁÃÔ
        if curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_LV) > ChConfig.Def_GameWallow_LV_First:
            return
        
        #---ÓÅÏȹ¥»÷Ö÷ÈË´òµÄ¶ÔÏó---
        masterAttackObj = AICommon.PlayerSummonAkObj(rolePet, tick, False)
        
        if masterAttackObj != None:
            __NPCFight(curPlayer, rolePet, masterAttackObj.GetID(), masterAttackObj.GetGameObjType(), tick)
            return
        
        #---¹¥»÷×Ô¼º³ðºÞÁбíÖеĶÔÏó---
        #Ë¢ÐÂ×Ô¼º³ðºÞ¶ÈÁбí
        rolePetControl.RefreshAngryList(tick)
        
        curAngry = rolePetControl.GetMaxAngryTag()
        
        if curAngry != None:
            __NPCFight(curPlayer, rolePet, curAngry.GetObjID(), curAngry.GetObjType(), tick)
            return
    
    #---ÎÞ³ðºÞÄ¿±êÂß¼­´¦Àí---
    curNPCAction = rolePet.GetCurAction()
    
    #¿ÕÏÐ״̬´¦Àí
    if curNPCAction == IPY_GameWorld.laNPCNull:
        #³èÎï¿ÕÏÐ״̬Ï»ØÑª
        RestoreHP(rolePet, tick)
 
        #Ö´ÐиúËæÒÆ¶¯Âß¼­
        if __SummonMove(curPlayer, rolePet, rolePetControl):
            return
 
        #³èÎï²»ÐèÒªÒÆ¶¯, ÐÞÕý³èÎïµÄλÖÃ, ²»ÈÃÖØµþ
        rolePetControl.FixTagPos(rolePet.GetPosX(), rolePet.GetPosY(), 1)
        return
 
    #¹¥»÷״̬´¦Àí
    if curNPCAction == IPY_GameWorld.laNPCAttack:
        rolePet.SetCurAction(IPY_GameWorld.laNPCNull)
 
    return
    
#---------------------------------------------------------------------
## Õ½¶·
#  @param curPlayer Íæ¼ÒʵÀý
#  @param rolePet ³èÎïʵÀý
#  @param tagID ¹¥»÷Ä¿±êID
#  @param tagType ¹¥»÷Ä¿±êÀàÐÍ
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks Õ½¶·
def __NPCFight(curPlayer, rolePet, tagID, tagType, tick):
    rolePetControl = NPCCommon.NPCControl(rolePet)
    
    #×·»÷·µ»Ø
    if __SummonOutRefreshArea(curPlayer, rolePet, rolePetControl):
        return
    
    #¿ªÊ¼¹¥»÷
    curTag = GameWorld.GetObj(tagID, tagType)
    
    if curTag == None or GameObj.GetHP(curTag) <= 0:
        return
    
    tagDist = GameWorld.GetDist(rolePet.GetPosX(), rolePet.GetPosY(), curTag.GetPosX(), curTag.GetPosY())
    
    #---ÓÅÏÈÊͷż¼ÄÜ---
    if AICommon.DoAutoUseSkill(rolePet, curTag, tagDist, tick):
        return
 
    #---ÊÍ·ÅÆÕͨ¹¥»÷---
    if tagDist > rolePet.GetAtkDist():
        rolePetControl.MoveToObj_Detel(curTag)
        return
    
    #¹¥»÷Âß¼­
    if tick - rolePet.GetAttackTick() < rolePet.GetAtkInterval():
        #¹¥»÷¼ä¸ôûÓе½, ·µ»Ø
        return
    
    if rolePetControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):
        #ÐÞÕýÕâ¸öNPCµÄÕ¾Á¢Î»ÖÃ
        return
    
    #ÆÕͨ¹¥»÷
    BaseAttack.Attack(rolePet, curTag, None, tick)
    return
#---------------------------------------------------------------------
## ÕÙ»½ÊÞÒÆ¶¯
#  @param rolePet ³èÎïʵÀý
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @param rolePetControl ³èÎï¿ØÖÆÆ÷
#  @return ²¼¶ûÖµ
#  @remarks ÕÙ»½ÊÞÒÆ¶¯
def __SummonMove(curPlayer, rolePet, rolePetControl):
    dist = GameWorld.GetDist(rolePet.GetPosX(), rolePet.GetPosY(), curPlayer.GetPosX(), curPlayer.GetPosY())
    #Í£Ö¹¾àÀë
    stopDist = 3
    #¸úËæ¾àÀë
    followDist = ChConfig.Def_Screen_Area
    
    if dist <=0: #ºÍÖ÷ÈËÔÚͬһ¸öλÖÃʱ£¬³èÎïÅÜ¿ª
        resultPos = GameMap.GetEmptyPlaceInArea(rolePet.GetPosX(), rolePet.GetPosY(), 2)
        moveDestX = resultPos.GetPosX()
        moveDestY = resultPos.GetPosY()
        
        if moveDestX != rolePet.GetPosX() or moveDestY != rolePet.GetPosY():
            #Çл»ÖÁ¿ìËÙÒÆ¶¯×´Ì¬
            NPCCommon.ChangeNPCMoveType(rolePet, IPY_GameWorld.mtRun)
            #NPC¿ªÊ¼Òƶ¯
            rolePet.Move(moveDestX, moveDestY)
            return True
        
    if dist < stopDist:
        return False
    
    if dist < followDist:
        rolePetControl.MoveToObj_Detel(curPlayer, 1)
    else:
        #˲¼äÒÆ¶¯
        __SummonResetPos(curPlayer, rolePet, rolePetControl)
    
    return True
#---------------------------------------------------------------------
## ÕÙ»½ÊÞ³¬¹ýÇø¼ä
#  @param curPlayer Íæ¼ÒʵÀý
#  @param rolePet ³èÎïʵÀý
#  @param npcControl npc¿ØÖÆÀà
#  @return ²¼¶ûÖµ
#  @remarks ÕÙ»½ÊÞ³¬¹ýÇø¼ä
def __SummonOutRefreshArea(curPlayer, rolePet, npcControl):
    dist = GameWorld.GetDist(rolePet.GetPosX(), rolePet.GetPosY(), curPlayer.GetPosX(), curPlayer.GetPosY())
    
    if dist < ChConfig.Def_PlayerSight_Default:
        return False
    
    #ÖØÖÃλÖÃ
    __SummonResetPos(curPlayer, rolePet, npcControl)
    return True
 
#---------------------------------------------------------------------
## ÖØÖÃλÖÃ
#  @param curPlayer µ±Ç°¶ÔÏó
#  @param rolePet ³èÎïʵÀý
#  @param rolePetControl ³èÎï¿ØÖÆÆ÷
#  @return None
#  @remarks ÖØÖÃλÖÃ
def __SummonResetPos(curPlayer, rolePet, rolePetControl):
    #Çå¿Õ³ðºÞ,Çå¿ÕÉËѪÁбí
    rolePetControl.ClearNPCAngry()
    rolePetControl.ClearNPCHurtList()
    
    #ÖØÖÃ×ø±ê
    moveDestX, moveDestY = rolePetControl.GetMoveNearPos(curPlayer.GetPosX(), curPlayer.GetPosY(), 1)
    rolePet.ResetPos(moveDestX, moveDestY)
    
    #ÖØÖÃNPCΪ¿ÕÏÐ״̬
    rolePet.SetCurAction(IPY_GameWorld.laNPCNull)
    return
 
#---------------------------------------------------------------------
##³èÎï¿ÕÏÐ״̬»ØÑª
# @param curNPC NPCʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ³èÎï¿ÕÏÐ״̬»ØÑª
def RestoreHP(rolePet, tick):
    curHP = GameObj.GetHP(rolePet)
    maxHP = GameObj.GetMaxHP(rolePet)
    
    if curHP == maxHP:
        #ÂúѪÁË
        return
    
    if tick - rolePet.GetRestoreTime() < ChConfig.Def_Pet_ProcessHP_Tick:
        #»Ö¸´Ê±¼äδµ½
        return
    
    #ÉèÖõ±Ç°Ê±¼äΪ»Ö¸´Æðʼʱ¼ä
    rolePet.SetRestoreTime(tick)
    
    #--ÉèÖûØÑª
    hpRestore = rolePet.GetHPRestore()
    
    if hpRestore == 0:
        return
    
    PetControl.AddPetHP(rolePet, hpRestore)
    return