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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerActivity
#
# @todo:Íæ¼ÒÿÈÕ»îÔ¾¶È
# @author xdh
# @date 2014-07-14
# @version 1.0
#
# ÏêϸÃèÊö: Íæ¼ÒÿÈÕ»îÔ¾¶È¡¢Ã¿Èջ
#---------------------------------------------------------------------
#"""Version = 2017-02-25 11:30"""
#---------------------------------------------------------------------
 
import ChConfig
import ChPyNetSendPack
import NetPackCommon
import ShareDefine
import GameWorld
import ItemCommon
import IPY_GameWorld
import PlayerControl
import ItemControler
import IpyGameDataPY
import PyGameData
import GameFuncComm
import EventShell
import PlayerTJG
import PlayerPet
import PlayerVip
import datetime
import time
import FormulaControl
import PlayerBossReborn
import PlayerActGarbageSorting
import PlayerTongTianLing
import PlayerActTask
import PlayerSuccess
import PlayerGubao
 
#¹ØÁªÀàÐÍ
(
RelatedType_1,  # 1¹ØÁªÈÕ³£»î¶¯±í
RelatedType_2,  # 2¹ØÁª¸±±¾×ܱí
) = range(1, 3)
 
 
def OnWeek(curPlayer, onWeekType):
    actionIDInfo = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetDailyActionCount()):
        ipyData = ipyDataMgr.GetDailyActionByIndex(i)
        weekTimesLimit = ipyData.GetWeekTimes()
        if not weekTimesLimit:
            continue
        # ÖØÖÃÀàÐͲ»Í¬µÄ²»´¦Àí
        if ipyData.GetWeekResetType() != onWeekType:
            continue
        key = ChConfig.Def_PDict_DailyActionWeekTimes % ipyData.GetDailyID()
        __SetPDictValue(curPlayer, key, 0)
    
        actionIDInfo.append(ipyData.GetDailyID())
            
    if actionIDInfo:
        SyncDailyActionInfo(curPlayer, actionIDInfo)
        
    return
 
 
## OnDay
#  @param curPlayer Íæ¼ÒʵÀý
#  @return
def OnDay(curPlayer, onEventType):
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    if onEventType == ShareDefine.Def_OnEventTypeEx:
        # ÖØÖÃÍê³É´ÎÊý
        for i in xrange(ipyDataMgr.GetDailyQuestCount()):
            ipyData = ipyDataMgr.GetDailyQuestByIndex(i)
            
            key = ChConfig.Def_PDict_Activity_FinishCnt % ipyData.GetID()
            curPBCnt = __GetPDictValue(curPlayer, key)  #µ¥´Î½ø¶ÈÖµ
            if curPBCnt:
                __SetPDictValue(curPlayer, key, 0)
            key = ChConfig.Def_PDict_Activity_AddTotal % ipyData.GetID()
            if __GetPDictValue(curPlayer, key):
                __SetPDictValue(curPlayer, key, 0)
        #×Ü»îÔ¾¶ÈÖØÖÃ
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_TotalPoint, 0)
        # ÖØÖÃÁì½±¼Ç¼
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityAwardRecord, 0)
        #ÖØÖöîÍâ»ñµÃÐÞÐеãÊý
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_ExtraRealmPoint, 0)
        #ÖØмÆËã½±Àø½×¶Î
        __CalcAwardStage(curPlayer)
        
        SyncDailyActivityInfo(curPlayer)
        
        # ¼Ç¼×òÈÕ»îÔ¾ÎüÄɾ­Ñé
        todayExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceTodayExp)
        todayExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceTodayExpPoint)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceTodayExp, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceTodayExpPoint, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceYestorDayExp, todayExp)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceYestorDayExpPoint, todayExpPoint)
        #»îÔ¾·ÅÖÃ
        Sync_ActivityPlaceInfo(curPlayer)
        
    #else:
    #    SendDayActionMail(curPlayer)
    
    #ÈÕ³£»î¶¯ÖØÖÃ
    actionIDInfo = []
    for i in xrange(ipyDataMgr.GetDailyActionCount()):
        ipyData = ipyDataMgr.GetDailyActionByIndex(i)
        dayTimesLimit = GetMaxDayTimes(ipyData)  #ipyData.GetDayTimes()
        if not dayTimesLimit:
            continue
        # ÖØÖÃÀàÐͲ»Í¬µÄ²»´¦Àí
        if ipyData.GetDayResetType() != onEventType:
            continue
        dailyID = ipyData.GetDailyID()
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayTimes % dailyID, 0)
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayBuyTimes % dailyID, 0)
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayItemTimes % dailyID, 0)
        
        actionIDInfo.append(ipyData.GetDailyID())
    if actionIDInfo:
        SyncDailyActionInfo(curPlayer, actionIDInfo)
    return
 
 
def SendDayActionMail(curPlayer):
    ##·¢ËÍÿÈջÓʼþ
    #if curPlayer.GetLV() >= IpyGameDataPY.GetFuncCfg('DailyQuestMailLvLimit'):
    #    PlayerControl.SendMailByKey('TodayDailyTask', [curPlayer.GetID()], [])
    return
 
 
#ÖØмÆËã½±Àø½×¶Î
def __CalcAwardStage(curPlayer):
    realmLV = curPlayer.GetOfficialRank()
    ipyData = IpyGameDataPY.IPY_Data().GetDailyLivenessRewardByIndex(0)
    if not ipyData:
        return
    stageLVList = ipyData.GetStageLV()
    curStage = 0
    for i, lv in enumerate(stageLVList):
        if realmLV < lv:
            break
        if realmLV >= lv:
            curStage = i
    __SetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_AwardStage, curStage)
    GameWorld.DebugLog('    ÖØмÆËã»îÔ¾½±Àø½×¶Î curStage=%s,realmLV=%s' % (curStage, realmLV))
    return
 
 
## OnLogin
#  @param curPlayer Íæ¼ÒʵÀý
#  @return
def OnLogin(curPlayer):
    # Í¬²½Íê³É¶È¼°Áì½±¼Ç¼
    SyncDailyActivityInfo(curPlayer)
    #ͬ²½ÈÕ³£»î¶¯´ÎÊý
    SyncDailyActionInfo(curPlayer)
    #»îÔ¾·ÅÖÃ
    Sync_ActivityPlaceInfo(curPlayer)
    return
 
 
## »ñÈ¡»îÔ¾¶ÈÍæ¼ÒÊý¾Ý¿â×ÖµäÐÅÏ¢Öµ
#  @param curPlayer Íæ¼ÒʵÀý
#  @param key ×Öµäkey
#  @param defaultValue Ä¬ÈÏÖµ
#  @return
def __GetPDictValue(curPlayer, key, defaultValue=0):
    return curPlayer.NomalDictGetProperty(key, defaultValue)
 
 
## ÉèÖûîÔ¾¶ÈÍæ¼ÒÊý¾Ý¿â×ÖµäÐÅÏ¢Öµ
#  @param curPlayer Íæ¼ÒʵÀý
#  @param key ×Öµäkey
#  @param value ÉèÖõÄÖµ
#  @return
def __SetPDictValue(curPlayer, key, value):
    PlayerControl.NomalDictSetProperty(curPlayer, key, value)
    return
 
 
## ¿Û³ý»õ±Ò»ñµÃ»îÔ¾¶È
#  @param curPlayer Íæ¼ÒʵÀý
#  @param type_Price 
#  @param price 
#  @return
def OnPayMoneyActivity(curPlayer, type_Price, price):
    #½ð×ÓÖ§¸¶
#    if type_Price == IPY_GameWorld.TYPE_Price_Gold_Money:
#        AddActivityFinishCnt(curPlayer, ShareDefine.ActivityNum_UseGoldCnt)
#    #½ðƱ֧¸¶
#    elif type_Price == IPY_GameWorld.TYPE_Price_Gold_Paper:
#        AddActivityFinishCnt(curPlayer, ShareDefine.ActivityNum_UseGoldPaperCnt)
        
    return
 
 
## ÃþNPC»ñµÃ»îÔ¾¶È
#  @param atkObj
#  @param curNPC 
#  @return
def OnAttackNPCActivity(atkObj, curNPC):
    atkObjType = atkObj.GetGameObjType()
    
    # ²»ÊÇÍæ¼ÒÔݲ»´¦Àí
    if atkObjType != IPY_GameWorld.gotPlayer:
        return
                
    # »÷ɱboss
#    if curNPC.GetIsBoss():
#        canAddBossIDList = ReadChConfig.GetEvalChConfig("Activity_BossID")
#        
#        if curNPC.GetNPCID() in canAddBossIDList:
#            AddActivityFinishCnt(atkObj, ShareDefine.ActivityNum_KillBoss)
        
    return
 
 
## Ôö¼ÓÍê³É»îÔ¾¶È´ÎÊý
#  @param curPlayer Íæ¼ÒʵÀý
#  @param activityNum »îÔ¾¶È±àºÅ 
#  @param finishCnt ÒÑÍê³É´ÎÊý
#  @param addCnt Ôö¼Ó´ÎÊý£¬Ä¬ÈÏ1 
#  @return
def AddActivityFinishCnt(curPlayer, activityNum, finishCnt, addCnt):
    
    dailyQuestData = IpyGameDataPY.GetIpyGameDataNotLog('DailyQuest', activityNum)
    if not dailyQuestData:
        return
    
    maxActiveValue = dailyQuestData.GetTotalActiveValue()
    onceActivity = dailyQuestData.GetOnceActivity()
    onceActivityTime = dailyQuestData.GetOnceActivityTime()
    if not onceActivity:
        return
    curAddTotal = None
    if maxActiveValue:
        if dailyQuestData.GetRelatedType() == RelatedType_1 and dailyQuestData.GetRelatedID() in [ShareDefine.DailyActionID_CrossBattlefield]:
            curAddTotal = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_AddTotal % activityNum)  #µ¥´Î½ø¶ÈÖµ
            if curAddTotal >= maxActiveValue:
                GameWorld.DebugLog("»îÔ¾¶È¿ÉÍê³É´ÎÊýÒÑ´ïµ½ÉÏÏÞ,activityNum=%s,curAddTotal=%s >= %s" % (activityNum, curAddTotal, maxActiveValue))
                return
        else:
            if finishCnt > maxActiveValue / onceActivity * onceActivityTime:
                #GameWorld.DebugLog("»îÔ¾¶È¿ÉÍê³É´ÎÊýÒÑ´ïµ½ÉÏÏÞ,activityNum=%s" % (activityNum))
                return
            
    key = ChConfig.Def_PDict_Activity_FinishCnt % activityNum
    curPBCnt = __GetPDictValue(curPlayer, key)  #µ¥´Î½ø¶ÈÖµ
    
    addValue = (addCnt + curPBCnt) / onceActivityTime * onceActivity  #Ôö¼ÓµÄ»îÔ¾¶È
    addPbCnt = (addCnt + curPBCnt) % onceActivityTime
    
    __SetPDictValue(curPlayer, key, addPbCnt)
    
    if curAddTotal != None:
        curAddTotal += addValue
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_AddTotal % activityNum, curAddTotal)
        
    #
    DoAddActivity(curPlayer, addValue, True)
    return
 
def DoAddActivityByLV(curPlayer, befLV, aftLV):
    ##Éý¼¶Ôö¼Ó»îÔ¾µã
    perLVAddPoint = IpyGameDataPY.GetFuncCfg('ImmortalDomainActivePoint', 3)
    skillTypeID, perAddLV, addPoint, maxPoint = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomainActivePoint', 4)
    learnSkillList, passiveSkillList = PlayerPet.GetPetLearnSkill(curPlayer)
    addValue = (aftLV-befLV)*perLVAddPoint
    if skillTypeID in passiveSkillList:
        for lv in xrange(befLV+1, aftLV+1):
            addValue += min(((lv-1)/perAddLV+1) * addPoint, maxPoint)
    DoAddActivity(curPlayer, addValue, False, True)
    return
 
def AddActivityByLVOnLearnSkill(curPlayer, skillID):
    ## »ñµÃ¼¼ÄÜʱ£¬´¦ÀíÔö¼ÓÉý¼¶»ñµÃ»îÔ¾µãЧ¹û
    skillTypeID, perAddLV, addPoint, maxPoint = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomainActivePoint', 4)
    if skillID != skillTypeID:
        return
    curLV = curPlayer.GetLV()
    addValue = 0
    for lv in xrange(2, curLV+1):
        addValue += min(((lv-1)/perAddLV+1) * addPoint, maxPoint)
    DoAddActivity(curPlayer, addValue, False, True)
    return
 
def DoAddActivity(curPlayer, addValue, isMultiple=False, isLVUp=False):
    if not addValue:
        return
    multiple = 1
    addExtraPoint = 0
    if isMultiple:
        multiple, extraPointLimit = __GetActionAddPer(curPlayer)
        curExtraPoint = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_ExtraRealmPoint)
        addExtraPoint = max(0, min(addValue * (multiple - 1),
                                   extraPointLimit - curExtraPoint)) if extraPointLimit else addValue * (multiple - 1)
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_ExtraRealmPoint, curExtraPoint + addExtraPoint)
        addValue = addValue + addExtraPoint
    curTotalPoint = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_TotalPoint)
    __SetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_TotalPoint, curTotalPoint + addValue)
    __AddCanCostActivityPoint(curPlayer, addValue, isLVUp)
    PlayerActGarbageSorting.AddActGarbageTaskProgress(curPlayer, ChConfig.Def_GarbageTask_Activity, addValue)
    PlayerTongTianLing.AddTongTianTaskValue(curPlayer, ChConfig.TTLTaskType_Activity, addValue)
    PlayerActTask.AddActTaskValue(curPlayer, ChConfig.ActTaskType_Activity, addValue)
    PlayerControl.NotifyCode(curPlayer, "GetActivity", [addValue])
    SyncDailyActivityInfo(curPlayer)
    EventShell.EventRespons_AddActivityValue(curPlayer)
    GameWorld.DebugLog("Ôö¼Ó»îÔ¾¶È,addValue=%s,multiple=%s,addExtraPoint=%s,isLVUp=%s" 
                       % (addValue, multiple, addExtraPoint, isLVUp), curPlayer.GetPlayerID())
    return
 
def __GetActionAddPer(curPlayer):
    multiple, extraPointLimit = 1, 0  #±¶Êý¡¢¶îÍâ¿É»ñµÃÐÞÐеãÉÏÏÞ
    actRealmPointInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_RealmPoint, {})  # ¶à±¶ÐÞÐеã»î¶¯
    if not actRealmPointInfo:
        return multiple, extraPointLimit
    if not actRealmPointInfo.get(ShareDefine.ActKey_State):
        return multiple, extraPointLimit
    actRealmPointIpyData = IpyGameDataPY.GetIpyGameData("ActRealmPoint", actRealmPointInfo.get(ShareDefine.ActKey_CfgID, 0))
    if not actRealmPointIpyData:
        return multiple, extraPointLimit
    if curPlayer.GetLV() < actRealmPointIpyData.GetLVLimit():
        return multiple, extraPointLimit
    return actRealmPointIpyData.GetMultiple(), actRealmPointIpyData.GetPointLimit()
 
def __AddCanCostActivityPoint(curPlayer, addValue, isLVUp):
    # Ôö¼Ó¿ÉÏûºÄµÄ»îÔ¾µã
    curPoint = __GetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityCanCostTotalPoint)
    if isLVUp:
        updPoint = min(ChConfig.Def_UpperLimit_DWord, curPoint + addValue)
    else:
        maxPoint = IpyGameDataPY.GetFuncCfg('ActivityPlace', 1)
        if maxPoint and curPoint >= maxPoint:
            GameWorld.DebugLog("¿ÉÏûºÄµÄ»îÔ¾µã³¬³öÉÏÏÞ£¬²»Ôö¼Ó! curPoint=%s,maxPoint=%s" % (curPoint, maxPoint))
            return
        updPoint = curPoint + addValue
    __SetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityCanCostTotalPoint, updPoint)
    
    costPoint = IpyGameDataPY.GetFuncCfg("ActivityPlace", 2) # µ¥´Î·ÅÖÃÏûºÄµÄ»îÔ¾µãÊý
    if updPoint >= costPoint:
        EventShell.EventRespons_ActivityPlace(curPlayer, "canstart", True)
    return
 
def CostActivityPoint(curPlayer, costPoint, isOnlyCheck=False):
    # ÏûºÄ»îÔ¾µã
    curPoint = __GetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityCanCostTotalPoint)
    if curPoint < costPoint:
        return
    if not isOnlyCheck:
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityCanCostTotalPoint,
                        curPoint - costPoint)
        SyncDailyActivityInfo(curPlayer)
    return True
 
## Í¬²½»îÔ¾¶ÈÐÅÏ¢
#  @param curPlayer
#  @param syncNum Ä¬ÈÏ-1ʱȫ²¿Í¬²½
#  @return None
def SyncDailyActivityInfo(curPlayer):
    sendPack = ChPyNetSendPack.tagMCDailyActivityInfoList()
    sendPack.Clear()
    sendPack.CurValue = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_TotalPoint)
    sendPack.StageIndex = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_AwardStage)
    sendPack.AwardRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityAwardRecord)
    sendPack.RealmPoint = __GetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityCanCostTotalPoint)
    sendPack.ExtraPoint = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_ExtraRealmPoint)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
 
## ÁìÈ¡»îÔ¾¶È½±Àø
#  @param curPlayer
#  @param awardIndex
#  @return None
def GetActivityAward(curPlayer, awardIndex):
    rewardCount = IpyGameDataPY.IPY_Data().GetDailyLivenessRewardCount()
 
    if awardIndex < 0 or awardIndex >= rewardCount:
        GameWorld.ErrLog("»îÔ¾¶È½±ÀøË÷Òý²»ºÏ·¨,index=%s,Len=%s" % (awardIndex, rewardCount))
        return
    
    # ÅжÏÊÇ·ñÒÑÁìÈ¡
    getAwardRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityAwardRecord)
    if getAwardRecord & pow(2, awardIndex):
        GameWorld.Log("ÒѾ­ÁìÈ¡¹ý¸Ã»îÔ¾¶È½±Àø,index=%s" % (awardIndex))
        return
    
    ipyData = IpyGameDataPY.IPY_Data().GetDailyLivenessRewardByIndex(awardIndex)
    
    needActivity = ipyData.GetLiveness()
    totalActivity = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_TotalPoint)
    
    # ÅжϻîÔ¾¶È
    if totalActivity < needActivity:
        GameWorld.Log("Áì½±»îÔ¾¶È²»×ã,index=%s,needActivity=%s,totalActivity=%s" 
                      % (awardIndex, needActivity, totalActivity))
        return
    
    awardStage = __GetPDictValue(curPlayer, ChConfig.Def_PDict_Activity_AwardStage)
   
    itemIDList = ipyData.GetItemID()
    itemCntList = ipyData.GetItemCount()
    itemIsBindList = ipyData.GetItemBind()
    if awardStage >= len(itemIDList) or awardStage >= len(itemCntList) or awardStage >= len(itemIsBindList):
        return
 
    itemID = itemIDList[awardStage]
    itemCnt = itemCntList[awardStage]
    isBind = itemIsBindList[awardStage]
    # ¼ì²é±³°ü
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
    if 1 > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    # ¸øÎïÆ·
    ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem])
 
    # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç
    updAwardRecord = getAwardRecord | (1 << awardIndex)
    __SetPDictValue(curPlayer, ChConfig.Def_PDict_ActivityAwardRecord, updAwardRecord)
    SyncDailyActivityInfo(curPlayer)
    GameWorld.DebugLog("ÁìÈ¡»îÔ¾¶È½±ÀøOK£¡awardStage=%s, index=%s,needActivity=%s,totalActivity=%s,awardRecord=%s" 
                       % (awardStage, awardIndex, needActivity, totalActivity, updAwardRecord))
    EventShell.EventRespons_ActivityAward(curPlayer, awardIndex)
    return
 
 
def GetActivityNum(relatedType, relatedID):
    ## »ñÈ¡ÈÕ³£ÈÎÎñID£¨»îÔ¾ID£©
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('DailyQuest', {"RelatedID":relatedID, "RelatedType":relatedType}, False, False)
    if not ipyData:
        return 0
    return ipyData.GetID()
 
#########################################ÈÕ³£»î¶¯###########################################
 
def GetDailyActionOpenEndTime(dailyID):
    ## »ñÈ¡ÈÕ³£»î¶¯¿ªÆô½áÊøʱ¼äµã
    ipyData = IpyGameDataPY.GetIpyGameData('DailyAction', dailyID)
    if not ipyData:
        return
    openTimeDict = ipyData.GetOpenTimeDict()
    duration = ipyData.GetDuration()
    if not openTimeDict or not duration:
        return
    allOpenTimeList = openTimeDict.values()
    if not allOpenTimeList:
        return
    openTimeList = allOpenTimeList[0] # Õâ±ßĬÈÏΪÿÈյĿªÆôʱ¼ä¶ÎÒ»Ñù£¬Ö±½ÓÈ¡µÚÒ»ÈÕ
    if len(openTimeList) == 1:
        openHour, openMinute = openTimeList[0]
    else:
        #openHour, openMinute = 
        # Ã¿Ìì¶à¸öʱ¼ä¶ÎµÄÔÙ˵£¬ÔÝʱûÓõ½
        return
    
    curDateTime = GameWorld.GetCurrentTime()
    openTimeStr = "%d-%d-%d %02d:%02d:00" % (curDateTime.year, curDateTime.month, curDateTime.day, openHour, openMinute)
    openDateTime = datetime.datetime.strptime(openTimeStr, ChConfig.TYPE_Time_Format)
    endDateTime = openDateTime + datetime.timedelta(minutes=duration)
    return openDateTime, endDateTime
 
def GetDailyActionRemainSeconds(dailyID):
    ## »ñÈ¡ÈÕ³£»î¶¯µ±Ç°Ê£ÓàÃëÊý
    openEndTimeInfo = GetDailyActionOpenEndTime(dailyID)
    if not openEndTimeInfo:
        return 0
    openDateTime, endDateTime = openEndTimeInfo
    curDateTime = GameWorld.GetCurrentTime()
    if curDateTime < openDateTime or curDateTime >= endDateTime:
        return 0
    remainDateTime = endDateTime - curDateTime
    return remainDateTime.seconds
 
def AddDailyActionFinishCnt(curPlayer, dailyID, addCnt=1):
    ##Ôö¼ÓÈÕ³£»î¶¯Íê³É´ÎÊý
    ipyData = IpyGameDataPY.GetIpyGameData('DailyAction', dailyID)
    if not ipyData:
        return
#    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_DailyQuest):
#        #GameWorld.DebugLog("ÈÕ³£ÈÎÎñ¹¦ÄÜ먦Æô£¡dailyID=%s" % dailyID)
#        return
    
    # ÓÉGameServer¾ö¶¨
    # Ä¿Ç°¿ç·þPKÔݲ»ÐèÒªÅжϣ¬ÒòΪ¿ç·þPK´ÎÊý½áËãÔÚ±¾·þ£¬Íæ¼Ò¿ÉÄÜÉÏ´Îδ½áËãÀëÏߣ¬µÈ·ÇÆ¥ÅäÆÚ¼äÉÏÏߣ¬Ò²ÐèÒª¼ÓÉÏ£¬ËùÒÔÔݲ»ÅжÏ
    if dailyID not in [ShareDefine.DailyActionID_CrossReamPK, ShareDefine.DailyActionID_CrossBattlefield]:
        if not GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % dailyID):
            GameWorld.DebugLog("ÈÕ³£»î¶¯Î´¿ªÆô£¡dailyID=%s" % dailyID)
            return
    
    dayTimesLimit = GetMaxDayTimes(ipyData)  #ipyData.GetDayTimes()
    weekTimesLimit = ipyData.GetWeekTimes()
    if not dayTimesLimit and not weekTimesLimit:
        return
    #¶ÔÓ¦µÄÈÕ³£ÈÎÎñ±íID
    activityNum = GetActivityNum(RelatedType_1, dailyID)
    dailyQuestData = IpyGameDataPY.GetIpyGameDataNotLog('DailyQuest', activityNum)
    unLimitCnt = dailyQuestData and not dailyQuestData.GetTotalActiveValue()
    funcID = dailyQuestData.GetUnLockFuncID() if dailyQuestData else 0
    #·âħ̳»îÔ¾²»ÅжϹ¦ÄÜ¿ªÆô ÌØÊâ´¦Àí
    if funcID and dailyID != ShareDefine.DailyActionID_SealDemon and not GameFuncComm.GetFuncCanUse(curPlayer, funcID) :
        return
        
    updDayTimes = 0
    if dayTimesLimit:
        key = ChConfig.Def_PDict_DailyActionDayTimes % dailyID
        curDayTimes = curPlayer.NomalDictGetProperty(key)
        curDayBuyTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyActionDayBuyTimes % dailyID)
        curDayItemTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyActionDayItemTimes % dailyID)
        if not unLimitCnt and curDayTimes >= dayTimesLimit + curDayBuyTimes + curDayItemTimes:
            return
        updDayTimes = curDayTimes + addCnt if unLimitCnt else min(dayTimesLimit + curDayBuyTimes + curDayItemTimes, curDayTimes + addCnt)
        addCnt = updDayTimes - curDayTimes
        PlayerControl.NomalDictSetProperty(curPlayer, key, updDayTimes)
        GameWorld.DebugLog('Ôö¼ÓÈÕ³£»î¶¯Íê³É´ÎÊý dailyID=%s, curDayTimes=%s, updDayTimes=%s' % (dailyID, curDayTimes, updDayTimes))
    updWeekTimes = 0
    if weekTimesLimit:
        key = ChConfig.Def_PDict_DailyActionWeekTimes % dailyID
        curWeekTimes = curPlayer.NomalDictGetProperty(key)
        if not unLimitCnt and curWeekTimes >= weekTimesLimit:
            return
        updWeekTimes = curWeekTimes + addCnt if unLimitCnt else min(weekTimesLimit, curWeekTimes + addCnt)
        addCnt = updWeekTimes - curWeekTimes
        PlayerControl.NomalDictSetProperty(curPlayer, key, updWeekTimes)
        GameWorld.DebugLog('Ôö¼ÓÈÕ³£»î¶¯Íê³É´ÎÊý dailyID=%s, curWeekTimes=%s, updWeekTimes=%s' % (dailyID, curWeekTimes, updWeekTimes))
 
    SyncDailyActionInfo(curPlayer, [dailyID])
    
    #¶ÔÓ¦µÄÈÕ³£ÈÎÎñ±íID
    updTimes = updDayTimes or updWeekTimes
    if addCnt and updTimes and dailyQuestData:
        AddActivityFinishCnt(curPlayer, activityNum, updTimes, addCnt)
    return True
 
 
def GetDailyActionFinishCnt(curPlayer, dailyID):
    key = ChConfig.Def_PDict_DailyActionDayTimes % dailyID
    curDayTimes = __GetPDictValue(curPlayer, key)
    ipyData = IpyGameDataPY.GetIpyGameData('DailyAction', dailyID)
    if not ipyData:
        return 0, 0
    dayTimesLimit = GetMaxDayTimes(ipyData)  #ipyData.GetDayTimes()
    return curDayTimes, dayTimesLimit
 
def GetDailyActionrRemainCnt(curPlayer, dailyID):
    ##»ñÈ¡»î¶¯Ê£Óà´ÎÊý
    curDayTimes = __GetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayTimes % dailyID)
    curDayBuyTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyActionDayBuyTimes % dailyID)
    curDayItemTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyActionDayItemTimes % dailyID)
    ipyData = IpyGameDataPY.GetIpyGameData('DailyAction', dailyID)
    dayTimesLimit = GetMaxDayTimes(ipyData)
    return max(0, dayTimesLimit+curDayBuyTimes+curDayItemTimes-curDayTimes)
 
def GetMaxDayTimes(ipyData):
    dayTimesLimit = ipyData.GetDayTimes()
    if ipyData.GetDailyID() == ShareDefine.DailyActionID_TowerSD:
        dayTimesLimit += IpyGameDataPY.GetFuncCfg('RuneTowerSweepBuy')
    return dayTimesLimit
 
 
#// A5 25 ¹ºÂòÈÕ³£»î¶¯´ÎÊý #tagCMBuyDailyActionCnt
#
#struct    tagCMBuyDailyActionCnt
#{
#    tagHead        Head;
#    DWORD    ActionID;    // ID
#    BYTE    AddType;    // 0-»¨ÏÉÓñ 1-ÓÃÎïÆ·
#};
def OnDailyActionBuyCnt(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    dailyID = clientData.ActionID
    addType = clientData.AddType  #0»¨ÏÉÓñ 1ʹÓÃÎïÆ·
    ipyData = IpyGameDataPY.GetIpyGameData('DailyAction', dailyID)
    if not ipyData:
        return
    curDayTimes = __GetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayTimes % dailyID)
    curDayBuyTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyActionDayBuyTimes % dailyID)
    curDayItemTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyActionDayItemTimes % dailyID)
    if curDayBuyTimes + curDayItemTimes - curDayTimes >= 0:
        GameWorld.DebugLog('Ê£Óà´ÎÊýÒÑ´ïÉÏÏÞ£¬²»¿ÉÔö¼Ó£¡')
        return
    
    if addType == 0:
        dayBuyTimesLimit = ipyData.GetDayBuyTimes()
        buyTimesPrivilegeID = ipyData.GetBuyTimesPrivilegeID()
        vipBuyCountEx = PlayerVip.GetPrivilegeValue(curPlayer, buyTimesPrivilegeID)
        dayBuyTimesLimit += vipBuyCountEx
        moneyType = ipyData.GetMoneyType()
        buyNeedMoneyList = ipyData.GetBuyNeedMoney()
        if not dayBuyTimesLimit or not buyNeedMoneyList:
            GameWorld.DebugLog("ÎÞ·¨¹ºÂò! dayBuyTimesLimit=%s,buyNeedMoneyList=%s" % (dayBuyTimesLimit, buyNeedMoneyList))
            return
        if curDayBuyTimes >= dayBuyTimesLimit:
            GameWorld.DebugLog('½ñÈÕ¹ºÂò´ÎÊýÒÑ´ïÉÏÏÞ£¬²»¿ÉÔö¼Ó£¡')
            return
        buyNeedMoney = buyNeedMoneyList[curDayBuyTimes] if len(buyNeedMoneyList) > curDayBuyTimes else buyNeedMoneyList[-1]
        if not PlayerControl.PayMoney(curPlayer, moneyType, buyNeedMoney, ChConfig.Def_Cost_BuyDailyActionCnt, {'dailyID':dailyID, 'curDayBuyTimes':curDayBuyTimes}):
            return
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyActionDayBuyTimes % dailyID, curDayBuyTimes + 1)
        
    elif addType == 1:
        dayItemAddTimesLimit = ipyData.GetDayItemAddTimes()
        dayItemID = ipyData.GetDayItemID()
        if not dayItemAddTimesLimit or not dayItemID:
            return
        if curDayItemTimes >= dayItemAddTimesLimit:
            GameWorld.DebugLog('½ñÈÕʹÓÃÎïÆ·Ôö¼Ó´ÎÊýÒÑ´ïÉÏÏÞ£¬²»¿ÉÔö¼Ó£¡')
            return
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
        enough, indexList, hasBind, lackCnt = ItemCommon.GetItem_FromPack_ByID_ExEx(dayItemID, itemPack, 1)
        if not enough:
            return
        ItemCommon.ReduceItem(curPlayer, itemPack, indexList, 1, False, "DailyActionCnt")
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyActionDayItemTimes % dailyID, curDayItemTimes + 1)
 
    else:
        return
    SyncDailyActionInfo(curPlayer, [dailyID])
    return
 
 
## Í¬²½»îÔ¾¶ÈÐÅÏ¢
#  @param curPlayer
#  @param syncNum Ä¬ÈÏ-1ʱȫ²¿Í¬²½
#  @return None
def SyncDailyActionInfo(curPlayer, syncNumList=[]):
    sendPack = ChPyNetSendPack.tagMCDailyActionCnt()
    sendPack.Clear()
    sendPack.ActionInfo = []
    syncNumList = syncNumList if syncNumList else ShareDefine.DailyActionIDList
 
    for activityNum in syncNumList:
        activityInfo = ChPyNetSendPack.tagMCDailyActionInfo()
        activityInfo.Clear()
        activityInfo.ActionID = activityNum
        activityInfo.DayFinishCnt = __GetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayTimes % activityNum)
        activityInfo.DayBuyTimes = __GetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayBuyTimes % activityNum)
        activityInfo.DayItemTimes = __GetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionDayItemTimes % activityNum)
        activityInfo.WeekFinishCnt = __GetPDictValue(curPlayer, ChConfig.Def_PDict_DailyActionWeekTimes % activityNum)
        sendPack.ActionInfo.append(activityInfo)
    
    sendPack.Count = len(sendPack.ActionInfo)
    NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
 
##################################¸±±¾ÀàÔö¼Ó»îÔ¾##########################################
## ²Î¼Ó¸±±¾»ñµÃ»îÔ¾¶È
#  @param curPlayer Íæ¼ÒʵÀý
#  @param tick 
#  @return
def OnEnterFBActivity(curPlayer, mapID, curDayTimes, addCount):
    activityNum = GetActivityNum(RelatedType_2, mapID)
    if activityNum: 
        AddActivityFinishCnt(curPlayer, activityNum, curDayTimes, addCount)
    return
 
 
################################## »îÔ¾·ÅÖà##############################################
 
#// B0 29 »îÔ¾·ÅÖÃÃ÷ϸ²éѯ #tagCMActivityPlaceQuery
#
#struct    tagCMActivityPlaceQuery
#{
#    tagHead        Head;
#};
def OnActivityPlaceQuery(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    Sync_ActivityPlaceInfo(curPlayer)
    return
 
#// B0 27 »îÔ¾·ÅÖÃÆô¶¯ #tagCMActivityPlaceStart
#
#struct    tagCMActivityPlaceStart
#{
#    tagHead        Head;
#};
def OnActivityPlaceStart(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    maxRewardCount = IpyGameDataPY.GetFuncCfg("ActivityPlace", 4) # ×î´óÀۼƷÅÖý±Àø´ÎÊý        
    remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount)
    rewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount)
    
    maxCanStartCount = maxRewardCount - remainCount - rewardCount
    if maxCanStartCount <= 0:
        GameWorld.DebugLog("»îÔ¾·ÅÖý±ÀøÀۼƴÎÊýÒÑ´ïÉÏÏÞ£¬ÎÞ·¨Æô¶¯!remainCount=%s + rewardCount=%s >= maxRewardCount=%s" 
                           % (remainCount, rewardCount, maxRewardCount))
        return
            
    costPoint = IpyGameDataPY.GetFuncCfg("ActivityPlace", 2) # µ¥´Î·ÅÖÃÏûºÄµÄ»îÔ¾µãÊý
    canUseActivityPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityCanCostTotalPoint)
    pointCanUseCount = canUseActivityPoint / costPoint
    startCount = min(maxCanStartCount, pointCanUseCount)
    if startCount <= 0:
        GameWorld.DebugLog("¿ÉÓûîÔ¾²»×㣬ÎÞ·¨Ìí¼Ó´ÎÊýÆô¶¯!canUseActivityPoint=%s,costPoint=%s" % (canUseActivityPoint, costPoint))
        return
    
    updRemainCount = remainCount + startCount
    GameWorld.DebugLog("Ìí¼Ó»îÔ¾·ÅÖôÎÊý: startCount=%s,rewardCount=%s,remainCount=%s,updRemainCount=%s" 
                       % (startCount, rewardCount, remainCount, updRemainCount))
    
    costPointTotal = costPoint * startCount
    CostActivityPoint(curPlayer, costPointTotal)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRemainCount, updRemainCount)
    
    if not remainCount:
        curTime = int(time.time())
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceStartTime, curTime)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceExpCount, 0)
        GameWorld.DebugLog("    Ã»ÓÐÊ£Óà´ÎÊý£¬¸üÐÂÆô¶¯Ê±¼ä: %s" % curTime)
        
    EventShell.EventRespons_ActivityPlace(curPlayer, "start")
    
    Sync_ActivityPlaceInfo(curPlayer)
    return
 
#// B0 28 »îÔ¾·ÅÖÿìËÙÍê³É #tagCMActivityPlaceQuickFinish
#
#struct    tagCMActivityPlaceQuickFinish
#{
#    tagHead        Head;
#    BYTE        FinishCount;    //Íê³É´ÎÊý
#};
def OnActivityPlaceQuickFinish(index, clientData, tick):
    ## ¾­Ñé¸ÄΪʵʱ»ñÈ¡£¬ÔÝÆÁ±Î¿ìËÙÍê³É
    return
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    finishCount = clientData.FinishCount
    remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount)
    if not remainCount:
        GameWorld.DebugLog("ûÓÐÊ£Óà»îÔ¾·ÅÖôÎÊý£¬ÎÞ·¨¿ìËÙÍê³É!")
        return
    finishCount = min(finishCount, remainCount)
    if not finishCount:
        return
    
    costItemID, costGoldParper = IpyGameDataPY.GetFuncEvalCfg("ActivityPlace", 5)
    costItemCount = finishCount # Ã¿´Î¿ÛÒ»¸ö
    
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, costItemID, costItemCount)
    lackCnt = costItemCount - bindCnt - unBindCnt
    delItemCount = costItemCount
    if lackCnt > 0:
        costGoldParperTotal = costGoldParper * lackCnt
        if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Paper, costGoldParperTotal, ChConfig.Def_Cost_ActivityPlace):
            return
        delItemCount -= lackCnt
        
    if delItemCount > 0:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delItemCount, ChConfig.ItemDel_ActivityPlace)
        
    __DoActivityPlaceRewardEnd(curPlayer, finishCount, isQuick=True)
    return
 
def ProcessActivityPlace(curPlayer):
    ## »îÔ¾·ÅÖö¨Ê±´¦Àí
    
    remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount)
    if remainCount <= 0:
        #GameWorld.DebugLog("ûÓÐÊ£Óà·ÅÖôÎÊý²»´¦Àí!")
        return
    
    curTime = int(time.time())
    startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceStartTime)
    if not startTime:
        startTime = curTime
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceStartTime, curTime)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceExpCount, 0)
        
    needSeconds = IpyGameDataPY.GetFuncCfg("ActivityPlace", 3) # µ¥´Î·ÅÖý±Àø³ÖÐøʱ¼ä£¬Ãë
    expSeconds = IpyGameDataPY.GetFuncCfg("ActivityPlaceExp", 1) # »îÔ¾·ÅÖûñµÃ¾­Ñé¶àÉÙÃëÒ»´Î
    passTime = curTime - startTime
    
    endCount = passTime / needSeconds
    endCount = min(endCount, remainCount)
    
    expCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceExpCount)
    maxExpCount = needSeconds / expSeconds # µ¥´Î·ÅÖÃ×î¶à¿É»ñµÃ¾­Ñé´ÎÊý
    # ÓÉÓÚ½áËãʱÖØÖÃÁË¿ªÆôÏ´εÄʱ¼ä¼°¾­Ñé´ÎÊý£¬ËùÒÔÈç¹ûÓÐÐèÒª½áË㣬ÔòÒç³öʱ¼ä²»¼Æ£¬·ÅÖöàËã¾­Ñé´ÎÊý
    if endCount >= 1:
        maxExpCount *= endCount
    canGetExpCount = min(maxExpCount, passTime / expSeconds)
    addExpCount = canGetExpCount - expCount
    if addExpCount > 0:
        #GameWorld.DebugLog("»îÔ¾·ÅÖö¨Ê±´¦Àí : curTime=%s,startTime=%s,passTime=%s,endCount=%s,expCount=%s,canGetExpCount=%s,maxExpCount=%s,addExpCount=%s" 
        #                   % (curTime, startTime, passTime, endCount, expCount, canGetExpCount, maxExpCount, addExpCount))
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceExpCount, expCount + addExpCount)
        lv = curPlayer.GetLV()
        reExp = PlayerControl.GetPlayerReExp(curPlayer)
        expLV, expFormat = 0, ""
        lvFormatList = IpyGameDataPY.GetFuncEvalCfg("ActivityPlaceExp", 2) # [[СÓÚµÈÓڵȼ¶, "¹«Ê½"],...]
        for eLV, eFormat in lvFormatList:
            if lv <= eLV:
                expLV, expFormat = eLV, eFormat
                break
        if not expLV:
            expLV, expFormat = lvFormatList[-1]
        addExp = eval(FormulaControl.GetCompileFormula("ActivityPlaceExp_%s" % expLV, expFormat)) * expSeconds * addExpCount
        playerControl = PlayerControl.PlayerControl(curPlayer)
        addExp = playerControl.AddExp(addExp, ShareDefine.Def_ViewExpType_Activity)
        
        todayExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceTodayExp)
        todayExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceTodayExpPoint)
        todayTotalExp = todayExpPoint * ChConfig.Def_PerPointValue + todayExp + addExp
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceTodayExp, todayTotalExp % ChConfig.Def_PerPointValue)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceTodayExpPoint, todayTotalExp / ChConfig.Def_PerPointValue)
        
        #GameWorld.DebugLog("passTime=%s,canGetExpCount=%s,expCount=%s,addExpCount=%s,addExp=%s,todayTotalExp=%s" 
        #                   % (passTime, canGetExpCount, expCount, addExpCount, addExp, todayTotalExp))
        
    if endCount > 0:
        __DoActivityPlaceRewardEnd(curPlayer, endCount)
    return
 
def __DoActivityPlaceRewardEnd(curPlayer, endCount, isQuick=False):
    ## ·ÅÖûîÔ¾½±Àø½áËã
    
    remainCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount)
    endCount = min(endCount, remainCount)
    if endCount <= 0:
        return
    
    countDataDict = {}
    lvDataDict = {}
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in xrange(ipyDataMgr.GetActivityPlaceRewardCount()):
        ipyData = ipyDataMgr.GetActivityPlaceRewardByIndex(index)
        placeCount = ipyData.GetPlaceCount()
        placeMaxLV = ipyData.GetPlaceMaxLV()
        if placeCount:
            countDataDict[placeCount] = ipyData
        else:
            lvDataDict[placeMaxLV] = ipyData
            
    lvRewardIpyData = None
    playerLV = curPlayer.GetLV()
    lvList = sorted(lvDataDict.keys())
    for lv in lvList:
        if playerLV <= lv:
            lvRewardIpyData = lvDataDict[lv]
            break
    if not lvRewardIpyData:
        lvRewardIpyData = lvDataDict[lvList[-1]]
        
    maxAppointCount = max(countDataDict) # ×î´ó¶¨Öƽ±Àø´ÎÊý
    rewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount)
    rewardTotalCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardTotalCount)
    
    rewardItemDict = {}
    GameWorld.DebugLog("½áËã·ÅÖûîÔ¾½±Àø: remainCount=%s,rewardCount=%s,endCount=%s,maxAppointCount=%s" % (remainCount, rewardCount, endCount, maxAppointCount))
    for _ in xrange(endCount):
        
        rewardIpyData = None
        
        # ¼Ó½±Àø´ÎÊý
        remainCount -= 1
        rewardCount += 1
        if rewardTotalCount < maxAppointCount:
            rewardTotalCount += 1
            if rewardTotalCount in countDataDict:
                rewardIpyData = countDataDict[rewardTotalCount]
                #GameWorld.DebugLog("    È¡¶¨ÖÆ´ÎÊý½±Àø: rewardTotalCount=%s" % rewardTotalCount)
                
        if not rewardIpyData:
            rewardIpyData = lvRewardIpyData
            #GameWorld.DebugLog("    È¡µÈ¼¶½±Àø: maxLV=%s" % rewardIpyData.GetPlaceMaxLV())
            
        # ¹Ì¶¨½±Àø
        for itemID, itemCount in rewardIpyData.GetFixedItemRewardList():
            rewardItemDict[itemID] = rewardItemDict.get(itemID, 0) + itemCount
        # ±ýͼ¿âA
        for _ in xrange(rewardIpyData.GetRandItemCountA()):
            itemID = GameWorld.GetResultByRandomList(rewardIpyData.GetRandItemRewardListA())
            if itemID:
                rewardItemDict[itemID] = rewardItemDict.get(itemID, 0) + 1
        # ±ýͼ¿âB
        for _ in xrange(rewardIpyData.GetRandItemCountB()):
            itemID = GameWorld.GetResultByRandomList(rewardIpyData.GetRandItemRewardListB())
            if itemID:
                rewardItemDict[itemID] = rewardItemDict.get(itemID, 0) + 1
                
        GameWorld.DebugLog("    remainCount=%s,rewardCount=%s,rewardTotalCount=%s, %s" % (remainCount, rewardCount, rewardTotalCount, rewardItemDict))
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRemainCount, remainCount)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardCount, rewardCount)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardTotalCount, rewardTotalCount)
    
    if remainCount > 0:
        nextStartTime = int(time.time())
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceStartTime, nextStartTime)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceExpCount, 0)
        GameWorld.DebugLog("    »¹ÓÐÊ£Óà´ÎÊý£¬¸üÐÂÆô¶¯Ê±¼ä: %s" % (nextStartTime))
        
    # ´æ´¢½±Àø
    rewardItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItem)
    for i in xrange(rewardItemCount):
        itemID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItemID % i)
        if itemID not in rewardItemDict:
            continue
        addCount = rewardItemDict.pop(itemID)
        itemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItemCount % i)
        updCount = itemCount + addCount
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItemCount % i, updCount)
        #GameWorld.DebugLog("    ¸üÐÂ̽Ë÷½±Àø: itemID=%s,itemCount=%s,addCount=%s,updCount=%s" % (itemID, itemCount, addCount, updCount))
        
    for itemID, itemCount in rewardItemDict.items():
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItemID % rewardItemCount, itemID)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItemCount % rewardItemCount, itemCount)
        rewardItemCount += 1
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItem, rewardItemCount)
        #GameWorld.DebugLog("    ÐÂÔö̽Ë÷½±Àø: itemID=%s,itemCount=%s,rewardItemCount=%s" % (itemID, itemCount, rewardItemCount))
        
    if isQuick:
        PlayerControl.NotifyCode(curPlayer, "ActivityPlaceQuickFinishOK")
        
    EventShell.EventRespons_ActivityPlace(curPlayer, "cangetreward")
    
    Sync_ActivityPlaceInfo(curPlayer)
    
    PlayerBossReborn.AddBossRebornActionCnt(curPlayer, ChConfig.Def_BRAct_ActivityPlace, endCount)
    return
 
def GetActivityPlaceReward(curPlayer):
    ## ÁìÈ¡»îÔ¾·ÅÖý±Àø
    
    rewardItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItem)
    if not rewardItemCount:
        GameWorld.DebugLog("ûÓлîÔ¾·ÅÖý±Àø£¬ÎÞ·¨ÁìÈ¡!")
        return
    
    rewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount)
    isAppointItem = 0
    rewardItemList = []
    for i in xrange(rewardItemCount):
        itemID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItemID % i)
        itemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItemCount % i)
        if not itemID or not itemCount:
            break
        rewardItemList.append([itemID, itemCount, isAppointItem])
        
        # ÁìÈ¡ºóÐèÒªÖØÖÃΪ0
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItemID % i, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItemCount % i, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardItem, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityPlaceRewardCount, 0)
    totalCount = min(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityCountTotal) + rewardCount, ChConfig.Def_UpperLimit_DWord)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_ActivityCountTotal, totalCount)
    
    GameWorld.DebugLog("ÁìÈ¡»îÔ¾·ÅÖý±Àø: totalCount=%s,rewardCount=%s,rewardItemCount=%s,rewardItemList=%s" % (totalCount, rewardCount, rewardItemCount, rewardItemList))
    ItemControler.GivePlayerItemOrMail(curPlayer, rewardItemList)
    
    EventShell.EventRespons_ActivityPlace(curPlayer, "getreward")
    PlayerActGarbageSorting.AddActGarbageTaskProgress(curPlayer, ChConfig.Def_GarbageTask_ActivityPlace, rewardCount)
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_ActivityPlace, rewardCount)
    PlayerGubao.AddGubaoItemEffValue(curPlayer, PlayerGubao.GubaoEffType_ActivityPlace, rewardCount)
    
    Sync_ActivityPlaceInfo(curPlayer)
    return
 
def Sync_ActivityPlaceInfo(curPlayer):
    ## Í¬²½»îÔ¾·ÅÖÃÐÅÏ¢
    rewardItemInfo = []
    rewardItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItem)
    for i in xrange(rewardItemCount):
        itemID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItemID % i)
        itemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardItemCount % i)
        rewardItemInfo.append([itemID, itemCount])
    placeInfo = ChPyNetSendPack.tagMCActivityPlaceInfo()
    placeInfo.StartTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceStartTime)
    placeInfo.PlaceCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRemainCount)
    placeInfo.RewardCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceRewardCount)
    placeInfo.RewardInfo = str(rewardItemInfo)
    placeInfo.RewardLen = len(placeInfo.RewardInfo)
    placeInfo.TodayExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceTodayExp)
    placeInfo.TodayExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceTodayExpPoint)
    placeInfo.YestordayExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceYestorDayExp)
    placeInfo.YestordayExpPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityPlaceYestorDayExpPoint)
    placeInfo.TotalCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_ActivityCountTotal)
    NetPackCommon.SendFakePack(curPlayer, placeInfo)
    return
 
#########################################################################################