hxp
2025-02-06 a90833bf05d8f4a338b0224a956a3794c106bb48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/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