| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #---------------------------------------------------------------------  | 
| #  | 
| #---------------------------------------------------------------------  | 
| ##@package PlayerBattle  | 
| # @todo: Íæ¼ÒÆÕͨ¹¥»÷,Õ½¶·Âß¼´¦Àí  | 
| #  | 
| # @author: panwei  | 
| # @date 2010-4-28  | 
| # @version 1.4  | 
| #  | 
| # @note:   | 
| #---------------------------------------------------------------------  | 
| # @change: "2013-03-11 18:00" wdb È¥³ý¶ÔÖÅ  | 
| # @change: "2013-06-05 18:00" Alee ÐÂÔöÑ¡ÖÐÍæ¼ÒÂß¼  | 
| # @change: "2013-06-06 21:30" Alee Õ½¶·×´Ì¬²»¿É½øÈëÈÎÎñ¶Ô»°£¬µ¼Ö¶ÔÏó±ä¸üµÈÎÊÌâ  | 
| # @change: "2016-09-23 16:30" hxp ²É¼¯ÖÐÑ¡ÖжÔÏó¸üÐÂʱ½áÊø²É¼¯  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2016-09-23 16:30"""  | 
| #---------------------------------------------------------------------  | 
| import IPY_GameWorld  | 
| import GameWorld  | 
| import NPCCommon  | 
| import PlayerControl  | 
| import PlayerState  | 
| import ChConfig  | 
| #import PlayerGameEvent  | 
| import BaseAttack  | 
| import OperControlManager  | 
| import GameObj  | 
| #---------------------------------------------------------------------  | 
|   | 
| #---------------------------------------------------------------------  | 
| #===============================================================================  | 
| # //////////////////////////////////////////////////////////////  | 
| # //06 01 ÈËÎïÆÕͨ¹¥»÷#tagCPlayerBaseAttack  | 
| # tagCPlayerBaseAttack       *   GettagCPlayerBaseAttack();  | 
| #   | 
| # class   IPY_CPlayerBaseAttack  | 
| # {  | 
| # public:  | 
| #   | 
| #    int      GetObjType();  | 
| #   | 
| #    int      GetObjID();  | 
| #   | 
| #    int      GetPosX();  | 
| #   | 
| #    int      GetPosY();  | 
| # };  | 
| #===============================================================================  | 
| ## Íæ¼ÒÆÕͨ¹¥»÷ 06 01  | 
| #  @param index Íæ¼ÒË÷Òý  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def PlayerNormalAttack(index, tick):  | 
|     GameWorld.GetPsycoFunc(__Func_PlayerNormalAttack)(index, tick)  | 
|     return  | 
|   | 
| ## Íæ¼ÒÆÕͨ¹¥»÷ 06 01  | 
| #  @param index Íæ¼ÒË÷Òý  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def __Func_PlayerNormalAttack(index, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|       | 
|     if not curPlayer.GetMapLoadOK():  | 
|         #Íæ¼ÒµØÍ¼¶Áȡδ³É¹¦, Ìß³öÕâÈË  | 
|         #Í̵ôÕâ¸ö°ü, ²»´¦Àí  | 
|         #curPlayer.Kick(IPY_GameWorld.disPlayerMovedWhenNotPrepare)  | 
|         return  | 
|       | 
|     if curPlayer.GetGMForbidenFight():  | 
|         #Play_Attack_Null ¶Ô²»Æð£¬ÄúÒѱ»GM½ûÖ¹Õ½¶·£¬¹¥»÷ʧ°Ü  | 
|         PlayerControl.NotifyCode(curPlayer , "Play_Attack_Null")  | 
|         return  | 
|       | 
|     if GameObj.GetHP(curPlayer) <= 0:  | 
|         #Íæ¼ÒÒѾËÀÍö  | 
|         #GameWorld.Log("Íæ¼ÒÆÕͨ¹¥»÷ʧ°Ü£¬Íæ¼ÒÒѾËÀÍö")  | 
|         return  | 
| #===============================================================================  | 
| #    #Íæ¼Òµ±Ç°×´Ì¬  | 
| #    curPlayerAction = curPlayer.GetPlayerAction()  | 
| #      | 
| #    if curPlayerAction  == IPY_GameWorld.paMove:  | 
| #        curPlayer.StopMove()  | 
| #===============================================================================  | 
|       | 
|     #״̬ÅжÏ, Ö»ÓÐÔÚ¿ÕÏÐ״̬,¹¥»÷ ²Å¿ÉÒÔ¹¥»÷  | 
|     if curPlayer.GetPlayerAction() not in ChConfig.Def_PlayerCanAttackState:  | 
|         PlayerControl.NotifyCode(curPlayer, "CannotAtk03")  | 
|         return  | 
|       | 
|     #ÆÕ¹¥ÐÐΪ״̬, ¿Í»§¶ËÏÞÖÆ  | 
|     if not OperControlManager.IsObjCanDoAction(curPlayer,   | 
|                                                ChConfig.Def_Obj_ActState_ClientSkill,   | 
|                                                ChConfig.Def_Action_Attack_Bit):  | 
|         return        | 
|       | 
|     #Óн»Í¨¹¤¾ßÒ²ÎÞ·¨¹¥»÷  | 
|     vehicle = curPlayer.GetPlayerVehicle()  | 
|       | 
|     #===========================================================================  | 
|     # if vehicle == IPY_GameWorld.pvHorse :  | 
|     #    PlayerControl.NotifyCode(curPlayer, "CannotAtk05")  | 
|     #    return  | 
|     #===========================================================================  | 
|       | 
|     if vehicle == IPY_GameWorld.pvTruck:  | 
|         PlayerControl.NotifyCode(curPlayer, "CannotAtk06")  | 
|         return  | 
|       | 
|     sendPack = IPY_GameWorld.IPY_CPlayerBaseAttack()  | 
|     sendPackObjID = sendPack.GetObjID()  | 
|     sendPackObjType = sendPack.GetObjType()  | 
|     sendPackPosX = sendPack.GetPosX()  | 
|     sendPackPosY = sendPack.GetPosY()   | 
|       | 
|     curTag = GameWorld.GetObj(sendPackObjID, sendPackObjType)  | 
|       | 
|     if curTag == None or GameObj.GetHP(curTag) <= 0:  | 
|         #Attack_Lost_AimDeath <n color="0,255,0">¶Ô²»Æð£¬Ä¿±êÒÑËÀÍö£¬¹¥»÷ÎÞЧ!</n>  | 
|         #PlayerControl.NotifyCode(curPlayer, "Attack_Lost_AimDeath")  | 
|         #GameWorld.Log("¹¥»÷NPC,¹¥»÷ÀàÐͲ»ÕýÈ·")  | 
|         return  | 
|       | 
|     if PlayerControl.PlayerRefreshPos(curPlayer, curPlayer, sendPackPosX, sendPackPosY, False) != True:  | 
|         #Íæ¼Òµ±Ç°Î»ÖÃË¢ÐÂʧ°Ü  | 
|         GameWorld.ErrLog("Íæ¼ÒÆÕͨ¹¥»÷, µ±Ç°Î»ÖÃË¢ÐÂʧ°Ü", curPlayer.GetPlayerID())  | 
|         return  | 
|   | 
|     #¼¤»îÍæ¼Ò,½â³ý´ôÖÍ  | 
|     PlayerControl.SetIsNeedProcess(curPlayer, True)  | 
|       | 
|     #playerLastAction = curPlayer.GetPlayerAction()  | 
|   | 
|     #Íæ¼Ò¹¥»÷NPC, ÉèÖÃÍæ¼ÒΪ¹¥»÷״̬, ÔÚÍæ¼ÒµÄºǫ́´¦Àí½Å±¾ÖпªÊ¼±íÑÝÍæ¼Ò¹¥»÷NPCµÄ¶¯»  | 
|     curPlayer.ClearUseSkillRec()  | 
|     curPlayer.SetActionObj(curTag)  | 
|     curPlayer.SetUseSkillTagID(curTag.GetID())  | 
|     curPlayer.SetUseSkillTagType(curTag.GetGameObjType())  | 
|     #@warning: ÉèÖù¥»÷ÆðµãΪ¿Í»§¶Ë·¢Ë͵Ä×ø±ê(´Ë´¦½«»á±»Íâ¹ÒÀûÓÃ)  | 
|     curPlayer.SetAttackTargetPos(sendPackPosX, sendPackPosY)  | 
|       | 
|     #ÒѾÔÚ¹¥»÷ÖÐ  | 
|     if curPlayer.GetPlayerAction() == IPY_GameWorld.paAttack:  | 
|         return  | 
|        | 
|     #ÉèÖù¥»÷±ê־λ  | 
|     PlayerControl.ChangePlayerAction(curPlayer, IPY_GameWorld.paAttack)  | 
|     #Ö´ÐÐÕ½¶·Âß¼  | 
|     PlayerState.ProcessFight(curPlayer, tick)  | 
| #===============================================================================  | 
| #    if playerLastAction != IPY_GameWorld.paAttack:  | 
| #        #Íæ¼ÒÓɷǹ¥»÷״̬½øÈë¹¥»÷״̬, ´¥·¢Ò»´ÎÍæ¼Ò״̬ˢР | 
| #        PlayerState.ProcessPlayerState(curPlayer, tick)  | 
| #        return  | 
| #===============================================================================  | 
|     return  | 
| #===============================================================================  | 
| # //////////////////////////////////////////////////////////////  | 
| # //06 05 ×Ô¶¯´ò¹Ö#tagCStartAutoFight  | 
| # tagCStartAutoFight       *   GettagCStartAutoFight();  | 
| #   | 
| # class   IPY_CStartAutoFight  | 
| # {  | 
| # public:  | 
| #    //0: ½áÊø×Ô¶¯´ò¹Ö 1: ¿ªÊ¼×Ô¶¯´ò¹Ö  | 
| #    int      GetType();  | 
| # };  | 
| #===============================================================================  | 
| ## ×Ô¶¯´ò¹Ö 06 05  | 
| #  @param index Íæ¼ÒË÷Òý  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def PlayerStartAutoFight(index, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     sendPack = IPY_GameWorld.IPY_CStartAutoFight()  | 
|     type = sendPack.GetType()  | 
|       | 
|     if type not in [ 0, 1 ]:  | 
|         GameWorld.ErrLog("¿ªÊ¼×Ô¶¯´ò¹Ö²ÎÊý²»ÕýÈ·%d"%(type), curPlayer.GetPlayerID())  | 
|         return  | 
|       | 
|     curPlayer.SetAutoFight(type)  | 
|     return  | 
| #===============================================================================  | 
| # //////////////////////////////////////////////////////////////  | 
| # //06 0BÈËÎï½øÈë¶ÔÖÅ״̬#tagCPlayerEnterBattle  | 
| # tagCPlayerEnterBattle       *   GettagCPlayerEnterBattle();  | 
| #   | 
| # class   IPY_CPlayerEnterBattle  | 
| # {  | 
| # public:  | 
| #   | 
| #    int      GetObjType();  | 
| #   | 
| #    int      GetObjID();  | 
| #    //0½øÈë;ÆäËûÍ˳ö  | 
| #    int      GetEnterOrExit();  | 
| # };  | 
| #===============================================================================  | 
| ## ÈËÎï½øÈë¶ÔÖÅ״̬ 06 0B  | 
| #  @param index Íæ¼ÒË÷Òý  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def PlayerConfronting(index, tick):  | 
| #    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
| #      | 
| #    sendPack = IPY_GameWorld.IPY_CPlayerEnterBattle()  | 
| #    sendPack_ObjID = sendPack.GetObjID()  | 
| #    sendPack_GetObjType = sendPack.GetObjType()  | 
| #    sendPack_EnterOrExit = sendPack.GetEnterOrExit()  | 
| #      | 
| #    #½øÈëÕ½¶·¶ÔÖÅ  | 
| #    if not sendPack_EnterOrExit:  | 
| #        __DoLogic_EnterPlayerConfronting(curPlayer, sendPack_ObjID, sendPack_GetObjType, tick)  | 
| #        return  | 
| #      | 
| #    #Í˳öÕ½¶·¶ÔÖÅ  | 
| #    __DoLogic_ExitPlayerConfronting(curPlayer)  | 
|     return  | 
|   | 
| ## ½øÈëÕ½¶·¶ÔÖÅ  | 
| #  @param curPlayer µ±Ç°Íæ¼Ò  | 
| #  @param sendPack_ObjID ¶ÔÏóID  | 
| #  @param sendPack_GetObjType ¶ÔÏóÀàÐÍ  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def __DoLogic_EnterPlayerConfronting(curPlayer, sendPack_ObjID, sendPack_GetObjType, tick):  | 
| #    #Óн»Í¨¹¤¾ß²»ÈýøÈëÕ½¶·¶ÔÖÅ  | 
| #    if curPlayer.GetPlayerVehicle() != IPY_GameWorld.pvNull:  | 
| #        return  | 
| #      | 
| #    curPlayerAction = curPlayer.GetPlayerAction()  | 
| #      | 
| #    if curPlayerAction not in ChConfig.Def_PlayerCanEnterConfronting:  | 
| #        return  | 
| #      | 
| #    if curPlayer.GetGMForbidenFight():  | 
| #        #Play_Attack_Null ¶Ô²»Æð£¬ÄúÒѱ»GM½ûÖ¹Õ½¶·£¬¹¥»÷ʧ°Ü  | 
| #        PlayerControl.NotifyCode(curPlayer, "Play_Attack_Null")  | 
| #        return  | 
| #      | 
| #    actObj = curPlayer.GetActionObj()  | 
| #      | 
| #    #ÒѾÔÚ¶ÔÖÅ״̬, ÇÒÄ¿±êÏàͬ²»´¦Àí  | 
| #    if curPlayer.GetIsConfronting() and actObj != None and actObj.GetID() == sendPack_ObjID and actObj.GetGameObjType() == sendPack_GetObjType:  | 
| #        return  | 
| #      | 
| #    findActObj = GameWorld.GetObj(sendPack_ObjID, sendPack_GetObjType)  | 
| #      | 
| #    if not findActObj:  | 
| #        return  | 
| #      | 
| #    relation = BaseAttack.GetTagRelation(curPlayer, findActObj, None, tick)  | 
| #    #ÅжÏÊÇ·ñµÐ¶Ô¹ØÏµ  | 
| #    if relation[0] != ChConfig.Type_Relation_Enemy :  | 
| #        return  | 
| #      | 
| #    #ÌøÎèµöÓã´ò¶Ï  | 
| #    if curPlayerAction == IPY_GameWorld.paGameEvent:  | 
| #        PlayerGameEvent.StopGameEvent(curPlayer, tick)  | 
| #      | 
| #    #½ø¶ÈÌõ´ò¶Ï  | 
| #    elif curPlayerAction == IPY_GameWorld.paPreparing:  | 
| #        PlayerControl.ChangePlayerAction(curPlayer, IPY_GameWorld.paNull)  | 
| #      | 
| #    #½øÈë¶ÔÖÅ״̬  | 
| #    curPlayer.SetActionObj(findActObj)  | 
| #    curPlayer.SetIsConfronting(True)  | 
| #    #֪ͨ¿Í»§¶Ë //0½øÈë;ÆäËûÍ˳ö  | 
| #    curPlayer.View_PlayerBattle(sendPack_ObjID, sendPack_GetObjType, 0)  | 
| #      | 
| #    #Ìí¼Ó²âÊÔÐÅÏ¢  | 
| #    GameWorld.GodLog(curPlayer, 'Client·¢°ü½øÈëÕ½¶·¶ÔÖųɹ¦')  | 
|     return  | 
|   | 
| ## Í˳öÕ½¶·¶ÔÖÅ  | 
| #  @param curPlayer   | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def __DoLogic_ExitPlayerConfronting(curPlayer):  | 
|     if not PlayerControl.IsPlayerInFight(curPlayer):  | 
|         return  | 
|       | 
|     #ÉèÖÿÕÄ¿±ê  | 
|     curPlayer.SetActionObj(None)  | 
|       | 
|     #Í˳ö¶ÔÖÅ״̬  | 
|     PlayerControl.ExitPlayerConfronting(curPlayer)  | 
|     return  | 
|   | 
| # Ä¿±êËÀÍöºÍÏûʧʱ·¢°üÈ¡Ïû¶ÔÏó£¬ÈËÎïËÀÍöÈ¡ÏûÑ¡ÖÐ  | 
| ##Ôö¼ÓËø¶¨Ä£Ê½amContest£¬Ëø¶¨Çé¿öÏÂÖ»Äܹ¥»÷Ä¿±ê   | 
| # @param None  | 
| # @return None  | 
| def SelectObj(index, clientData, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     if curPlayer.GetPlayerAction() == IPY_GameWorld.paDie:  | 
|         return  | 
|       | 
|     if clientData.isSelect == 0:  | 
|         curPlayer.SetDict(ChConfig.Def_PlayerKey_SelectObjID, 0)  | 
|         curPlayer.SetDict(ChConfig.Def_PlayerKey_SelectObjType, 0)  | 
|         return  | 
|       | 
|     curTag = GameWorld.GetObj(clientData.ID, clientData.Type)  | 
|     if curTag == None or curTag.IsEmpty():  | 
|         return  | 
|       | 
|     if curPlayer.GetAttackMode() == IPY_GameWorld.amContest and curTag.GetGameObjType() == IPY_GameWorld.gotPlayer:  | 
|         if curPlayer.GetTeamID() and curPlayer.GetTeamID() == curTag.GetTeamID():  | 
|             #GameWorld.DebugLog("Ëø¶¨Ä£Ê½²»Ëø¶¨¶ÓÓÑ")  | 
|             return  | 
|           | 
|     #ÕâÀï²»ÑéÖ¤ÊÇ·ñËÀÍö  | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_SelectObjID, clientData.ID)  | 
|     curPlayer.SetDict(ChConfig.Def_PlayerKey_SelectObjType, clientData.Type)  | 
|       | 
|     return  | 
|   |