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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.CrossActCTGBillboard
#
# @todo:¿ç·þÔËÓª»î¶¯ - ³äÖµÅÅÐÐ
# @author hxp
# @date 2020-01-13
# @version 1.0
#
# ÏêϸÃèÊö: ¿ç·þÔËÓª»î¶¯ - ³äÖµÅÅÐÐ
#
#-------------------------------------------------------------------------------
#"""Version = 2020-01-13 17:00"""
#-------------------------------------------------------------------------------
 
import ChConfig
import ShareDefine
import PlayerControl
import NetPackCommon
import PlayerBillboard
import CrossRealmPlayer
import ChPyNetSendPack
import ItemControler
import IPY_GameWorld
import IpyGameDataPY
import GameWorld
import CommFunc
 
def OnPlayerLogin(curPlayer):
    isReset = __CheckPlayerCrossActCTGBillboard(curPlayer)
    if not isReset:
        actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_CTGBillboard)
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if actInfo.get(ShareDefine.ActKey_State):
            Sync_CrossActCTGBillboardInfo(curPlayer)
            Sync_CrossActCTGBillboardPlayerInfo(curPlayer)
            UpdateCTGRMBCrossBillboard(curPlayer, actInfo)
    return
 
def RefreshCrossActCTGBillboardInfo():
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if curPlayer.GetID() == 0:
            continue
        __CheckPlayerCrossActCTGBillboard(curPlayer)
    return
 
def __CheckPlayerCrossActCTGBillboard(curPlayer):
    ## ¼ì²éÍæ¼ÒÀۼƳäÖµ»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    
    actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_CTGBillboard)
    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)
    templateID = actInfo.get(ShareDefine.ActKey_TemplateID, 0)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardID) # Íæ¼ÒÉíÉϵĻID
    playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardTemplateID)
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("¿ç·þ³äÖµÅÅÐлID²»±ä£¬²»´¦Àí£¡cfgID=%s,dayIndex=%s,templateID=%s" % (cfgID, dayIndex, templateID), playerID)
        if state:
            if playerTemplateID != templateID and templateID:
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardTemplateID, templateID)
                GameWorld.DebugLog("    »î¶¯Ä£°åID±ä¸ü£¬¸üÐÂÍæ¼ÒÉíÉÏÄ£°åID¼Ç¼£¡playerTemplateID=%s,updTemplateID=%s" 
                                   % (playerTemplateID, templateID), playerID)
                Sync_CrossActCTGBillboardInfo(curPlayer)
                
        return
    
    GameWorld.DebugLog("¿ç·þ³äÖµÅÅÐлÖØÖÃ! cfgID=%s,actID=%s,playerActID=%s,state=%s" % (cfgID, actID, playerActID, state), playerID)
    
    if not state:
        CrossRealmPlayer.NotifyCrossActEnd(curPlayer, ShareDefine.CrossActName_CTGBillboard)
        
    if playerActID and playerTemplateID:
        __SendDabiaoAwardMail(curPlayer, playerTemplateID)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardID, actID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardTemplateID, templateID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardRMB, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardAward, 0)
    
    Sync_CrossActCTGBillboardInfo(curPlayer)
    Sync_CrossActCTGBillboardPlayerInfo(curPlayer)
    return True
 
def __SendDabiaoAwardMail(curPlayer, playerTemplateID):
    ## ²¹·¢Î´ÁìÈ¡µÄ´ï±ê½±Àø
    
    totalRMB = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardRMB)
    if not totalRMB:
        return
    
    ipyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActCTGBillboardDabiao", playerTemplateID)
    if not ipyDataList:
        return
    
    playerID = curPlayer.GetPlayerID()
    awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardAward)
    batchPlayerIDList, batchAddItemList, batchParamList = [], [], []
    for ipyData in ipyDataList:
        ctgNeed = ipyData.GetCTGNeed()
        awardIndex = ipyData.GetAwardIndex()
        if totalRMB < CommFunc.RMBToCoin(ctgNeed):
            continue
        if awardRecord & pow(2, awardIndex):
            continue
        batchPlayerIDList.append([playerID])
        batchAddItemList.append(ipyData.GetAwardItemList())
        batchParamList.append([ctgNeed])
        awardRecord = awardRecord | pow(2, awardIndex)
        
    if not batchPlayerIDList:
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardAward, awardRecord)
    
    GameWorld.DebugLog("²¹·¢¿ç·þ³äÖµÅÅÐлδÁìÈ¡´ï±ê½±Àø!", playerID)
    PlayerControl.SendMailBatch("CACTGBillboardDabiao", batchPlayerIDList, batchAddItemList, batchParamList)
    return
 
def GetDabiaoAward(curPlayer, awardIndex):
    ## ÊÖ¶¯ÁìÈ¡´ï±ê½±Àø
    
    actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_CTGBillboard)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    if not state:
        GameWorld.DebugLog("·Ç»î¶¯ÖÐ")
        return
    
    totalRMB = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardRMB)
    awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardAward)
    if awardRecord & pow(2, awardIndex):
        GameWorld.DebugLog("ÒÑÁìÈ¡¹ý¸Ã½±Àø! awardIndex=%s" % awardIndex)
        return
        
    playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardTemplateID)
    ipyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActCTGBillboardDabiao", playerTemplateID)
    if not ipyDataList:
        return
    
    awardItemList = []
    for ipyData in ipyDataList:
        ctgNeed = CommFunc.RMBToCoin(ipyData.GetCTGNeed())
        if awardIndex == ipyData.GetAwardIndex():
            if totalRMB < ctgNeed:
                GameWorld.DebugLog("³äÖµ¶î¶Èδ´ï±ê£¬ÎÞ·¨ÁìÈ¡! awardIndex=%s,totalRMB=%s,ctgNeed=%s" 
                                   % (awardIndex, totalRMB, ctgNeed))
                return
            awardItemList = ipyData.GetAwardItemList()
            break
        
    GameWorld.DebugLog("ÁìÈ¡¿ç·þ³äÖµ»î¶¯´ï±ê½±Àø£¡awardIndex=%s,awardItemList=%s" % (awardIndex, awardItemList))
    if not awardItemList:
        return
    
    if not ItemControler.CheckPackSpaceEnough(curPlayer, awardItemList):
        return
    
    updAwardRecord = awardRecord | pow(2, awardIndex)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardAward, updAwardRecord)
    Sync_CrossActCTGBillboardPlayerInfo(curPlayer)
    
    for itemID, itemCount, isAuctionItem in awardItemList:
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], 
                                     event=["CrossActCTGBillboard", False, {}])
        
    return
 
def AddCTGRMB(curPlayer, addRMB):
    ## Ôö¼Ó»î¶¯ÒÑÀۼƳäÖµRMB
    actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_CTGBillboard) 
    if not actInfo:
        return
    
    if not actInfo.get(ShareDefine.ActKey_State):
        GameWorld.DebugLog("Íæ¼ÒÇø·þID¿ç·þ³äÖµÅÅÐзǻÖÐ!playerServerID=%s" % GameWorld.GetPlayerServerID(curPlayer))
        return
    
    totalRMB = min(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardRMB) + addRMB, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CA_CTGBillboardRMB, totalRMB)
    
    GameWorld.DebugLog("¿ç·þ³äÖµÅÅÐлÔö¼ÓÍæ¼ÒÀۼƳäÖµRMB: addRMB=%s,totalRMB=%s" % (addRMB, totalRMB), curPlayer.GetPlayerID())
    Sync_CrossActCTGBillboardPlayerInfo(curPlayer)
    UpdateCTGRMBCrossBillboard(curPlayer, actInfo)
    return
 
def UpdateCTGRMBCrossBillboard(curPlayer, actInfo):
    ## ¸üпç·þ³äÖµ»î¶¯°ñ
    totalRMB = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardRMB)
    if not totalRMB:
        return
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
    if not cfgID:
        return
    
    playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardTemplateID)
    orderIpyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActCTGBillboardOrder", playerTemplateID)
    if not orderIpyDataList:
        return
    
    atleastRMBMin = None
    for orderIpyData in orderIpyDataList:
        atleastRMB = orderIpyData.GetCTGAtleast()
        if atleastRMBMin == None or atleastRMBMin > atleastRMB:
            atleastRMBMin = atleastRMB
            
    if atleastRMBMin == None:
        return
    
    if totalRMB < atleastRMBMin:
        GameWorld.DebugLog("¿ç·þ³äÖµÅÅÐл³äÖµ¶î¶È²»×㣬ÎÞ·¨ÉÏ°ñ! totalRMB(%s) < atleastRMBMin(%s)" 
                           % (totalRMB, atleastRMBMin), curPlayer.GetPlayerID())
        return
    
    cmpValue = totalRMB
    PlayerBillboard.UpdatePlayerCrossBillboard(curPlayer, ShareDefine.Def_CBT_ActCTG, cfgID, cmpValue)
    return
 
def Sync_CrossActCTGBillboardPlayerInfo(curPlayer):
    ## Í¨Öª»î¶¯Íæ¼ÒÊý¾ÝÐÅÏ¢
    playerActInfo = ChPyNetSendPack.tagMCCACTGBillboardPlayerInfo()
    playerActInfo.CTGRMBTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardRMB)
    playerActInfo.DabiaoAwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CA_CTGBillboardAward)
    NetPackCommon.SendFakePack(curPlayer, playerActInfo)
    return
 
def Sync_CrossActCTGBillboardInfo(curPlayer):
    ## Í¨Öª»î¶¯ÐÅÏ¢
    
    actInfo = CrossRealmPlayer.GetPlayerCrossActInfo(curPlayer, ShareDefine.CrossActName_CTGBillboard)
    if not actInfo:
        return
    
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    ipyDataDict = actInfo.get(ShareDefine.ActKey_IpyDataInfo, {})
    if not ipyDataDict:
        return 0
    
    templateIDList = ipyDataDict.get("TemplateIDList", [])
    if not templateIDList:
        return
    
    actPack = ChPyNetSendPack.tagMCCACTGBillboardInfo()
    actPack.ServerIDRangeInfo = str(actInfo.get(ShareDefine.ActKey_ServerIDRangeList, []))
    actPack.ServerInfoLen = len(actPack.ServerIDRangeInfo)
    actPack.GroupValue1 = actInfo.get(ShareDefine.ActKey_CfgID, 0)
    actPack.StartDate = ipyDataDict.get("StartDate", "")
    actPack.EndtDate = ipyDataDict.get("EndDate", "")
    actPack.TemplateID = actInfo.get(ShareDefine.ActKey_TemplateID, 0)
    actPack.TempInfo = []
    for templateID in templateIDList:
        tempInfo = ChPyNetSendPack.tagMCCACTGBillboardTempInfo()
        
        # ´ï±ê
        tempInfo.TemplateID = templateID
        tempInfo.DabiaoAwardInfo = []
        dabiaoIpyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActCTGBillboardDabiao", templateID)
        if dabiaoIpyDataList:
            for dabiaoIpyData in dabiaoIpyDataList:
                dabiaoInfo = ChPyNetSendPack.tagMCCACTGBillboardDabiao()
                dabiaoInfo.NeedRMB = dabiaoIpyData.GetCTGNeed()
                dabiaoInfo.AwardIndex = dabiaoIpyData.GetAwardIndex()
                dabiaoInfo.AwardItemList = []
                for itemID, itemCount, isBind in dabiaoIpyData.GetAwardItemList():
                    itemInfo = ChPyNetSendPack.tagMCCACTGBillboardAwardItem()
                    itemInfo.ItemID = itemID
                    itemInfo.ItemCount = itemCount
                    itemInfo.IsBind = isBind
                    dabiaoInfo.AwardItemList.append(itemInfo)
                dabiaoInfo.AwardItemCount = len(dabiaoInfo.AwardItemList)
                tempInfo.DabiaoAwardInfo.append(dabiaoInfo)
        tempInfo.DabiaoAwardCount = len(tempInfo.DabiaoAwardInfo)
        
        # ÅÅÐÐ
        tempInfo.OrderAwardInfo = []
        orderIpyDataList = IpyGameDataPY.GetIpyGameDataList("CrossActCTGBillboardOrder", templateID)
        if orderIpyDataList:
            for orderIpyData in orderIpyDataList:
                orderInfo = ChPyNetSendPack.tagMCCACTGBillboardOrder()
                orderInfo.OrderA = orderIpyData.GetOrderA()
                orderInfo.OrderB = orderIpyData.GetOrderB()
                orderInfo.NeedRMB = orderIpyData.GetCTGAtleast()
                orderInfo.AwardItemList = []
                for itemID, itemCount, isBind in orderIpyData.GetAwardItemList():
                    itemInfo = ChPyNetSendPack.tagMCCACTGBillboardAwardItem()
                    itemInfo.ItemID = itemID
                    itemInfo.ItemCount = itemCount
                    itemInfo.IsBind = isBind
                    orderInfo.AwardItemList.append(itemInfo)
                orderInfo.AwardItemCount = len(orderInfo.AwardItemList)
                tempInfo.OrderAwardInfo.append(orderInfo)
        tempInfo.OrderAwardCount = len(tempInfo.OrderAwardInfo)
        
        actPack.TempInfo.append(tempInfo)
        
    actPack.TemplateCount = len(actPack.TempInfo)
    NetPackCommon.SendFakePack(curPlayer, actPack)
    return