| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package GM.Commands.CrossFB  | 
| #  | 
| # @todo:¿ç·þ¸±±¾  | 
| # @author hxp  | 
| # @date 2022-01-06  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ¿ç·þ¸±±¾  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2022-01-06 20:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import GameWorld  | 
| import PyGameData  | 
| import IpyGameDataPY  | 
| import PlayerFB  | 
|   | 
| #---------------------------------------------------------------------  | 
| #Â߼ʵÏÖ  | 
| ## Ö´ÐÐÂß¼  | 
| #  @param curPlayer µ±Ç°Íæ¼Ò  | 
| #  @param gmList [cmdIndex gmAccID msg]  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def OnExec(curPlayer, gmList):  | 
|     ## ±¾·þ´¦Àí  | 
|     GameWorld.DebugAnswer(curPlayer, "----------------------------")  | 
|     if not gmList:  | 
|         GameWorld.DebugAnswer(curPlayer, "Êä³öÈËÊý: CrossFB mapID")  | 
|         GameWorld.DebugAnswer(curPlayer, "ÐéÄâ½øÈë: CrossFB mapID ¹¦ÄÜÏß· ÈËÊý µÈ¼¶")  | 
|         GameWorld.DebugAnswer(curPlayer, "Ìí¼ÓÈËÊý: CrossFB 1 ³¡¾°ID ÐéÄâÏß· ÔÚÏß ÀëÏß")  | 
|         GameWorld.DebugAnswer(curPlayer, "¿Û³ýÈËÊý: CrossFB 2 ³¡¾°ID ÐéÄâÏß· ÔÚÏß ÀëÏß")  | 
|     return  | 
|   | 
| def OnMergeServerExec(gmList, tick):  | 
|     ## ¿ç·þ´¦Àí  | 
|       | 
|     serverGroupID = gmList[-2]  | 
|     playerID = gmList[-1]  | 
|       | 
|     dynamicLineMapDict = IpyGameDataPY.GetFuncEvalCfg("CrossDynamicLineMap", 1, {})  | 
|     gmList = gmList[:-2]  | 
|     if not gmList:  | 
|         GameWorld.DebugAnswerCross(playerID, serverGroupID, "---ÒÔÏÂΪ¿É·ÖÁ÷³¡¾°ÐéÄâÏß·ÌõÊý")  | 
|         for mapID, mapIDList in dynamicLineMapDict.items():  | 
|             gameMap = GameWorld.GetMap(mapID)  | 
|             if not gameMap:  | 
|                 continue  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "¶¯Ì¬·ÖÁ÷: %s¡¾mapID:%s¡¿" % (gameMap.GetMapName(), mapID))  | 
|             for realMapID in mapIDList:  | 
|                 GameWorld.DebugAnswerCross(playerID, serverGroupID, "    ·ÖÁ÷³¡¾°ÐéÄâÏß·Êý:%s\t%s"   | 
|                                            % (realMapID, PyGameData.g_crossMapCopyMapCountDict.get(realMapID, 0)))  | 
|         return  | 
|       | 
|     value0 = gmList[0]  | 
|     mapID = value0  | 
|     if value0 in [1, 2]:  | 
|         if len(gmList) != 5:  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "²ÎÊý²»×㣬ÇëÖØÐÂÊäÈë")  | 
|             return  | 
|         realMapID, copyMapID, fbPlayerCount, offlineCount = gmList[1:]  | 
|           | 
|         key = (realMapID, copyMapID)  | 
|         if key not in PyGameData.g_crossDynamicLineCopyMapInfo:  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "²»´æÔڸó¡¾°Ïß·»ò먦Æô!realMapID=%s,copyMapID=%s" % (realMapID, copyMapID))  | 
|             return  | 
|         copyMapObj = PyGameData.g_crossDynamicLineCopyMapInfo[key] # CrossCopyMapInfo  | 
|           | 
|         mapID = __GetMapIDByRealMapID(dynamicLineMapDict, realMapID)  | 
|         if mapID not in dynamicLineMapDict:  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "·ÖÁ÷³¡¾°µØÍ¼´íÎó")  | 
|             return  | 
|           | 
|         # Ìí¼Ó  | 
|         if value0 == 1:  | 
|             robotID = __GetMapRobotID(dynamicLineMapDict[mapID])  | 
|             for _ in xrange(fbPlayerCount):  | 
|                 robotID += 1  | 
|                 copyMapObj.fbPlayerDict[robotID] = serverGroupID  | 
|                   | 
|             for _ in xrange(offlineCount):  | 
|                 robotID += 1  | 
|                 copyMapObj.offlinePlayerDict[robotID] = serverGroupID  | 
|                   | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "³¡¾°%sÏß%s:Ìí¼ÓÔÚÏß(%s),ÀëÏß(%s)" % (realMapID, copyMapID, fbPlayerCount, offlineCount))  | 
|               | 
|         # ¿Û³ý  | 
|         else:  | 
|             delFBPlayerCount, delOfflinePlayerCount = 0, 0  | 
|             fbPlayerIDList = copyMapObj.fbPlayerDict.keys()  | 
|             for pID in fbPlayerIDList:  | 
|                 if pID < 10000:  | 
|                     copyMapObj.fbPlayerDict.pop(pID, 0)  | 
|                     delFBPlayerCount += 1  | 
|                     if delFBPlayerCount >= fbPlayerCount:  | 
|                         break  | 
|                       | 
|             offlinePlayerIDList = copyMapObj.offlinePlayerDict.keys()  | 
|             for pID in offlinePlayerIDList:  | 
|                 if pID < 10000:  | 
|                     copyMapObj.offlinePlayerDict.pop(pID, 0)  | 
|                     delOfflinePlayerCount += 1  | 
|                     if delOfflinePlayerCount >= offlineCount:  | 
|                         break  | 
|               | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "³¡¾°%sÏß%s:ɾ³ýÔÚÏß(%s),ÀëÏß(%s)" % (realMapID, copyMapID, delFBPlayerCount, delOfflinePlayerCount))  | 
|               | 
|         waitPlayerCount, fbPlayerCount, offlinePlayerCount = len(copyMapObj.waitPlayerDict), len(copyMapObj.fbPlayerDict), len(copyMapObj.offlinePlayerDict)  | 
|         GameWorld.DebugAnswerCross(playerID, serverGroupID, "    %s,¹¦ÄÜÇø-Ïß-³¡:%s-%s-%s,µÈ´ý%s,¸±±¾%s,ÀëÏß%s"   | 
|                                    % (copyMapID, copyMapObj.zoneID, copyMapObj.funcLineID, copyMapObj.newFuncLineNum,   | 
|                                       waitPlayerCount, fbPlayerCount, offlinePlayerCount))  | 
|           | 
|     # ÐéÄâÍæ¼Ò½øÈë: CrossFB mapID funcLineID µÈ¼¶ ÈËÊý  | 
|     elif len(gmList) >= 4:  | 
|         mapID, funcLineID, enterCount, lv = gmList  | 
|         if mapID not in dynamicLineMapDict:  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "mapID´íÎó")  | 
|             return  | 
|           | 
|         robotID = __GetMapRobotID(dynamicLineMapDict[mapID])  | 
|           | 
|         GameWorld.DebugLog("mapID=%s,robotID=%s" % (mapID, robotID))  | 
|         okCount = 0  | 
|         copyMapObj = None  | 
|         for _ in xrange(enterCount):  | 
|             robotID += 1  | 
|             msgData = {"PlayerID":robotID, "MapID":mapID, "FuncLineID":funcLineID, "LV":lv}  | 
|             copyMapObj = PlayerFB.ClientServerMsg_EnterFB(serverGroupID, msgData, tick)  | 
|             if not copyMapObj:  | 
|                 GameWorld.DebugAnswerCross(playerID, serverGroupID, "½øÈëʧ°Ü£¬²é¿´¿ç·þGameServerÈÕÖ¾")  | 
|                 break  | 
|             okCount += 1  | 
|             copyMapObj.waitPlayerDict.pop(robotID, None)  | 
|             copyMapObj.offlinePlayerDict.pop(robotID, None)  | 
|             copyMapObj.fbPlayerDict[robotID] = serverGroupID  | 
|               | 
|         if copyMapObj:  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "ÐéÄâ½øÈë:%s - %s, LV:(%s), ¸öÊý(%s), ³É¹¦(%s)" % (mapID, funcLineID, lv, enterCount, okCount))  | 
|             waitPlayerCount, fbPlayerCount, offlinePlayerCount = len(copyMapObj.waitPlayerDict), len(copyMapObj.fbPlayerDict), len(copyMapObj.offlinePlayerDict)  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "    %s,¹¦ÄÜÇø-Ïß-³¡:%s-%s-%s,µÈ´ý%s,¸±±¾%s,ÀëÏß%s"   | 
|                                        % (copyMapObj.copyMapID, copyMapObj.zoneID, copyMapObj.funcLineID, copyMapObj.newFuncLineNum,   | 
|                                           waitPlayerCount, fbPlayerCount, offlinePlayerCount))  | 
|               | 
|     elif len(gmList) == 1:  | 
|         pass  | 
|     else:  | 
|         GameWorld.DebugAnswerCross(playerID, serverGroupID, "²ÎÊý¸öÊý´íÎó!")  | 
|         return  | 
|       | 
|     gameMap = GameWorld.GetMap(mapID)  | 
|     if mapID not in dynamicLineMapDict or not gameMap:  | 
|         GameWorld.DebugAnswerCross(playerID, serverGroupID, "²»´æÔڸ÷ÖÁ÷¸±±¾µØÍ¼! %s" % mapID)  | 
|         return  | 
|       | 
|     GameWorld.DebugAnswerCross(playerID, serverGroupID, "---·ÖÁ÷³¡¾°Ã÷ϸ: %s¡¾mapID:%s¡¿" % (gameMap.GetMapName(), mapID))  | 
|     dynamicMapIDList = dynamicLineMapDict[mapID]  | 
|     for realMapID in dynamicMapIDList:  | 
|         copyMapCount = PyGameData.g_crossMapCopyMapCountDict.get(realMapID, 0)  | 
|         GameWorld.DebugAnswerCross(playerID, serverGroupID, "·ÖÁ÷³¡¾°¡¾%s¡¿ÐéÄâÏß·Êý%sÌõ" % (realMapID, copyMapCount))  | 
|           | 
|         playerCountTotal = 0  | 
|         for copyMapID in xrange(copyMapCount):  | 
|             key = (realMapID, copyMapID)  | 
|             if key not in PyGameData.g_crossDynamicLineCopyMapInfo:  | 
|                 continue  | 
|             copyMapObj = PyGameData.g_crossDynamicLineCopyMapInfo[key] # CrossCopyMapInfo  | 
|               | 
|             waitPlayerCount, fbPlayerCount, offlinePlayerCount = len(copyMapObj.waitPlayerDict), len(copyMapObj.fbPlayerDict), len(copyMapObj.offlinePlayerDict)  | 
|             playerCount = waitPlayerCount + fbPlayerCount + offlinePlayerCount  | 
|             #if not playerCount:  | 
|             #    continue  | 
|               | 
|             playerCountTotal += playerCount  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "    %s,¹¦ÄÜÇø-Ïß-³¡:%s-%s-%s,µÈ´ý%s,¸±±¾%s,ÀëÏß%s"   | 
|                                        % (copyMapID, copyMapObj.zoneID, copyMapObj.funcLineID, copyMapObj.newFuncLineNum,   | 
|                                           waitPlayerCount, fbPlayerCount, offlinePlayerCount))  | 
|               | 
|         if not playerCountTotal:  | 
|             GameWorld.DebugAnswerCross(playerID, serverGroupID, "    ¸Ã·ÖÁ÷³¡¾°µØÍ¼Ã»ÈË!")  | 
|               | 
|     return  | 
|   | 
| def OnGetMergeParam(curPlayer):  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     serverGroupID = GameWorld.GetServerGroupID()  | 
|     return [serverGroupID, playerID]  | 
|   | 
| def __GetMapIDByRealMapID(dynamicLineMapDict, realMapID):  | 
|     for mapID, mapIDList in dynamicLineMapDict.items():  | 
|         if realMapID in mapIDList:  | 
|             return mapID  | 
|     return 0  | 
|   | 
| def __GetMapRobotID(dynamicMapIDList):  | 
|     robotID = 0  | 
|     for realMapID in dynamicMapIDList:  | 
|         copyMapCount = PyGameData.g_crossMapCopyMapCountDict.get(realMapID, 0)  | 
|         for copyMapID in xrange(copyMapCount):  | 
|             key = (realMapID, copyMapID)  | 
|             if key not in PyGameData.g_crossDynamicLineCopyMapInfo:  | 
|                 continue  | 
|             copyMapObj = PyGameData.g_crossDynamicLineCopyMapInfo[key] # CrossCopyMapInfo  | 
|             playerIDList = list(set(copyMapObj.waitPlayerDict.keys() + copyMapObj.fbPlayerDict.keys() + copyMapObj.offlinePlayerDict.keys()))  | 
|             for playerID in playerIDList:  | 
|                 if playerID < 10000 and playerID > robotID:  | 
|                     robotID = playerID  | 
|     return robotID  |