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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActGubao
#
# @todo:¹Å±¦Ñø³É»î¶¯
# @author hxp
# @date 2024-08-12
# @version 1.0
#
# ÏêϸÃèÊö: ¹Å±¦Ñø³É»î¶¯
#
#-------------------------------------------------------------------------------
#"""Version = 2024-08-12 19:30"""
#-------------------------------------------------------------------------------
 
import PyGameData
import ShareDefine
import PlayerControl
import IpyGameDataPY
import CrossRealmPlayer
import FunctionNPCCommon
import PlayerBillboard
import ChPyNetSendPack
import PlayerZhanling
import NetPackCommon
import GameWorld
import ChConfig
 
def OnMixFirstLogin(curPlayer):
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)
        if not score:
            continue
        GameWorld.Log("¹Å±¦Ñø³ÉºÏ·þÊ×µÇͬ²½»ý·Ö°ñµ¥: actNum=%s,score=%s" % (actNum, score), curPlayer.GetPlayerID())
        PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_GubaoScore, score, autoSort=True)
        break
    
    return
 
def OnPlayerLogin(curPlayer):
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        isReset = __CheckPlayerGubaoAction(curPlayer, actNum)
        if not isReset:
            # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
            if actInfo.get(ShareDefine.ActKey_State):
                Sync_GubaoActionInfo(curPlayer, actNum)
                Sync_GubaoPlayerInfo(curPlayer, actNum)
                
    if not __CheckPlayerCrossActGubao(curPlayer):
        Sync_CrossActGubaoActionInfo(curPlayer)
        
    return
 
def RefreshGubaoActionInfo(actNum):
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckPlayerGubaoAction(curPlayer, actNum)
    return
 
def __CheckPlayerGubaoAction(curPlayer, actNum):
    ## ¼ì²éÍæ¼Ò»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Gubao, actNum)
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoID % actNum) # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("¹Å±¦Ñø³É»î¶¯ID²»±ä£¬²»´¦Àí£¡actNum=%s,actID=%s" % (actNum, actID), playerID)
        return
    
    GameWorld.DebugLog("¹Å±¦Ñø³ÉÖØÖÃ! actNum=%s,actID=%s,playerActID=%s,state=%s,cfgID=%s" 
                       % (actNum, actID, playerActID, state, cfgID), playerID)
    score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)
    PlayerZhanling.ResetZhanling(curPlayer, PlayerZhanling.ZhanlingType_GubaoTrain, score)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActGubaoID % actNum, actID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActGubaoScore % actNum, 0)
    
    if state:
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
        ipyData = IpyGameDataPY.GetIpyGameData("ActGubao", cfgID)
        if ipyData and ipyData.GetActShopType():
            FunctionNPCCommon.ResetShopItemBuyCountByShopType(curPlayer, [ipyData.GetActShopType()])
        Sync_GubaoActionInfo(curPlayer, actNum)
        Sync_GubaoPlayerInfo(curPlayer, actNum)
    return True
 
def RefreshCrossActGubaoInfo():
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckPlayerCrossActGubao(curPlayer)
        
    return
 
def __CheckPlayerCrossActGubao(curPlayer):
    
    playerID = curPlayer.GetPlayerID()
    
    actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_Gubao)
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    dayIndex = actInfo.get(ShareDefine.ActKey_DayIndex, 0)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_GubaoID) # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("¿ç·þ¹Å±¦Ñø³É»î¶¯ID²»±ä£¬²»´¦Àí£¡cfgID=%s,dayIndex=%s,actID=%s" % (cfgID, dayIndex, actID), playerID)   
        return
    GameWorld.DebugLog("¿ç·þ¹Å±¦Ñø³É»î¶¯ÖØÖÃ! cfgID=%s,actID=%s,playerActID=%s,state=%s" % (cfgID, actID, playerActID, state), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_GubaoID, actID)
    
    if not state:
        CrossRealmPlayer.NotifyCrossActEnd(curPlayer, ShareDefine.CrossActName_Gubao)
        
    Sync_CrossActGubaoActionInfo(curPlayer)
    return True
 
def OnGubaoCost(curPlayer, costPieceInfo, costItemList):
    
    playerID = curPlayer.GetPlayerID()
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
        ipyData = IpyGameDataPY.GetIpyGameData("ActGubao", cfgID)
        if not ipyData:
            continue
        
        if ipyData.GetIsRelationCrossAct():
            crossActInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_Gubao)
            if crossActInfo.get(ShareDefine.ActKey_State, 0):
                if crossActInfo.get(ShareDefine.ActKey_StateJoin) != ShareDefine.ActStateJoin_Start:
                    GameWorld.Log("¿ç·þ¹Å±¦Ñø³É·Ç²ÎÓë»î¶¯ÖÐ: actNum=%s" % actNum, playerID)
                    continue
        else:
            if actInfo.get(ShareDefine.ActKey_StateJoin) != ShareDefine.ActStateJoin_Start:
                GameWorld.Log("¹Å±¦Ñø³É·Ç²ÎÓë»î¶¯ÖÐ: actNum=%s" % actNum, playerID)
                continue
            
        addGubaoScore = 0
        pieceQualityScoreDict = IpyGameDataPY.GetFuncEvalCfg("GubaoAct", 1, {})
        for pieceID, pieceCount in costPieceInfo.items():
            gbIpyData = IpyGameDataPY.GetIpyGameData("Gubao", pieceID)
            if not gbIpyData:
                continue
            quality = gbIpyData.GetGubaoQuality()
            if str(quality) not in pieceQualityScoreDict:
                continue
            qualityScore = pieceQualityScoreDict[str(quality)] * pieceCount
            addGubaoScore += qualityScore
            GameWorld.DebugLog("¹Å±¦»î¶¯ËéƬ»ý·Öͳ¼Æ: actNum=%s,pieceID=%s,quality=%s,pieceCount=%s,qualityScore=%s, %s" 
                               % (actNum, pieceID, quality, pieceCount, qualityScore, addGubaoScore))
            
        otherAddScore = IpyGameDataPY.GetFuncCfg("GubaoAct", 2)
        for itemID, costCount in costItemList:
            otherScore = costCount * otherAddScore
            addGubaoScore += otherScore
            GameWorld.DebugLog("¹Å±¦»î¶¯ÆäËû»ý·Öͳ¼Æ: actNum=%s,itemID=%s,costCount=%s,otherScore=%s, %s" 
                               % (actNum, itemID, costCount, otherScore, addGubaoScore))
            
        if addGubaoScore <= 0:
            continue
        
        AddPlayerScore(curPlayer, actNum, addGubaoScore, ipyData.GetIsRelationCrossAct())
        
    return
 
def AddPlayerScore(curPlayer, actNum, addScore, isRelationCrossAct):
    if addScore <= 0:
        return 0
    score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)
    updScore = score + addScore
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActGubaoScore % actNum, updScore)
    GameWorld.DebugLog("¹Å±¦»î¶¯Ôö¼Ó»ý·Ö: actNum=%s,addScore=%s,updScore=%s" % (actNum, addScore, updScore))
    Sync_GubaoPlayerInfo(curPlayer, actNum)
    PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_GubaoTrainScore, addScore, "ActGubaoTrain")
    PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_GubaoScore, updScore, autoSort=True)
    SendToGameServer_Gubao(curPlayer, "AddGubaoScore", [addScore, updScore, isRelationCrossAct])
    return updScore
 
def SendToGameServer_Gubao(curPlayer, msgType, dataMsg=""):
    playerID = curPlayer.GetPlayerID()
    msgList = str([msgType, dataMsg])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(playerID, 0, 0, "ActGubao", msgList, len(msgList))
    GameWorld.Log("¹Å±¦Ñø³É·¢ËÍGameServer: %s, %s" % (msgType, dataMsg), playerID)
    return
 
def GetActGubaoTrainScore(curPlayer):
    ## »ñÈ¡»î¶¯ÖÐÑø³É»ý·Ö
    actScore = 0
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Gubao, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)
        actScore = max(score, actScore)
    return actScore
 
def Sync_GubaoActionInfo(curPlayer, actNum):
    ## Í¨Öª»î¶¯ÐÅÏ¢
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Gubao, actNum)
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    ipyData = IpyGameDataPY.GetIpyGameData("ActGubao", cfgID)
    if not ipyData:
        return
    
    personalTempID = ipyData.GetPersonalTemplateID()
    personalTempIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGubaoBillTemp", personalTempID) if personalTempID else []
    
    startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
    
    clientPack = ChPyNetSendPack.tagMCActGubaoInfo()
    clientPack.ActNum = actNum
    clientPack.StartDate = startDateStr
    clientPack.EndtDate = endDateStr
    clientPack.JoinStartTime = ipyData.GetJoinStartTime()
    clientPack.JoinEndTime = ipyData.GetJoinEndTime()
    clientPack.LimitLV = ipyData.GetLVLimit()
    clientPack.ShopType = ipyData.GetActShopType()
    
    clientPack.PersonalBillboardInfoList = __GetTempRankBillPackList(personalTempIpyDataList)
    clientPack.PersonalBillCount = len(clientPack.PersonalBillboardInfoList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def Sync_GubaoPlayerInfo(curPlayer, actNum):
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Gubao, actNum)
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    clientPack = ChPyNetSendPack.tagMCActGubaoPlayerInfo()
    clientPack.ActNum = actNum
    clientPack.Score = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActGubaoScore % actNum)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def Sync_CrossActGubaoActionInfo(curPlayer):
    ## Í¨Öª»î¶¯ÐÅÏ¢
    actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_Gubao)
    if not actInfo:
        return
    
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})
    if not ipyDataDict:
        return
    
    personalTempID = ipyDataDict.get("PersonalTemplateID", 0)
    personalTempIpyDataList = IpyGameDataPY.GetIpyGameDataList("ActGubaoBillTemp", personalTempID) if personalTempID else []
    
    clientPack = ChPyNetSendPack.tagMCCrossActGubaoInfo()
    clientPack.ServerIDRangeInfo = str(actInfo.get(ShareDefine.ActKey_ServerIDRangeList, []))
    clientPack.ServerInfoLen = len(clientPack.ServerIDRangeInfo)
    clientPack.GroupValue1 = ipyDataDict.get("ZoneID", 0)
    clientPack.StartDate = ipyDataDict.get("StartDate", "")
    clientPack.EndtDate = ipyDataDict.get("EndDate", "")
    clientPack.JoinStartTime = ipyDataDict.get("JoinStartTime", "")
    clientPack.JoinEndTime = ipyDataDict.get("JoinEndTime", "")
    
    clientPack.PersonalBillboardInfoList = __GetTempRankBillPackList(personalTempIpyDataList)
    clientPack.PersonalBillCount = len(clientPack.PersonalBillboardInfoList)
    
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def __GetTempRankBillPackList(ipyDataList):
    packBillList = []
    if not ipyDataList:
        return packBillList
    for tempIpyData in ipyDataList:
        rankInfo = ChPyNetSendPack.tagMCActGubaoBillard()
        rankInfo.Rank = tempIpyData.GetRank()
        
        rankInfo.AwardItemList = []
        awardItemList = tempIpyData.GetAwardItemList()
        for itemID, itemCount, isAuctionItem in awardItemList:
            item = ChPyNetSendPack.tagMCActGubaoItem()
            item.Clear()
            item.ItemID = itemID
            item.ItemCount = itemCount
            item.IsBind = isAuctionItem
            rankInfo.AwardItemList.append(item)
        rankInfo.Count = len(rankInfo.AwardItemList)
        
#        rankInfo.MemAwardItemList = []
#        memAwardItemList = tempIpyData.GetMemAwardItemList()
#        for itemID, itemCount, isAuctionItem in memAwardItemList:
#            item = ChPyNetSendPack.tagMCActGubaoItem()
#            item.Clear()
#            item.ItemID = itemID
#            item.ItemCount = itemCount
#            item.IsBind = isAuctionItem
#            rankInfo.MemAwardItemList.append(item)
#        rankInfo.MemCount = len(rankInfo.MemAwardItemList)
        
        rankInfo.NeedScore = tempIpyData.GetNeedScore()
        rankInfo.AwardItemExList = []
        scoreAwardEx = tempIpyData.GetScoreAwardEx()
        scoreExList = scoreAwardEx.keys()
        scoreExList.sort()
        for scoreEx in scoreExList:
            itemExList = scoreAwardEx[scoreEx]
            awardEx = ChPyNetSendPack.tagMCActGubaoAwardEx()
            awardEx.NeedScore = scoreEx
            awardEx.AwardItemList = []
            for itemID, itemCount, isAuctionItem in itemExList:
                item = ChPyNetSendPack.tagMCActGubaoItem()
                item.Clear()
                item.ItemID = itemID
                item.ItemCount = itemCount
                item.IsBind = isAuctionItem
                awardEx.AwardItemList.append(item)
            awardEx.Count = len(awardEx.AwardItemList)
            
            rankInfo.AwardItemExList.append(awardEx)
        rankInfo.CountEx = len(rankInfo.AwardItemExList)
        
        packBillList.append(rankInfo)
    return packBillList