| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package NPCAI.AIType_21  | 
| #  | 
| # @todo:¸±±¾»î¶¯»úÆ÷ÈË  | 
| # @author hxp  | 
| # @date 2018-12-06  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¸±±¾»î¶¯»úÆ÷ÈË  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2018-12-06 20:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import ChConfig  | 
| import AICommon  | 
| import NPCCommon  | 
| import BaseAttack  | 
| import IpyGameDataPY  | 
| import IPY_GameWorld  | 
| import GameWorld  | 
| import FBCommon  | 
| import GameObj  | 
|   | 
| import random  | 
| #---------------------------------------------------------------------  | 
|   | 
| #---------------------------------------------------------------------  | 
| ## ³õʼ»¯  | 
| #  @param curNPC µ±Ç°npc  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def DoInit(curNPC):  | 
|     curNPC.GetNPCAngry().Init(ChConfig.Def_SuperFBBossAngryCount)  | 
|     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():  | 
|         return  | 
|       | 
|     #Ë¢ÐÂ×Ô¼ºµÄbuff  | 
|     npcControl.RefreshBuffState(tick)  | 
|     if GameObj.GetHP(curNPC) == 0:  | 
|         # BUFFË¢ÐÂÖпÉÄܻᵼÖÂNPCËÀÍö  | 
|         return  | 
|       | 
|     #Ë¢ÐÂ×Ô¼º³ðºÞ¶ÈÁÐ±í  | 
|     npcControl.RefreshAngryList(tick)  | 
|     curNPCAngry = npcControl.GetMaxAngryTag()  | 
|       | 
|     #³ðºÞ¶ÈÁбíÖеÄÈËΪ¿Õ  | 
|     if curNPCAngry == None:  | 
|         if curNPC.GetSpeed() != 0:  | 
|             __RobotMove(curNPC)  | 
|         return  | 
|       | 
|     #³ðºÞ¶ÔÏóÀàÐÍ,³ðºÞ¶ÔÏóID  | 
|     curNPCAngryType = curNPCAngry.GetObjType()  | 
|     curNPCAngryID = curNPCAngry.GetObjID()  | 
|       | 
|     #Ö´Ðй¥»÷Âß¼  | 
|     __NPCFight(curNPC, curNPCAngryID, curNPCAngryType, tick)  | 
|     return  | 
|   | 
| def __RobotMove(curNPC):  | 
|     if curNPC.GetCurAction() == IPY_GameWorld.laNPCMove:  | 
|         #GameWorld.DebugLog("ÒÆ¶¯Öв»´¦Àí£¡(%s,%s)" % (curNPC.GetPosX(), curNPC.GetPosY()))  | 
|         return  | 
|     mapID = GameWorld.GetMap().GetMapID()  | 
|     lineID = FBCommon.GetFBPropertyMark()  | 
|     posKey = "%d%02d" % (mapID, lineID)  | 
|     fbMovePosDict = IpyGameDataPY.GetFuncCfg("AI198Point", 1)  | 
|     if posKey not in fbMovePosDict:  | 
|         posKey = "%d%02d" % (mapID, 0)  | 
|         if posKey not in fbMovePosDict:  | 
|             return  | 
|           | 
|     posList = fbMovePosDict[posKey]  | 
|     Key_PosIndex = "RobotMovePosIndex" # NPCÉÏ´ÎÒÆ¶¯µÄ×ø±êË÷Òý£¬´æÖµ+1  | 
|     posIndex =  curNPC.GetDictByKey(Key_PosIndex) - 1  | 
|     if posIndex < 0:  | 
|         # »¹Ã»ÓÐ×ß¹ýµãµÄ£¬Ñ°ÕÒËùÓеãÖÐ×î½üµÄµã  | 
|         posIndex = random.randint(0, len(posList) - 1)  | 
|     else:  | 
|         tagPosX, tagPosY = posList[posIndex]  | 
|         tagDist = GameWorld.GetDist(curNPC.GetPosX(), curNPC.GetPosY(), tagPosX, tagPosY)  | 
|         if tagDist < 2:  | 
|             posIndex += 1  | 
|               | 
|     if posIndex < 0 or posIndex >= len(posList):  | 
|         posIndex = random.randint(0, len(posList) - 1)  | 
|           | 
|     curNPC.SetDict(Key_PosIndex, posIndex + 1)  | 
|     tagPosX, tagPosY = posList[posIndex]  | 
|     curNPC.Move(tagPosX, tagPosY)  | 
|     return  | 
|   | 
| #---------------------------------------------------------------------  | 
| ## 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)  | 
|       | 
|     #¿ªÊ¼¹¥»÷  | 
|     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 AICommon.DoAutoUseSkill(curNPC, curTag, tagDist, tick):  | 
|         return  | 
|       | 
|     #---ÊÍ·ÅÆÕͨ¹¥»÷---  | 
|       | 
|     if curNPC.GetSpeed() == 0:  | 
|         # ²»¿ÉÒÆ¶¯NPC  | 
|         if tagDist > curNPC.GetAtkDist():  | 
|             return  | 
|           | 
|         if tick - curNPC.GetAttackTick() < curNPC.GetAtkInterval():  | 
|             #¹¥»÷¼ä¸ôûÓе½, ·µ»Ø  | 
|             return  | 
|           | 
|         #ÆÕͨ¹¥»÷  | 
|         BaseAttack.Attack(curNPC, curTag, None, tick)  | 
|         return  | 
|       | 
|     #³¬¹ý¹¥»÷¾àÀë,ÒÆ¶¯¹ýÈ¥  | 
|     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  | 
|       | 
|     #ÆÕͨ¹¥»÷  | 
|     BaseAttack.Attack(curNPC, curTag, None, tick)  | 
|     return  | 
|   | 
| ## NPCËÀÍö  | 
| #  @param curNPC µ±Ç°npc  | 
| #  @param hurtType É˺¦ÕßµÄobjÀàÐÍ  | 
| #  @param hurtID É˺¦ÕßµÄobjID  | 
| #  @return None  | 
| def OnDie(curNPC, hurtType, hurtID):  | 
|     AICommon.DoNPCUseSkillOnDie(curNPC)  | 
|     return  | 
|   |