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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActTurntable
#
# @todo:תÅ̻
# @author hxp
# @date 2021-05-06
# @version 1.0
#
# ÏêϸÃèÊö: ×ªÅ̻
#
#-------------------------------------------------------------------------------
#"""Version = 2021-05-06 16:30"""
#-------------------------------------------------------------------------------
 
 
import PyGameData
import ShareDefine
import PlayerControl
import IpyGameDataPY
import ItemControler
import ChPyNetSendPack
import IPY_GameWorld
import NetPackCommon
import GameWorld
import ChConfig
import CommFunc
 
import random
 
# ÎïÆ·¿âÀàÐÍ
(
ItemLibType_Comm, # ³£¹æÎïÆ·
ItemLibType_Good, # ¼«Æ·ÎïÆ·
ItemLibType_Super, # ÖÕ¼«ÎïÆ·
) = range(1, 3 + 1)
 
def OnPlayerLogin(curPlayer):
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Turntable, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        isReset = __CheckPlayerTurntableAction(curPlayer, actNum)
        if not isReset:
            # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
            if actInfo.get(ShareDefine.ActKey_State):
                AddTurntableUseCountByLogin(curPlayer, actNum)
                Sync_TurntableActionInfo(curPlayer, actNum)
                Sync_TurntablePlayerInfo(curPlayer, actNum)
                
    return
 
def PlayerOnDay(curPlayer):
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Turntable, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        if not actInfo.get(ShareDefine.ActKey_State):
            continue
        
        # ¹ýÌìÖØÖÃ
        AddTurntableUseCountByLogin(curPlayer, actNum)
        Sync_TurntablePlayerInfo(curPlayer, actNum)
        
    return
    
def RefreshTurntableActionInfo(actNum):
    ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢
    playerManager = GameWorld.GetPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if curPlayer.GetID() == 0:
            continue
        __CheckPlayerTurntableAction(curPlayer, actNum)
    return
 
def __CheckPlayerTurntableAction(curPlayer, actNum):
    ## ¼ì²éÍæ¼Ò»î¶¯Êý¾ÝÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Turntable, actNum)
    actID = actInfo.get(ShareDefine.ActKey_ID, 0)
    state = actInfo.get(ShareDefine.ActKey_State, 0)
    
    playerActID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableID % actNum) # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if actID == playerActID:
        GameWorld.DebugLog("תÅ̻ID²»±ä£¬²»´¦Àí£¡actNum=%s,actID=%s" % (actNum, actID), playerID)
        return
        
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
    actWorldLV = actInfo.get(ShareDefine.ActKey_WorldLV, 0)
    
    GameWorld.DebugLog("תÅ̻ÖØÖÃ! cfgID=%s,actNum=%s,actID=%s,playerActID=%s,state=%s" % (cfgID, actNum, actID, playerActID, state), playerID)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableID % actNum, actID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableWorldLV % actNum, actWorldLV)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableLoginState % actNum, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableCTGValue % actNum, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableUseGold % actNum, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableCanUseCount % actNum, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemState % actNum, 0)
    
    ipyData = None if not cfgID else IpyGameDataPY.GetIpyGameData("ActTurntable", cfgID)
    if ipyData:
        numCountList = ipyData.GetLibChooseCountList()
        numCountTotal = sum([numCount for numCount in numCountList])
        for num in xrange(1, numCountTotal + 1):
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemID % (actNum, num), 0)
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemCount % (actNum, num), 0)
            
        if state:
            # Ëæ»úÉú³É³£¹æÎïÆ·
            commItemCount = numCountList[0]
            commItemLib = GameWorld.GetDictValueByRangeKey(ipyData.GetCommItemLib(), actWorldLV, [])
            random.shuffle(commItemLib) # ´òÂÒÏÂ˳Ðò
            commItemList = commItemLib[:commItemCount]
            GameWorld.DebugLog("    Ëæ»úÉú³É³£¹æÎïÆ·: %s, %s" % (commItemCount, commItemList))
            for num, itemInfo in enumerate(commItemList, 1):
                itemID, itemCount, _ = itemInfo
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemID % (actNum, num), itemID * 10 + ItemLibType_Comm)
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemCount % (actNum, num), itemCount)
                
            # Ôö¼ÓµÇ¼½±ÀøתÅÌ´ÎÊý
            AddTurntableUseCountByLogin(curPlayer, actNum)
            
    Sync_TurntableActionInfo(curPlayer, actNum)
    Sync_TurntablePlayerInfo(curPlayer, actNum)
    return True
 
def AddTurntableUseCountByLogin(curPlayer, actNum):
    ## µÇ¼Ôö¼ÓתÅÌ´ÎÊý
    todayTime = GameWorld.GetTodayTime()
    loginState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableLoginState % actNum)
    if loginState == todayTime:
        GameWorld.DebugLog("µÇ¼Ôö¼ÓתÅÌ´ÎÊý£¬ÒѾ­Ôö¼Ó¹ý: actNum=%s,todayTime=%s" % (actNum, todayTime))
        return
    GameWorld.DebugLog("µÇ¼Ôö¼ÓתÅÌ´ÎÊý: actNum=%s,todayTime=%s" % (actNum, todayTime))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableLoginState % actNum, todayTime)
    AddTurntableUseCount(curPlayer, actNum, 1)
    return
 
def AddTurntableUseCount(curPlayer, actNum, addCount):
    ## Ôö¼ÓתÅÌ´ÎÊý
    canUseCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableCanUseCount % actNum) + addCount
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableCanUseCount % actNum, canUseCount)
    GameWorld.DebugLog("    Ôö¼ÓתÅ̻´ÎÊý: actNum=%s,addCount=%s,canUseCount=%s" % (actNum, addCount, canUseCount))
    return
 
def OnPlayerRecharge(curPlayer, curRechargeValue, coinType):
    ## Íæ¼Ò³äÖµ
    if curRechargeValue <= 0:
        return
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Turntable, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        if not actInfo.get(ShareDefine.ActKey_State):
            GameWorld.DebugLog("תÅ̵±Ç°Î´¿ªÆô! actNum=%s" % actNum)
            continue
        
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
        if not cfgID:
            continue
        
        ipyData = IpyGameDataPY.GetIpyGameData("ActTurntable", cfgID)
        if not ipyData:
            continue
        
        ctgTypeEffValue = ipyData.GetCTGTypeEffValue()
        if not ctgTypeEffValue & pow(2, coinType):
            GameWorld.DebugLog("תÅ̻³äÖµÀàÐͶԸûÎÞЧ! actNum=%s,coinType=%s,ctgTypeEffValue=%s" 
                               % (actNum, coinType, ctgTypeEffValue), curPlayer.GetPlayerID())
            continue
        
        ctgPrizeList = [CommFunc.RMBToCoin(floatRMB) for floatRMB in ipyData.GetCTGPrizeList()]
        nowCTGValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableCTGValue % actNum)
        if nowCTGValue >= max(ctgPrizeList):
            GameWorld.DebugLog("תÅ̻³äÖµÒÑ´ï×î´ó¼Ç¼£¬actNum=%s,nowCTGValue=%s,maxCTGValue=%s" 
                               % (actNum, nowCTGValue, max(ctgPrizeList)))
            continue
        
        updCTGValue = nowCTGValue + curRechargeValue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableCTGValue % actNum, updCTGValue)
        GameWorld.DebugLog("תÅ̻³äÖµ£¬actNum=%s,nowCTGValue=%s,updCTGValue=%s,curRechargeValue=%s" 
                           % (actNum, nowCTGValue, updCTGValue, curRechargeValue))
        
        addTurntableCount = 0
        for ctgValue in ctgPrizeList:
            if updCTGValue < ctgValue:
                break
            
            if nowCTGValue < ctgValue and updCTGValue >= ctgValue:
                addTurntableCount += 1
                GameWorld.DebugLog("    ctgValue=%s,addTurntableCount=%s" % (ctgValue, addTurntableCount))
                
        if addTurntableCount > 0:
            AddTurntableUseCount(curPlayer, actNum, addTurntableCount)
        Sync_TurntablePlayerInfo(curPlayer, actNum)
        
    return
 
def OnPlayerUseGold(curPlayer, moneyType, addUseGold):
    ## Íæ¼ÒÏûºÄ»õ±Ò
    
    if addUseGold <= 0:
        return
    
    for actInfo in PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_Turntable, {}).values():
        actNum = actInfo.get(ShareDefine.ActKey_ActNum, 0)
        if not actInfo.get(ShareDefine.ActKey_State):
            GameWorld.DebugLog("תÅ̵±Ç°Î´¿ªÆô! actNum=%s" % actNum)
            continue
        
        cfgID = actInfo.get(ShareDefine.ActKey_CfgID, 0)
        if not cfgID:
            continue
        
        ipyData = IpyGameDataPY.GetIpyGameData("ActTurntable", cfgID)
        if not ipyData:
            continue
        
        if moneyType != ipyData.GetUseMoneyType():
            continue
        
        useMoneyPrizeList = ipyData.GetUseMoneyPrizeList()
        nowUseGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableUseGold % actNum)
        if nowUseGold >= max(useMoneyPrizeList):
            GameWorld.DebugLog("תÅ̻ÏûºÄ»õ±ÒÒÑ´ï×î´ó¼Ç¼£¬actNum=%s,moneyType=%s,nowUseGold=%s,maxUseMoneyValue=%s" 
                               % (actNum, moneyType, nowUseGold, max(useMoneyPrizeList)))
            continue
        
        updUseGold = nowUseGold + addUseGold
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableUseGold % actNum, updUseGold)
        GameWorld.DebugLog("תÅ̻ÏûºÄ»õ±Ò£¬actNum=%s,moneyType=%s,nowUseGold=%s,updUseGold=%s,addUseGold=%s" 
                           % (actNum, moneyType, nowUseGold, updUseGold, addUseGold))
        
        addTurntableCount = 0
        for useGold in useMoneyPrizeList:
            if updUseGold < useGold:
                break
            
            if nowUseGold < useGold and updUseGold >= useGold:
                addTurntableCount += 1
                GameWorld.DebugLog("    useGold=%s,addTurntableCount=%s" % (useGold, addTurntableCount))
                
        if addTurntableCount > 0:
            AddTurntableUseCount(curPlayer, actNum, addTurntableCount)
        Sync_TurntablePlayerInfo(curPlayer, actNum)
        
    return
 
#// AA 12 Ñ¡ÔñתÅ̻ÎïÆ· #tagCMActTurntableChooseItem
#
#struct    tagCMActTurntableChooseItem
#{
#    tagHead        Head;
#    BYTE        ActNum;        // »î¶¯±àºÅ
#    BYTE        GoodItemNumCount;
#    BYTE        GoodItemNumList[GoodItemNumCount];    // Ñ¡ÔñµÄ¼«Æ·ÎïÆ·±àºÅÁбí
#    BYTE        SuperItemNumCount;
#    BYTE        SuperItemNumList[SuperItemNumCount];    // Ñ¡ÔñµÄÖÕ¼«ÎïÆ·±àºÅÁбí
#};
def OnTurntableChooseItem(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    actNum = clientData.ActNum
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Turntable, actNum)
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    if not cfgID:
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("ActTurntable", cfgID)
    if not ipyData:
        return
    
    numCountList = ipyData.GetLibChooseCountList()
    numCountTotal = sum([numCount for numCount in numCountList])
    if len(numCountList) != 3:
        return
    commCount, goodCount, superCount = numCountList
    
    canChoose = True
    for num in xrange(1, numCountTotal + 1):
        itemIDInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableItemID % (actNum, num))
        itemID, itemLibType = itemIDInfo / 10, itemIDInfo % 10
        if itemID and itemLibType != ItemLibType_Comm:
            canChoose = False
            GameWorld.DebugLog("    ÒѾ­Ñ¡Ôñ¹ýÁËתÅÌÎïÆ·ÁË£¬ÎÞ·¨Öظ´Ñ¡Ôñ!")
            break
        
    if not canChoose:
        return
    
    actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableWorldLV % actNum)
    goodItemLib = GameWorld.GetDictValueByRangeKey(ipyData.GetGoodItemLib(), actWorldLV, [])
    chooseGoodItemNumList = clientData.GoodItemNumList
    if not chooseGoodItemNumList or len(chooseGoodItemNumList) != goodCount or min(chooseGoodItemNumList) <= 0 or max(chooseGoodItemNumList) > len(goodItemLib):
        GameWorld.ErrLog("    ×ªÅ̻¼«Æ·ÎïÆ·Ñ¡Ôñ´íÎó!actNum=%s,chooseGoodItemNumList=%s,goodCount=%s,goodItemLibLen=%s" 
                         % (actNum, chooseGoodItemNumList, goodCount, len(goodItemLib)))
        return
    
    superItemLib = GameWorld.GetDictValueByRangeKey(ipyData.GetSuperItemLib(), actWorldLV, [])
    chooseSuperItemNumList = clientData.SuperItemNumList
    if not chooseSuperItemNumList or len(chooseSuperItemNumList) != superCount or min(chooseSuperItemNumList) <= 0 or max(chooseSuperItemNumList) > len(superItemLib):
        GameWorld.ErrLog("    ×ªÅ̻ÖÕ¼«ÎïÆ·Ñ¡Ôñ´íÎó!actNum=%s,chooseSuperItemNumList=%s,superCount=%s,superItemLibLen=%s" 
                         % (actNum, chooseSuperItemNumList, superCount, len(superItemLib)))
        return
    
    useNum = commCount # ÒÔÆÕͨÎïÆ·¸öÊýΪ±àºÅ£¬µÝÔö
    GameWorld.DebugLog("תÅ̻ѡÔñÎïÆ·: actNum=%s,chooseGoodItemNumList=%s,chooseSuperItemNumList=%s" % (actNum, chooseGoodItemNumList, chooseSuperItemNumList))
    for chooseGoodNum in chooseGoodItemNumList:
        useNum += 1
        itemID, itemCount, _ = goodItemLib[chooseGoodNum - 1]
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemID % (actNum, useNum), itemID * 10 + ItemLibType_Good)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemCount % (actNum, useNum), itemCount)
        GameWorld.DebugLog("    ´æ´¢Ñ¡Ôñ¼«Æ·ÎïÆ·: useNum=%s,itemID=%s,itemCount=%s" % (useNum, itemID, itemCount))
        
    for chooseSuperNum in chooseSuperItemNumList:
        useNum += 1
        itemID, itemCount, _ = superItemLib[chooseSuperNum - 1]
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemID % (actNum, useNum), itemID * 10 + ItemLibType_Super)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemCount % (actNum, useNum), itemCount)
        GameWorld.DebugLog("    ´æ´¢Ñ¡ÔñÖÕ¼«ÎïÆ·: useNum=%s,itemID=%s,itemCount=%s" % (useNum, itemID, itemCount))
        
    Sync_TurntableActionInfo(curPlayer, actNum)
    return
 
#// AA 13 Æô¶¯×ªÅÌ #tagCMActTurntableStart
#
#struct    tagCMActTurntableStart
#{
#    tagHead        Head;
#    BYTE        ActNum;        // »î¶¯±àºÅ
#};
def OnTurntableStart(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    actNum = clientData.ActNum
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Turntable, actNum)
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    if not cfgID:
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("ActTurntable", cfgID)
    if not ipyData:
        return
    
    canUseCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableCanUseCount % actNum)
    if canUseCount <= 0:
        GameWorld.DebugLog("ûÓÐתÅ̻´ÎÊý!actNum=%s" % actNum)
        return
    
    itemState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableItemState % actNum)
    
    numCountList = ipyData.GetLibChooseCountList()
    numCountTotal = sum([numCount for numCount in numCountList])
    
    canStart = False
    hadGetCount = 0
    isAuctionItem = 0 # Ä¬ÈÏ·ÇÅÄÆ·
    canGetItemInfoDict = {} # »¹¿ÉÒÔ»ñµÃµÄÎïÆ·ÐÅÏ¢ {itemLibType:{num:itemInfo, ...}, ...}
    for num in xrange(1, numCountTotal + 1):
        itemIDInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableItemID % (actNum, num))
        itemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableItemCount % (actNum, num))
        itemID, itemLibType = itemIDInfo / 10, itemIDInfo % 10
        if not itemID or not itemCount:
            continue
        
        if itemLibType != ItemLibType_Comm:
            canStart = True
            
        if itemState & pow(2, num):
            hadGetCount += 1
            continue
        
        if itemLibType not in canGetItemInfoDict:
            canGetItemInfoDict[itemLibType] = {}
        canGetItemInfoDict[itemLibType][num] = [itemID, itemCount, isAuctionItem]
        
    if not canStart:
        GameWorld.DebugLog("δѡÔñתÅ̻¼«Æ·ÖÕ¼«ÎïÆ·£¬ÎÞ·¨Æô¶¯×ªÅÌ£¡")
        return
    
    if not ItemControler.CheckPackHasSpace(curPlayer, isNotify=True):
        return
    
    superRate, superLimitTurnCount = ipyData.GetSuperItemLimitRule() # ÖÕ¼«¿â²ú³öÍò·ÖÂÊ|ÖÁÉÙX´Îºó¿É²ú³ö
    
    GameWorld.DebugLog("Æô¶¯×ªÅ̻! actNum=%s,itemState=%s,hadGetCount=%s, superLimitTurnCount=%s,superRate=%s" 
                       % (actNum, itemState, hadGetCount, superLimitTurnCount, superRate))
    GameWorld.DebugLog("    canGetItemInfoDict=%s" % canGetItemInfoDict)
    
    if not canGetItemInfoDict:
        return
    
    randNum = 0
    worldNotifyKey = ""
    giveItemInfo = []
    canGetCommNumList = canGetItemInfoDict.get(ItemLibType_Comm, {}).keys()
    canGetGoodNumList = canGetItemInfoDict.get(ItemLibType_Good, {}).keys()
    randNumWithoutSuperList = canGetCommNumList + canGetGoodNumList
    GameWorld.DebugLog("    ²»º¬ÖÕ¼«ÎïÆ·µÄ±àºÅ: %s" % (randNumWithoutSuperList))
    
    if hadGetCount >= superLimitTurnCount and ItemLibType_Super in canGetItemInfoDict:
        GameWorld.DebugLog("    Óлú»á»ñµÃÖÕ¼«ÎïÆ·: superRate=%s" % superRate)
        if not randNumWithoutSuperList or GameWorld.CanHappen(superRate): # Ã»ÓÐÆäËûÎïÆ·Á˱سöÖÕ¼«
            randNum = random.choice(canGetItemInfoDict[ItemLibType_Super].keys())
            giveItemInfo = canGetItemInfoDict[ItemLibType_Super][randNum]
            GameWorld.DebugLog("    »ñµÃÖÕ¼«ÎïÆ·! randNum=%s,giveItemInfo=%s" % (randNum, giveItemInfo))
            worldNotifyKey = ipyData.GetWorldNotifyKey()
        
    if not giveItemInfo and randNumWithoutSuperList:
        randNum = random.choice(randNumWithoutSuperList)
        
        if randNum in canGetGoodNumList:
            giveItemInfo = canGetItemInfoDict[ItemLibType_Good][randNum]
            GameWorld.DebugLog("    »ñµÃ¼«Æ·ÎïÆ·! randNum=%s,giveItemInfo=%s" % (randNum, giveItemInfo))
            worldNotifyKey = ipyData.GetWorldNotifyKey()
        else:
            giveItemInfo = canGetItemInfoDict[ItemLibType_Comm][randNum]
            GameWorld.DebugLog("    »ñµÃ³£¹æÎïÆ·! randNum=%s,giveItemInfo=%s" % (randNum, giveItemInfo))
                
    if not giveItemInfo or not randNum:
        return
    
    updItemState = itemState | pow(2, randNum)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableItemState % actNum, updItemState)
    updCanUseCount = canUseCount - 1
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TurntableCanUseCount % actNum, updCanUseCount)
    GameWorld.DebugLog("    randNum=%s,updItemState=%s,updCanUseCount=%s" % (randNum, updItemState, updCanUseCount))
    
    itemID, itemCount, isAuctionItem = giveItemInfo
    ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], event=["ActTurntable", False, {}])
    
    if worldNotifyKey:
        PlayerControl.WorldNotify(0, worldNotifyKey, [curPlayer.GetPlayerName(), itemID, itemCount])
        
    Sync_TurntablePlayerInfo(curPlayer, actNum, randNum)
    return
 
 
def Sync_TurntablePlayerInfo(curPlayer, actNum, getItemNum=0):
    ## Í¨ÖªÍæ¼ÒÊý¾ÝÐÅÏ¢
    # @param getItemNum: ±¾´ÎתÅÌ»ñµÃµÄ¶ÔÓ¦ÎïÆ·±àºÅ
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Turntable, actNum)
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    if not cfgID:
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("ActTurntable", cfgID)
    if not ipyData:
        return
    
    playerActInfo = ChPyNetSendPack.tagMCActTurntablePlayerInfo()
    playerActInfo.ActNum = actNum
    playerActInfo.CanUseCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableCanUseCount % actNum)
    playerActInfo.CTGTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableCTGValue % actNum)
    playerActInfo.UseMoneyTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableUseGold % actNum)
    playerActInfo.TurnItemState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableItemState % actNum)
    playerActInfo.GetItemNum = getItemNum
    NetPackCommon.SendFakePack(curPlayer, playerActInfo)
    return
 
def Sync_TurntableActionInfo(curPlayer, actNum):
    ## Í¨Öª»î¶¯ÐÅÏ¢
    
    actInfo = GameWorld.GetActInfo(ShareDefine.OperationActionName_Turntable, actNum)
    if not actInfo.get(ShareDefine.ActKey_State):
        return
    
    cfgID = actInfo.get(ShareDefine.ActKey_CfgID)
    if not cfgID:
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("ActTurntable", cfgID)
    if not ipyData:
        return
    
    actWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableWorldLV % actNum)
    startDateStr, endDateStr = GameWorld.GetOperationActionDateStr(ipyData)
    
    clientPack = ChPyNetSendPack.tagMCActTurntableInfo()
    clientPack.ActNum = actNum
    clientPack.StartDate = startDateStr
    clientPack.EndtDate = endDateStr
    clientPack.IsDayReset = ipyData.GetIsDayReset()
    clientPack.LimitLV = ipyData.GetLVLimit()
    clientPack.CTGPrizeList = [CommFunc.RMBToCoin(floatRMB) for floatRMB in ipyData.GetCTGPrizeList()]
    clientPack.CTGPrizeCount = len(clientPack.CTGPrizeList)
    clientPack.UseMoneyType = ipyData.GetUseMoneyType()
    clientPack.UseMoneyPrizeList = ipyData.GetUseMoneyPrizeList()
    clientPack.UseMoneyPrizeCount = len(clientPack.UseMoneyPrizeList)
    
    numCountList = ipyData.GetLibChooseCountList()
    numCountTotal = sum([numCount for numCount in numCountList])
    
    clientPack.TurnItemList = []
    for num in xrange(1, numCountTotal + 1):
        itemIDInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableItemID % (actNum, num))
        itemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TurntableItemCount % (actNum, num))
        itemID, itemLibType = itemIDInfo / 10, itemIDInfo % 10
        if not itemID:
            break
        packItem = ChPyNetSendPack.tagMCActTurntableItem()
        packItem.ItemNum = num
        packItem.ItemLibType = itemLibType
        packItem.ItemID = itemID
        packItem.ItemCount = itemCount
        clientPack.TurnItemList.append(packItem)
    clientPack.TurnItemCount = len(clientPack.TurnItemList)
    
    clientPack.GoodItemCanChooseCount = numCountList[1] if len(numCountList) > 1 else 0
    goodItemLib = GameWorld.GetDictValueByRangeKey(ipyData.GetGoodItemLib(), actWorldLV, [])
    for num, itemInfo in enumerate(goodItemLib, 1):
        itemID, itemCount, _ = itemInfo
        packItem = ChPyNetSendPack.tagMCActTurntableItem()
        packItem.ItemNum = num
        packItem.ItemLibType = ItemLibType_Good
        packItem.ItemID = itemID
        packItem.ItemCount = itemCount
        clientPack.GoodItemList.append(packItem)
    clientPack.GoodItemCount = len(clientPack.GoodItemList)
    
    clientPack.SuperItemCanChooseCount = numCountList[2] if len(numCountList) > 2 else 0
    superItemLib = GameWorld.GetDictValueByRangeKey(ipyData.GetSuperItemLib(), actWorldLV, [])
    for num, itemInfo in enumerate(superItemLib, 1):
        itemID, itemCount, _ = itemInfo
        packItem = ChPyNetSendPack.tagMCActTurntableItem()
        packItem.ItemNum = num
        packItem.ItemLibType = ItemLibType_Super
        packItem.ItemID = itemID
        packItem.ItemCount = itemCount
        clientPack.SuperItemList.append(packItem)
    clientPack.SuperItemCount = len(clientPack.SuperItemList)
    
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return