| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.RemoteQuery.GY_Query_EnterFB  | 
| #  | 
| # @todo:½øÈ븱±¾  | 
| # @author hxp  | 
| # @date 2014-04-16  | 
| # @version 1.4  | 
| #  | 
| # ÏêϸÃèÊö: ½øÈ븱±¾  | 
| # @change: "2014-04-16 18:00" hxp ½øÈ븱±¾ÐÞ¸Ä  | 
| # @change: "2015-03-21 16:00" hxp ½øÈëÕ½Ã˼ÒÔ°  | 
| # @change: "2015-03-25 21:30" hxp ½øÈëÕ½Ã˼ÒÔ°Ôö¼ÓÑӳٹرմ¦Àí  | 
| # @change: "2015-06-29 17:20" ljd ¾µäÕ½ÒÛ  | 
| #  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2015-06-29 17:20"""  | 
| #---------------------------------------------------------------------  | 
|   | 
| #µ¼Èë  | 
| import FBLogic  | 
| import GameLogic_SealDemon  | 
| import GameLogic_ZhuXianBoss  | 
| import IPY_GameWorld  | 
| import PlayerControl  | 
| import GameWorld  | 
| import FBCommon  | 
| import ChConfig  | 
| import IpyGameDataPY  | 
| #---------------------------------------------------------------------  | 
| #È«¾Ö±äÁ¿  | 
| #---------------------------------------------------------------------  | 
| (  | 
| MapInfo_MapID, # Ä¿±êµØÍ¼ÐÅÏ¢ - µØÍ¼id  | 
| MapInfo_LineID, # Ä¿±êµØÍ¼ÐÅÏ¢ - ³¡´Î·ÖÏßid  | 
| ) = range(2)  | 
| #---------------------------------------------------------------------  | 
| #Â߼ʵÏÖ  | 
| ## ÇëÇóÂß¼  | 
| #  @param query_Type ÇëÇóÀàÐÍ  | 
| #  @param query_ID ÇëÇóµÄÍæ¼ÒID  | 
| #  @param packCMDList ·¢°üÃüÁî [ ]  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return "True" or "False" or ""  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def DoLogic(query_Type, query_ID, packCMDList, tick):  | 
|     GameWorld.Log("GY_Query_EnterFB DoLogic() query_Type=%s,query_ID=%s,packCMDList=%s,tick=%s" % \  | 
|                   (query_Type, query_ID, packCMDList, tick))  | 
|       | 
|   | 
|     if not packCMDList or len(packCMDList) < 2:  | 
|         GameWorld.Log("    DoLogic() return []")  | 
|         return []  | 
|       | 
|     tagMapID = packCMDList[0]  # Ä¿±êµØÍ¼id  | 
|     tagMapLineID = packCMDList[1]  # Ä¿±êµØÍ¼Ïß·ÊôÐÔ,´Ó0¿ªÊ¼  | 
|     resultLineID = -1  # ½á¹ûlineID  | 
|     notifyMark = 'GeRen_chenxin_500807' #²»ÄܽøµÄÌáʾ  | 
|     if tagMapID in ChConfig.Def_MapID_LineIDToPropertyID:          | 
|         GameWorld.Log("    DoLogic() tagMapID in ChConfig.Def_MapID_LineIDToPropertyID")  | 
|         tagMapPropertyID = tagMapLineID + 1 # ÒòΪPropertyIDĬÈÏÊÇ0£¬ËùÒÔʹÓÃʱ´Ó1¿ªÊ¼  | 
|           | 
|         resultLineID = -1  # ½á¹ûlineID  | 
|           | 
|         gameWorldManager = GameWorld.GetGameWorld()  | 
|         maxPlayerCount = FBLogic.GetFBLineMaxPlayerCount(tagMapID, tagMapLineID)  | 
|           | 
|         GameWorld.Log("    DoLogic()  tagMapID=%s,tagMapLineID=%s,maxPlayerCount=%s" % (tagMapID, tagMapLineID,maxPlayerCount))  | 
|         firstEmptyGameWorld = None  | 
|         sameLineGameWorldList = []  | 
|         for index in xrange(gameWorldManager.GetGameWorldCount()):  | 
|             gameWorld = IPY_GameWorld.IPY_GameWorld(index)  | 
|             playerManager = gameWorld.GetMapCopyPlayerManagerByFbIndex(index)  | 
|             propertyID = gameWorld.GetPropertyID()  | 
|             curPlayerCnt = playerManager.GetPlayerCount()  | 
| #            GameWorld.Log("    DoLogic()  check gameworld index=%s,propertyID=%s,playerCount=%s" \  | 
| #                          % (index, propertyID, curPlayerCnt))  | 
|             if propertyID == 0 and not firstEmptyGameWorld:  | 
|                 firstEmptyGameWorld = gameWorld  | 
|             # Èç¹û²»ÊÇͬһÏß·ÊôÐԵģ¬ÔòÌø¹ý  | 
|             # Èç¹ûµ±Ç°ÈËÊý³¬¹ý¶î¶¨ÈËÊý£¬ÔòÌø¹ý  | 
|             if propertyID == tagMapPropertyID and curPlayerCnt < maxPlayerCount:  | 
|                 sameLineGameWorldList.append([gameWorld, curPlayerCnt])  | 
|         findGameWorld = None  | 
|         if sameLineGameWorldList:  | 
|             sameLineGameWorldList.sort(key=lambda asd:asd[1])  | 
|             findGameWorld = sameLineGameWorldList[0][0]  | 
|         elif firstEmptyGameWorld:  | 
|             findGameWorld = firstEmptyGameWorld  | 
|         if findGameWorld:  | 
|             if findGameWorld.GetPropertyID() == 0:  | 
|                 findGameWorld.SetFBFirstOpen(1) # ¿ªÆô¸±±¾  | 
|             findGameWorld.SetPropertyID(tagMapPropertyID)  | 
|             resultLineID = findGameWorld.GetLineID()  | 
|             GameWorld.Log("    DoLogic()  check ok!resultLineID=%s" % (resultLineID))  | 
|               | 
|               | 
| #===================================================================================================  | 
| #    # Õ½Ã˼ÒÔ°  | 
| #    elif tagMapID == ChConfig.Def_MapID_FamilyHome:  | 
| #          | 
| #        if len(packCMDList) < 4:  | 
| #            GameWorld.DebugLog("    ÇëÇó½øÈëÕ½Ã˼ÒÔ°£ºÎÞÄ¿±êÕ½ÃËID£¡")  | 
| #            return  | 
| #          | 
| #        tagFamilyID = packCMDList[2]  | 
| #        tagFamilyHomeLV = packCMDList[3]  | 
| #        if tagFamilyID <= 0:  | 
| #            GameWorld.DebugLog("    ÇëÇó½øÈëÕ½Ã˼ÒÔ°£ºÄ¿±êÕ½ÃËID´íÎó=%s£¡" % tagFamilyID)  | 
| #            return  | 
| #          | 
| #        resultLineID = -1  # ½á¹ûlineID  | 
| #          | 
| #        gameWorldManager = GameWorld.GetGameWorld()  | 
| #        firstNotPropertyGameWorld = None  | 
| #          | 
| #        for index in range(gameWorldManager.GetGameWorldCount()):  | 
| #            gameWorld = IPY_GameWorld.IPY_GameWorld(index)  | 
| #            playerManager = gameWorld.GetMapCopyPlayerManagerByFbIndex(index)  | 
| #            propertyID = gameWorld.GetPropertyID()  | 
| #              | 
| #            # ²»¿É½øÈë  | 
| #            if gameWorld.GetCloseFBTick() > 0:  | 
| #                continue  | 
| #   | 
| #            if gameWorld.GetOpenState() == IPY_GameWorld.fbosWaitForClose:  | 
| #                continue  | 
| #              | 
| #            if propertyID <= 0 and firstNotPropertyGameWorld == None:  | 
| #                firstNotPropertyGameWorld = gameWorld  | 
| #              | 
| #            if propertyID == tagFamilyID:  | 
| #                resultLineID = gameWorld.GetLineID()  | 
| #                GameWorld.DebugLog("    ÕÒµ½ÒѾ´æÔÚµÄÕ½Ã˼ÒÔ°: tagFamilyID=%s,resultLineID=%s" % (tagFamilyID, resultLineID))  | 
| #                break  | 
| #              | 
| #        if resultLineID < 0 and firstNotPropertyGameWorld != None and firstNotPropertyGameWorld.GetPropertyID() <= 0:  | 
| #            firstNotPropertyGameWorld.SetPropertyID(tagFamilyID)  | 
| #            firstNotPropertyGameWorld.SetFBFirstOpen(1) # ¿ªÆô¸±±¾  | 
| #            resultLineID = firstNotPropertyGameWorld.GetLineID()  | 
| #            GameWorld.GetGameWorld().SetGameWorldDict("FamilyHomeLV_%s" % tagFamilyID, tagFamilyHomeLV)  | 
| #            GameWorld.DebugLog("    ´´½¨ÐÂÕ½Ã˼ÒÔ°: tagFamilyID=%s,tagFamilyHomeLV=%s,resultLineID=%s"   | 
| #                               % (tagFamilyID, tagFamilyHomeLV, resultLineID))  | 
| #===================================================================================================  | 
|     elif tagMapID in [ChConfig.Def_FBMapID_HorsePetBoss, ChConfig.Def_FBMapID_SealDemon, ChConfig.Def_FBMapID_ZhuXianBoss, ChConfig.Def_FBMapID_AllFamilyBoss, ChConfig.Def_FBMapID_DemonKing]:  | 
|         tagMapPropertyID = tagMapLineID + 1 # ÒòΪPropertyIDĬÈÏÊÇ0£¬ËùÒÔʹÓÃʱ´Ó1¿ªÊ¼  | 
|         resultLineID = -1  # ½á¹ûlineID  | 
|           | 
|         gameWorldManager = GameWorld.GetGameWorld()  | 
|         GameWorld.Log("    DoLogic()  tagMapID=%s,tagMapLineID=%s" % (tagMapID, tagMapLineID))  | 
|         findGameWord = None  | 
|         findPlayerManager = None  | 
|         for index in range(gameWorldManager.GetGameWorldCount()):  | 
|             gameWorld = IPY_GameWorld.IPY_GameWorld(index)  | 
|             playerManager = gameWorld.GetMapCopyPlayerManagerByFbIndex(index)  | 
|             propertyID = gameWorld.GetPropertyID()  | 
|             if gameWorld.GetCloseFBTick() > 0:  | 
|                 #ÕýÔڹرՠ²»¿É½ø  | 
|                 continue  | 
|               | 
| #            GameWorld.Log("    DoLogic()  check gameworld index=%s,propertyID=%s,playerCount=%s" \  | 
| #                          % (index, propertyID, playerManager.GetPlayerCount()))  | 
|             # Èç¹û²»ÊÇͬһÏß·ÊôÐԵģ¬ÔòÌø¹ý  | 
|             if propertyID == tagMapPropertyID:  | 
|                 if tagMapID == ChConfig.Def_FBMapID_SealDemon:  | 
|                     if GameLogic_SealDemon.GetBossRemainHPPer(index, tagMapLineID, tick) < 15:  | 
|                         findGameWord = None  | 
|                         findPlayerManager = None  | 
|                         notifyMark = "DemonJar_Text4"  | 
|                         break  | 
|                 elif tagMapID == ChConfig.Def_FBMapID_ZhuXianBoss:  | 
|                     if GameLogic_ZhuXianBoss.GetBossRemainHPPer(index, tagMapLineID, tick) < IpyGameDataPY.GetFuncCfg('ZhuXianBossCntCfg', 4):  | 
|                         findGameWord = None  | 
|                         findPlayerManager = None  | 
|                         notifyMark = "DemonJar_Text4"  | 
|                         break  | 
|                       | 
|                 findGameWord = gameWorld  | 
|                 findPlayerManager = playerManager  | 
|                 break  | 
|             if not findGameWord and propertyID == 0:  | 
|                 findGameWord = gameWorld  | 
|                 findPlayerManager = playerManager  | 
|           | 
|         if findPlayerManager and tagMapID == ChConfig.Def_FBMapID_ZhuXianBoss:  | 
|             if packCMDList[3] !=-1 and not GameLogic_ZhuXianBoss.GetHasSameFamilyMerber(packCMDList[3], findPlayerManager):  | 
|                 notifyMark = "TryEnterJadeDynastyBossError_6"  | 
|                 findGameWord = None  | 
|                 GameWorld.DebugLog("    ¹éÊô´ÎÊýΪ0ÇÒûÓÐͬÃËÍæ¼ÒÔÚ¸±±¾Àï!")  | 
|                   | 
|         if findGameWord:  | 
|             if findGameWord.GetPropertyID() == 0:  | 
|                 findGameWord.SetFBFirstOpen(1) # ¿ªÆô¸±±¾  | 
|             findGameWord.SetPropertyID(tagMapPropertyID)  | 
|             resultLineID = findGameWord.GetLineID()  | 
|   | 
|     else:  | 
|         #resultLineID = tagMapLineID  | 
|         resultLineID = 0  | 
|           | 
|     return ['%s' % packCMDList, '%d' % resultLineID, notifyMark]  | 
| #---------------------------------------------------------------------  | 
|   | 
|   | 
| #Ö´Ðнá¹û  | 
| ## Ö´Ðнá¹û  | 
| #  @param curPlayer ·¢³öÇëÇóµÄÍæ¼Ò  | 
| #  @param callFunName ¹¦ÄÜÃû³Æ  | 
| #  @param funResult ²éѯµÄ½á¹û  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def DoResult(curPlayer, callFunName, funResult, tick):  | 
|       | 
|     #»¹Ô¸ñʽ '[]' -> []  | 
|     funResult = eval(funResult)  | 
|     if not funResult or len(funResult) < 3:  | 
|         GameWorld.Log("GY_Query_EnterFB DoResult() return []")  | 
|         return  | 
|       | 
|     tagMapInfo = eval(funResult[0])  | 
|     backFBID = int(funResult[1]) # ·µ»ØµÄÇÐͼÏß·id(0~N)  | 
|     notifyMark = funResult[2]  | 
|     mapID = tagMapInfo[0] # ÇëÇóµÄÇÐͼid  | 
|     funcLineID = tagMapInfo[1]   # ÇëÇóµÄ³¡´ÎÏß·id(0~6)  | 
|     GameWorld.Log("GY_Query_EnterFB DoResult() mapID=%s,funcLineID=%s,backFBID=%s" % (mapID, funcLineID, backFBID), curPlayer.GetPlayerID())  | 
|       | 
|     if backFBID == -1: # Î´ÕÒµ½¿É½øÈëµÄ·ÖÏߣ¬Ôò·µ»Ø£¬ÌáʾÈËÊýÒÑÂú  | 
|         PlayerControl.NotifyCode(curPlayer, notifyMark)  | 
|         return  | 
|       | 
|     if curPlayer.GetMapID() == mapID:  | 
|         #ÒÑÔڸõØÍ¼¾Í²»ÈýøÁË  | 
|         return  | 
|       | 
|     # ÇëÇó½øÈëFBµã  | 
|     ipyEnterPosInfo = FBCommon.GetFBLineEnterPosInfo(mapID, funcLineID)  | 
|     retPos = FBLogic.OnGetFBEnterPos(curPlayer, mapID, funcLineID, ipyEnterPosInfo, tick)  | 
|       | 
|     if not retPos:  | 
|         return  | 
|       | 
|     # ´«ËÍÂß¼  | 
|     PlayerControl.PlayerResetWorldPosFB(curPlayer, mapID, retPos[0], retPos[1], False, backFBID, funcLineID=funcLineID)  | 
|     return  | 
|   |