#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#  
 | 
##@package  
 | 
#  
 | 
# @todo:   
 | 
#  
 | 
# @author: Alee  
 | 
# @date 2018-4-3 ÏÂÎç05:03:18  
 | 
# @version 1.0  
 | 
#  
 | 
# @note:   
 | 
#  
 | 
#---------------------------------------------------------------------  
 | 
  
 | 
import IPY_GameWorld  
 | 
import GameWorld  
 | 
import NPCCommon  
 | 
import BaseAttack  
 | 
import ChConfig  
 | 
import AICommon  
 | 
import random  
 | 
import GameObj  
 | 
import IpyGameDataPY  
 | 
#---------------------------------------------------------------------  
 | 
  
 | 
  
 | 
#---------------------------------------------------------------------  
 | 
## ³õʼ»¯  
 | 
#  @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):  
 | 
  
 | 
    if AppearMove(curNPC):  
 | 
        return  
 | 
      
 | 
    npcControl = NPCCommon.NPCControl(curNPC)  
 | 
  
 | 
    #Ë¢ÐÂ×Ô¼ºµÄbuff  
 | 
    npcControl.RefreshBuffState(tick)  
 | 
    if GameObj.GetHP(curNPC) == 0 :  
 | 
        # BUFFË¢ÐÂÖпÉÄܻᵼÖÂNPCËÀÍö  
 | 
        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()  
 | 
  
 | 
    #Ö´Ðй¥»÷Âß¼  
 | 
    __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() :  
 | 
        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 npcControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):  
 | 
        #ÐÞÕýÕâ¸öNPCµÄÕ¾Á¢Î»Öà  
 | 
        return  
 | 
      
 | 
    curNPCAction = curNPC.GetCurAction()  
 | 
    if curNPCAction == IPY_GameWorld.laNPCMove:  
 | 
        return  
 | 
      
 | 
    #ÆÕͨ¹¥»÷  
 | 
    BaseAttack.Attack( curNPC, curTag, None, tick )  
 | 
    return  
 | 
          
 | 
# ³ö³¡Òƶ¯  
 | 
def AppearMove(curNPC):  
 | 
    if curNPC.GetDictByKey("appearmove"):  
 | 
        # ÒÑ´¦Àí  
 | 
        return False  
 | 
    if curNPC.GetCurAction() == IPY_GameWorld.laNPCMove:  
 | 
        return  
 | 
    aiRefreshPointNPCRun = IpyGameDataPY.GetFuncEvalCfg("AIRefreshPointNPCRun", 1, {})  
 | 
  
 | 
    refreshMark = curNPC.GetDictByKey(ChConfig.Def_NPC_Dict_FromRefreshMark)  
 | 
    movePointList = aiRefreshPointNPCRun.get(refreshMark, [])  
 | 
    if not movePointList:  
 | 
        return False  
 | 
      
 | 
    # ÆðµãΪ³öÉúµã  
 | 
    destPosX, destPosY = movePointList[0]  
 | 
          
 | 
    curNPC.Move(destPosX, destPosY)  
 | 
    curNPC.SetDict("appearmove", 1)  
 | 
      
 | 
    return True 
 |