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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerTreasure
#
# @todo:Ñ°±¦
# @author hxp
# @date 2018-04-28
# @version 1.0
#
# ÏêϸÃèÊö: ÊÖÓÎÑ°±¦, Ö§³Öµ¥³é¡¢Á¬³é
#
#-------------------------------------------------------------------------------
#"""Version = 2018-04-28 16:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import PlayerRune
import ShareDefine
import GameFuncComm
import IpyGameDataPY
import IPY_GameWorld
import FormulaControl
import ChPyNetSendPack
import PlayerControl
import ItemControler
import NetPackCommon
import PlayerBossReborn
import PlayerFeastTravel
import PlayerFairyCeremony
import PlayerNewFairyCeremony
import PlayerActLunhuidian
import PlayerActYunshi
import PlayerActTask
import ItemCommon
import ChConfig
 
import random
import time
 
# Ñ°±¦ÀàÐÍ£º >=100µÄΪ²ß»®×ÔÐÐÅäÖõÄ×Ô¶¨ÒåÑ°±¦ÀàÐÍ£¬<100µÄÓÃÓÚÖ¸¶¨ÏµÍ³Ñ°±¦¹¦ÄÜ
TreasureTypeList = (
TreasureType_Jipin, # ¼«Æ·Ñ°±¦ 1
TreasureType_Rune, # ·ûÓ¡Ñ°±¦ 2
TreasureType_Jueshi, # ¾øÊÀÑ°±¦ 3
TreasureType_GatherTheSoul, # ¾Û»êÁÔħ 4
TreasureType_Gubao, # ¹Å±¦Ñ°±¦ 5
) = range(1, 1 + 5)
 
def DoTreasureOpen(curPlayer):
    ## Ñ°±¦¿ªÆô
    Sync_TreasureInfo(curPlayer)
    return
 
def OnTreasureLogin(curPlayer):
    #if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_Treasure):
    #    return
    Sync_TreasureInfo(curPlayer)
    return
 
def OnDay(curPlayer):
    syncTypeList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetTreasureSetCount()):
        ipyData = ipyDataMgr.GetTreasureSetByIndex(i)
        treasureType = ipyData.GetTreasureType()
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureFreeCount % (treasureType)):
            continue
        syncTypeList.append(treasureType)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), 0)
    if syncTypeList:
        Sync_TreasureInfo(curPlayer, syncTypeList)
    return
 
def ResetTreasureType(curPlayer, treasureTypeList):
    ## ÖØÖÃÑ°±¦ÀàÐÍÊý
    for treasureType in treasureTypeList:
        setIpyData = IpyGameDataPY.GetIpyGameData("TreasureSet", treasureType)
        if not setIpyData:
            continue
        recycleItemMail = setIpyData.GetRecycleItemMail()
        costItemID = setIpyData.GetCostItemID()
        if recycleItemMail and costItemID:
            ItemControler.RecycleItem(curPlayer, costItemID, recycleItemMail)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCount % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureLuck % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCntAward % (treasureType), 0)
        
        gridNumMaxLimitInfo = setIpyData.GetGridNumMaxLimitInfo()
        for gridNumStr in gridNumMaxLimitInfo.keys():
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureGridCnt % (treasureType, int(gridNumStr)), 0)
            
    Sync_TreasureInfo(curPlayer, treasureTypeList)
    return
 
def IsActTreasureType(curPlayer, treasureType):
    ## ÊÇ·ñ»î¶¯ÖеÄÑ°±¦ÀàÐÍ
    if PlayerActYunshi.IsActTreasureType(curPlayer, treasureType):
        return True
    return False
 
#// A5 68 ÇëÇóÑ°±¦ #tagCMRequestTreasure
#
#struct tagCMRequestTreasure
#{
#    tagHead        Head;
#    BYTE        TreasureType;    //Ñ°±¦ÀàÐÍ
#    BYTE        TreasureIndex;       //Ñ°±¦Ë÷Òý
#    BYTE        CostType;    //ÏûºÄÀàÐÍ£º0-ĬÈÏÏÉÓñ£»1-Ãâ·Ñ´ÎÊý£»2-Ñ°±¦µÀ¾ß
#};
def OnRequestTreasure(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerLV = curPlayer.GetLV()
    playerID = curPlayer.GetPlayerID()
    treasureType = clientData.TreasureType
    treasureIndex = clientData.TreasureIndex
    costType = clientData.CostType
    
    GameWorld.DebugLog("Íæ¼ÒÑ°±¦: treasureType=%s,treasureIndex=%s,costType=%s,playerLV=%s" 
                       % (treasureType, treasureIndex, costType, playerLV), playerID)
    
    setIpyData = IpyGameDataPY.GetIpyGameData("TreasureSet", treasureType)
    if not setIpyData:
        return
    if setIpyData.GetIsActType():
        if not IsActTreasureType(curPlayer, treasureType):
            GameWorld.ErrLog("¸ÃÑ°±¦ÀàÐͷǻÖУ¬ÎÞ·¨Ñ°±¦! treasureType=%s" % (treasureType), playerID)
            return
    treasureCountList = setIpyData.GetTreasureCountList() # Ñ°±¦»ñµÃ¸öÊýÁбí
    if not treasureCountList:
        GameWorld.DebugLog("ûÓÐÑ°±¦´ÎÊýÁбíÅäÖÃ!", playerID)
        return
    if treasureIndex < 0 or treasureIndex >= len(treasureCountList):
        GameWorld.ErrLog("Ñ°±¦´ÎÊýË÷Òý²»´æÔÚ!treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
        return
    treasureCount = treasureCountList[treasureIndex]
    if not treasureCount:
        GameWorld.DebugLog("ûÓÐÑ°±¦´ÎÊýÅäÖÃ!", playerID)
        return
    
    packType = setIpyData.GetPackType()
    if setIpyData.GetCheckPack():
        if not ItemCommon.CheckPackHasSpace(curPlayer, packType, True):
            GameWorld.DebugLog("¶ÔӦѰ±¦±³°üûÓпոñ×Ó!packType=%s" % packType, playerID)
            return
        
    # Ãâ·Ñ´ÎÊý
    if costType == 1:
        dailyFreeCount = setIpyData.GetDailyFreeCount()
        if not dailyFreeCount:
            GameWorld.ErrLog("¸ÃÑ°±¦ÀàÐÍË÷Òý²»Ö§³ÖÃâ·Ñ´ÎÊýÑ°±¦!treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
            return
        freeCountToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureFreeCount % (treasureType))
        updFreeCountToday = freeCountToday + treasureCount
        if updFreeCountToday > dailyFreeCount:
            GameWorld.DebugLog("½ñÈÕÃâ·Ñ´ÎÊý²»×㣬ÎÞ·¨Ê¹ÓÃÃâ·ÑÑ°±¦! freeCountToday=%s + %s > %s" % (freeCountToday, treasureCount, dailyFreeCount), playerID)
            return
        
    # Ñ°±¦µÀ¾ß, Ä¿Ç°Ä¬ÈÏÏûºÄ1¸ö
    elif costType == 2:
        costItemID = setIpyData.GetCostItemID()
        costItemList = setIpyData.GetCostItemCountList() # ÏûºÄµÀ¾ßÎïÆ·IDÁбí
        if not costItemID or not costItemList or treasureIndex >= len(costItemList):
            GameWorld.ErrLog("¸ÃÑ°±¦ÀàÐÍË÷Òý²»Ö§³ÖÏûºÄµÀ¾ßÑ°±¦!treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
            return
        costItemNeedCount = costItemList[treasureIndex]
        if not costItemID or not costItemNeedCount:
            return
        costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, costItemID)
        lackCount = max(0, costItemNeedCount - bindCnt - unBindCnt)
        delCostItemCount = costItemNeedCount - lackCount
        lackCountCostMoney = 0
        if lackCount > 0:
            costGoldList = setIpyData.GetCostMoneyList() # ÏûºÄ»õ±ÒÁбí
            costGoldType = setIpyData.GetCostMoneyType() # ÏûºÄ»õ±ÒÀàÐÍ
            if not costGoldType or not costGoldList or treasureIndex >= len(costGoldList) or not costGoldList[treasureIndex]:
                GameWorld.ErrLog("Ñ°±¦µÀ¾ß²»×㣬¸ÃÑ°±¦ÀàÐͲ»Ö§³ÖÏûºÄ»õ±ÒÑ°±¦! treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
                return
            costGold = costGoldList[treasureIndex]
            perItemGold = int(costGold / costItemNeedCount) # µÀ¾ßµ¥¼Û
            lackCountCostMoney = perItemGold * lackCount
            GameWorld.DebugLog("Ñ°±¦µÀ¾ß²»×㣬ʹÓöÔÓ¦»õ±Ò¿Û³ý: costItemID=%s,perItemGold=%s,lackCount=%s,lackCountCostMoney=%s,costGoldType=%s" 
                               % (costItemID, perItemGold, lackCount, lackCountCostMoney, costGoldType), playerID)
            if lackCountCostMoney:
                moneyType = costGoldType
                infoDict = {ChConfig.Def_Cost_Reason_SonKey:costItemID}
                if not PlayerControl.HaveMoney(curPlayer, moneyType, lackCountCostMoney):
                    return
            else:
                GameWorld.DebugLog("Ñ°±¦ÏûºÄµÀ¾ß²»×ã!costItemID=%s,costItemNeedCount=%s,bindCnt=%s,unBindCnt=%s" 
                                   % (costItemID, costItemNeedCount, bindCnt, unBindCnt), playerID)
                return
        
    # ÏÉÓñÑ°±¦
    else:
        costGoldList = setIpyData.GetCostMoneyList() # ÏûºÄ»õ±ÒÁбí
        costGoldType = setIpyData.GetCostMoneyType() # ÏûºÄ»õ±ÒÀàÐÍ
        if not costGoldType or not costGoldList or treasureIndex >= len(costGoldList):
            GameWorld.ErrLog("¸ÃÑ°±¦ÀàÐÍË÷Òý²»Ö§³ÖÏûºÄ»õ±ÒÑ°±¦!treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
            return
        costGold = costGoldList[treasureIndex]
        if not costGold:
            return
        
        if not PlayerControl.HaveMoney(curPlayer, costGoldType, costGold):
            return
        
    ipyData = IpyGameDataPY.InterpolationSearch("TreasureHouse", "MinLV", playerLV, {"TreasureType":treasureType})
    if not ipyData:
        GameWorld.ErrLog("ÕÒ²»µ½¸ÃµÈ¼¶¶ÔӦѰ±¦¿âÅäÖÃ!treasureType=%s,curLV=%s" % (treasureType, curPlayer.GetLV()), playerID)
        return
    
    luckyItemRateList = ipyData.GetLuckyItemRateList()
    luckyGridNumList = []
    if luckyItemRateList:
        for _, gridNum in luckyItemRateList:
            luckyGridNumList.append(gridNum)
    elif setIpyData.GetLuckyGridNum():
        luckyGridNumList = [setIpyData.GetLuckyGridNum()]
    GameWorld.DebugLog("luckyGridNumList=%s, %s" % (luckyGridNumList, luckyItemRateList), playerID)
    luckFormula = setIpyData.GetLuckyRateFormat() # ÐÒÔËÎïÆ·¸ÅÂʹ«Ê½
    addLuck = setIpyData.GetOnceLucky() # Ôö¼ÓÐÒÔËÖµ
    maxLuck = setIpyData.GetFullLucky() # ÂúÐÒÔËÖµ
    curLuck = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureLuck % (treasureType)) # µ±Ç°ÐÒÔËÖµ
    updLuck = curLuck
    
    curTreasureCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCount % (treasureType)) # µ±Ç°ÒÑÑ°±¦´ÎÊý
    updTreasureCount = curTreasureCount
    
    beSureCountDict = ipyData.GetGridItemRateList3() # µÚx´Î±Ø³ö²ú³ö¸ñ×Ó±àºÅ±ýͼ
    ensureCount = setIpyData.GetEnsureCount() # Ã¿¶àÉٴδ¥·¢±£µ×²ú³ö¿â
    ensureRateList = ipyData.GetGridItemRateList2()
    GameWorld.DebugLog("beSureCountDict=%s" % beSureCountDict, playerID)
    GameWorld.DebugLog("ensureCount=%s, %s" % (ensureCount, ensureRateList), playerID)
    notifyGridNumList = setIpyData.GetNotifyGridNumList() # ¶îÍâÐèÒª¹ã²¥µÄ¸ñ×Ó£¬ÐÒÔ˱سö¡¢´ÎÊý±Ø³ö¿É²»ÅäÖÃ
    gridNumMaxLimitInfo = setIpyData.GetGridNumMaxLimitInfo() # {"¸ñ×Ó":×î´ó¿É²ú³ö´ÎÊý, ...}
    gridNumCountInfo = {} # ÓÐÏÞÖƲú³ö´ÎÊýµÄ¸ñ×ÓÒѾ­²ú³öÊý
    for gridNumStr in gridNumMaxLimitInfo.keys():
        gridNumCountInfo[int(gridNumStr)] = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureGridCnt % (treasureType, gridNumStr))
    GameWorld.DebugLog("gridNumMaxLimitInfo=%s,gridNumCountInfo=%s" % (gridNumMaxLimitInfo, gridNumCountInfo), playerID)
    
    # µ¥³é²ú³öÓÅÏȼ¶£º ÐÒÔËÎïÆ· > ±Ø³ö > ±£µ× > ÆÕͨ
    # Á¬³éûÓÐÓÅÏȼ¶ÏÞÖÆ£¬Ö»ÒªÂú×ãÌõ¼þ¼´¿É²ú³ö
    getGridResult = []
    for tIndex in range(treasureCount):
        updLuck = min(updLuck + addLuck, maxLuck)
        updTreasureCount += 1
        GameWorld.DebugLog("%s,ÀۼƴÎÊý=%s,ÐÒÔË=%s" % (tIndex + 1, updTreasureCount, updLuck), playerID)
        if gridNumMaxLimitInfo:
            GameWorld.DebugLog("    gridNumMaxLimitInfo=%s,gridNumCountInfo=%s" % (gridNumMaxLimitInfo, gridNumCountInfo), playerID)
        baseRateList, commItemRateList = GetUpdLuckyItemRateList(ipyData, luckyGridNumList, updLuck, luckFormula, costType) # ³£¹æ²ú³öÎïÆ·¸ñ×Ó±ýͼ£¬ÐÒÔËÎïÆ·¸ÅÂÊÒѱä¸ü
        commItemRateList = GetRemoveLimitGridRateList(commItemRateList, gridNumCountInfo, gridNumMaxLimitInfo)        
        GameWorld.DebugLog("    »ù´¡±ýͼ=%s" % baseRateList, playerID)
        GameWorld.DebugLog("    ³£¹æ±ýͼ=%s" % commItemRateList, playerID)
        
        curRateList = [] # ¿ÉÄÜ»á¸Ä±ä±ýͼ£¬Ã¿´Î³é½±Ê¹ÓÃеıýͼ¶ÔÏ󣬲»Òª¸Ä±äÅäÖõıýͼ¸ÅÂÊ
        
        # ÂúÐÒÔ˱سö
        if updLuck >= maxLuck and luckyGridNumList:
            if luckyItemRateList:
                curRateList = GetRemoveLimitGridRateList(luckyItemRateList, gridNumCountInfo, gridNumMaxLimitInfo)
            else:
                curRateList = GetRemoveLimitGridRateList([(10000, luckyGridNumList[0])], gridNumCountInfo, gridNumMaxLimitInfo)
            GameWorld.DebugLog("    ¡¾ÂúÐÒÔ˱ýͼ¡¿: %s" % curRateList)
            
        # ´ÎÊý±Ø³ö
        if not curRateList and updTreasureCount in beSureCountDict:
            besureGridRateList = beSureCountDict[updTreasureCount]
            curRateList = GetRemoveLimitGridRateList(besureGridRateList, gridNumCountInfo, gridNumMaxLimitInfo)
            GameWorld.DebugLog("    ¡¾µÚ%s´ÎÊý±Ø³ö±ýͼ¡¿: %s" % (updTreasureCount, curRateList))
            
        # Âú´ÎÊý±Ø³ö
        if not curRateList and ensureCount and updTreasureCount % ensureCount == 0 and ensureRateList:
            curRateList = GetRemoveLimitGridRateList(ensureRateList, gridNumCountInfo, gridNumMaxLimitInfo)
            GameWorld.DebugLog("    ¡¾Âú%s´ÎÊý±Ø³ö±ýͼ¡¿: %s" % (ensureCount, curRateList))
            
        doCount = 0
        while doCount <= 50: # ÏÞÖÆ×î´ó´ÎÊý
            doCount += 1
            if doCount > 1 or not curRateList: # ÖØÐÂËæ»úµÄĬÈÏʹÓó£¹æ±ýͼ
                curRateList = commItemRateList
                
            gridNum = GameWorld.GetResultByRandomList(curRateList)
            if gridNum in luckyGridNumList and gridNum in getGridResult:
                GameWorld.DebugLog("    ÐÒÔËÎïÆ·ÒѾ­³ö¹ý£¬²»ÔÙÖظ´²ú³ö£¡ gridNum=%s in %s" % (gridNum, getGridResult))
                continue
            
            # ÆäËû²ú³öÏÞÖÆ...
            
            if not gridNum:
                continue
            
            getGridResult.append(gridNum)
            GameWorld.DebugLog("    ±¾´Î²ú³ö: gridNum=%s, %s" % (gridNum, getGridResult), playerID)
            if gridNum in luckyGridNumList:
                updLuck = 0
                GameWorld.DebugLog("    ¡¾²ú³öÐÒÔ˸ñ×Ó¡¿: gridNum=%s" % (gridNum), playerID)
            if gridNum in gridNumCountInfo:
                gridNumCountInfo[gridNum] = gridNumCountInfo[gridNum] + 1
                GameWorld.DebugLog("    ¡¾¸üвú³ö´ÎÊý¡¿: gridNum=%s, %s" % (gridNum, gridNumCountInfo), playerID)
            break
        
    GameWorld.DebugLog("Ñ°±¦¸ñ×Ó½á¹û: getGridResult=%s" % getGridResult, playerID)
    if len(getGridResult) != treasureCount:
        GameWorld.ErrLog("Ñ°±¦Òì³££¬Êµ¼Ê»ñµÃÊýÁ¿ÓëÑ°±¦ÇëÇóÊý²»Í¬£¡treasureType=%s,treasureIndex=%s" % (treasureType, treasureIndex), playerID)
        return
    
    isBind = 0 # ÔÝʱĬÈϲ»°ó¶¨
    job = curPlayer.GetJob()
    gridItemInfoDict = ipyData.GetGridItemInfo() # ¸ñ×Ó¶ÔÓ¦ÎïÆ·ÐÅÏ¢ {"¸ñ×Ó±àºÅ":[ÎïÆ·ID, ÊýÁ¿], ...}
    gridLibInfoDict = ipyData.GetGridLibInfo() # ¸ñ×Ó±àºÅ¶ÔÓ¦¿âID {"±àºÅ":ÎïÆ·¿âID, ...}
    jobItemList = ipyData.GetJobItemList()
    treasureResult = []
    randItemIDDict = IpyGameDataPY.GetFuncEvalCfg("TreasureSet", 2)
    
    for gridNum in getGridResult:
        gridNum = str(gridNum)
        if gridNum in gridItemInfoDict:
            itemID, itemCount = gridItemInfoDict[gridNum]
            itemID = GetJobItem(job, itemID, jobItemList)
            if not itemID:
                GameWorld.ErrLog("Ñ°±¦¸ñ×ÓÎïÆ·IDÒì³£!treasureType=%s,gridNum=%s" % (treasureType, gridNum), playerID)
                return
            
            # Ëæ»ú²ú³öÎïÆ·
            if itemID in randItemIDDict:
                canRandItemList = []
                randItemIDList = randItemIDDict[itemID]
                for randItemID in randItemIDList:
                    itemData = GameWorld.GetGameData().GetItemByTypeID(randItemID)
                    if itemData.GetType() == ChConfig.Def_ItemType_Rune and not PlayerRune.GetIsOpenByRuneID(curPlayer, randItemID):
                        GameWorld.DebugLog("δ½âËøµÄ·ûÓ¡²»²ú³ö£¡itemID=%s,randItemID=%s" % (itemID, randItemID), playerID)
                        continue
                    canRandItemList.append(randItemID)
                if not canRandItemList:
                    GameWorld.ErrLog("Ñ°±¦Ëæ»ú¸ñ×ÓûÓпÉËæ»úµÄÎïÆ·!treasureType=%s,treasureIndex=%s,gridNum=%s,itemID=%s" 
                                     % (treasureType, treasureIndex, gridNum, itemID), playerID)
                    return
                itemID = random.choice(canRandItemList)
        # ¸ù¾ÝÎïÆ·¿âÀ´Ëæ»ú
        elif gridNum in gridLibInfoDict:
            libID = gridLibInfoDict[gridNum]
            libItemList = IpyGameDataPY.GetIpyGameDataList("TreasureItemLib", libID)
            if not libItemList:
                return
            itemWeightList = []
            for libItem in libItemList:
                itemWeight, itemID, itemCount = libItem.GetItemWeight(), libItem.GetItemID(), libItem.GetItemCount()
                itemData = GameWorld.GetGameData().GetItemByTypeID(itemID)
                if not itemData:
                    continue
                itemWeightList.append([itemWeight, [itemID, itemCount]])
            if not itemWeightList:
                GameWorld.ErrLog("Ñ°±¦Ëæ»ú¸ñ×ÓûÓпÉËæ»úµÄÎïÆ·!treasureType=%s,treasureIndex=%s,gridNum=%s,libID=%s" 
                                 % (treasureType, treasureIndex, gridNum, libID), playerID)
                return
            itemID, itemCount = GameWorld.GetResultByWeightList(itemWeightList)
        else:
            GameWorld.ErrLog("Ñ°±¦¸ñ×Ó²»´æÔÚ!treasureType=%s,gridNum=%s" % (treasureType, gridNum), playerID)
            return
        
        treasureResult.append([gridNum, itemID, itemCount, isBind])
        
    # ¿ÛÏûºÄ
    if costType == 1:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), updFreeCountToday)
        GameWorld.DebugLog("ÏûºÄÃâ·Ñ´ÎÊý£¬¸üнñÈÕÒÑʹÓÃÃâ·Ñ´ÎÊý: %s" % updFreeCountToday, playerID)
    elif costType == 2:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delCostItemCount, ChConfig.ItemDel_Treasure)
        GameWorld.DebugLog("¿Û³ýÑ°±¦µÀ¾ß,costItemID=%s,delCostItemCount=%s" % (costItemID, delCostItemCount), playerID)
        if lackCountCostMoney:
            infoDict = {"TreasureType":treasureType, "TreasureIndex":treasureIndex, "CostItemID":costItemID, "LackCount":lackCount}
            PlayerControl.PayMoney(curPlayer, moneyType, lackCountCostMoney, ChConfig.Def_Cost_Treasure, infoDict, lackCount)
    else:
        infoDict = {"TreasureType":treasureType, "TreasureIndex":treasureIndex}
        PlayerControl.PayMoney(curPlayer, costGoldType, costGold, ChConfig.Def_Cost_Treasure, infoDict)
        GameWorld.DebugLog("¿Û³ý»õ±Ò,costGoldType=%s,costGold=%s" % (costGoldType, costGold), playerID)
        
    # ¼ÓÊý¾Ý
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCount % (treasureType), updTreasureCount)
    for luckyGridNum in luckyGridNumList:
        if luckyGridNum in getGridResult:
            updLuck = 0
            break
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureLuck % (treasureType), updLuck)
    for gridNum, updCount in gridNumCountInfo.items():
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureGridCnt % (treasureType, gridNum), updCount)
        
    addScoreType = setIpyData.GetAwardMoneyType() # ¶îÍâ½±Àø»õ±ÒÀàÐÍ
    addScore = setIpyData.GetAwardMoneyValue() # µ¥´Î½±Àø»õ±ÒÊý
    if addScoreType and addScore:
        PlayerControl.GiveMoney(curPlayer, addScoreType, addScore)
        
    if treasureType == TreasureType_Rune:
        PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_RuneTreasure, treasureCount)
        PlayerFeastTravel.AddFeastTravelTaskValue(curPlayer, ChConfig.Def_FeastTravel_RuneTreasure, treasureCount)
        PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_RuneTreasure, treasureCount)
        PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_TreasureRune, treasureCount)
    elif treasureType == TreasureType_Jipin:
        PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_Treasure, treasureCount)
        PlayerFeastTravel.AddFeastTravelTaskValue(curPlayer, ChConfig.Def_FeastTravel_Treasure, treasureCount)
        PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_Treasure, treasureCount)
        PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_TreasureJipin, treasureCount)
    elif treasureType == TreasureType_Jueshi:
        PlayerFairyCeremony.AddFCPartyActionCnt(curPlayer, ChConfig.Def_PPAct_JSTreasure, treasureCount)
        PlayerFeastTravel.AddFeastTravelTaskValue(curPlayer, ChConfig.Def_FeastTravel_JSTreasure, treasureCount)
        PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_JSTreasure, treasureCount)
        PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_TreasureJueshi, treasureCount)
    elif treasureType == TreasureType_GatherTheSoul:
        PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_TreasureGatherTheSoul, treasureCount)
    elif treasureType == TreasureType_Gubao:
        PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_TreasureGubao, treasureCount)
        
    PlayerActLunhuidian.AddLunhuidianValue(curPlayer, PlayerActLunhuidian.AwardType_Treasure, treasureType, treasureCount)
    
    # ¸øÎïÆ·
    mailItemList = []
    itemControl = ItemControler.PlayerItemControler(curPlayer)
    for gridNum, itemID, itemCount, isBind in treasureResult:
        itemObj = ItemControler.GetOutPutItemObj(itemID, itemCount, False, curPlayer=curPlayer)
        mailItemDict = ItemCommon.GetMailItemDict(itemObj)
        
        if int(gridNum) in notifyGridNumList:
            PlayerControl.WorldNotify(0, "HappyXB", [curPlayer.GetPlayerName(), itemID, itemObj.GetUserData(), itemCount])
            
        if mailItemList or not itemControl.PutInItem(packType, itemObj, event=[ChConfig.ItemGive_Treasure, False, {}]):
            mailItemList.append(mailItemDict)
            itemObj.Clear()
            
    if mailItemList:
        PlayerControl.SendMailByKey("HappyXBUnEnough", [playerID], mailItemList)
        
    GameWorld.DebugLog("Ñ°±¦³É¹¦: treasureType=%s,updTreasureCount=%s,updLuck=%s,addScoreType=%s,addScore=%s,gridNumCountInfo=%s" 
                       % (treasureType, updTreasureCount, updLuck, addScoreType, addScore, gridNumCountInfo), playerID)
    GameWorld.DebugLog("    treasureResult=%s" % (treasureResult), playerID)
    GameWorld.DebugLog("    mailItemList=%s" % (mailItemList), playerID)
    
    # Í¨ÖªÇ°¶Ë
    sendPack = ChPyNetSendPack.tagMCTreasureResult()
    sendPack.Clear()
    sendPack.AddMoneyType = addScoreType
    sendPack.AddMoneyValue = addScore
    sendPack.AddTreasureLuck = addLuck
    sendPack.TreasureResult = str(treasureResult)
    sendPack.TreasureResultLen = len(sendPack.TreasureResult)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    
    Sync_TreasureInfo(curPlayer, [treasureType])
    return
 
def GetRemoveLimitGridRateList(srcGridNumRateList, gridNumCountInfo, gridNumMaxLimitInfo):
    ## »ñÈ¡ÒƳýÏÞÖƲú³öµÄ¸ñ×ÓºóµÄ±ýͼÁбí
    # @param srcGridNumRateList: Ô­Ê¼¸ÅÂÊ [(¸ÅÂÊ, ¸ñ×Ó±àºÅ), ...]
    # @param gridNumCountInfo: ÓÐÏÞÖƲú³öÊýµÄ¸ñ×ÓÒѾ­²ú³öÊýÁ¿ÐÅÏ¢ {gridNum:count, ...}
    # @param gridNumMaxLimitInfo: ÓÐÏÞÖƲú³öÊýµÄ¸ñ×Ó×î´ó²ú³öÊýÁ¿ÐÅÏ¢ {"gridNum":countLimit, ...}
    newRateList = []
    if not gridNumMaxLimitInfo:
        return newRateList + srcGridNumRateList # ²»Ê¹ÓÃÔ­ÅäÖñýͼ£¬²»È»¿ÉÄܵ¼ÖÂÐ޸ĵôԭʼÅäÖñýͼµ¼ÖÂbug
    for i, rateInfo in enumerate(srcGridNumRateList):
        rate, gridNum = rateInfo
        if str(gridNum) in gridNumMaxLimitInfo:
            limitCount = gridNumMaxLimitInfo[str(gridNum)]
            if limitCount and gridNumCountInfo.get(gridNum, 0) >= limitCount:
                # ÒÑ´ïµ½ÏÞÖƲú³öÊý£¬²»ÔÙ²ú³ö
                continue
        srcRate = rate if i == 0 else (rate - srcGridNumRateList[i - 1][0]) # Ô­¸ÅÂÊ
        newRate = srcRate if not newRateList else (newRateList[-1][0] + srcRate)
        newRateList.append((newRate, gridNum))
    return newRateList
 
def GetUpdLuckyItemRateList(ipyData, luckyGridNumList, curLuck, luckFormula, costType):
    # »ñÈ¡ÐÒÔËÎïÆ·ÌáÉý¸ÅÂʺóµÄ±ýͼ
    treasureType = ipyData.GetTreasureType()
    srcPieList = ipyData.GetGridItemRateListFree() if costType == 1 else ipyData.GetGridItemRateList1()
    if not srcPieList:
        srcPieList = ipyData.GetGridItemRateList1()
        
    updRateList = []
    for i, rateInfo in enumerate(srcPieList):
        rate, gridNum = rateInfo
        baseRate = rate if i == 0 else (rate - srcPieList[i - 1][0]) # Ô­¸ÅÂÊ
        
        if gridNum in luckyGridNumList:
            newRate = eval(FormulaControl.GetCompileFormula("TreasureLuckyRate%s" % treasureType, luckFormula))
        else:
            newRate = baseRate
            
        specRate = newRate if not updRateList else (updRateList[-1][0] + newRate) # ÌáÉýºó¶ÔÓ¦±ýͼ¸ÅÂÊ
        updRateList.append((specRate, gridNum))
        
    return srcPieList, updRateList
 
def GetJobItem(job, itemID, jobItemList):
    ## »ñÈ¡±¦ÏäÎïÆ·½±Àø¶ÔÓ¦µÄÖ°ÒµÎïÆ·£¬ Ö°Òµ´Ó1¿ªÊ¼
    for jobItemIDList in jobItemList:
        if type(jobItemIDList) not in [list, tuple]:
            GameWorld.ErrLog("Ö°ÒµÎïÆ·×é¸ñʽ´íÎó!jobItemList=%s" % (jobItemList))
            return 0
        if itemID in jobItemIDList:
            if job <= 0 or job > len(jobItemIDList):
                GameWorld.ErrLog("Ö°ÒµÎïÆ·ÅäÖôíÎó,ûÓиÃÖ°Òµ¶ÔÓ¦ÎïÆ·ID!job=%s,itemID=%s" % (job, itemID))
                return 0
            return jobItemIDList[job - 1]
    return itemID
 
def GetTreasureCntAward(curPlayer, treasureType, needTreasureCnt):
    ## ÁìÈ¡Ñ°±¦ÀۼƴÎÊý½±Àø
    needTreasureCnt = GameWorld.ToIntDef(needTreasureCnt, 0)
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("TreasureCntAward", treasureType, needTreasureCnt)
    if not ipyData:
        return
    awardIndex = ipyData.GetAwardIndex()
    awardItemList = ipyData.GetAwardItemList()
    
    awardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCntAward % (treasureType))
    if awardState&pow(2, awardIndex):
        GameWorld.DebugLog("¸ÃÑ°±¦´ÎÊý½±ÀøÒÑÁì½±! treasureType=%s,needTreasureCnt=%s,awardIndex=%s" 
                           % (treasureType, needTreasureCnt, awardIndex), playerID)
        return
    
    treasureCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCount % (treasureType))
    if treasureCount < needTreasureCnt:
        GameWorld.DebugLog("¸ÃÑ°±¦´ÎÊý²»×㣬ÎÞ·¨Áì½±! treasureType=%s,treasureCount=%s < %s" 
                           % (treasureType, treasureCount, needTreasureCnt), playerID)
        return
    
    updState = awardState|pow(2, awardIndex)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCntAward % (treasureType), updState)
    GameWorld.DebugLog("ÁìÈ¡Ñ°±¦´ÎÊý½±Àø! treasureType=%s,needTreasureCnt=%s,awardIndex=%s,awardState=%s,updState=%s" 
                       % (treasureType, needTreasureCnt, awardIndex, awardState, updState), playerID)
    
    ItemControler.GivePlayerItemOrMail(curPlayer, awardItemList, event=["TreasureCntAward", False, {}])
    Sync_TreasureInfo(curPlayer, [treasureType])
    return
 
def Sync_TreasureInfo(curPlayer, syncTypeList=None):
    if syncTypeList == None:
        syncTypeList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetTreasureSetCount()):
            ipyData = ipyDataMgr.GetTreasureSetByIndex(i)
            syncTypeList.append(ipyData.GetTreasureType())
            
    treasureInfoPack = ChPyNetSendPack.tagMCTreasureInfo()
    treasureInfoPack.Clear()
    treasureInfoPack.TreasuerInfoList = []
    for tType in syncTypeList:
        setIpyData = IpyGameDataPY.GetIpyGameData("TreasureSet", tType)
        if not setIpyData:
            continue
        if setIpyData.GetIsActType():
            if not IsActTreasureType(curPlayer, tType):
                continue
        gridNumMaxLimitInfo = setIpyData.GetGridNumMaxLimitInfo()
        tTypeInfo = ChPyNetSendPack.tagMCTreasureTypeInfo()
        tTypeInfo.Clear()
        tTypeInfo.TreasureType = tType
        tTypeInfo.LuckValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureLuck % (tType))
        tTypeInfo.TreasureCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCount % (tType))
        tTypeInfo.FreeCountToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureFreeCount % (tType))
        tTypeInfo.TreasureCntAward = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCntAward % (tType))
        for gridNumStr in gridNumMaxLimitInfo.keys():
            gridNum = int(gridNumStr)
            gridLimit = ChPyNetSendPack.tagMCTreasureGridLimit()
            gridLimit.GridNum = gridNum
            gridLimit.GridCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureGridCnt % (tType, gridNum))
            tTypeInfo.GridLimitCntList.append(gridLimit)
        tTypeInfo.GridLimitCnt = len(tTypeInfo.GridLimitCntList)
        treasureInfoPack.TreasuerInfoList.append(tTypeInfo)
    treasureInfoPack.InfoCount = len(treasureInfoPack.TreasuerInfoList)
    NetPackCommon.SendFakePack(curPlayer, treasureInfoPack)
    return