#!/usr/bin/python
|
# -*- coding: GBK -*-
|
|
##@package AIType_1
|
#ÆÕͨNPC(½üÕ½, С¹Ö)µÄAIÂß¼, °´¸ÅÂʾö¶¨ÊÇ·ñ×·»÷,
|
## ´ËAIʹÓÃÂÊ×î¸ß£¬Í¨¹ýÔÚÏßÓû§¾ö¶¨AIÖ´ÐÐÆµÂÊ£¬²»È»»á¿¨ËÀ
|
#
|
# @author eggxp
|
# @date 2010-4-23
|
# @version 1.8
|
#
|
|
#------------------------------------------------------------------------------
|
"""Version = 2017-03-25 17:39"""
|
#---------------------------------------------------------------------
|
import IPY_GameWorld
|
import GameWorld
|
import NPCCommon
|
import BaseAttack
|
import ChConfig
|
import AICommon
|
import random
|
import GameObj
|
#---------------------------------------------------------------------
|
|
Def_LastAI1ProTick = "LastAI1ProTick" # ×îºóÒ»´ÎÖ´ÐÐtick
|
Def_AI1ProcessTick = "AI1Process" # Ö´ÐÐÆµÂÊ ºÁÃë
|
|
#---------------------------------------------------------------------
|
## ³õʼ»¯
|
# @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
|
|
## Ö´ÐÐÆµÂÊ, ÿ10ÈËÑÓ³¤1ÃëÖ´ÐÐÆµÂÊ---------------------------
|
if tick - curNPC.GetDictByKey(Def_LastAI1ProTick) < curNPC.GetDictByKey(Def_AI1ProcessTick):
|
return
|
playerCount = GameWorld.GetPlayerManager().OnlineCount()
|
delayTime = max(playerCount/10-3, 0) * 1000
|
curNPC.SetDict(Def_AI1ProcessTick, delayTime)
|
curNPC.SetDict(Def_LastAI1ProTick, tick)
|
#-------------------------------------------------------
|
|
|
#Ë¢ÐÂ×Ô¼ºµÄbuff
|
npcControl.RefreshBuffState(tick)
|
if GameObj.GetHP(curNPC) == 0 :
|
# BUFFË¢ÐÂÖпÉÄܻᵼÖÂNPCËÀÍö
|
return
|
|
|
# #ÅжÏÒ쳣״̬
|
# if curNPC.GetAbnormalState() == IPY_GameWorld.sctFaint:
|
# return
|
|
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)
|
|
|
## npc¹¥»÷Âß¼
|
# @param curNPC µ±Ç°npc
|
# @param tagID curNPCAngryID
|
# @param tagType curNPCAngryType
|
# @param tick µ±Ç°Ê±¼ä
|
# @return None
|
# @remarks º¯ÊýÏêϸ˵Ã÷.
|
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 tagDist > curNPC.GetAtkDist() :
|
if __CheckNPCBeAttackCanMove(curNPC, tick):
|
destDist = GameWorld.GetDist(curNPC.GetDestPosX() , curNPC.GetDestPosY(), curTag.GetPosX(), curTag.GetPosY())
|
if destDist <= curNPC.GetAtkDist() and curNPC.GetCurAction() == IPY_GameWorld.laNPCMove:
|
# Ä¿±êÔÚÒÆ¶¯µÄ¹¥»÷·¶Î§ÄÚ£¬²»¸Ä±äÄ¿±êµã
|
return
|
npcControl.MoveToObj_Detel(curTag)
|
return
|
else:
|
curNPC.StopMove()
|
|
if tick - curNPC.GetAttackTick() < curNPC.GetAtkInterval():
|
#¹¥»÷¼ä¸ôûÓе½, ·µ»Ø
|
return
|
|
if __CheckNPCBeAttackCanMove(curNPC, tick):
|
if npcControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):
|
#ÐÞÕýÕâ¸öNPCµÄÕ¾Á¢Î»ÖÃ
|
return
|
|
curNPCAction = curNPC.GetCurAction()
|
if curNPCAction == IPY_GameWorld.laNPCMove:
|
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
|
|