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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package PlayerGoldGift
#
# @todo: ¼ÇÂ¼Íæ¼ÒµÄ³äÖµºÀÀñ½±ÀøÐÅÏ¢£¬¶þ½øÖÆÎ»±êʾ£¬Ä¿Ç°ÓÃÁËÒ»¸ö×Öµä
# @author hxp
# @date 2013-10-16 17:00
#
# @version 3.0
# ¼òҪ˵Ã÷:
# ÏêϸÃèÊö: 
# @change: "2013-10-22 11:10" hxp Ð޸ĶÁÈ¡½±ÀøÎïÆ·±í·½Ê½
# @change: "2013-11-12 17:00" hxp Ôö¼ÓÊ׳佱ÀøÁìÈ¡Âß¼­
# @change: "2013-12-09 18:00" hxp Ôö¼ÓÁ콱ȫ·þ¹ã²¥mark
# @change: "2014-05-11 14:35" xcc Ôö¼ÓmarkÈç¹ûΪ¿Õ£¬¾Í²»Ìáʾ
# @change: "2014-06-06 20:30" hxp Á콱ȫ·þ¹ã²¥ÐÞ¸Ä
# @change: "2014-06-12 21:00" hxp Ôö¼ÓÌìÌìÊ׳ä
# @change: "2014-08-22 12:00" hxp È¥³ý¶àÓàÈ«·þ¹ã²¥
# @change: "2014-10-09 14:00" hxp Ê׳ä/ÌìÌìÊ׳乿ÔòÐ޸ģ¬ÌìÌìÊ׳äÒ»ÌìÖ»ÄÜÁìȡһ´Î
# @change: "2014-12-16 18:00" hxp ·¢ËͳäÖµºÀÀñ·¢ËÍÓʼþ
# @change: "2014-12-22 14:00" hxp Ôö¼Óµ¥ÈÕ³äÖµ¶àѡһÀñ°ü
# @change: "2015-02-06 10:30" hxp µ¥ÈÕ³äÖµ¶àѡһÀñ°üÖ§³ÖÅäÖÃÐÇÆÚ¼¸
# @change: "2015-02-11 18:30" hxp µ¥ÈÕ³äÖµ¶àѡһÀñ°ü¿ª·þǰ¼¸Ìì²»¿ªÆôµÄ½öÏÞÖÆÐÇÆÚ¼¸µÄ»î¶¯
# @change: "2015-04-23 12:00" hxp µ±ÈÕ³äÖµ¶àѡһÀñ°üÖ§³Ö¶à¸ö×êʯµµ½±Àø
# @change: "2015-04-28 16:00" hxp Ôö¼ÓÿÈÕ³äÖµÔª±¦Êý֪ͨ
# @change: "2015-05-21 14:30" hxp Ôö¼Óµ±ÈÕ³äÖµÎÞÏÞÁìÈ¡Àñ°ü
# @change: "2015-06-09 20:30" hxp ½±ÀøÃû³Æ¸ÄΪ¿Í»§¶ËÅäÖÃ
# @change: "2016-01-26 15:00" hxp PY±íÖ§³ÖÖØ¶Á
# @change: "2016-06-27 14:00" hxp Ê׳äÖ§³Ö¿ÉÅäÖöî¶È
#------------------------------------------------------------------------------ 
#"""Version = 2017-05-12 18:00"""
#------------------------------------------------------------------------------ 
import GameWorld
import IPY_GameWorld
import ReadChConfig
import ItemControler
import ChConfig
import ItemCommon
import PlayerControl
import ShareDefine
import DataRecordPack
import ChPyNetSendPack
import PlayerFamilyRedPacket
import NetPackCommon
import PyMapTable
import PlayerCoin
import IpyGameDataPY
import PlayerTJG
import ChEquip
 
import time
import FunctionNPCCommon
 
# ¶¨ÒåÅä±íÍâΧË÷Òý
(
Def_NotifyMark, # ÏµÍ³Ìáʾmark
Def_NeedSpace, # ËùÐè¸ñ×ÓÊý
Def_GiftInfo, # ½±Æ·ÐÅÏ¢
) = range(3)
 
# ¶¨Òå½±ÀøÎïÆ·ÐÅÏ¢Ë÷Òý
(
Def_InfoIndex_ItemType, # ÎïÆ·ÀàÐÍ 
Def_InfoIndex_ItemID, # ÎïÆ·id»ò¶¨ÖÆÎïÆ·Ë÷Òý
Def_InfoIndex_ItemCount, # ÎïÆ·¸öÊý
Def_InfoIndex_IsBind, # ÊÇ·ñ°ó¶¨
) = range(4)
 
 
# ¶¨ÒåÎïÆ·ÀàÐÍ
(
Def_ItemType_CommonItem, # Ò»°ãÎïÆ·
Def_ItemType_AppointItem, # ÌØÊâ¶¨ÖÆÎïÆ·
) = range(2)
 
## ÁìÈ¡Íæ¼Ò³äÖµºÀÀñ½±Àø
#  @param giftNum£ººÀÀñ±àºÅ£¬´Ó0¿ªÊ¼
#  @return None
def GetPlayerGoldGift(curPlayer, giftNum):
    
    # ¼ì²é¿É·ñÁìÈ¡
    if not __CheckCanGetGift(curPlayer, giftNum):
        GameWorld.DebugLog("return can not Get GoldGift!!!")
        return
    
    goldGiftInfo = ReadChConfig.GetEvalChConfig("GoldGiftInfo_%s" % giftNum)
    
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    needSpace = goldGiftInfo[Def_NeedSpace]
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    # ¸øÎïÆ·
    if not __GiveGoldGift(curPlayer, goldGiftInfo[Def_GiftInfo]):
        return
    
    # È«·þÌáʾ
    notifyMark = goldGiftInfo[Def_NotifyMark]
    #Èç¹ûÓÐÏûÏ¢Ìáʾ
    if notifyMark.strip() != "":
        PlayerControl.WorldNotify(0, notifyMark, [curPlayer.GetPlayerName()])
    vipLV = curPlayer.GetVIPLv()
    msgParamList = [vipLV, curPlayer.GetPlayerName(), giftNum + 1]
    PlayerControl.WorldNotify(0, "GeRen_liubo_927007", msgParamList)
        
    # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç
    __UpdateLVAwardGetRecord(curPlayer, giftNum)
    
    # ¼Ç¼Áìȡʼþ
    DataRecordPack.DR_GoldGiftGiveItem(curPlayer, giftNum)
    
    # Í¨Öª¿Í»§¶Ë
    Sync_GoldGiftGetRecordInfo(curPlayer)
    return
 
 
## Í¨Öª³äÖµºÀÀñÁìÈ¡¼Ç¼ÐÅÏ¢
#  @param None
#  @return None
def Sync_GoldGiftGetRecordInfo(curPlayer):
    #getRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GoldGiftGetRecord, 0,
    #                                          ChConfig.Def_PDictType_GoldGift)
    #ChPlayer.Sync_RewardGetRecordInfo(curPlayer, ShareDefine.Def_RewardType_GoldGift, getRecord)
    return
 
 
## ¸øÍæ¼Ò³äÖµºÀÀñ½±ÀøÎïÆ·
#  @param curPlayer£ºÍæ¼ÒʵÀý
#  @param goldGiftInfoDict£º³äÖµºÀÀñÎïÆ·ÅäÖÃ×Öµä
#  @return None
def __GiveGoldGift(curPlayer, goldGiftInfoDict):
 
    goldGiftInfoList = __GetGoldGiftInfoList(curPlayer, goldGiftInfoDict)
    
    # Èç¹ûÕÒ²»µ½¶ÔÓ¦µÄ½±ÀøÐÅÏ¢£¬Ôò·µ»ØFalse
    if not goldGiftInfoList:
        return False
    
    # ¸øÎïÆ·
    for giftInfo in goldGiftInfoList:
        itemType = giftInfo[Def_InfoIndex_ItemType]
        itemCount = giftInfo[Def_InfoIndex_ItemCount]
        itemID = giftInfo[Def_InfoIndex_ItemID]
        isBind = 0
        if len(giftInfo) > Def_InfoIndex_IsBind:
            isBind = giftInfo[Def_InfoIndex_IsBind]
 
        if itemCount <= 0:
            continue
        
        # Ò»°ãÎïÆ·
        if itemType == Def_ItemType_CommonItem:
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isBind, [IPY_GameWorld.rptItem], True, showSysInfo=True)
        
        # ÌØÊâ¶¨ÖÆÎïÆ·
        elif itemType == Def_ItemType_AppointItem:
            itemData = PyMapTable.GetPyMapTable("AppointItemList").GetRecord("ItemIndex", str(itemID))
            GameWorld.DebugLog("__GiveGoldGift itemData=%s" % itemData)
            if not itemData:
                GameWorld.ErrLog("__GiveGoldGift()itemType=%s,ItemIndex=%s not data" % (itemType, itemID))
                continue
            
            if len(itemData) != 1:
                GameWorld.ErrLog("__GiveGoldGift()itemType=%s,ItemIndex=%s,recordCount=%s !=1 error" % \
                                                        (itemType, itemID, len(itemData)))
                continue
            
            itemDictData = itemData[0]
            itemDictData['IsBind'] = str(isBind)
            ItemControler.GivePlayerEquip(curPlayer, itemDictData, True, showSysInfo=True)
 
    return True
 
 
## ¸øÍæ¼Ò³äÖµºÀÀñ½±ÀøÎïÆ·ÐÅÏ¢Áбí
#  @param curPlayer£ºÍæ¼ÒʵÀý
#  @param awardItemInfoDict£º½±ÀøÎïÆ·ÅäÖÃ×Öµä
#  @return None
def __GetGoldGiftInfoList(curPlayer, goldGiftInfoDict):
    infoKey = () # Ä¬ÈÏkey
    job = curPlayer.GetJob()
    for key in goldGiftInfoDict.keys():
        # Èç¹ûÍæ¼ÒÖ°ÒµÔÚÅäÖõÄkeyÀÔòȡָ¶¨µÄkeyÐÅÏ¢
        if job in key:
            infoKey = key
            break
        
    return goldGiftInfoDict[infoKey]
 
 
## ¸üÐÂÁìÈ¡¼Ç¼
#  @param giftNum£ººÀÀñ±àºÅ£¬´Ó0¿ªÊ¼
#  @return None
def __UpdateLVAwardGetRecord(curPlayer, giftNum):
    
    curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GoldGiftGetRecord, 0,
                                              ChConfig.Def_PDictType_GoldGift)
    
    curValue = curValue|(1 << giftNum)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GoldGiftGetRecord, curValue,
                                   ChConfig.Def_PDictType_GoldGift)
    return
 
## ¼ì²é¿É·ñÁìÈ¡
#  @param giftNum£ººÀÀñ±àºÅ
#  @return True-¿ÉÁìÈ¡
def __CheckCanGetGift(curPlayer, giftNum):
    
    needGoldCntList = ReadChConfig.GetEvalChConfig("NeedGoldCntList")
    
    # ·Ç·¨Ë÷Òý
    if giftNum < 0 or giftNum >= len(needGoldCntList):
        GameWorld.ErrLog("__CheckCanGetGift() error£ºnot giftNum=%s" % (giftNum))
        return False
    
    # ÅжÏÒѳåÔª±¦ÊýÊÇ·ñÂú×ã
    curChangeCoin = curPlayer.GetChangeCoinPointTotal()
    curChangeGold = PlayerCoin.GetCoinRate() * curChangeCoin
    if curChangeGold < needGoldCntList[giftNum]:
        GameWorld.DebugLog("__CheckCanGetGift() curChangeGold not enough " + \
                                       "giftNum=%s,needGold=%s,changeGold=%s" % \
                                       (giftNum, needGoldCntList[giftNum], curChangeGold))
        return False
    
    # ÅжÏÊÇ·ñÒÑÁìÈ¡
    curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GoldGiftGetRecord, 0,
                                              ChConfig.Def_PDictType_GoldGift)
    return not (curValue & pow(2, giftNum))
 
 
##------------------------------------------------------------------------------
def DoFirstGoldOpen(curPlayer):
    ## Ê׳俪Æô  ¼Ç¼ÌáʾʣÓàʱ¼ä
    if curPlayer.GetChangeCoinPointTotal():
        return
    showSysTime = IpyGameDataPY.GetFuncCfg("FirstGold", 3)
    if not showSysTime:
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldRemainTime, showSysTime)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldTipStartTime, int(time.time()))
    
    Sync_FirstGoldTime(curPlayer)
    return
 
def UpdateFirstGoldTime(curPlayer):
    #¸üÐÂÊ׳äÌáʾʣÓàʱ¼ä
    if PlayerTJG.GetIsTJG(curPlayer):
        return
    remainTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstGoldRemainTime)
    if not remainTime:
        return
    if curPlayer.GetChangeCoinPointTotal():
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldRemainTime, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldTipStartTime, 0)
    else:
        curTime = int(time.time())
        startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstGoldTipStartTime)
        remainTime = max(0, remainTime - (curTime - startTime))
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldRemainTime, remainTime)
        if not remainTime:
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldTipStartTime, 0)
    return
 
def Sync_FirstGoldTime(curPlayer):
    ##֪ͨÊ׳äÌáʾʣÓàʱ¼ä
    showSysTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstGoldRemainTime)
    if not showSysTime:
        return
    sendPack = ChPyNetSendPack.tagMCFirstGoldTime()
    sendPack.Clear()
    sendPack.FirstGoldRemainTime = showSysTime
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
 
def GetPlayerGoldGiftFirst(curPlayer):
    '''ÁìÈ¡Íæ¼ÒÊ׳佱Àø
    '''
    
    isGet = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GoldGiftFirstRecord)
    if isGet:
        GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ýÊ׳佱Àø£¡", curPlayer.GetPlayerID())
        return
    
    if not curPlayer.GetChangeCoinPointTotal():
        GameWorld.DebugLog("ûÓгäÖµ¹ý£¬ÎÞ·¨ÁìÈ¡Ê׳佱Àø!", curPlayer.GetPlayerID())
        return
    
    firstGoldRewardDict = IpyGameDataPY.GetFuncEvalCfg("FirstGold", 1)
    jobStr = str(curPlayer.GetJob())
    if jobStr not in firstGoldRewardDict:
        GameWorld.ErrLog("ûÓÐÅäÖøÃÖ°Òµ¶ÔÓ¦µÄÊ׳佱Àø!job=%s" % jobStr, curPlayer.GetPlayerID())
        return
    rewardItemList = firstGoldRewardDict[jobStr]
    if not rewardItemList:
        return
    needSpace = len(rewardItemList)
    
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GoldGiftFirstRecord, 1)
    
    # ¸øÎïÆ·
    for itemID, itemCount, isBind in rewardItemList:        
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isBind, [IPY_GameWorld.rptItem])
        
    # È«·þÌáʾ
    if len(rewardItemList) >= 2:
        PlayerControl.WorldNotify(0, "FirstPayReward1", [curPlayer.GetPlayerName(), rewardItemList[0][0], rewardItemList[1][0]])
    # ¼Ç¼Áìȡʼþ
    DataRecordPack.DR_GoldGiftGiveItem(curPlayer, "FirstGoldGift")
    
    # Í¨Öª¿Í»§¶Ë
    Sync_FirstGoldInfo(curPlayer)
    return
 
###################################################################
 
## ³äÖµºÀÀñOnDay
#  @param curPlayer: Íæ¼Ò
#  @return: None
def OnDay(curPlayer):
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyChargeState, 0)
    
    #===============================================================================================
    # curChangeCoin = curPlayer.GetChangeCoinPointTotal()
    # # ½ñÌì֮ǰÓгäÖµ¹ý²ÅÐèÒª´¦ÀíÌìÌìÊ׳ä
    # if curChangeCoin > 0:
    #    # ÌìÌìÊ׳ä״̬¿ªÆô
    #    dailyGoldState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargeState, 0)
    #    if not dailyGoldState:
    #        UpdateDailyGoldState(curPlayer, 1)
    #    
    #    # ÌìÌìÊ׳äÁ콱״̬ 0-²»¿ÉÁ죻1-¿ÉÁ죻2-ÒÑÁì
    #    dailyGoldRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargePrizeRecord, 0)
    #    if dailyGoldRecord != 1:
    #        UpdateDailyGoldRecord(curPlayer, 0)
    #===============================================================================================
            
    # ÖØÖýñÈÕÒѳäÖµÊý, ÁìÈ¡Àñ°üË÷Òý
    #PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyGoldChargeCnt, 0)
    #PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleGoldGiftIndex, 0)
    #PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_UnlimitedGoldGiftCnt, 0)
    # Í¨Öªµ¥ÈÕ³äÖµ¶àѡһÀñ°üÐÅÏ¢
    #Sync_SingleGoldGiftInfo(curPlayer, True)
    #Sync_UnlimitedGoldGiftRecord(curPlayer)
    return
 
## ³äÖµºÀÀñOnLogin
#  @param curPlayer: Íæ¼Ò
#  @return: None
def OnLogin(curPlayer):
    Sync_FirstGoldInfo(curPlayer)
    
    Sync_FirstGoldTime(curPlayer)
    #¸üÐÂÊ׳äÌáʾ¿ªÊ¼¼ÆÊ±Ê±¼ä
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstGoldRemainTime):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldTipStartTime, int(time.time()))
    return
 
## Íæ¼Ò³äÖµÔª±¦
#  @param curPlayer: Íæ¼Ò
#  @param addGold: ³äÔª±¦Êý
#  @return: None
def OnPlayerChargeGold(curPlayer, addGold):
    
    # ¸üнñÈÕÒѳäÖµÊý
    dailyGoldCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargeCnt)
    updDailyGoldCnt = dailyGoldCnt + addGold
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyGoldChargeCnt, updDailyGoldCnt)
    #PlayerControl.NotifyPlayerDictValue(curPlayer, ChConfig.Def_PDict_DailyGoldChargeCnt)
    
    # ÌìÌìÊ׳äÒÑ¿ªÆô²Å´¦Àí
    dailyGoldState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargeState, 0)
    if dailyGoldState:
        # ÌìÌìÊ׳äÁ콱״̬ 0-²»¿ÉÁ죻1-¿ÉÁ죻2-ÒÑÁì
        dailyGoldRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargePrizeRecord, 0)
        # ²»¿ÉÁìµÄʱºò²ÅÖÃΪ¿ÉÁì
        if dailyGoldRecord == 0:
            UpdateDailyGoldRecord(curPlayer, 1)
    
    # ³äÖµ´ïµ½¶î¶¨Ôª±¦»ñµÃ½±Àø£¬Óʼþ·¢ËÍ
    __GiveGoldGiftByMail(curPlayer)
    
    # Í¨Öªµ¥ÈÕ³äÖµ¶àѡһÀñ°üÐÅÏ¢
    Sync_SingleGoldGiftInfo(curPlayer, True)
    return
 
## µ¥ÈÕ³äÖµÈÎѡһ½±Àø
#  @param curPlayer: Íæ¼Ò
#  @param giftIndex: Àñ°üË÷Òý
#  @param giftLV: Àñ°üµµ´Î
#  @return: None
def GetSingleGoldGift(curPlayer, giftIndex, giftLV, giftType):
    
    findSingleGoldGift = GetTodaySingleGoldGiftInfo()
    
    GameWorld.DebugLog("µ±ÈÕ³äÖµ½±ÀøÁì½± (µµ%s - %s) giftType=%s,findSingleGoldGift=%s" 
                       % (giftLV, giftIndex, giftType, str(findSingleGoldGift)))
    
    if not findSingleGoldGift:
        GameWorld.DebugLog("    ½ñÈÕδÅäÖóäÖµµ¥Ñ¡Àñ°ü!")
        return
 
    todayGiftType = findSingleGoldGift[2]
    if giftType != todayGiftType:
        GameWorld.DebugLog("    ·Çµ±ÈÕ³äÖµÀñ°üÀàÐÍ£¡todayGiftType=%s" % todayGiftType)
        return
    
    goldGiftInfoList = findSingleGoldGift[3]
    
    # ÎÞÏÞÁìÈ¡Àñ°üÀàÐÍ
    if giftType == 1:
        __GetUnlimitedGoldGift(curPlayer, goldGiftInfoList)
        return
    
    if giftIndex <= 0:
        return
    
    if giftLV >= len(goldGiftInfoList):
        GameWorld.ErrLog("µ¥ÈÕ³äÖµµ¥Ñ¡Àñ°üÅäÖôíÎóSingleGoldGift.txt ²»´æÔڸý±Àøµµ!giftLV=%s" % giftLV)
        return
    
    curGoldGiftInfo = goldGiftInfoList[giftLV]
    needGold, chooseGiftList = curGoldGiftInfo
    
    dailyGoldCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargeCnt)
    
    if dailyGoldCnt < needGold:
        GameWorld.DebugLog("    ½ñÈÕ³äÖµ¶î¶ÈδÂú×㣬ÎÞ·¨Áì½±!needGold=%s,dailyGoldCnt=%s" 
                           % (needGold, dailyGoldCnt))
        return
    
    goldGiftAwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleGoldGiftIndex)
    singleGoldGiftIndex = GameWorld.GetDataByDigitPlace(goldGiftAwardRecord, giftLV)
    if singleGoldGiftIndex > 0:
        GameWorld.DebugLog("    ½ñÈÕÒÑÁìÈ¡!singleGoldGiftIndex=%s" % (singleGoldGiftIndex))
        return
    
    if giftIndex > len(chooseGiftList):
        GameWorld.ErrLog("µ¥ÈÕ³äÖµµ¥Ñ¡Àñ°üÅäÖôíÎóSingleGoldGift.txt giftIndex=%s ²»ÔÚ½±ÀøÁбíÀï!" % giftIndex)
        return
    
    hasSpace = ItemCommon.CheckPackHasSpace(curPlayer, IPY_GameWorld.rptItem)
    if not hasSpace:
        GameWorld.DebugLog("    ±³°üÒÑÂú£¡")
        return
    
    # ¸üÐÂÁì½±Ë÷Òý
    updGoldGiftRecord = GameWorld.ChangeDataByDigitPlace(goldGiftAwardRecord, giftLV, giftIndex)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_SingleGoldGiftIndex, updGoldGiftRecord)
    
    itemID, itemCount, isBind = chooseGiftList[giftIndex - 1]
    isOK = ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isBind, [IPY_GameWorld.rptItem], True)
    if not isOK:
        return
 
    # Á÷Ïò
    infoDict = {"SingleGiftIndex":giftIndex, "ItemID":itemID, "ItemCount":itemCount, "IsBind":isBind,
                "SingleGiftLV":giftLV, "GoldGiftAwardRecord":updGoldGiftRecord}
    DataRecordPack.DR_GoldGiftGiveItem(curPlayer, "SingleGoldGift", infoDict)
    
    # Í¬²½¿Í»§¶Ë״̬
    Sync_SingleGoldGiftInfo(curPlayer)
    GameWorld.DebugLog("    awardRecord=%s,updRecord=%s,infoDict=%s" % (goldGiftAwardRecord, updGoldGiftRecord, infoDict))
    return
 
def __GetUnlimitedGoldGift(curPlayer, goldGiftInfoList):
    
    dailyGoldCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargeCnt)
    
    # ÒÑÁìÈ¡´ÎÊý
    hadGetCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_UnlimitedGoldGiftCnt)
    
    maxGetCnt = goldGiftInfoList[0] # ×î´óÖØ¸´ÁìÈ¡´ÎÊý
    perNeedGold = goldGiftInfoList[1] # Ã¿´ÎÁìÈ¡ÐèÒª³äÖµ×êʯÊý
    curCanGetCnt = dailyGoldCnt / perNeedGold # µ±Ç°¿ÉÁìÈ¡µÄ×î´ó´ÎÊý
    if maxGetCnt > 0:
        curCanGetCnt = min(curCanGetCnt, maxGetCnt)
    
    GameWorld.DebugLog("ÁìÈ¡µ±ÈÕ³äÖµÎÞÏÞÁìÈ¡Àñ°ü£ºdailyGoldCnt=%s / per(%s) = canCnt(%s),hadGetCnt=%s,MaxCntCfg=%s" 
                       % (dailyGoldCnt, perNeedGold, curCanGetCnt, hadGetCnt, maxGetCnt))
    
    if curCanGetCnt <= 0:
        GameWorld.DebugLog("    ¿ÉÁìÈ¡´ÎÊý=%s,²»¿ÉÁìÈ¡!" % curCanGetCnt)
        return
    
    if hadGetCnt >= curCanGetCnt:
        GameWorld.DebugLog("    ÒÑ´ïµ½×î´óÁìÈ¡´ÎÊý!%s" % curCanGetCnt)
        return
    
    getCnt = curCanGetCnt - hadGetCnt
    
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    needSpace = goldGiftInfoList[2]
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
 
    # ¸øÎïÆ·
    curGetCnt = getCnt
    awardItemList = goldGiftInfoList[3]
    for itemID, itemCnt, isBind in awardItemList:
        gameData = GameWorld.GetGameData()
        curItemData = gameData.GetItemByTypeID(itemID)
        if curItemData == None:
            GameWorld.ErrLog("ÁìÈ¡µ±ÈÕ³äÖµÎÞÏÞÁìÈ¡Àñ°ü£¬ÎïÆ·IDÊý¾Ý´íÎó£¡(%s)" % itemID, curPlayer.GetPlayerID())
            return
        
        maxPackCount = curItemData.GetPackCount()
        perSpaceCanGetCnt = maxPackCount / itemCnt # µ¥¸ö¿Õλ×î´ó¿ÉÁìÈ¡´ÎÊý
        curGetCnt = min(perSpaceCanGetCnt, curGetCnt)
        #GameWorld.DebugLog("    itemID=%s,maxPackCount=%s,giveCnt=%s,perSpaceCanGetCnt=%s,curGetCnt=%s" 
        #                   % (itemID, maxPackCount, itemCnt, perSpaceCanGetCnt, curGetCnt))
    
    # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç
    updGetCnt = hadGetCnt + curGetCnt
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_UnlimitedGoldGiftCnt, updGetCnt)
 
    # ¸øÎïÆ·
    awardItemList = goldGiftInfoList[3]
    isOKStr = ""
    for itemID, itemCnt, isBind in awardItemList:
        isOK = ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt * curGetCnt, isBind, 
                                            [IPY_GameWorld.rptItem, IPY_GameWorld.rptAnyWhere], True)
        
        isOKStr = "%s%s" % (str(int(isOK)), isOKStr)
    
    # ¼Ç¼Áìȡʼþ
    addDataDict = {"isOKStr":isOKStr, "awardItemList":str(awardItemList), "DailyGoldCnt":dailyGoldCnt,
                   "TodayGetCnt":updGetCnt, "CurGetCnt":curGetCnt}
    DataRecordPack.DR_FuncGiveItem(curPlayer, "UnlimitedGoldGift", addDataDict)
    
    # Í¨Öª¿Í»§¶Ë
    Sync_UnlimitedGoldGiftRecord(curPlayer)
    GameWorld.DebugLog("    ÁìÈ¡³äÖµÎÞÏÞÁìÈ¡Àñ°ü½±ÀøOK£¡TodayGetCnt=%s,CurGetCnt=%s" % (updGetCnt, curGetCnt))
    return
 
 
## Í¨ÖªÎÞÏÞÁìÈ¡Àñ°üÒÑÁìÈ¡´ÎÊý
#  @param None
#  @return None
def Sync_UnlimitedGoldGiftRecord(curPlayer):
    #record = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_UnlimitedGoldGiftCnt)
    #ChPlayer.Sync_RewardGetRecordInfo(curPlayer, ShareDefine.Def_RewardType_UnlimitedGoldGift, record)
    return
 
 
## Íæ¼ÒÀۼƳäÖµÔª±¦·¢ËÍÓʼþ½±Àø
#  @param curPlayer: Íæ¼Ò
#  @return: None
def __GiveGoldGiftByMail(curPlayer):
    coinPointTotal = curPlayer.GetChangeCoinPointTotal()
    goldTotal = PlayerCoin.GetCoinRate() * coinPointTotal
    GameWorld.DebugLog("Óʼþ·¢ËͳäÖµºÀÀñ£ºgoldTotal=%s" % (goldTotal))
    if goldTotal <= 0:
        return
    
    goldGiftByMailList = ReadChConfig.GetEvalChConfig("GoldGiftByMail")
    playerID = curPlayer.GetPlayerID()
    for i, giftInfo in enumerate(goldGiftByMailList):
        
        needGold = giftInfo[0]
        giftItemList = giftInfo[1]
        mailTitle = giftInfo[2]
        mailContent = giftInfo[3]
        getDays = giftInfo[4]
        
        curMailRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GoldGiftMailRecord, 0, 
                                                       ChConfig.Def_PDictType_GoldGift)
        
        if curMailRecord&pow(2, i):
            GameWorld.DebugLog("Óʼþ·¢ËͳäÖµºÀÀñ£ºÒÑ·¢Ë͹ý£¡i=%s,needGold=%s" % (i, needGold))
            continue
    
        if goldTotal < needGold:
            continue
        
        if not PlayerControl.SendMail(mailTitle, mailContent, getDays, [playerID], giftItemList):
            continue
        
        updMailRecord = curMailRecord|pow(2, i)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GoldGiftMailRecord, updMailRecord,
                                       ChConfig.Def_PDictType_GoldGift)
        
        GameWorld.DebugLog("Óʼþ·¢ËͳäÖµºÀÀñ£ºi=%s,needGold=%s,giftItemList=%s,updMailRecord=%s" 
                           % (i, needGold, str(giftItemList), updMailRecord))
        # Á÷Ïò
        DataRecordPack.DR_GoldGiftGiveItem(curPlayer, "GoldGiftSendMail_%s_%s" % (i, needGold))
    return
 
## ÁìÈ¡Íæ¼ÒÌìÌìÊ׳佱Àø
#  @param curPlayer
#  @return None
def GetPlayerDailyGoldChargeGift(curPlayer):
    
    dailyGoldRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargePrizeRecord, 0)
    
    if dailyGoldRecord != 1:
        GameWorld.DebugLog("ÌìÌìÊ׳䲻¿ÉÁ죡µ±Ç°×´Ì¬=%s" % dailyGoldRecord)
        return
    
    dailyFirstGoldPrizeInfo = ReadChConfig.GetEvalChConfig("GoldGiftInfoFirstDaily")
    
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    needSpace = dailyFirstGoldPrizeInfo[Def_NeedSpace]
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    # ¸øÎïÆ·
    if not __GiveGoldGift(curPlayer, dailyFirstGoldPrizeInfo[Def_GiftInfo]):
        return
 
    # È«·þÌáʾ
    notifyMark = dailyFirstGoldPrizeInfo[Def_NotifyMark]
    if notifyMark:
        PlayerControl.WorldNotify(0, notifyMark, [curPlayer.GetPlayerName()])
 
    UpdateDailyGoldRecord(curPlayer, 2)
    
    # ¼Ç¼Áìȡʼþ
    DataRecordPack.DR_GoldGiftGiveItem(curPlayer, "dailyFirstGoldPrize")
    return
 
 
## ¸üÐÂÌìÌìÊ׳佱Àø¼Ç¼
#  @param curPlayer
#  @return None
def UpdateDailyGoldRecord(curPlayer, record):
    #PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyGoldChargePrizeRecord, record)
    #Sync_DailyGoldRecordInfo(curPlayer)
    return
 
def Sync_FirstGoldInfo(curPlayer):
    ## Í¨ÖªÊ׳äÐÅÏ¢
    sendPack = ChPyNetSendPack.tagMCFirstGoldInfo()
    sendPack.Clear()
    sendPack.FirstGoldRewardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GoldGiftFirstRecord)
    sendPack.FirstGoldTry = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstGoldTry)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
## Í¨Öªµ¥ÈÕ³äÖµ¶àѡһÀñ°üÐÅÏ¢
#  @param curPlayer
#  @return None
def Sync_SingleGoldGiftInfo(curPlayer, isCheckTime=False):
    #===============================================================================================
    # if isCheckTime:
    #    todayGiftInfo = GetTodaySingleGoldGiftInfo()
    #    if not todayGiftInfo:
    #        return
    # 
    # sendPack = ChPyNetSendPack.tagMCSingleGoldGift()
    # sendPack.Clear()
    # sendPack.GoldCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyGoldChargeCnt)
    # sendPack.GiftIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_SingleGoldGiftIndex)
    # NetPackCommon.SendFakePack(curPlayer, sendPack)
    #===============================================================================================
    return
 
## »ñÈ¡µ¥ÈÕ³äÖµ¶àѡһÀñ°üÐÅÏ¢
#  @param None
#  @return None´ú±í½ñÈÕÎ޻
def GetTodaySingleGoldGiftInfo():
    # ¿ª·þǰ7ÌìĬÈϲ»¿ªÆô
    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay)
    
    singleGoldGiftList = ReadChConfig.GetEvalChConfig("SingleGoldGift")
    
    curDataTimeStr = GameWorld.GetCurrentDataTimeStr()
    
    curTime = GameWorld.GetCurrentTime()
    weekday = curTime.weekday() + 1
    
    findSingleGoldGift = None
    for giftInfo in singleGoldGiftList:
        
        # ÅжÏÈÕÆÚ, ÈÕÆÚ»î¶¯ÓÅÏÈ
        dateTimeInfo = giftInfo[0]
        if dateTimeInfo:
            startTime = dateTimeInfo[0]
            endTime = dateTimeInfo[1]
            if startTime <= curDataTimeStr <= endTime:
                findSingleGoldGift = giftInfo
                break
        
        # ÅжÏÐÇÆÚ, ¿ª·þǰ7ÌìĬÈϲ»¿ªÆôÐÇÆÚ»î¶¯
        weekDayInfo = giftInfo[1]
        if weekday in weekDayInfo and openServerDay >= ShareDefine.Def_OSC_ValidDay:
            findSingleGoldGift = giftInfo
            break
    
    return findSingleGoldGift
 
 
#// A5 11 ÊÔÓÃÊ׳äÎäÆ÷ #tagCMTryFirstGoldItem
#
#struct    tagCMTryFirstGoldItem
#
#{
#    tagHead        Head;
#};
def OnTryFirstGoldItem(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstGoldTry) != 1:
        return
    tryItemDict = IpyGameDataPY.GetFuncEvalCfg('FirstGoldTryItem', 1, {})
    tryItemID = tryItemDict.get(curPlayer.GetJob(), 0)
    if not tryItemID:
        return
    
    
    #ÏÈжÏÂÖ÷ÊÖÎäÆ÷£¨Èô±³°üÂúÔò·¢Óʼþ£©£¬ÔÙ´©ÉÏË͵ÄÎäÆ÷
    equipPlace = ShareDefine.retWeapon
    curPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
    curItem = curPack.GetAt(equipPlace)
    if ItemCommon.CheckItemCanUse(curItem):
        spaceIndex = ItemControler.GetItemPackSpaceIndex(curPlayer, IPY_GameWorld.rptItem)
        if spaceIndex == -1:
            itemObj = ItemCommon.GetMailItemDict(curItem)
            PlayerControl.SendMailByKey('', [curPlayer.GetID()], [itemObj])
            ItemCommon.DelItem(curPlayer, curItem, 1, False)
        else:
            result = ItemControler.PlayerItemControler(curPlayer).UnEquipItem(equipPlace, spaceIndex)
            if not result:
                GameWorld.Log('    ÊÔÓÃÊ׳äÎäÆ÷ Ð¶ÏÂÔ­×°±¸Ê§°Ü£¡£¡', curPlayer.GetID())
                return
            
    tryItem = ItemControler.GetOutPutItemObj(tryItemID, 1, 1)
    if ChEquip.DoPlayerEquipItem(curPlayer, tryItem, equipPlace, tick):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstGoldTry, 2)
    else:
        curItem.clear()
        GameWorld.Log('    ÊÔÓÃÊ׳äÎäÆ÷ ÊÔ´©Ê§°Ü£¡£¡tryItemID=%s'%tryItemID, curPlayer.GetID())
    Sync_FirstGoldInfo(curPlayer)
    return
 
def FirstGoldTryItemOutTime(curPlayer):
    ##Ê׳äÊÔÓÃÎïÆ·¹ýÆÚÁË Èô±³°ü²Ö¿âûÎäÆ÷ÔòËÍÒ»°Ñ
    
    haveEquip = False #ÊÇ·ñÓпɴ©µÄÎäÆ÷
    playerItemControl = ItemControler.PlayerItemControler(curPlayer)
    for packIndex in [IPY_GameWorld.rptItem, IPY_GameWorld.rptWarehouse]:
        curPack = curPlayer.GetItemManager().GetPack(packIndex)
        for i in range(0, curPack.GetCount()):
            curItem = curPack.GetAt(i)
            if not ItemCommon.CheckItemCanUse(curItem):
                continue
            if curItem.GetEquipPlace() != ShareDefine.retWeapon:
                continue
            if not ItemCommon.CheckItemCanUseByExpireTime(curItem):
                # ¹ýÆÚ
                continue
            if not playerItemControl.PlayerCanEquipItem(curItem, False):
                continue
            haveEquip = True
            break
    if not haveEquip:
        giveItemDict = IpyGameDataPY.GetFuncEvalCfg('FirstGoldTryItem', 2, {})
        giveItemID = giveItemDict.get(curPlayer.GetJob(), 0)
        if not giveItemID:
            return
        GameWorld.DebugLog('Ê׳äÊÔÓÃÎïÆ·¹ýÆÚÁË ±³°ü²Ö¿âûÎäÆ÷ÔòËÍÒ»°ÑgiveItemID=%s'%giveItemID, curPlayer.GetID())
        if not ItemControler.GivePlayerItem(curPlayer, giveItemID, 1, True, [IPY_GameWorld.rptItem], True):
            GameWorld.DebugLog('Ê׳äÊÔÓÃÎïÆ·¹ýÆÚÁË ±³°ü²Ö¿âûÎäÆ÷ÔòËÍÒ»°Ñ Ã»¸ø³É¹¦£¡£¡giveItemID=%s'%giveItemID, curPlayer.GetID())
            
    return
#ÿÈÕ³äÖµÈÎÒâ½ð¶îºì°ü½±Àø
def DayChargeRedPackAward(curPlayer):
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyChargeState) == 1:
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyChargeState, 1)
    PlayerFamilyRedPacket.CreatRedPacketByID(curPlayer, 2)
    return