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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GameWorldSkyTower
#
# @todo:ÌìÐÇËþ
# @author hxp
# @date 2020Äê03ÔÂ02ÈÕ
# @version 1.0
#
# ÏêϸÃèÊö: ÌìÐÇËþ
#
#-------------------------------------------------------------------------------
#"""Version = 2020Äê03ÔÂ02ÈÕ 20:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import ShareDefine
import ChPyNetSendPack
import NetPackCommon
import PlayerViewCache
import IpyGameDataPY
 
ConfigExKey_SkyTowerPassPlayerIDList = "SkyTowerPassPlayerIDList"
 
def OnPlayerLogin(curPlayer):
    Sync_SkyTowerPassPlayer(curPlayer)
    return
 
def __GetPassPlayerRecDataByFloorID(floorID):
    ## »ñÈ¡¹ý¹Ø²ã¼Ç¼Êý¾Ý
    recTypeListData = GameWorld.GetUniversalRecMgr().GetTypeList(ShareDefine.Def_UniversalGameRecType_SkyTowerPassPlayer)
    
    recData = None
    for index in xrange(recTypeListData.Count()):
        universalRecData = recTypeListData.At(index)
        if universalRecData.GetValue1() == floorID:
            recData = universalRecData
            break
        
    return recData
 
def MapServer_SkyTowerInfo(curPlayer, msgList):
    ## ÌìÐÇËþ¹ý¹Ø
    msgType, msgData = msgList
    
    # ¹ý¹Ø
    if msgType == "ServerChallengePass":
        rankIndex = __OnServerChallengePass(curPlayer, msgData)
        return msgList + [rankIndex]
    
    # Áì½±
    if msgType == "ServerChallengeReward":
        floorID, needPlayerCount, _ = msgData
        recData = __GetPassPlayerRecDataByFloorID(floorID)
        passPlayerIDList = __GetPassPlayerIDList(recData)
        canGet = 1 if len(passPlayerIDList) >= needPlayerCount else 0
        return msgList + [canGet]
    
    # ºÏ·þÊ×µÇ
    if msgType == "MixFirstLogin":
        __OnMixFirstLogin(curPlayer, msgData)
        return
    
    return
 
def __OnMixFirstLogin(curPlayer, msgData):
    
    playerID = curPlayer.GetPlayerID()
    passFloorInfo = msgData[0]
    
    GameWorld.Log("ºÏ·þÊ×µÇÌî³äÌìÐÇËþÈ«·þ¹ý¹ØÐÅÏ¢: %s" % passFloorInfo, playerID)
    syncRecDataList = []
    recTypeListData = GameWorld.GetUniversalRecMgr().GetTypeList(ShareDefine.Def_UniversalGameRecType_SkyTowerPassPlayer)
    for index in xrange(recTypeListData.Count()):
        recData = recTypeListData.At(index)
        floorID = recData.GetValue1()
        if floorID not in passFloorInfo:
            continue
        maxNeedPassCount = passFloorInfo.pop(floorID)
        passPlayerIDList = __GetPassPlayerIDList(recData)
        if playerID in passPlayerIDList:
            continue
        if len(passPlayerIDList) >= maxNeedPassCount:
            continue
        __AddPassPlayerIDList(recData, passPlayerIDList, playerID)
        syncRecDataList.append(recData)
        GameWorld.Log("    Ìí¼ÓÌìÐÇËþ¹ý¹Ø¼Ç¼: floorID=%s,passPlayerIDList=%s" % (floorID, passPlayerIDList), playerID)
        
    for floorID, maxNeedPassCount in passFloorInfo.items():
        recData = recTypeListData.AddRec()
        recData.SetValue1(floorID)
        passPlayerIDList = []
        __AddPassPlayerIDList(recData, passPlayerIDList, playerID)
        syncRecDataList.append(recData)
        GameWorld.Log("    ÐÂÔöÌìÐÇËþ¹ý¹Ø¼Ç¼: floorID=%s,passPlayerIDList=%s" % (floorID, passPlayerIDList), playerID)
        
    if syncRecDataList:
        Sync_SkyTowerPassPlayer(None, syncRecDataList)
        
    return
 
def __GetPassPlayerIDList(recData):
    strValue3 = recData.GetStrValue3()
    try:
        passPlayerIDList = eval(strValue3) if strValue3 else []
    except:
        passPlayerIDList = []
    return passPlayerIDList
 
def __AddPassPlayerIDList(recData, passPlayerIDList, playerID):
    isAdd = False
    if playerID not in passPlayerIDList:
        passPlayerIDList.append(playerID)
        isAdd = True
    updStr = str(passPlayerIDList).replace(" ", "")
    if len(updStr) > 255:
        passPlayerIDList.remove(playerID)
        updStr = str(passPlayerIDList).replace(" ", "")
        isAdd = False
    recData.SetStrValue3(updStr)
    if isAdd:
        SkyTowerPassPlayerIDList = IpyGameDataPY.GetConfigEx(ConfigExKey_SkyTowerPassPlayerIDList)
        if SkyTowerPassPlayerIDList and playerID not in SkyTowerPassPlayerIDList:
            SkyTowerPassPlayerIDList.append(playerID)
            IpyGameDataPY.SetConfigEx(ConfigExKey_SkyTowerPassPlayerIDList, SkyTowerPassPlayerIDList)
            GameWorld.DebugLog("__AddPassPlayerIDList SkyTowerPassPlayerIDList=%s" % SkyTowerPassPlayerIDList)
    return passPlayerIDList
 
def IsSkyTowerPassPlayer(playerID):
    SkyTowerPassPlayerIDList = IpyGameDataPY.GetConfigEx(ConfigExKey_SkyTowerPassPlayerIDList)
    if not SkyTowerPassPlayerIDList:
        SkyTowerPassPlayerIDList = []
        recTypeListData = GameWorld.GetUniversalRecMgr().GetTypeList(ShareDefine.Def_UniversalGameRecType_SkyTowerPassPlayer)
        for index in xrange(recTypeListData.Count()):
            recData = recTypeListData.At(index)
            passPlayerIDList = __GetPassPlayerIDList(recData)
            for pID in passPlayerIDList:
                if pID not in SkyTowerPassPlayerIDList:
                    SkyTowerPassPlayerIDList.append(pID)
        IpyGameDataPY.SetConfigEx(ConfigExKey_SkyTowerPassPlayerIDList, SkyTowerPassPlayerIDList)
    #GameWorld.DebugLog("IsSkyTowerPassPlayer SkyTowerPassPlayerIDList=%s" % SkyTowerPassPlayerIDList)
    return playerID in SkyTowerPassPlayerIDList
 
def __OnServerChallengePass(curPlayer, msgData):
    ## È«·þÌôÕ½²ã¹ý¹Ø
    playerID = curPlayer.GetPlayerID()
    floorID, maxNeedPassCount, _ = msgData
    GameWorld.DebugLog("ÐÂÔöÌìÐÇËþÈ«·þÌôÕ½²ã¹ý¹Ø¼Ç¼! floorID=%s,maxNeedPassCount=%s" % (floorID, maxNeedPassCount), playerID)
    
    recData = __GetPassPlayerRecDataByFloorID(floorID)
    if not recData:
        recTypeListData = GameWorld.GetUniversalRecMgr().GetTypeList(ShareDefine.Def_UniversalGameRecType_SkyTowerPassPlayer)
        recData = recTypeListData.AddRec()
        recData.SetValue1(floorID)
        
    passPlayerIDList = __GetPassPlayerIDList(recData)
    if len(passPlayerIDList) >= maxNeedPassCount:
        return -1
    
    passPlayerIDList = __AddPassPlayerIDList(recData, passPlayerIDList, playerID)    
    # ¹ã²¥µ¥ÌõÊý¾Ý
    Sync_SkyTowerPassPlayer(None, [recData])
    return passPlayerIDList.index(playerID)
 
def GMAddRobotPassFloor(floorID, robotCount):
    recData = __GetPassPlayerRecDataByFloorID(floorID)
    if not recData:
        recTypeListData = GameWorld.GetUniversalRecMgr().GetTypeList(ShareDefine.Def_UniversalGameRecType_SkyTowerPassPlayer)
        recData = recTypeListData.AddRec()
        recData.SetValue1(floorID)
        
    robotID = 0
    passPlayerIDList = __GetPassPlayerIDList(recData)
    for _ in range(robotCount):
        robotID += 1
        passPlayerIDList = __AddPassPlayerIDList(recData, passPlayerIDList, robotID)
        
    GameWorld.DebugLog("GMÌí¼ÓÌìÐÇËþ»úÆ÷È˹ý¹ØÈ«·þ²ã: floorID=%s,robotCount=%s,passPlayerIDList=%s" 
                       % (floorID, robotCount, passPlayerIDList))
    # ¹ã²¥µ¥ÌõÊý¾Ý
    Sync_SkyTowerPassPlayer(None, [recData])
    return
 
def GMClearPassFloor():
    recTypeListData = GameWorld.GetUniversalRecMgr().GetTypeList(ShareDefine.Def_UniversalGameRecType_SkyTowerPassPlayer)
    recTypeListData.Clear()
    IpyGameDataPY.SetConfigEx(ConfigExKey_SkyTowerPassPlayerIDList, [])
    GameWorld.DebugLog("GMÇå¿ÕÌìÐÇËþÈ«·þ¹ý¹ØÐÅÏ¢")
    return
 
def Sync_SkyTowerPassPlayer(curPlayer=None, recDataList=None):
    if recDataList == None:
        recDataList = []
        recTypeListData = GameWorld.GetUniversalRecMgr().GetTypeList(ShareDefine.Def_UniversalGameRecType_SkyTowerPassPlayer)
        for index in xrange(recTypeListData.Count()):
            recDataList.append(recTypeListData.At(index))
            
    passFloorList = []
    passPlayerIDList = []
    for recData in recDataList:
        floorID = recData.GetValue1()
        playerIDList = __GetPassPlayerIDList(recData)
        for playerID in playerIDList:
            if playerID not in passPlayerIDList:
                passPlayerIDList.append(playerID)
                
        passFloorInfo = ChPyNetSendPack.tagGCSkyTowerPassFloor()
        passFloorInfo.FloorID= floorID
        passFloorInfo.PassPlayerIDList = playerIDList
        passFloorInfo.PassPlayerCount = len(passFloorInfo.PassPlayerIDList)
        passFloorList.append(passFloorInfo)
        
    if not passFloorList and not passPlayerIDList:
        return
    
    passPlayerList = []
    for playerID in passPlayerIDList:
        curCache = PlayerViewCache.FindViewCache(playerID)
        cacheDict = PlayerViewCache.GetCachePropDataDict(curCache) if curCache else {}
        
        playerInfo = ChPyNetSendPack.tagGCSkyTowerPassPlayer()
        playerInfo.PlayerID = playerID
        playerInfo.PlayerName = ("robot%s" % playerID) if playerID < 1000 else cacheDict.get("Name", str(playerID))
        playerInfo.Job = cacheDict.get("Job", 1)
        playerInfo.LV = cacheDict.get("LV", 1)
        playerInfo.RealmLV = cacheDict.get("RealmLV", 0)
        playerInfo.Face = cacheDict.get("Face", 0)
        playerInfo.FacePic = cacheDict.get("FacePic", 0)
        
        passPlayerList.append(playerInfo)
        
    clientPack = ChPyNetSendPack.tagGCSkyTowerPassPlayerInfo()
    clientPack.Clear()
    clientPack.PassFloorList = passFloorList
    clientPack.FloorCount = len(clientPack.PassFloorList)
    clientPack.PassPlayerList = passPlayerList
    clientPack.PlayerCount = len(clientPack.PassPlayerList)
    
    if curPlayer:
        NetPackCommon.SendFakePack(curPlayer, clientPack)
    else:        
        playerManager = GameWorld.GetPlayerManager()
        for i in range(0, playerManager.GetPlayerCount()):
            curPlayer = playerManager.GetPlayerByIndex(i)
            if curPlayer == None or not curPlayer.GetInitOK():
                continue
            NetPackCommon.SendFakePack(curPlayer, clientPack)
    return