| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #  | 
| #  | 
| ##@package AIType_104  | 
| # @todo: ³èÎïAI  | 
| #  | 
| # @author chenxuewei  | 
| # @date 2010-06-26  | 
| # @version 2.2  | 
| #  | 
| # @change: "2010-06-28 20:56" panwei ³èÎï¿ÕÏÐʱ°´±í¸ñÊýÖµ»ØÑª  | 
| # @change: "2010-07-02 13:40" chenxuewei ³èÎï¸úËæÖ÷È˹¥»÷£¬ÔÚ¹¥»÷ǰÇå¿ÕÆä×ÔÉíËùÓгðºÞÖµ¡£  | 
| # @change: "2010-07-13 19:30" panwei Ð޸ijèÎïAI  | 
| # @change: "2010-07-14 18:10" panwei Ð޸ijèÎïAI  | 
| # @change: "2010-07-29 17:00" panwei ³èÎïÑéÖ¤Âß¼Ìáµ½Èë¿Ú´¦  | 
|   | 
| # @change: "2010-08-04 15:20" panwei ³èÎïÐÂÔö×Ô¶¯Êͷż¼ÄÜÂß¼  | 
| # @change: "2010-09-02 16:15" panwei ³èÎïÒÆ¶¯·½Ê½ÐÞ¸Ä  | 
| # @change: "2010-09-09 13:50" panwei ³èÎïÍ£Ö¹½ÃÕý×ø±êº¯ÊýÐÞ¸Ä  | 
| # @change: "2010-09-26 16:45" panwei ³èÎïÒÆ¶¯Âß¼Åж¨ÐÞ¸Ä  | 
| # @change: "2010-10-21 17:45" Alee ³èÎïÌí¼ÓAIģʽ£¬¸úËæAI  | 
| # @change: "2011-07-01 12:40" Alee ·À³ÁÃÔÏÞÖÆ  | 
| # @change: "2017-02-15 10:00" xdh ºÍÖ÷ÈËÔÚͬһ¸öλÖÃʱ£¬³èÎïÅÜ¿ª  | 
| #------------------------------------------------------------------------------   | 
| """Version = 2017-02-15 10:00"""  | 
| #---------------------------------------------------------------------  | 
| #µ¼Èë  | 
| import IPY_GameWorld  | 
| import GameWorld  | 
| import NPCCommon  | 
| import BaseAttack  | 
| import ChConfig  | 
| import AICommon  | 
| import SkillShell  | 
| import SkillCommon  | 
| import PetControl  | 
| import GameMap  | 
| import GameObj  | 
| #---------------------------------------------------------------------  | 
| ## ³õʼ»¯  | 
| #  @param rolePet ³èÎïʵÀý  | 
| #  @return None  | 
| #  @remarks ³õʼ»¯  | 
| def DoInit(rolePet):  | 
|     rolePet.GetNPCAngry().Init(ChConfig.Def_Pet_Angry_Count)  | 
|     return  | 
| #---------------------------------------------------------------------  | 
| ## Ö´ÐÐAI  | 
| #  @param rolePet ³èÎïʵÀý  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks Ö´ÐÐAI  | 
| def ProcessAI(rolePet, tick):  | 
|     #---²éÕÒ³èÎïÖ÷ÈË---  | 
|     curPlayer = NPCCommon.GetSummonNPCOwner(IPY_GameWorld.gotPlayer, rolePet)  | 
|   | 
|     if curPlayer == None:  | 
|         GameWorld.ErrLog('³èÎï = %sÎÞ·¨²éÕÒÖ÷ÈË, AIÖ´ÐÐʧ°Ü'%(rolePet.GetID()))  | 
|         return  | 
|       | 
|     #---ˢгèÎïµÄBuff---  | 
|     rolePetControl = NPCCommon.NPCControl(rolePet)  | 
|     rolePetControl.RefreshBuffState(tick)  | 
|     if GameObj.GetHP(rolePet) == 0 :  | 
|         # BUFFË¢ÐÂÖпÉÄܻᵼÖÂNPCËÀÍö  | 
|         return  | 
|       | 
|     #---³èÎïÒÆ¶¯ÖÐ---  | 
|     if rolePet.GetCurAction() == IPY_GameWorld.laNPCMove and \  | 
|         __SummonOutRefreshArea(curPlayer, rolePet, rolePetControl):  | 
|         return  | 
|       | 
|     #---AIģʽÊÇ Õ½¶·Ä£Ê½---  | 
|     if rolePet.GetAIMode() == IPY_GameWorld.pamAttack:  | 
|           | 
|         #·À³ÁÃÔ  | 
|         if curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_Wallow_LV) > ChConfig.Def_GameWallow_LV_First:  | 
|             return  | 
|           | 
|         #---ÓÅÏȹ¥»÷Ö÷ÈË´òµÄ¶ÔÏó---  | 
|         masterAttackObj = AICommon.PlayerSummonAkObj(rolePet, tick, False)  | 
|           | 
|         if masterAttackObj != None:  | 
|             __NPCFight(curPlayer, rolePet, masterAttackObj.GetID(), masterAttackObj.GetGameObjType(), tick)  | 
|             return  | 
|           | 
|         #---¹¥»÷×Ô¼º³ðºÞÁбíÖеĶÔÏó---  | 
|         #Ë¢ÐÂ×Ô¼º³ðºÞ¶ÈÁÐ±í  | 
|         rolePetControl.RefreshAngryList(tick)  | 
|           | 
|         curAngry = rolePetControl.GetMaxAngryTag()  | 
|           | 
|         if curAngry != None:  | 
|             __NPCFight(curPlayer, rolePet, curAngry.GetObjID(), curAngry.GetObjType(), tick)  | 
|             return  | 
|       | 
|     #---ÎÞ³ðºÞÄ¿±êÂß¼´¦Àí---  | 
|     curNPCAction = rolePet.GetCurAction()  | 
|       | 
|     #¿ÕÏÐ״̬´¦Àí  | 
|     if curNPCAction == IPY_GameWorld.laNPCNull:  | 
|         #³èÎï¿ÕÏÐ״̬Ï»ØÑª  | 
|         RestoreHP(rolePet, tick)  | 
|   | 
|         #Ö´ÐиúËæÒÆ¶¯Âß¼  | 
|         if __SummonMove(curPlayer, rolePet, rolePetControl):  | 
|             return  | 
|   | 
|         #³èÎï²»ÐèÒªÒÆ¶¯, ÐÞÕý³èÎïµÄλÖÃ, ²»ÈÃÖØµþ  | 
|         rolePetControl.FixTagPos(rolePet.GetPosX(), rolePet.GetPosY(), 1)  | 
|         return  | 
|   | 
|     #¹¥»÷״̬´¦Àí  | 
|     if curNPCAction == IPY_GameWorld.laNPCAttack:  | 
|         rolePet.SetCurAction(IPY_GameWorld.laNPCNull)  | 
|   | 
|     return  | 
|       | 
| #---------------------------------------------------------------------  | 
| ## Õ½¶·  | 
| #  @param curPlayer Íæ¼ÒʵÀý  | 
| #  @param rolePet ³èÎïʵÀý  | 
| #  @param tagID ¹¥»÷Ä¿±êID  | 
| #  @param tagType ¹¥»÷Ä¿±êÀàÐÍ  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks Õ½¶·  | 
| def __NPCFight(curPlayer, rolePet, tagID, tagType, tick):  | 
|     rolePetControl = NPCCommon.NPCControl(rolePet)  | 
|       | 
|     #×·»÷·µ»Ø  | 
|     if __SummonOutRefreshArea(curPlayer, rolePet, rolePetControl):  | 
|         return  | 
|       | 
|     #¿ªÊ¼¹¥»÷  | 
|     curTag = GameWorld.GetObj(tagID, tagType)  | 
|       | 
|     if curTag == None or GameObj.GetHP(curTag) <= 0:  | 
|         return  | 
|       | 
|     tagDist = GameWorld.GetDist(rolePet.GetPosX(), rolePet.GetPosY(), curTag.GetPosX(), curTag.GetPosY())  | 
|       | 
|     #---ÓÅÏÈÊͷż¼ÄÜ---  | 
|     if AICommon.DoAutoUseSkill(rolePet, curTag, tagDist, tick):  | 
|         return  | 
|   | 
|     #---ÊÍ·ÅÆÕͨ¹¥»÷---  | 
|     if tagDist > rolePet.GetAtkDist():  | 
|         rolePetControl.MoveToObj_Detel(curTag)  | 
|         return  | 
|       | 
|     #¹¥»÷Âß¼  | 
|     if tick - rolePet.GetAttackTick() < rolePet.GetAtkInterval():  | 
|         #¹¥»÷¼ä¸ôûÓе½, ·µ»Ø  | 
|         return  | 
|       | 
|     if rolePetControl.FixTagPos(curTag.GetPosX(), curTag.GetPosY()):  | 
|         #ÐÞÕýÕâ¸öNPCµÄÕ¾Á¢Î»Öà  | 
|         return  | 
|       | 
|     #ÆÕͨ¹¥»÷  | 
|     BaseAttack.Attack(rolePet, curTag, None, tick)  | 
|     return  | 
| #---------------------------------------------------------------------  | 
| ## ÕÙ»½ÊÞÒÆ¶¯  | 
| #  @param rolePet ³èÎïʵÀý  | 
| #  @param curPlayer µ±Ç°Íæ¼Ò  | 
| #  @param rolePetControl ³èÎï¿ØÖÆÆ÷  | 
| #  @return ²¼¶ûÖµ  | 
| #  @remarks ÕÙ»½ÊÞÒÆ¶¯  | 
| def __SummonMove(curPlayer, rolePet, rolePetControl):  | 
|     dist = GameWorld.GetDist(rolePet.GetPosX(), rolePet.GetPosY(), curPlayer.GetPosX(), curPlayer.GetPosY())  | 
|     #Í£Ö¹¾àÀë  | 
|     stopDist = 3  | 
|     #¸úËæ¾àÀë  | 
|     followDist = ChConfig.Def_Screen_Area  | 
|       | 
|     if dist <=0: #ºÍÖ÷ÈËÔÚͬһ¸öλÖÃʱ£¬³èÎïÅÜ¿ª  | 
|         resultPos = GameMap.GetEmptyPlaceInArea(rolePet.GetPosX(), rolePet.GetPosY(), 2)  | 
|         moveDestX = resultPos.GetPosX()  | 
|         moveDestY = resultPos.GetPosY()  | 
|           | 
|         if moveDestX != rolePet.GetPosX() or moveDestY != rolePet.GetPosY():  | 
|             #Çл»ÖÁ¿ìËÙÒÆ¶¯×´Ì¬  | 
|             NPCCommon.ChangeNPCMoveType(rolePet, IPY_GameWorld.mtRun)  | 
|             #NPC¿ªÊ¼Òƶ¯  | 
|             rolePet.Move(moveDestX, moveDestY)  | 
|             return True  | 
|           | 
|     if dist < stopDist:  | 
|         return False  | 
|       | 
|     if dist < followDist:  | 
|         rolePetControl.MoveToObj_Detel(curPlayer, 1)  | 
|     else:  | 
|         #˲¼äÒÆ¶¯  | 
|         __SummonResetPos(curPlayer, rolePet, rolePetControl)  | 
|       | 
|     return True  | 
| #---------------------------------------------------------------------  | 
| ## ÕÙ»½ÊÞ³¬¹ýÇø¼ä  | 
| #  @param curPlayer Íæ¼ÒʵÀý  | 
| #  @param rolePet ³èÎïʵÀý  | 
| #  @param npcControl npc¿ØÖÆÀà  | 
| #  @return ²¼¶ûÖµ  | 
| #  @remarks ÕÙ»½ÊÞ³¬¹ýÇø¼ä  | 
| def __SummonOutRefreshArea(curPlayer, rolePet, npcControl):  | 
|     dist = GameWorld.GetDist(rolePet.GetPosX(), rolePet.GetPosY(), curPlayer.GetPosX(), curPlayer.GetPosY())  | 
|       | 
|     if dist < ChConfig.Def_PlayerSight_Default:  | 
|         return False  | 
|       | 
|     #ÖØÖÃλÖà  | 
|     __SummonResetPos(curPlayer, rolePet, npcControl)  | 
|     return True  | 
|   | 
| #---------------------------------------------------------------------  | 
| ## ÖØÖÃλÖà  | 
| #  @param curPlayer µ±Ç°¶ÔÏó  | 
| #  @param rolePet ³èÎïʵÀý  | 
| #  @param rolePetControl ³èÎï¿ØÖÆÆ÷  | 
| #  @return None  | 
| #  @remarks ÖØÖÃλÖà  | 
| def __SummonResetPos(curPlayer, rolePet, rolePetControl):  | 
|     #Çå¿Õ³ðºÞ,Çå¿ÕÉËѪÁÐ±í  | 
|     rolePetControl.ClearNPCAngry()  | 
|     rolePetControl.ClearNPCHurtList()  | 
|       | 
|     #ÖØÖÃ×ø±ê  | 
|     moveDestX, moveDestY = rolePetControl.GetMoveNearPos(curPlayer.GetPosX(), curPlayer.GetPosY(), 1)  | 
|     rolePet.ResetPos(moveDestX, moveDestY)  | 
|       | 
|     #ÖØÖÃNPCΪ¿ÕÏÐ״̬  | 
|     rolePet.SetCurAction(IPY_GameWorld.laNPCNull)  | 
|     return  | 
|   | 
| #---------------------------------------------------------------------  | 
| ##³èÎï¿ÕÏÐ״̬»ØÑª  | 
| # @param curNPC NPCʵÀý  | 
| # @param tick Ê±¼ä´Á  | 
| # @return ·µ»ØÖµÎÞÒâÒå  | 
| # @remarks ³èÎï¿ÕÏÐ״̬»ØÑª  | 
| def RestoreHP(rolePet, tick):  | 
|     curHP = rolePet.GetHP()  | 
|     maxHP = rolePet.GetMaxHP()  | 
|       | 
|     if curHP == maxHP:  | 
|         #ÂúѪÁË  | 
|         return  | 
|       | 
|     if tick - rolePet.GetRestoreTime() < ChConfig.Def_Pet_ProcessHP_Tick:  | 
|         #»Ö¸´Ê±¼äδµ½  | 
|         return  | 
|       | 
|     #ÉèÖõ±Ç°Ê±¼äΪ»Ö¸´Æðʼʱ¼ä  | 
|     rolePet.SetRestoreTime(tick)  | 
|       | 
|     #--ÉèÖûØÑª  | 
|     hpRestore = rolePet.GetHPRestore()  | 
|       | 
|     if hpRestore == 0:  | 
|         return  | 
|       | 
|     PetControl.AddPetHP(rolePet, hpRestore)  | 
|     return  | 
|   |