#!/usr/bin/python
|
# -*- coding: GBK -*-
|
#-------------------------------------------------------------------------------
|
#
|
##@package NPCAI.AIType_198
|
#
|
# @todo:ÅÜÅÜÅÜ-Ëæ»ú
|
# @author hxp
|
# @date 2017-11-27
|
# @version 1.0
|
#
|
# ÏêϸÃèÊö: ÅÜÅÜÅÜ-Ëæ»ú£¬ÌÓÀëÍæ¼ÒAI
|
#
|
#-------------------------------------------------------------------------------
|
#"""Version = 2017-11-27 16:30"""
|
#-------------------------------------------------------------------------------
|
|
import ChConfig
|
import GameWorld
|
import IPY_GameWorld
|
import NPCCommon
|
|
import random
|
#-------------------------------------------------------------------------------
|
|
## ³õʼ»¯
|
# @param curNPC µ±Ç°npc
|
# @return None
|
# @remarks º¯ÊýÏêϸ˵Ã÷.
|
def DoInit(curNPC):
|
curNPC.GetNPCAngry().Init(ChConfig.Def_NormalNPCAngryCount)
|
return
|
|
def OnNPCReborn(curNPC):
|
curNPC.SetIsNeedProcess(True)
|
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
|
|
if curNPC.GetCurAction() == IPY_GameWorld.laNPCMove:
|
#GameWorld.DebugLog("ÒÆ¶¯Öв»´¦Àí£¡(%s,%s)" % (curNPC.GetPosX(), curNPC.GetPosY()))
|
return
|
|
#Ë¢ÐÂ×Ô¼º³ðºÞ¶ÈÁбí
|
curTag = None
|
npcControl.RefreshAngryList(tick)
|
curNPCAngry = npcControl.GetMaxAngryTag()
|
if curNPCAngry:
|
#³ðºÞ¶ÔÏóÀàÐÍ,³ðºÞ¶ÔÏóID
|
curNPCAngryType = curNPCAngry.GetObjType()
|
curNPCAngryID = curNPCAngry.GetObjID()
|
curTag = GameWorld.GetObj(curNPCAngryID, curNPCAngryType)
|
|
if curTag == None:
|
# µØÍ¼ÄÚËæ»úÒÆ¶¯
|
__RandMove(curNPC)
|
else:
|
__RunawayFromAngryObj(curNPC, curTag)
|
|
return
|
|
def __RunawayFromAngryObj(curNPC, curNPCAngry):
|
## Ô¶Àë³ðºÞÍæ¼Ò
|
moveArea = curNPC.GetMoveArea() # µ¥´ÎÒÆ¶¯·¶Î§
|
posX = curNPC.GetPosX()
|
posY = curNPC.GetPosY()
|
angryObjPosX, angryObjPosY = curNPCAngry.GetPosX(), curNPCAngry.GetPosY()
|
diffX, diffY = posX - angryObjPosX, posY - angryObjPosY # Á½Õß×ø±ê²î
|
dirX = 1 if diffX >= 0 else - 1 # x×ø±ê²î·½Ïò
|
dirY = 1 if diffY >= 0 else - 1 # y×ø±ê²î·½Ïò
|
|
#for _ in xrange(moveArea * moveArea):
|
randDist = max(3, random.randint(moveArea / 2, moveArea)) # Ëæ»úÒÆ¶¯¾àÀë
|
distX = randDist * dirX
|
distY = randDist * dirY
|
|
newPosX = posX + distX
|
newPosY = posY + distY
|
|
if (posX == newPosX and posY == newPosY) or not GameWorld.GetMap().CanMove(newPosX, newPosY):
|
# Á½Õß×ø±ê²îÔÚNPCÒÆ¶¯·¶Î§ÄÚ£¬Ôò³¯³ðºÞÄ¿±êºó·½Òƶ¯, ·ñÔòÔò·´ÏòËæ»úÒÆ¶¯
|
if abs(diffX) <= 5 and abs(diffY) <= 5:
|
newPosX = angryObjPosX - 3 * dirX
|
newPosY = angryObjPosY - 3 * dirY
|
#GameWorld.DebugLog("³¯Íæ¼Òºó·½Òƶ¯: (%s,%s),angry(%s,%s),diff(%s,%s),dir(%s,%s),moveArea=%s,new(%s,%s)"
|
# % (posX, posY, angryObjPosX, angryObjPosY, diffX, diffY, dirX, dirY, moveArea, newPosX, newPosY))
|
else:
|
__RandMove(curNPC)
|
return
|
|
if posX == newPosX or posY == newPosY:
|
return
|
#GameWorld.DebugLog("ÌÓÀëÒÆ¶¯: (%s,%s) to (%s,%s)" % (posX, posY, newPosX, newPosY))
|
curNPC.Move(newPosX, newPosY)
|
return
|
|
def __RandMove(curNPC):
|
## Ëæ»úÒÆ¶¯
|
moveArea = curNPC.GetMoveArea()
|
posX = curNPC.GetPosX()
|
posY = curNPC.GetPosY()
|
gameMap = GameWorld.GetMap()
|
|
for _ in xrange(moveArea * moveArea):
|
randX = posX + random.randint(-moveArea, moveArea)
|
randY = posY + random.randint(-moveArea, moveArea)
|
if posX == randX and posY == randY:
|
continue
|
if gameMap.CanMove(randX, randY):
|
#GameWorld.DebugLog("Ëæ»úÒÆ¶¯: (%s,%s) to (%s,%s)" % (posX, posY, randX, randY))
|
curNPC.Move(randX, randY)
|
return
|
return
|
|