hch
2 天以前 35d98e9c630fd4408561c8c54b4c09193bb9ce9e
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
#!/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 IPY_GameWorld
import IpyGameDataPY
import FormulaControl
import ChPyNetSendPack
import PlayerControl
import ItemControler
import NetPackCommon
import PlayerActLunhuidian
import PlayerActHeroAppear
import PlayerActivity
import PlayerSuccess
import PlayerGoldInvest
import OpenServerActivity
import PlayerBillboard
import ShareDefine
import ItemCommon
import PlayerHero
import PyGameData
import PlayerTask
import PlayerMail
import DBDataMgr
import ChPlayer
import ChConfig
 
import random
 
(
CostType_Money, # ÏûºÄ»õ±Ò 0
CostType_DayFree, # Ã¿ÈÕÃâ·Ñ 1
CostType_Item, # ÏûºÄµÀ¾ß 2
CostType_ADFree, # ¹ã¸æÃâ·Ñ 3
) = range(4)
CostFreeTypes = [CostType_DayFree, CostType_ADFree]
 
# Ñ°±¦ÀàÐÍ£º >=100µÄΪ²ß»®×ÔÐÐÅäÖõÄ×Ô¶¨ÒåѰ±¦ÀàÐÍ£¬<100µÄÓÃÓÚÖ¸¶¨ÏµÍ³Ñ°±¦¹¦ÄÜ
TreasureTypeList = (
TreasureType_Jipin, # ¼«Æ·Ñ°±¦ 1
TreasureType_Rune, # ·ûӡѰ±¦ 2
TreasureType_Jueshi, # ¾øÊÀѰ±¦ 3
TreasureType_GatherTheSoul, # ¾Û»êÁÔħ 4
TreasureType_Gubao, # ¹Å±¦Ñ°±¦ 5
) = range(1, 1 + 5)
 
#TreasureType_HeroComm = 11 # Ó¢ÐÛÕÐļ - ÆÕͨ
TreasureType_HeroHigh = 12 # Ó¢ÐÛÕÐļ - ¸ß¼¶
TreasureType_HeroScore = 13 # Ó¢ÐÛÕÐļ - »ý·Ö
#Î佫ÕÐļµÄËùÓÐÀàÐÍ
TreasureType_HeroCallList = [TreasureType_HeroHigh, TreasureType_HeroScore]
 
#»î¶¯Ñ°±¦ÀàÐÍ
ActType_HeroAppear = 1 # Î佫µÇ³¡
 
def OnTreasureLogin(curPlayer):
    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_TreasureCountToday % (treasureType)) and \
            not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureFreeCount % (treasureType)) and \
            not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCountTodayGold % (treasureType)):
            continue
        syncTypeList.append(treasureType)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountToday % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountTodayGold % (treasureType), 0)
        
        # Ã¿ÈÕÐÄÔ¸ÖØÖÃ
        wishLibSelect = ipyData.GetWishLibSelect()
        wishReset = ipyData.GetWishReset()
        if wishReset == 1 and wishLibSelect:
            for libIDStr in wishLibSelect.keys():
                libID = int(libIDStr)
                libItemList = IpyGameDataPY.GetIpyGameDataList("TreasureItemLib", libID)
                if not libItemList:
                    continue
                for libItem in libItemList:
                    wishID = libItem.GetID()
                    outCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishOut % (treasureType, wishID))
                    if not outCnt:
                        continue
                    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureWishOut % (treasureType, wishID), 0)
                    GameWorld.DebugLog("Ѱ±¦Ã¿ÈÕÐÄÔ¸ÖØÖÃ: treasureType=%s,libID=%s,wishID=%s,×òÈÕÐÄÔ¸²ú³ö´ÎÊý=%s" % (treasureType, libID, wishID, outCnt))
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureWishLibOut % (treasureType, libID), 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_TreasureCountEx % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountToday % (treasureType), 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountTodayGold % (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)
        
        houseList = IpyGameDataPY.GetIpyGameDataList("TreasureHouse", treasureType)
        if houseList:
            for hourseIpyData in houseList:
                for gridNum in hourseIpyData.GetAtLeastCntLimitInfo().items():
                    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureAtleastCnt % (treasureType, gridNum), 0)
                    
    Sync_TreasureInfo(curPlayer, treasureTypeList)
    return
 
def ResetLifeCardLucky(curPlayer):
    treasureTypeList = []
    for treasureType in TreasureType_HeroCallList:
        if treasureType in treasureTypeList:
            continue
        houseList = IpyGameDataPY.GetIpyGameDataList("TreasureHouse", treasureType)
        if not houseList:
            continue
        for hourseIpyData in houseList:
            if hourseIpyData.GetLuckyItemRateInfoEx():
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureLuck % (treasureType), 0)
                treasureTypeList.append(treasureType)
                GameWorld.DebugLog("¿ªÍ¨ÓÀ¾Ã¿¨ÖØÖÃÎ佫ÕÐļÓÀ¾Ã¿¨ÐÒÔËÖµ! treasureType=%s" % treasureType)
                break
    if not treasureTypeList:
        return
    Sync_TreasureInfo(curPlayer, treasureTypeList)
    return
 
def IsActTreasureType(curPlayer, treasureType, actType):
    ## ÊÇ·ñ»î¶¯ÖеÄѰ±¦ÀàÐÍ
    if actType == ActType_HeroAppear:
        return PlayerActHeroAppear.GetActNumByTreasureType(curPlayer, treasureType) > 0
    return False
 
#// A5 69 Ñ°±¦ÐÄÔ¸ÎïÆ·Ñ¡Ôñ #tagCSTreasureWishSelect
#
#struct tagCSTreasureWishSelect
#{
#    tagHead        Head;
#    BYTE        TreasureType;    //Ѱ±¦ÀàÐÍ
#    BYTE        WishCnt;
#    DWORD        WishIDList[WishCnt];    // Ñ¡ÔñµÄѰ±¦ÎïÆ·¿âÖеÄÊý¾ÝID£¬×¢Òâ²»ÊÇ¿âID
#    BYTE        WishCardUseCnt;
#    WORD        WishCardUseLibIDList[WishCardUseCnt];        // Ê¹ÓÃÐÄÔ¸¿¨µÄ¿âIDÁбí
#};
def OnTreasureWishSelect(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    treasureType = clientData.TreasureType
    reqSelectWishIDList = clientData.WishIDList
    wishCardUseLibIDList = clientData.WishCardUseLibIDList
    
    setIpyData = IpyGameDataPY.GetIpyGameData("TreasureSet", treasureType)
    if not setIpyData:
        return
    wishLibSelect = setIpyData.GetWishLibSelect()
    if not wishLibSelect:
        GameWorld.DebugLog("¸ÃѰ±¦ÀàÐÍûÓÐÐÄÔ¸ÎïÆ·¹¦ÄÜ! treasureType=%s" % (treasureType))
        return
    
    GameWorld.DebugLog("Ѱ±¦Ñ¡ÔñÐÄÔ¸ÎïÆ·: treasureType=%s,reqSelectWishIDList=%s" % (treasureType, reqSelectWishIDList))
    
    selectLibItemDict = {} # ÖØÐÂÑ¡ÔñµÄÐÄÔ¸ÎïÆ·»ã×Ü {libID:[wishID, ...], ...}
    for wishID in reqSelectWishIDList:
        if not wishID:
            continue
        libItemIpyData = IpyGameDataPY.GetIpyGameDataByCondition("TreasureItemLib", {"ID":wishID}, False)
        if not libItemIpyData:
            return
        
        itemID = libItemIpyData.GetItemID()
        if not libItemIpyData.GetIsWishItem():
            GameWorld.DebugLog("·ÇÐÄÔ¸ÎïÆ·£¬²»¿ÉÑ¡Ôñ! wishID=%s" % (wishID))
            return
        
        # °´ËùÊô¿â¹éÀà»ã×Ü
        libID = libItemIpyData.GetLibID()
        if libID not in selectLibItemDict:
            selectLibItemDict[libID] = []
        selectLibWishIDList = selectLibItemDict[libID]
        if wishID not in selectLibWishIDList:
            selectLibWishIDList.append(wishID)
            
        # Î佫ÕÐ¶îÍâÏÞÖÆ
        if treasureType in TreasureType_HeroCallList:
            heroIpyData = IpyGameDataPY.GetIpyGameData("Hero", itemID)
            if not heroIpyData:
                return
            if heroIpyData.GetRecruitBySelf() and not PlayerHero.GetHeroActivite(curPlayer, itemID):
                GameWorld.DebugLog("ÐèÒª¼¤»î±¾ÌåµÄÎ佫δ¼¤»î²»¿ÉÑ¡Ôñ£¡itemID=%s" % itemID)
                return
            
    # ¹«¹²´ÎÊýģʽ£¬²»ÏÞÖÆÇл»
    if setIpyData.GetWishLibPubFreeCnt():
        # ÎÞÏÞÖÆ£¬Ö±½Ó±£´æ
        pass
    
    # ¶ÀÁ¢´ÎÊýģʽ£¬Óвú³öºóµÄÐÄÔ¸ÎïÆ·ÎÞ·¨Çл»
    else: 
        GameWorld.DebugLog("ÖØÑ¡ÐÄÔ¸¿â¶ÔÓ¦ID»ã×Ü: %s" % selectLibItemDict)
        for libIDStr, wishCnt in wishLibSelect.items():
            libID = int(libIDStr)
            selectLibWishIDList = selectLibItemDict.get(libID, [])
            if selectLibWishIDList and len(selectLibWishIDList) != wishCnt:
                GameWorld.DebugLog("Ñ¡ÔñÐÄÔ¸¿âµÄÎïÆ·ÊýÁ¿ÓëÉ趨µÄÐÄÔ¸ÎïÆ·ÊýÁ¿²»Ò»Ö£¡libID=%s,wishCnt=%s,selectCnt=%s,%s" 
                                   % (libID, wishCnt, len(selectLibWishIDList), selectLibWishIDList))
                return
            
            libItemList = IpyGameDataPY.GetIpyGameDataList("TreasureItemLib", libID)
            if not libItemList:
                return
            for libItem in libItemList:
                wishID = libItem.GetID()
                outCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishOut % (treasureType, wishID))
                if not outCnt:
                    continue
                if wishID not in selectLibWishIDList:
                    GameWorld.DebugLogEx("ÒѾ­²ú³ö¹ýµÄÐÄÔ¸ÎïÆ·²»¿É´ÓÑ¡ÔñÖÐÈ¥³ý! outCnt=%s,wishID=%s not in %s", outCnt, wishID, selectLibWishIDList)
                    return
                
    # Ñé֤ͨ¹ý£¬±£´æ
    for libIDStr, wishCnt in wishLibSelect.items():
        libID = int(libIDStr)
        wishIDList = selectLibItemDict.get(libID, [])
        for wishIndex in range(wishCnt):
            wishID = wishIDList[wishIndex] if len(wishIDList) > wishIndex else 0
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureWishSelect % (treasureType, libIDStr, wishIndex), wishID)
            GameWorld.DebugLog("±£´æÐÄԸѡÔñ: libID=%s,wishIndex=%s,wishID=%s" % (libID, wishIndex, wishID))
            
        isUse = 1 if libID in wishCardUseLibIDList else 0
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureWishUseItem % (treasureType, libID), isUse)
        GameWorld.DebugLog("±£´æÐÄÔ¸¿¨ÊÇ·ñʹÓÃ: libID=%s,isUse=%s" % (libID, isUse))
        
    Sync_TreasureInfo(curPlayer, [treasureType])
    return
 
                
#// 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)
    treasureType = clientData.TreasureType
    treasureIndex = clientData.TreasureIndex
    costType = clientData.CostType
    DoTreasure(curPlayer, treasureType, costType, treasureIndex)
    return
 
def DoTreasure(curPlayer, treasureType, costType, treasureIndex=0):
    playerLV = curPlayer.GetLV()
    playerID = curPlayer.GetPlayerID()
    GameWorld.DebugLog("Íæ¼ÒѰ±¦: treasureType=%s,treasureIndex=%s,costType=%s,playerLV=%s" 
                       % (treasureType, treasureIndex, costType, playerLV), playerID)
    
    setIpyData = IpyGameDataPY.GetIpyGameData("TreasureSet", treasureType)
    if not setIpyData:
        return
    actType = setIpyData.GetActType()
    if actType:
        if not IsActTreasureType(curPlayer, treasureType, actType):
            GameWorld.ErrLog("¸ÃѰ±¦ÀàÐͷǻÖУ¬ÎÞ·¨Ñ°±¦! treasureType=%s,actType=%s" % (treasureType, actType), playerID)
            return
    treasureCountList = setIpyData.GetTreasureCountList() # Ñ°±¦»ñµÃ¸öÊýÁбí
    if not treasureCountList:
        GameWorld.DebugLog("ûÓÐѰ±¦´ÎÊýÁбíÅäÖÃ!", playerID)
        return
    if costType == CostType_ADFree:
        treasureIndex = 0
        GameWorld.DebugLog("¹ã¸æÑ°±¦Ç¿ÖÆÉèÖÃ: treasureIndex=%s" % treasureIndex, playerID)
    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
    dailyMaxCount = setIpyData.GetDailyMaxCount()
    curTreasureCountToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCountToday % (treasureType)) # ½ñÈÕÒÑѰ±¦´ÎÊý
    updTreasureCountToday = curTreasureCountToday + treasureCount
    if dailyMaxCount and updTreasureCountToday > dailyMaxCount:
        GameWorld.DebugLog("Ѱ±¦ºó½«³¬¹ýÿÈÕ×î´ó´ÎÊý£¬ÎÞ·¨Ñ°±¦! treasureCount(%s) + curTreasureCountToday(%s) = %s > %s" 
                           % (treasureCount, curTreasureCountToday, updTreasureCountToday, dailyMaxCount), playerID)
        return
    
    checkPackList = setIpyData.GetCheckPackList()
    for checkPackType in checkPackList:
        if not ItemCommon.CheckPackHasSpace(curPlayer, checkPackType, True):
            GameWorld.DebugLog("¶ÔӦѰ±¦±³°üûÓпոñ×Ó! checkPackType=%s" % checkPackType, playerID)
            return
        
    curTreasureCountTodayGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCountTodayGold % (treasureType)) # ½ñÈÕÔª±¦ÒÑѰ±¦´ÎÊý
    updTreasureCountTodayGold = curTreasureCountTodayGold
    
    # Ãâ·Ñ´ÎÊý
    if costType == CostType_DayFree:
        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
    # ¹ã¸æÃâ·Ñ
    elif costType == CostType_ADFree:
        pass
    # Ñ°±¦µÀ¾ß, Ä¿Ç°Ä¬ÈÏÏûºÄ1¸ö
    elif costType == CostType_Item:
        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:
        dailyMaxCountMoney = setIpyData.GetDailyMaxCountMoney()
        updTreasureCountTodayGold = curTreasureCountTodayGold + treasureCount
        if dailyMaxCountMoney and updTreasureCountTodayGold > dailyMaxCountMoney:
            GameWorld.DebugLog("Ѱ±¦ºó½«³¬¹ýÿÈÕ×î´óÏûºÄ»õ±Ò´ÎÊý£¬ÎÞ·¨Ñ°±¦! treasureCount(%s) + curTreasureCountTodayGold(%s) = %s > %s" 
                               % (treasureCount, curTreasureCountTodayGold, updTreasureCountTodayGold, dailyMaxCountMoney), playerID)
            return
        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
    
    setLuckyGridNum = setIpyData.GetLuckyGridNum() # ±êµÄ¸ñ×Ó
    atLeastCntLimitInfo = ipyData.GetAtLeastCntLimitInfo() # ÖÁÉÙÐèÒªÐÒÔ˲ú³ö¸ÅÂʱýͼ {"ÐÒÔËÖµ":[[¸ÅÂÊ, ¸ñ×Ó±àºÅ], ...], ...}
    atLeastCntLimitDict = {}
    for gridNum, needAtLeastCnt in atLeastCntLimitInfo.items():
        curAtLeastCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureAtleastCnt % (treasureType, gridNum))
        atLeastCntLimitDict[gridNum] = [curAtLeastCnt, needAtLeastCnt]
    GameWorld.DebugLog("atLeastCntLimitDict=%s" % (atLeastCntLimitDict), playerID)
    luckyItemRateInfo = ipyData.GetLuckyItemRateInfo() # ÐÒÔ˲ú³ö¸ÅÂʱýͼ {"ÐÒÔËÖµ":[[¸ÅÂÊ, ¸ñ×Ó±àºÅ], ...], ...}
    if treasureType in TreasureType_HeroCallList:
        if not PlayerGoldInvest.GetInvestState(curPlayer, ChConfig.InvestType_Life):
            luckyItemRateInfo = ipyData.GetLuckyItemRateInfoEx()
            GameWorld.DebugLog("ÖÕÉí¿¨Î´¿ªÍ¨£¬Î佫ÕÐļʹÓÃÄÚÖñ£µ×", playerID)
    luckyItemRateDict = {int(k):v for k, v in luckyItemRateInfo.items()}
    luckyValueList = sorted(luckyItemRateDict.keys())
    luckyGridNumList = [] # ÐÒÔ˸ñ×Ó±àºÅÁбí
    luckFormula = setIpyData.GetLuckyRateFormat() # ÐÒÔËÎïÆ·¸ÅÂʹ«Ê½
    addLuck = setIpyData.GetOnceLucky() # Ôö¼ÓÐÒÔËÖµ
    maxLuck = max(luckyValueList) if luckyValueList else 0 # ÂúÐÒÔËÖµ
    updLuck = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureLuck % (treasureType)) # µ±Ç°ÐÒÔËÖµ
    GameWorld.DebugLog("updLuck=%s,maxLuck=%s,setLuckyGridNum=%s,luckyItemRateDict=%s" % (updLuck, maxLuck, setLuckyGridNum, luckyItemRateDict), playerID)
    
    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)
    recordGridNumList = setIpyData.GetRecordGridNumList() # ÐèÒª¼Ç¼²ú³öµÄ¸ñ×Ó
    notifyGridNumList = setIpyData.GetNotifyGridNumList() # ¶îÍâÐèÒª¹ã²¥µÄ¸ñ×Ó£¬ÐÒÔ˱سö¡¢´ÎÊý±Ø³ö¿É²»ÅäÖÃ
    notifyKeyDict = setIpyData.GetNotifyKeyDict()
    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)
    
    treasureCountEx = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCountEx % (treasureType)) # µ±Ç°µÚx´Îµ¥³é¡¢x³é
    curIndexCount, maxIndexCount = 0, 0
    beSureCountByIndexDict = {}
    beSureCountByIndexList = ipyData.GetGridItemRateList4() # µÚx´Îx³é±Ø³ö£¬×î¶àÖ§³Ö¶¨ÖƵ½9´Î
    if beSureCountByIndexList and treasureIndex < len(beSureCountByIndexList):
        beSureCountByIndexDict = beSureCountByIndexList[treasureIndex]
        maxIndexCount = min(9, max(beSureCountByIndexDict))
        curIndexCount = GameWorld.GetDataByDigitPlace(treasureCountEx, treasureIndex) + 1
    beSureCountByIndexCfg = []
    if curIndexCount <= maxIndexCount and curIndexCount in beSureCountByIndexDict:
        beSureCountByIndexCfg = beSureCountByIndexDict[curIndexCount]
        
    gridItemInfoDict = ipyData.GetGridItemInfo() # ¸ñ×Ó¶ÔÓ¦ÎïÆ·ÐÅÏ¢ {"¸ñ×Ó±àºÅ":[ÎïÆ·ID, ÊýÁ¿], ...}
    gridLibInfoDict = ipyData.GetGridLibInfo() # ¸ñ×Ó±àºÅ¶ÔÓ¦¿âID {"±àºÅ":ÎïÆ·¿âID, ...}
    
    # ÐÄÔ¸É趨
    wishLibSelect = setIpyData.GetWishLibSelect() # {"ÐÄÔ¸¿â":¿ÉÑ¡ÔñÎïÆ·Êý, ...}
    wishPubFreeCntDict = setIpyData.GetWishLibPubFreeCnt() # ÐÄÔ¸¿â¹«¹²Ãâ·Ñ´ÎÊý {"ÐÄÔ¸¿â":Ãâ·Ñ´ÎÊý, ...}
    wishPubCardDict = setIpyData.GetWishLibCard() # ÐÄÔ¸¿â¹«¹²´ÎÊýÐÄÔ¸¿¨ {"ÐÄÔ¸¿â":ÐÄÔ¸¿¨ID, ...}
    
    # ÐÄÔ¸ÓÅÏȲú³öÏà¹Ø
    preOutWishDict = {} # ÐÄÔ¸ÎïÆ·Ô¤¼Æ²ú³öÊý{libID:Ô¤¼ÆÓÅÏȲú³öÊý, ...}
    retOutWishDict = {} # ÐÄÔ¸ÎïÆ·Êµ¼Ê²ú³öÊý{libID:{wishID:ʵ¼ÊÓÅÏȲú³öÊý, ...}, ...}
    selectWishIDDict = {} # ¿âµ±Ç°¶ÔӦѡÔñµÄÐÄÔ¸ÎïÆ· {libID:[wishID, ...], ...}
    
    # ¹«¹²ÐÄÔ¸
    canFreeOutWishLibDict = {} # ÐÄÔ¸ÎïÆ·¿â¹«¹²»¹¿ÉÃâ·Ñ²ú³öÊý {libID:»¹¿ÉÃâ·Ñ²ú³öÊý, ...}
    wishCardItemLibDict = {} # ¹«¹²ÐÄÔ¸´ÎÊýÐÄÔ¸¿¨±³°üÎïÆ· {libID:wishCardItem, ...}
    
    # ¶ÀÁ¢ÐÄÔ¸
    canFreeOutWishIDict = {} # ÐÄÔ¸ÎïÆ·¶ÀÁ¢»¹¿ÉÃâ·Ñ²ú³öÊý {wishID:»¹¿ÉÃâ·Ñ²ú³öÊý, ...}
    
    for libIDStr, selectCnt in wishLibSelect.items():
        libID = int(libIDStr)
        
        if wishPubFreeCntDict:
            outTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishLibOut % (treasureType, libID))
            freeCnt = wishPubFreeCntDict.get(libIDStr, 0)
            canFreeOutPub = freeCnt - outTotal
            if canFreeOutPub > 0:
                canFreeOutWishLibDict[libID] = canFreeOutPub
                
        for wishIndex in range(selectCnt):
            wishID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishSelect % (treasureType, libIDStr, wishIndex))
            if not wishID:
                continue
            libItemIpyData = IpyGameDataPY.GetIpyGameDataByCondition("TreasureItemLib", {"ID":wishID}, False)
            if not libItemIpyData:
                continue
            if not libItemIpyData.GetIsWishItem():
                # ·ÇÐÄÔ¸ÎïÆ·
                continue
            
            if libID not in selectWishIDDict:
                selectWishIDDict[libID] = []
            selectWishIDList = selectWishIDDict[libID]
            selectWishIDList.append(wishID)
            
            # ¹«¹²´ÎÊý
            if wishPubFreeCntDict:
                pass
            
            # ¶ÀÁ¢´ÎÊý
            else:
                outCntLimit = libItemIpyData.GetWishOutCnt()
                outCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishOut % (treasureType, wishID))
                canFreeOut = outCntLimit - outCnt
                if canFreeOut <= 0:
                    continue
                canFreeOutWishIDict[wishID] = canFreeOut
                
    if wishLibSelect:
        GameWorld.DebugLog("µ±Ç°ÐÄÔ¸¿âÑ¡ÔñµÄÐÄÔ¸IDÁбí: %s" % selectWishIDDict, playerID)
        GameWorld.DebugLog("»¹¿ÉÓÅÏȲú³öµÄÐÄÔ¸Ãâ·Ñ´ÎÊý:%s" % canFreeOutWishLibDict, playerID)
        
    # µ¥³é²ú³öÓÅÏȼ¶£º ÐÒÔËÎïÆ· > ±Ø³ö > ±£µ× > ÆÕͨ
    # Á¬³éûÓÐÓÅÏȼ¶ÏÞÖÆ£¬Ö»ÒªÂú×ãÌõ¼þ¼´¿É²ú³ö
    getGridResult = []
    for tIndex in range(treasureCount):
        updLuck = min(updLuck + addLuck, maxLuck)
        stageLuck, luckItemRateList = __getLuckyRateInfo(updLuck, luckyItemRateDict, luckyValueList)
        luckyGridNumList = []
        for _, gridNum in luckItemRateList:
            luckyGridNumList.append(gridNum)
            
        updTreasureCount += 1
        GameWorld.DebugLog("%s,ÀۼƴÎÊý=%s,ÐÒÔË=%s,½×¶ÎÐÒÔË=%s,ÐÒÔ˱ýͼ=%s" % (tIndex + 1, updTreasureCount, updLuck, stageLuck, luckItemRateList), 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)
        
        curRateList = [] # ¿ÉÄÜ»á¸Ä±ä±ýͼ£¬Ã¿´Î³é½±Ê¹ÓÃеıýͼ¶ÔÏ󣬲»Òª¸Ä±äÅäÖõıýͼ¸ÅÂÊ
        
        # µÚx´Îx³é±Ø³ö£¬ÓÅÏȼ¶×î¸ß£¬ÎÞÊÓÆäËû
        if not curRateList and beSureCountByIndexCfg:
            if tIndex == 0:
                curRateList = [[10000, beSureCountByIndexCfg[0]]]
            else:
                curRateList = beSureCountByIndexCfg[1]
            GameWorld.DebugLog("    ¡¾µÚx´Îx³é±Ø³ö¡¿: treasureIndex=%s,curIndexCount=%s,%s" 
                               % (treasureIndex, curIndexCount, curRateList), playerID)
            
        # ÂúÐÒÔ˱سö
        if not curRateList and stageLuck and updLuck >= stageLuck and luckItemRateList:
            curRateList = GetRemoveLimitGridRateList(luckItemRateList, gridNumCountInfo, gridNumMaxLimitInfo)
            GameWorld.DebugLog("    ¡¾ÂúÐÒÔ˱سö±ýͼ¡¿: %s" % curRateList, playerID)
            
        # ´ÎÊý±Ø³ö
        if not curRateList and updTreasureCount in beSureCountDict:
            besureGridRateList = beSureCountDict[updTreasureCount]
            curRateList = GetRemoveLimitGridRateList(besureGridRateList, gridNumCountInfo, gridNumMaxLimitInfo)
            GameWorld.DebugLog("    ¡¾µÚ%s´ÎÊý±Ø³ö±ýͼ¡¿: %s" % (updTreasureCount, curRateList), playerID)
            
        # Âú´ÎÊý±Ø³ö
        if not curRateList and ensureCount and updTreasureCount % ensureCount == 0 and ensureRateList:
            curRateList = GetRemoveLimitGridRateList(ensureRateList, gridNumCountInfo, gridNumMaxLimitInfo)
            GameWorld.DebugLog("    ¡¾Âú%s´ÎÊý±Ø³ö±ýͼ¡¿: %s" % (ensureCount, curRateList), playerID)
            
        isNormalRate = False
        doCount = 0
        while doCount <= 50: # ÏÞÖÆ×î´ó´ÎÊý
            doCount += 1
            if doCount > 1 or not curRateList: # ÖØÐÂËæ»úµÄĬÈÏʹÓ󣹿±ýͼ
                curRateList = commItemRateList
                GameWorld.DebugLog("    Ê¹Ó󣹿±ýͼ=%s" % curRateList, playerID)
                isNormalRate = True
                
            gridNum = GameWorld.GetResultByRandomList(curRateList)
            if gridNum in luckyGridNumList and gridNum in getGridResult:
                GameWorld.DebugLog("    ÐÒÔËÎïÆ·ÒѾ­³ö¹ý£¬²»ÔÙÖØ¸´²ú³öÖØÐÂËæ»ú£¡ gridNum=%s in %s" % (gridNum, getGridResult), playerID)
                continue
            
            # ³£¹æ¸ÅÂʵĶîÍâÂß¼­
            if isNormalRate:
                # ÑéÖ¤ÖÁÉÙËùÐè´ÎÊýÏÞÖÆ
                if gridNum in atLeastCntLimitDict:
                    curAtLeastCnt, needAtLeastCnt = atLeastCntLimitDict[gridNum]
                    if curAtLeastCnt < needAtLeastCnt:
                        GameWorld.DebugLog("    ¸Ã¸ñ×Óδ´ïµ½×îСѰ±¦´ÎÊý²»²ú³ö£¡ gridNum=%s,curAtLeastCnt=%s < %s" 
                                           % (gridNum, curAtLeastCnt, needAtLeastCnt), playerID)
                        continue
                    
            # ÐÄÔ¸¿âÎïÆ·£¬¼ì²éÐÄÔ¸Ô¤²ú³ö
            gridNumStr = str(gridNum)
            wishLibID = 0
            if wishLibSelect and gridNumStr in gridLibInfoDict and str(gridLibInfoDict[gridNumStr]) in wishLibSelect:
                wishLibID = gridLibInfoDict[gridNumStr]
                if wishPubFreeCntDict:
                    # ¹«¹²ÐÄԸĬÈϾù¿ÉÕý³£²ú³ö£¬Ö»ÊÇ´¦ÀíÊÇ·ñÓÅÏȲú³öÐÄÔ¸
                    __prePubWishOut(curPlayer, treasureType, gridNum, wishLibID, selectWishIDDict, 
                                    preOutWishDict, canFreeOutWishLibDict, wishPubCardDict, wishCardItemLibDict)
                #else:
                #    # ·Ç¹«¹²µÄÔݲ»Ö§³Ö£¬ºóÐøÓÐÐèÒªÔÙ´¦Àí
                #    return
                
            if not gridNum:
                continue
            
            getGridResult.append(gridNum)
            GameWorld.DebugLog("    ±¾´Î²ú³ö: gridNum=%s, %s, doCount=%s" % (gridNum, getGridResult, doCount), playerID)
            if gridNum in luckyGridNumList or updLuck >= maxLuck:
                if addLuck:
                    if gridNum == setLuckyGridNum or updLuck >= maxLuck:
                        updLuck = 0
                    else:
                        updLuck = stageLuck # Ö±½ÓÇл»µ½ÏÂÒ»½×¶ÎÐÒÔË
                else:
                    updLuck = 0
                    GameWorld.DebugLog("    ²»¼ÓÐÒÔËÊ±Ç¿ÖÆÖØÖÃÐÒÔËÖµ: gridNum=%s,updLuck=%s" % (gridNum, updLuck), playerID)
                GameWorld.DebugLog("    ¡¾²ú³öÐÒÔ˸ñ×Ó¡¿: gridNum=%s,updLuck=%s" % (gridNum, updLuck), playerID)
            if wishLibID:
                GameWorld.DebugLog("    ¡¾²ú³öµÄÊÇÐÄÔ¸¿âÎïÆ·¡¿: gridNum=%s,wishLibID=%s" % (gridNum, wishLibID), playerID)
                
            if gridNum in gridNumCountInfo:
                gridNumCountInfo[gridNum] = gridNumCountInfo[gridNum] + 1
                GameWorld.DebugLog("    ¡¾¸üвú³ö´ÎÊý¡¿: gridNum=%s, %s" % (gridNum, gridNumCountInfo), playerID)
                
            for gNum, atLeastInfo in atLeastCntLimitDict.items():
                curAtLeastCnt, needAtLeastCnt = atLeastInfo
                if gNum  == gridNum:
                    curAtLeastCnt = 0
                else:
                    curAtLeastCnt += 1
                atLeastCntLimitDict[gNum] = [curAtLeastCnt, needAtLeastCnt]
                GameWorld.DebugLog("        ¸üÐÂ×îÉÙËùÐè´ÎÊý½ø¶È: gridNum=%s,%s/%s" % (gNum, curAtLeastCnt, needAtLeastCnt), 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()
    jobItemList = ipyData.GetJobItemList()
    treasureResult = []
    randItemIDDict = IpyGameDataPY.GetFuncEvalCfg("TreasureSet", 2)
    
    for gridNum in getGridResult:
        gridNumStr = str(gridNum)
        if gridNumStr in gridItemInfoDict:
            itemID, itemCount = gridItemInfoDict[gridNumStr]
            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:
                    if not __checkItemCanTreasure(curPlayer, treasureType, randItemID, actType, gridNum):
                        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 gridNumStr in gridLibInfoDict:
            libID = gridLibInfoDict[gridNumStr]
            libItemList = IpyGameDataPY.GetIpyGameDataList("TreasureItemLib", libID)
            if not libItemList:
                return
            wishWeightList = [] # ÐÄÔ¸ÎïÆ·È¨ÖØ
            itemWeightList = []
            for libItem in libItemList:
                curID = libItem.GetID()
                itemWeight, itemID, itemCount = libItem.GetItemWeight(), libItem.GetItemID(), libItem.GetItemCount()
                if not itemWeight:
                    continue
                if not __checkItemCanTreasure(curPlayer, treasureType, itemID, actType, gridNum):
                    continue
                itemWeightList.append([itemWeight, [itemID, itemCount]])
                
                # ¹«¹²´ÎÊý
                if wishPubFreeCntDict:
                    selectWishIDList = selectWishIDDict.get(libID, [])
                    if curID not in selectWishIDList:
                        continue
                    preOutWishCnt = preOutWishDict.get(libID, 0)
                    if preOutWishCnt <= 0:
                        continue
                    preOutWishDict[libID] = preOutWishCnt - 1
                    wishWeightList.append([itemWeight, [itemID, itemCount, curID]])
                    
            if not itemWeightList:
                GameWorld.ErrLog("Ѱ±¦Ëæ»ú¸ñ×ÓûÓпÉËæ»úµÄÎïÆ·!treasureType=%s,treasureIndex=%s,gridNum=%s,libID=%s" 
                                 % (treasureType, treasureIndex, gridNum, libID), playerID)
                return
            # ÓÅÏȲú³öÑ¡ÔñµÄÐÄÔ¸ÎïÆ·
            if wishWeightList:
                itemID, itemCount, curID = GameWorld.GetResultByWeightList(wishWeightList)
                GameWorld.DebugLog("ÓÅÏȲú³öÐÄÔ¸ÎïÆ·: gridNum=%s,libID=%s,wishID=%s,itemID=%s" % (gridNum, libID, curID, itemID), playerID)
                if libID not in retOutWishDict:
                    retOutWishDict[libID] = {}
                retOutWishIDDict = retOutWishDict[libID]
                retOutWishIDDict[curID] = retOutWishIDDict.get(curID, 0) + 1 # ÀÛ¼Óʵ¼ÊÓÅÏȲú³ö
                
            else:
                itemID, itemCount = GameWorld.GetResultByWeightList(itemWeightList)
        else:
            GameWorld.ErrLog("Ѱ±¦¸ñ×Ó²»´æÔÚ!treasureType=%s,gridNum=%s" % (treasureType, gridNum), playerID)
            return
        
        isTrans = 0 # ÊÇ·ñת»¯
        treasureResult.append([gridNumStr, itemID, itemCount, isTrans])
        
    # ¿ÛÏûºÄ
    if costType == CostType_DayFree:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureFreeCount % (treasureType), updFreeCountToday)
        GameWorld.DebugLog("ÏûºÄÃâ·Ñ´ÎÊý£¬¸üнñÈÕÒÑʹÓÃÃâ·Ñ´ÎÊý: %s" % updFreeCountToday, playerID)
    elif costType == CostType_ADFree:
        GameWorld.DebugLog("¹ã¸æÑ°±¦Ãâ·Ñ", playerID)
    elif costType == CostType_Item:
        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_TreasureCountToday % (treasureType), updTreasureCountToday)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCount % (treasureType), updTreasureCount)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountTodayGold % (treasureType), updTreasureCountTodayGold)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureLuck % (treasureType), updLuck)
    for gridNum, atLeastInfo in atLeastCntLimitDict.items():
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureAtleastCnt % (treasureType, gridNum), atLeastInfo[0])
    for gridNum, updCount in gridNumCountInfo.items():
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureGridCnt % (treasureType, gridNum), updCount)
    if curIndexCount <= maxIndexCount:
        treasureCountEx = GameWorld.ChangeDataByDigitPlace(treasureCountEx, treasureIndex, curIndexCount)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureCountEx % (treasureType), treasureCountEx)
        GameWorld.DebugLog("¸üеÚx´Îx³é´ÎÊý: treasureIndex=%s,curIndexCount=%s,maxIndexCount=%s,treasureCountEx=%s" % (treasureIndex, curIndexCount, maxIndexCount, treasureCountEx), playerID)
    # ÐÄÔ¸²ú³ö´ÎÊý
    for libID, retOutWishIDDict in retOutWishDict.items():
        retOutTotal = 0
        for wishID, retOutCnt in retOutWishIDDict.items():
            retOutTotal += retOutCnt
            outCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishOut % (treasureType, wishID))
            updOutCnt = outCnt + retOutCnt
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureWishOut % (treasureType, wishID), updOutCnt)
            GameWorld.DebugLog("¸üÐÂÐÄÔ¸ÎïÆ·ÓÅÏȲú³ö´ÎÊý: libID=%s,wishID=%s,retOutCnt=%s,updOutCnt=%s" % (libID, wishID, retOutCnt, updOutCnt), playerID)
            
        outTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishLibOut % (treasureType, libID))
        updOutTotal = outTotal + retOutTotal
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TreasureWishLibOut % (treasureType, libID), updOutTotal)
        GameWorld.DebugLog("¸üÐÂÐÄÔ¸¿âÎïÆ·ÀÛ¼ÆÓÅÏȲú³ö´ÎÊý: libID=%s,retOutTotal=%s,updOutTotal=%s" % (libID, retOutTotal, updOutTotal), playerID)
        
        canFreeCnt = canFreeOutWishLibDict.get(libID, 0)
        costWishCardCnt = retOutTotal - canFreeCnt
        if costWishCardCnt > 0 and libID in wishCardItemLibDict:
            wishCardItem = wishCardItemLibDict[libID]
            cardItemID = wishCardItem.GetItemTypeID() if wishCardItem else 0
            costWishCardCnt = min(costWishCardCnt, ItemControler.GetItemCount(wishCardItem))
            GameWorld.DebugLog("¿Û³ýÐÄÔ¸¿¨¸öÊý: cardItemID=%s,costWishCardCnt=%s" % (cardItemID, costWishCardCnt), playerID)
            if wishCardItem:
                ItemCommon.DelItem(curPlayer, wishCardItem, costWishCardCnt)
                
    addScoreType = setIpyData.GetAwardMoneyType() # ¶îÍâ½±Àø»õ±ÒÀàÐÍ
    addScore = setIpyData.GetAwardMoneyValue() # µ¥´Î½±Àø»õ±ÒÊý
    awardItemInfo = setIpyData.GetAwardItemInfo() # µ¥´Î¶îÍâ½±ÀøµÀ¾ß£¬ÎïÆ·ID|¸öÊý
    if addScoreType and addScore:
        PlayerControl.GiveMoney(curPlayer, addScoreType, addScore * treasureCount)
        
    if treasureType in TreasureType_HeroCallList:
        PlayerTask.AddTaskValue(curPlayer, ChConfig.TaskType_HeroCall, treasureCount)
        PlayerActivity.AddDailyTaskValue(curPlayer, ChConfig.DailyTask_HeroCall, treasureCount)
        heroCallCnt = GetHeroCallCnt(curPlayer)
        OpenServerActivity.UpdOSA_HeroCallBillboard(curPlayer, heroCallCnt)
        PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_OSAHeroCall, heroCallCnt)
        
    PlayerActLunhuidian.AddLunhuidianValue(curPlayer, PlayerActLunhuidian.AwardType_Treasure, treasureType, treasureCount)
    
    if actType == ActType_HeroAppear:
        actNum = PlayerActHeroAppear.GetActNumByTreasureType(curPlayer, treasureType)
        if actNum:
            PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_ActHeroAppear, updTreasureCount, groupValue1=actNum)
            
    # ¸øÎïÆ·
    mailItemList = []
    itemControl = ItemControler.PlayerItemControler(curPlayer)
    for tResult in treasureResult:
        gridNumStr, itemID, itemCount = tResult[:3]
        gridNum = int(gridNumStr)
        PyGameData.g_transItemSign = 0
        itemObj = ItemControler.GetOutPutItemObj(itemID, itemCount, isBind, curPlayer=curPlayer)
        mailItemDict = ItemCommon.GetMailItemDict(itemObj)
        
        if gridNum in notifyGridNumList and notifyKeyDict:
            notifyKey = notifyKeyDict.get(gridNum, notifyKeyDict.get(0, ""))
            if itemObj.GetType() == ChConfig.Def_ItemType_Hero:
                if treasureType in TreasureType_HeroCallList and PlayerHero.GetHeroActivite(curPlayer, itemID):
                    notifyKey = ""
                    GameWorld.DebugLog("ÕÐļÎ佫·ÇÊ״λñµÃµÄ²»¹ã²¥ÁË! itemID=%s" % itemID, playerID)
                elif notifyKey:
                    heroIpyData = IpyGameDataPY.GetIpyGameData("Hero", itemID)
                    if heroIpyData:
                        heroQuality = heroIpyData.GetQuality()
                        PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), heroQuality, itemID])
            elif notifyKey:
                PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), itemID, itemObj.GetUserData(), itemCount])
            
        packType = ChConfig.GetItemPackType(itemObj)
        if mailItemList or not itemControl.PutInItem(packType, itemObj, event=[ChConfig.ItemGive_Treasure, False, {}]):
            mailItemList.append(mailItemDict)
            itemObj.Clear()
            
        # ¼ì²éÎïÆ·×ª»¯
        if PyGameData.g_transItemSign:
            tResult[3] = 1 # ÓÐת»¯ÎïÆ·Ê±ÉèÖÃת»¯±ê¼Ç
            
        # ¼Ç¼²ú³ö
        if gridNum in recordGridNumList:
            # ¿ÉÀ©Õ¹ÊÇ·ñ¿ç·þÀàÐ͵ÄѰ±¦£¬ÐèÒª´æ´¢µ½¿ç·þ·þÎñÆ÷
            maxCount = 50 # ×î¶à¼Ç¼ÌõÊý
            recTypeIDMgr = DBDataMgr.GetGameRecMgr().GetRecTypeIDMgr(ShareDefine.Def_GameRecType_Treasure, treasureType)
            recData = recTypeIDMgr.AddRecData(maxCount)
            recData.SetValue1(itemID)
            recData.SetValue2(itemCount)
            recData.SetValue3(playerID)
            recData.SetValue4(curPlayer.GetServerID())
            recData.GetUserDict().update({"Name":curPlayer.GetPlayerName()})
            ChPlayer.SyncGameRecInfo(curPlayer, [recData]) # Ö÷¶¯Í¬²½²îÒ죬ǰ¶Ëÿ´ÎµÇ¼Ê״οªÆô½çÃæÖ÷¶¯²éѯһ´Î£¬²¢¸ù¾ÝTimeÖµ×ÔÐÐÅÅÐò
            
    # ¶îÍâÔùËÍÎïÆ·
    addItemID, addItemCount = 0, 0
    if awardItemInfo and len(awardItemInfo) >= 2:
        addItemID, addItemCount = awardItemInfo[:2]
        addItemCount *= treasureCount
        itemObj = ItemControler.GetOutPutItemObj(addItemID, addItemCount, isBind, curPlayer=curPlayer)
        if itemObj:
            packType = ChConfig.GetItemPackType(itemObj)
            if mailItemList or not itemControl.PutInItem(packType, itemObj, event=[ChConfig.ItemGive_Treasure, False, {}]):
                mailItemList.append(ItemCommon.GetMailItemDict(itemObj))
                itemObj.Clear()
                
    if mailItemList:
        PlayerMail.SendMailByKey("", playerID, mailItemList)
        
    GameWorld.DebugLog("Ѱ±¦³É¹¦: treasureType=%s,updTreasureCount=%s(%s),updLuck=%s,addScoreType=%s,addScore=%s,gridNumCountInfo=%s,treasureCountEx=%s" 
                       % (treasureType, updTreasureCount, updTreasureCountToday, updLuck, addScoreType, addScore, gridNumCountInfo, treasureCountEx), playerID)
    GameWorld.DebugLog("    treasureResult=%s" % (treasureResult), playerID)
    GameWorld.DebugLog("    mailItemList=%s" % (mailItemList), playerID)
    
    # Í¨ÖªÇ°¶Ë
    sendPack = ChPyNetSendPack.tagMCTreasureResult()
    sendPack.Clear()
    sendPack.TreasureType = treasureType
    sendPack.TreasureIndex = treasureIndex
    sendPack.CostType = costType
    sendPack.AddMoneyType = addScoreType
    sendPack.AddMoneyValue = addScore
    sendPack.AddItemID = addItemID
    sendPack.AddItemCount = addItemCount
    sendPack.AddTreasureLuck = addLuck
    sendPack.TreasureResult = str(treasureResult)
    sendPack.TreasureResultLen = len(sendPack.TreasureResult)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    
    Sync_TreasureInfo(curPlayer, [treasureType])
    return
 
def __prePubWishOut(curPlayer, treasureType, gridNum, wishLibID, selectWishIDDict, preOutWishDict, 
                    canFreeOutWishLibDict, wishPubCardDict, wishCardItemLibDict):
    ## ¹«¹²ÐÄÔ¸²ú³öÔ¤´¦Àí
    
    playerID = curPlayer.GetPlayerID()
    selectWishIDList = selectWishIDDict.get(wishLibID, [])
    if not selectWishIDList:
        GameWorld.DebugLog("    ¹«¹²ÐÄԸδѡÔñÐÄÔ¸ÎïÆ·£¬×ßĬÈÏËæ»ú¹æÔò", playerID)
        return
    
    preOutTotal = preOutWishDict.get(wishLibID, 0)
    canFreeCnt = canFreeOutWishLibDict.get(wishLibID, 0)
    GameWorld.DebugLog("    ¹«¹²Ãâ·ÑÐÄÔ¸´ÎÊý£¡ gridNum=%s,wishLibID=%s,preOutTotal=%s,canFreeCnt=%s" 
                       % (gridNum, wishLibID, preOutTotal, canFreeCnt), playerID)
    
    if treasureType in TreasureType_HeroCallList and PlayerGoldInvest.GetInvestState(curPlayer, ChConfig.InvestType_Month):
        GameWorld.DebugLog("    Ô¿¨ÌØÈ¨ÐÄÔ¸Ãâ·Ñ")
    elif preOutTotal >= canFreeCnt:
        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishUseItem % (treasureType, wishLibID)):
            GameWorld.DebugLog("    Íæ¼ÒÐÄÔ¸¿¨Î´ÆôÓã¬×ßĬÈÏËæ»ú¹æÔò£¡ gridNum=%s,wishLibID=%s" % (gridNum, wishLibID), playerID)
            return
        
        wishCardID = wishPubCardDict.get(str(wishLibID), 0)
        if not wishCardID:
            GameWorld.DebugLog("    ¸Ã¿âûÓÐÐÄÔ¸¿¨ÅäÖã¬×ßĬÈÏËæ»ú¹æÔò£¡ gridNum=%s,wishLibID=%s" % (gridNum, wishLibID), playerID)
            return
        
        if wishLibID not in wishCardItemLibDict:
            wishCardItem = ItemCommon.FindItemInPackByItemID(curPlayer, wishCardID, IPY_GameWorld.rptItem)
            if not wishCardItem:
                GameWorld.DebugLog("    Íæ¼ÒûÓжÔÓ¦ÐÄÔ¸¿¨ÎïÆ·£¬×ßĬÈÏËæ»ú¹æÔò£¡ gridNum=%s,wishLibID=%s,wishCardID=%s" 
                                   % (gridNum, wishLibID, wishCardID), playerID)
                return
            wishCardItemLibDict[wishLibID] = wishCardItem
        wishCardItem = wishCardItemLibDict[wishLibID]
        cardItemCount = ItemControler.GetItemCount(wishCardItem)
        canOutTotal = canFreeCnt + cardItemCount
        if preOutTotal >= canOutTotal:
            GameWorld.DebugLog("    ÐÄÔ¸¿¨¸öÊýÔ¤²ú³öÒÑÏûºÄÍ꣬×ßĬÈÏËæ»ú¹æÔò£¡ gridNum=%s,wishLibID=%s,wishCardID=%s" 
                               % (gridNum, wishLibID, wishCardID), playerID)
            return
        GameWorld.DebugLog("    ÐÄÔ¸¿¨¸öÊý»¹¿É²ú³ö£¡ gridNum=%s,wishLibID=%s,wishCardID=%s,cardItemCount=%s" 
                                   % (gridNum, wishLibID, wishCardID, cardItemCount), playerID)
    else:
        GameWorld.DebugLog("        ¹«¹²ÐÄÔ¸»¹ÓÐÃâ·Ñ´ÎÊýÇ¿ÖÆÏûºÄ´ÎÊý", playerID)
        
    preOutWishDict[wishLibID] = preOutTotal + 1 
    return
 
def GetHeroCallCnt(curPlayer):
    ## »ñÈ¡Î佫ÕÐļ×Ü´ÎÊý
    callCount = 0
    for treasureType in TreasureType_HeroCallList:
        callCount += curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCount % (treasureType))
    return callCount
 
def __getLuckyRateInfo(curLuck, luckyItemRateDict, luckyValueList):
    if not luckyItemRateDict or not luckyValueList:
        return 0, []
    for luck in luckyValueList:
        if curLuck <= luck:
            return luck, luckyItemRateDict[luck]
    lastLuck = luckyValueList[-1]
    return lastLuck, luckyItemRateDict[lastLuck]
 
def __checkItemCanTreasure(curPlayer, treasureType, itemID, actType, gridNum):
    ## ¼ì²éÎïÆ·IDÊÇ·ñ¿ÉѰ±¦²ú³ö
    itemData = GameWorld.GetGameData().GetItemByTypeID(itemID)
    if not itemData:
        return
    
    playerID = curPlayer.GetPlayerID()
    itemType = itemData.GetType()
    heroID = 0
    if itemType == ChConfig.Def_ItemType_Hero:
        heroID = itemID
    elif itemType == ChConfig.Def_ItemType_HeroPiece:
        heroID = itemData.GetEffectByIndex(0).GetEffectValue(0)
        if not heroID:
            GameWorld.DebugLog("Î佫ËéÆ¬Ð§¹û1AֵδÅäÖöÔÓ¦µÄÎ佫ID£¡ itemID=%s" % itemID, playerID)
            return
    if heroID:
        heroIpyData = IpyGameDataPY.GetIpyGameData("Hero", heroID)
        if not heroIpyData:
            GameWorld.DebugLog("²»´æÔÚ¸ÃÎ佫²»²ú³ö£¡ itemID=%s,heroID=%s" % (itemID, heroID), playerID)
            return
        if heroIpyData.GetRecruitBySelf() and not PlayerHero.GetHeroActivite(curPlayer, heroID):
            GameWorld.DebugLog("Î佫δ¼¤»î²»²ú³ö£¡ itemID=%s,heroID=%s" % (itemID, heroID), playerID)
            return
        
        # Î佫µÇ³¡
        if actType == ActType_HeroAppear:
            if not PlayerActHeroAppear.IsActCanTreasureHero(curPlayer, treasureType, heroID, gridNum):
                return
            
    return True
 
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 in CostFreeTypes 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
        actType = setIpyData.GetActType()
        if actType:
            if not IsActTreasureType(curPlayer, tType, actType):
                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.TreasureCountToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCountToday % (tType))
        tTypeInfo.TreasureCountTodayGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureCountTodayGold % (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)
        
        tTypeInfo.WishLibList = []
        wishLibSelect = setIpyData.GetWishLibSelect()
        for libIDStr, wishCnt in wishLibSelect.items():
            libID = int(libIDStr)
            wishLib = ChPyNetSendPack.tagMCTreasureWishLib()
            wishLib.LibID = libID
            wishLib.OutCntTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishLibOut % (tType, libID))
            wishLib.IsUseWishCard = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishUseItem % (tType, libID))
            wishLib.WishList = []
            for wishIndex in range(wishCnt):
                wishID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishSelect % (tType, libID, wishIndex))
                wish = ChPyNetSendPack.tagMCTreasureWish()
                wish.WishID = wishID
                wish.OutCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TreasureWishOut % (tType, wishID))
                wishLib.WishList.append(wish)
            wishLib.WishCnt = len(wishLib.WishList)
            
            tTypeInfo.WishLibList.append(wishLib)
        tTypeInfo.WishLibCnt = len(tTypeInfo.WishLibList)
        
        treasureInfoPack.TreasuerInfoList.append(tTypeInfo)
    treasureInfoPack.InfoCount = len(treasureInfoPack.TreasuerInfoList)
    NetPackCommon.SendFakePack(curPlayer, treasureInfoPack)
    return