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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package NPCAI.AIType_2
#
# @todo:С¹ÖAI£¬Ö§³ÖÊͷż¼ÄÜ
# @author hxp
# @date 2017-11-27
# @version 1.0
#
# ÏêϸÃèÊö: Ð¡¹ÖAI£¬Ö§³ÖÊͷż¼ÄÜ
#
#-------------------------------------------------------------------------------
#"""Version = 2017-11-27 16:30"""
#-------------------------------------------------------------------------------
 
import IPY_GameWorld
import GameWorld
import NPCCommon
import BaseAttack
import ChConfig
import AICommon
import GameObj
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
## ³õʼ»¯
#  @param curNPC µ±Ç°npc
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def DoInit(curNPC):
    curNPC.GetNPCAngry().Init(ChConfig.Def_NormalNPCAngryCount)
    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():
        #NPCËÀÍö, ½øÈëËÀÍöµ¹¼ÆÊ±
        if npcControl.DieTick(tick) == 0:
            return
         
    #Ë¢ÐÂ×Ô¼ºµÄbuff
    #npcControl.RefreshBuffState(tick)
    
    curNPCAction = curNPC.GetCurAction()
    #NPC¿ìËÙ±¼ÅÜÖÐ, ´¦Àí
    if curNPCAction == IPY_GameWorld.laNPCMove and curNPC.GetCurMoveType() == IPY_GameWorld.mtRun :
        AICommon.NormalNPCFast_Move(curNPC, tick)
        return
    
    #Ë¢ÐÂ×Ô¼º³ðºÞ¶ÈÁбí
    npcControl.RefreshAngryList(tick)
    
    if not curNPC.GetIsNeedProcess():
        AICommon.NormalNPCFree_Move(curNPC, tick)
        return
    
    curNPCAngry = npcControl.GetMaxAngryTag()
    
    #³ðºÞ¶ÈÁбíÖеÄÈËΪ¿Õ
    if curNPCAngry == None :
        AICommon.NormalNPCFree_Move(curNPC, tick)
        return
 
    #³ðºÞ¶ÔÏóÀàÐÍ,³ðºÞ¶ÔÏóID
    curNPCAngryType = curNPCAngry.GetObjType()
    curNPCAngryID = curNPCAngry.GetObjID()
    #Õ½¶·ÖлØÑª
    npcControl.ProcessBattleHPRestore(tick)
    #Ö´Ðй¥»÷Âß¼­
    __NPCFight(curNPC, curNPCAngryID, curNPCAngryType, tick)
    return
 
def __NPCFight(curNPC, tagID, tagType, tick):
    #ÉèÖýøÈëÕ½¶·×´Ì¬
    NPCCommon.SetNPCInBattleState(curNPC)
    npcControl = NPCCommon.NPCControl(curNPC)
    
    #ÊÇ·ñÔÚÒÆ¶¯·¶Î§ÄÚ
    if not npcControl.IsInRefreshArea():
        #×·»÷·µ»Ø
        npcControl.MoveBack()
        return
    
    #¿ªÊ¼¹¥»÷
    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 tagDist > curNPC.GetAtkDist() :
        if __CheckNPCBeAttackCanMove(curNPC, tick):
            npcControl.MoveToObj_Detel(curTag)
        return
    
    if tick - curNPC.GetAttackTick() < curNPC.GetAtkInterval():
        #¹¥»÷¼ä¸ôûÓе½, ·µ»Ø
        return
    
    if __CheckNPCBeAttackCanMove(curNPC, tick):
        if npcControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):
            #ÐÞÕýÕâ¸öNPCµÄÕ¾Á¢Î»ÖÃ
            return
    
    #ÆÕͨ¹¥»÷
    BaseAttack.Attack( curNPC, curTag, None, tick )
    return
        
 
# 2017-11-21 ÐÂÐèÇóС¹ÖAI1±»»÷²»×öÒÆ¶¯´¦Àí
def __CheckNPCBeAttackCanMove(curNPC, tick):
    if curNPC.GetIsBoss():
        return True
    
    if tick - curNPC.GetDictByKey("NPCBeAttackedAI1") > 300:
        return True
    
    return False