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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package NPCAI.AIType_4
#
# @todo:¿ìËÙÒÆ¶¯µÄѲÂß¹Ö
# @author hxp
# @date 2016-11-25
# @version 1.0
#
# ÏêϸÃèÊö: ¿ìËÙÒÆ¶¯µÄѲÂß¹Ö, ÒÔË¢¹ÖµãΪÖÐÐÄµã£¬ÒÆ¶¯ÇøÓòΪ°ë¾¶µÄÇøÓòËæ»úÒÆ¶¯
#
#-------------------------------------------------------------------------------
#"""Version = 2016-11-25 15:00"""
#-------------------------------------------------------------------------------
 
import NPCCommon
import IPY_GameWorld
import GameWorld
import random
 
 
## ³õʼ»¯
#  @param curNPC µ±Ç°npc
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def DoInit(curNPC):
    curNPC.GetNPCAngry().Init(0)
    return
 
## Ö´ÐÐAI
#  @param curNPC µ±Ç°npc
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def ProcessAI(curNPC, tick):
    #GameWorld.DebugLog("AIType_4... id=%s,npcID=%s" % (curNPC.GetID(), curNPC.GetNPCID()))
    
    npcControl = NPCCommon.NPCControl(curNPC)
    
    if curNPC.GetCurAction() == IPY_GameWorld.laNPCDie or curNPC.IsAlive() != True:
        #NPCËÀÍö, ½øÈëËÀÍöµ¹¼ÆÊ±
        if npcControl.DieTick(tick) == 0:
            return
        
    curNPCAction = curNPC.GetCurAction()    
    if curNPCAction == IPY_GameWorld.laNPCMove:
        return
    
    PosMap = curNPC.GetRefreshPosAt(curNPC.GetCurRefreshPointIndex())
    if not PosMap:
        return
    posMapX = PosMap.GetPosX()
    posMapY = PosMap.GetPosY()
    #posMapArea = PosMap.GetArea() # Ë¢¹ÖÇøÓò
    
    moveDist = PosMap.GetMoveDist() # Òƶ¯ÇøÓò
    
    #moveArea = curNPC.GetMoveArea()
    #posX = curNPC.GetPosX()
    #posY = curNPC.GetPosY()
    
    minMovePosX = posMapX - moveDist
    maxMovePosX = posMapX + moveDist
    minMovePosY = posMapY - moveDist
    maxMovePosY = posMapY + moveDist
    
    # Ëæ»úÒ»¸öÒÔË¢¹ÖµãΪÖÐÐÄµã£¬ÒÆ¶¯ÇøÓòΪ°ë¾¶µÄµã
    randPosX = random.randint(minMovePosX, maxMovePosX)
    randPosY = random.randint(minMovePosY, maxMovePosY)
    
    #NPCÒÆ¶¯
    newPoint = GameWorld.GetMap().LineNearToPos(curNPC.GetPosX(), curNPC.GetPosY(), randPosX, randPosY, 0)
    #GameWorld.DebugLog("    posMap=(%s,%s,%s), moveDist=%s, randPos=(%s,%s),newPoint=(%s,%s)" 
    #                   % (posMapX, posMapY, posMapArea, moveDist, randPosX, randPosY, newPoint.GetPosX(), newPoint.GetPosY()))
    
    curNPC.Move(newPoint.GetPosX(), newPoint.GetPosY())
    return