hch
2018-11-26 0ff8e21c92b39adfdf062b40c4e0147213bba70a
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package NPCAI.AIType_20
#
# @todo:ÖúÕ½»úÆ÷ÈË
# @author hxp
# @date 2018-11-24
# @version 1.0
#
# ÏêϸÃèÊö: ÖúÕ½»úÆ÷ÈË
#     Íæ¼ÒÕýÔÚ¹¥»÷µÄÄ¿±ê£¨±äÏà¸úËæÍæ¼Ò£©, Íæ¼ÒÎÞ¹¥»÷Ä¿±êʱ£¬»úÆ÷È˹¥»÷×ÔÉíÊÓÒ°Öпɹ¥»÷Ä¿±ê
#     Èç¹û¶¼Ã»ÓÐÄ¿±ê£¬¸úËæÍæ¼Ò
#     Íæ¼ÒµôÏߣ¬»úÆ÷È˲»ÔÙ¹¥»÷
#     ÖúÕ½»úÆ÷ÈËÓÀÔ¶²»ËÀ£¬ÑªÁ¿µÍÓÚ50%×Ô¶¯»ØÑª£¬ºó¶Ë×Ô¶¨
#-------------------------------------------------------------------------------
#"""Version = 2018-11-24 22:30"""
#-------------------------------------------------------------------------------
 
import NPCCommon
import ChConfig
import GameWorld
import GameObj
import BaseAttack
import FBCommon
import AICommon
import GameMap
 
import random
 
 
## ³õʼ»¯
#  @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):
    curHP = GameObj.GetHP(curNPC)
    protectHP = GameObj.GetMaxHP(curNPC) / 2 # ±£Ö¤ÑªÁ¿²»µÍÓÚÒ»°ë
    if curHP <= protectHP:
        GameObj.SetHP(curNPC, curHP + random.randint(protectHP / 3, protectHP))
        GameWorld.DebugLog("»úÆ÷ÈË»ØÑª!objID=%s" % curNPC.GetID())
        
    fbPlayer = FBCommon.GetCurSingleFBPlayer()
    if not fbPlayer:
        # ¸±±¾ÖÐûÓÐÍæ¼ÒÔò²»´¦Àí
        GameWorld.DebugLog("¸±±¾ÖÐûÓÐÍæ¼ÒÔò²»´¦Àí!objID=%s" % curNPC.GetID())
        return
    
    curTag = None
    playerAtkObjID = fbPlayer.GetDictByKey(ChConfig.Def_PlayerKey_LastHurtNPCObjID)
    if playerAtkObjID:
        curTag = GameWorld.FindNPCByID(playerAtkObjID)
        
    npcControl = NPCCommon.NPCControl(curNPC)
    # Ã»ÓÐÍæ¼ÒÕýÔÚ¹¥»÷µÄÄ¿±êÔòÈ¡×ÔÉíµÄ³ðºÞÁбí
    if not curTag:
        #GameWorld.DebugLog("ûÓÐÍæ¼ÒÕýÔÚ¹¥»÷µÄÄ¿±ê£¬Ë¢ÐÂ×ÔÉí³ðºÞÄ¿±ê!objID=%s,maxHP=%s" % (curNPC.GetID(), GameObj.GetMaxHP(curNPC)))
        npcControl.RefreshAngryList(tick)
        curNPCAngry = npcControl.GetMaxAngryTag()
        if curNPCAngry:
            curNPCAngryType = curNPCAngry.GetObjType()
            curNPCAngryID = curNPCAngry.GetObjID()
            curTag = GameWorld.GetObj(curNPCAngryID, curNPCAngryType)
            
    # Ã»Óй¥»÷Ä¿±êÔò¸úËæÍæ¼Ò
    if not curTag:
        #GameWorld.DebugLog("ûÓй¥»÷Ä¿±ê£¬¸úËæÍæ¼Ò£¡objID=%s" % curNPC.GetID())
        dist = GameWorld.GetDist(fbPlayer.GetPosX(), fbPlayer.GetPosY(), curNPC.GetPosX(), curNPC.GetPosY())
        if dist > 12:
            resultPos = GameMap.GetEmptyPlaceInArea(fbPlayer.GetPosX(), fbPlayer.GetPosY(), 3)
            curNPC.ResetPos(resultPos.GetPosX(), resultPos.GetPosY())
        elif dist > 5:
            npcControl.MoveToObj_Detel(fbPlayer, 5)
        return
    __NPCFight(npcControl, curNPC, curTag, tick)
    return
 
def __NPCFight(npcControl, curNPC, curTag, tick):
    #ÉèÖýøÈëÕ½¶·×´Ì¬
    NPCCommon.SetNPCInBattleState(curNPC)
    #¿ªÊ¼¹¥»÷
    if curTag == None or GameObj.GetHP(curTag) <= 0:
        return
    tagDist = GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), curTag.GetPosX(), curTag.GetPosY())
    GameWorld.DebugLog("    ÓëÄ¿±ê¾àÀë: %s" % tagDist)
    if tagDist > 20:
        resultPos = GameMap.GetEmptyPlaceInArea(curTag.GetPosX(), curTag.GetPosY(), 3)
        curNPC.ResetPos(resultPos.GetPosX(), resultPos.GetPosY())
        tagDist = GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), curTag.GetPosX(), curTag.GetPosY())
        
    #---ÓÅÏÈÊͷż¼ÄÜ---
    if AICommon.DoAutoUseSkill(curNPC, curTag, tagDist, tick):
        return
    #---ÊÍ·ÅÆÕͨ¹¥»÷---
    #³¬¹ý¹¥»÷¾àÀë,ÒÆ¶¯¹ýÈ¥
    if tagDist > curNPC.GetAtkDist():
        npcControl.MoveToObj_Detel(curTag)
        return
    if tick - curNPC.GetAttackTick() < curNPC.GetAtkInterval():
        #¹¥»÷¼ä¸ôûÓе½, ·µ»Ø
        return
    if npcControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):
        #ÐÞÕýÕâ¸öNPCµÄÕ¾Á¢Î»ÖÃ
        return
    #ÆÕͨ¹¥»÷
    BaseAttack.Attack(curNPC, curTag, None, tick)
    return
 
def OnCheckCanDie(atkObj, curNPC, skill, tick):
    ## ¼ì²éNPCÊÇ·ñ¿ÉËÀÍö
    GameObj.SetHP(curNPC, GameObj.GetMaxHP(curNPC) / 2) # »ØÒ»°ëѪ
    GameWorld.ErrLog("¸ÃNPC²»¿ÉÒÔËÀÍö£¡npcID=%s,curHP=%s" % (curNPC.GetNPCID(), GameObj.GetHP(curNPC)))
    return False