hxp
2022-02-21 0c27822ef5e6c67782ed143a4ff03ecfbdfda1fb
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package AIType_222
#
# @todo: ÏÝÚå
# @author Alee
# @date 2010-12-16 20:50
# @version 1.1
#
# @change: "2016-11-26 19:00" hxp ÏÝÚå¸ÄΪËÀÍöÊͷŹ¥»÷¼¼ÄÜ, Ö§³Öʱ¼äµ½ºó×Ô±¬
#
# ÏêϸÃèÊö:ÏÝÚå
#
#------------------------------------------------------------------------------ 
#"""Version = 2016-11-26 19:00"""
#------------------------------------------------------------------------------
import SkillShell
import NPCCommon
import ChConfig
import GameWorld
import IPY_GameWorld
import GameObj
import GameMap
import AttackCommon
import SkillCommon
import AICommon
 
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
## ³õʼ»¯
#  @param curNPC µ±Ç°npc
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def DoInit(curNPC):
    curNPC.GetNPCAngry().Init(ChConfig.Def_SummonNPC_Angry_Count)
 
## Ö´ÐÐAI
#  @param curNPC µ±Ç°npc
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def ProcessAI(curNPC, tick):
    #1.¼ì²éÕâ¸öNPCµÄ³ðºÞÁÐ±í£¬ Èç¹û³ðºÞÁбíΪ¿Õ£¬ ²»´¦Àí
    if curNPC.IsAlive() != True:
        #NPCËÀÍö, ½øÈëËÀÍöµ¹¼ÆÊ±
        return
    
    #»ñµÃNPC¹ÜÀíÆ÷
    npcControl = NPCCommon.NPCControl(curNPC)
    if curNPC.GetLastTime() != 0 and tick - curNPC.GetBornTime() >= curNPC.GetLastTime():
        #GameWorld.Log("ÏÝÚ峬¹ý´æÔÚʱ¼ä,ÒÑÏûʧ")
        npcControl.SetKilled()
        return
    
    if tick - curNPC.GetBornTime() <= ChConfig.Def_Trap_Born_Idle_Time:
        return
    
    npcControl = NPCCommon.NPCControl(curNPC)
    #Ë¢ÐÂ×Ô¼º³ðºÞ¶ÈÁбí
    npcControl.RefreshAngryList(tick, 500) # ÎªÈ·±£²ÈÏÝÚåÌåÑ飬
    #±éÀú³ðºÞÁбíÕÒµ½×î½üµÄ,²¢´¥·¢
    for i in range(0, curNPC.GetNPCAngry().GetAngryCount()):
        curAngry = curNPC.GetNPCAngry().GetAngryValueTag(i)
        
        if curAngry == None or curAngry.GetObjID() == 0:
            continue
        
        curObj = GameWorld.GetObj(curAngry.GetObjID(), curAngry.GetObjType())
        
        if curObj == None or GameObj.GetHP(curObj) <= 0:
            continue
        
        #ÓÐNPC¿¿½ü,µ±³¬¹ý¹¥»÷¾àÀë
        if GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), 
                             curObj.GetPosX(), curObj.GetPosY()) > curNPC.GetAtkDist():
            continue
        
        #½øÈëÕ½¶·
        if not NPCFight(curNPC, npcControl, curObj, tick):
            continue
        return
           
    return
 
## npc¹¥»÷Âß¼­
#  @param curNPC µ±Ç°npc
#  @param npcControl NPC¹ÜÀíÆ÷
#  @param curObj Ä¿±êʵÀý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def NPCFight(curNPC, npcControl, curObj, tick):
    #»ñµÃ¼¼ÄܹÜÀíÆ÷
    skillManager = curNPC.GetSkillManager()
    #´Ó¼¼ÄܹÜÀíÆ÷,»ñÈ¡¿ÉÒÔʹÓõļ¼ÄÜ
    curSkill = skillManager.GetSkillByIndex(0)
    
    if curSkill == None:
        GameWorld.Log("ÏÝÚå = %s Êý¾Ý¿â²éÕÒ¼¼ÄÜʧ°Ü"%curNPC.GetName())
        return True
    
    battleRelationType = AttackCommon.GetBattleRelationType(curNPC, curObj)
    
    skillBattleType = SkillCommon.GetSkillBattleType(curSkill)
    if not AttackCommon.CheckBattleRelationType(skillBattleType, battleRelationType):
        # PKģʽµÄÅж¨
        return False
    
    curNPC.SetDict("traptagType", curObj.GetGameObjType())
    curNPC.SetDict("traptagID", curObj.GetID())
    
    #´¥·¢¼¼ÄÜ, ¸ÄΪͳһÔÚËÀÍöʱÊͷż¼ÄÜ
    #SkillShell.NPCUseSkillTag(curNPC, curObj, curSkill, tick)
 
    #ÓÐÍæ¼Ò½øÈë³ðºÞÁбí,,,×Ô±¬
    npcControl.SetKilled()
    return True
 
## NPCËÀÍö
#  @param curNPC µ±Ç°npc
#  @param hurtType É˺¦ÕßµÄobjÀàÐÍ
#  @param hurtID É˺¦ÕßµÄobjID
#  @return None
def OnDie(curNPC, hurtType, hurtID):
    
    #ËÀÍöNPC²»Äܹ¥»÷, ÕâÀïÉèÖÃNPCѪÁ¿Îª1
    GameObj.SetHP(curNPC, 1)
    
    #»ñµÃ¼¼ÄܹÜÀíÆ÷
    skillManager = curNPC.GetSkillManager()
    curSkill = skillManager.GetSkillByIndex(0)
    if not curSkill:
        return
 
    curObj = GameWorld.GetObj(curNPC.GetDictByKey("traptagID"), curNPC.GetDictByKey("traptagType"))
    tick = GameWorld.GetGameWorld().GetTick()
    if curObj == None or GameObj.GetHP(curObj) <= 0:
        SkillShell.NPCUseSkill(curNPC, curSkill, tick)
        return
    
    AICommon.DoNPCUseSkill(curNPC, curObj, curSkill, 0, tick)
    
    GameObj.SetHP(curNPC, 0)
    return
 
#===============================================================================
# def OnGetOwnerRelation(curNPC, owner):
#    # ÏÝÚåÓëÖ÷È˵ĹØÏµ
#    
#    if owner.GetGameObjType() == IPY_GameWorld.gotPlayer:
#        #×ÔÓÉPKÇø or ·Ç°²È«ÇøÄÚ¿ªÈ«Ìå Ê±¿É¹¥»÷Ö÷ÈË
#        if GameMap.GetAreaTypeByMapPos(owner.GetPosX(), owner.GetPosY()) == IPY_GameWorld.gatFreePK \
#            or (GameMap.GetAreaTypeByMapPos(owner.GetPosX(), owner.GetPosY()) != IPY_GameWorld.gatSafe and \
#                owner.GetAttackMode() == IPY_GameWorld.amAll):
#            return ChConfig.Type_Relation_Enemy , ChConfig.Def_PASysMessage_None
#        
#    return ChConfig.Type_Relation_Friend , ChConfig.Def_PASysMessage_None
#===============================================================================