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
1121
1122
1123
1124
1125
1126
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package PlayerLove
#
# @todo:ÇéԵϵͳ
# @author hxp
# @date 2021-11-09
# @version 1.0
#
# ÏêϸÃèÊö: ÇéԵϵͳ
#
#-------------------------------------------------------------------------------
#"""Version = 2021-11-09 20:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import PyDataManager
import PlayerControl
import ChPyNetSendPack
import PlayerCompensation
import PlayerFamilyRedPacket
import PyGameDataStruct
import NetPackCommon
import IpyGameDataPY
import PlayerSocial
import PlayerCharm
import ShareDefine
import PyGameData
import CommFunc
 
import operator
import time
import math
 
class MarryReq():
    ## ½øÐÐÖеÄÇóÇ×£¬²»´æµµ£¬»ØÓ¦·½ÉÏÏßÒ²²»Í¨Öª£¬½öË«·½¶¼ÔÚÏßʱͬ²½´¦Àí£¬·þÎñÆ÷ά»¤²»´æµµ£¬ÖØÐÂÇëÇó
    
    def __init__(self):
        self.playerIDA = 0 # ÇëÇó·½
        self.playerIDB = 0 # »ØÓ¦·½
        self.bridePriceID = 0 # Æ¸ÀñID
        self.reqTime = 0 # ÇëÇóʱ¼ä´Á
        return
    
class MarryCandy():
    ## Ï²ÌÇÑç»á£¬²»´æ¿â£¬·þÎñÆ÷¹Ø·þʱδ½áÊøµÄϲÑçÇ¿ÖÆ½áËã
    
    def __init__(self):
        self.playerIDA = 0
        self.playerNameA = ""
        self.playerIDB = 0
        self.playerNameB = ""
        self.bridePriceID = 0 # Æ¸ÀñID
        self.marryTime = 0 # ³ÉÇ×ʱ¼ä´Á
        self.endTime = 0 # ½áËãʱ¼ä´Á
        self.prosperity = 0 # ×Ü·±ÈÙ¶È
        self.prosperitySuccessList = [] # ·±ÈÙ¶È´ï±ê³É¾ÍÒÑ´¦ÀíÖµ
        self.playerFreeEatCountDict = {} # Íæ¼ÒÃâ·Ñ³ÔϲÌÇ´ÎÊý {playerID:´ÎÊý, ...}
        self.fireworksCountDict = {} # ÑÌ»¨´ÎÊýÐÅÏ¢ {playerID:´ÎÊý, ...}
        return
    
class PlayerCouple():
    
    def __init__(self, coupleData):
        self.coupleData = coupleData # PyGameDataStruct.tagDBPyCouple()
        
        # ¸üÐÂ×î´óƸÀñID
        self.BridePriceMaxID = 0
        maxCount = IpyGameDataPY.IPY_Data().GetMarryCount()
        for index in range(maxCount)[::-1]:
            ipyData = IpyGameDataPY.IPY_Data().GetMarryByIndex(index)
            priceID = ipyData.GetBridePriceID()
            if self.GetBridePriceBuyCount(priceID):
                self.BridePriceMaxID = priceID
                break
        return
    
    def GetCoupleID(self, playerID):
        return self.coupleData.PlayerIDA if (playerID == self.coupleData.PlayerIDB) else self.coupleData.PlayerIDB
    def GetCoupleName(self, playerID): return PlayerSocial.GetSocialPlayerName(self.GetCoupleID(playerID))
    def GetCoupleJob(self, playerID): return PlayerSocial.GetSocialPlayerJob(self.GetCoupleID(playerID))
    def GetNewMarryTime(self): return self.coupleData.NewMarryTime
    def GetMarryTime(self): return self.coupleData.MarryTime
    def GetBridePriceState(self): return self.coupleData.BridePriceState
    def GetBridePriceBuyCount(self, priceID): return GameWorld.GetDataByDigitPlace(self.coupleData.BridePriceState, priceID - 1)
    def SetBridePriceBuyCount(self, priceID, buyCount):
        self.coupleData.BridePriceState = GameWorld.ChangeDataByDigitPlace(self.coupleData.BridePriceState, priceID - 1, min(buyCount, 9))
        return self.coupleData.BridePriceState
    def GetBreakRequestID(self): return self.coupleData.BreakRequestID
    def GetBreakRequestTime(self): return self.coupleData.BreakRequestTime
    def SetBreakRequestID(self, reqID):
        self.coupleData.BreakRequestID = reqID
        self.coupleData.BreakRequestTime = 0
        if reqID > 0:
            curTime = int(time.time())
            self.coupleData.BreakRequestTime = curTime
            if reqID == self.coupleData.PlayerIDA:
                self.coupleData.BreakRequestTimeA = curTime
            else:
                self.coupleData.BreakRequestTimeB = curTime
        return
    def GetPlayerBreakRequestTime(self, playerID):
        return self.coupleData.BreakRequestTimeA if (playerID == self.coupleData.PlayerIDA) else self.coupleData.BreakRequestTimeB
    def GetSendMapServerCoupleInfo(self, playerID): 
        coupleID = self.GetCoupleID(playerID)
        coupleName = self.GetCoupleName(playerID)
        coupleJob = self.GetCoupleJob(playerID)
        bridePriceMaxID = self.BridePriceMaxID
        return coupleID, coupleName, coupleJob, bridePriceMaxID
    
class DBPyCoupleManager(object):
    ## °éÂÂÊý¾Ý¹ÜÀí
    
    def __init__(self):
        self.coupleDict = {} # {(playerIDA, playerIDB):PlayerCouple, ...}
        self.coupleIDDict = {} # {playerID:(playerIDA, playerIDB), ...} # °é¶ÔÓ¦¹ØÏµ
        return
    
    def DelCouple(self, playerIDA, playerIDB):
        ## É¾³ý°éÂÂÊý¾Ý£¬Èç¹ûÒÑÀë»éÇÒ¾ùÒÑ֪ͨ£¬Ôò¿ÉÖ±½Óɾ³ý
        key = (playerIDA, playerIDB)
        if key in self.coupleDict:
            self.coupleDict.pop(key)
        
        if playerIDA in self.coupleIDDict and self.coupleIDDict[playerIDA] == key:
            self.coupleIDDict.pop(playerIDA)
            
        if playerIDB in self.coupleIDDict and self.coupleIDDict[playerIDB] == key:
            self.coupleIDDict.pop(playerIDB)
        return
    
    def AddCouple(self, playerIDA, playerIDB, coupleData):
        ## Ìí¼ÓаéÂÂ
        coupleKey = (playerIDA, playerIDB)
        couple = PlayerCouple(coupleData)
        self.coupleDict[coupleKey] = couple
        self.coupleIDDict[playerIDA] = coupleKey
        self.coupleIDDict[playerIDB] = coupleKey
        return couple
    
    def GetCouple(self, playerID):
        ## »ñÈ¡°éÂÂ
        coupleData = None
        # ²»¿ÉÄܳÉÁ¢µÄÌõ¼þ£¬Ö»ÊÇΪÁË. Äܳö´úÂëÌáʾָÏò PlayerCouple Àà
        if False:
            coupleData = PlayerCouple(None)
        if playerID not in self.coupleIDDict:
            return coupleData
        coupleKey = self.coupleIDDict[playerID]
        if coupleKey not in self.coupleDict:
            return coupleData
        coupleData = self.coupleDict[coupleKey]
        return coupleData
    
    def SendMapServerCoupleInfo(self, syncPlayerIDList=None):
        ## Í¬²½µØÍ¼°éÂÂÐÅÏ¢
        syncCoupleInfo = {}
        if syncPlayerIDList == None:
            syncPlayerIDList = self.coupleIDDict.keys()
        for playerID in syncPlayerIDList:
            couple = self.GetCouple(playerID)
            if not couple:
                syncCoupleInfo[playerID] = []
            else:
                syncCoupleInfo[playerID] = couple.GetSendMapServerCoupleInfo(playerID)
        GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_CoupleInfo, syncCoupleInfo)
        return
    
    # ±£´æÊý¾Ý ´æÊý¾Ý¿âºÍrealtimebackup
    def GetSaveData(self):
        savaData = ""
        cntData = ""
        cnt = 0
        
        for couple in self.coupleDict.values():
            cnt += 1
            savaData += couple.coupleData.getBuffer()
                
        GameWorld.Log("Save DBPyMarry count :%s len=%s" % (cnt, len(savaData)))
        return CommFunc.WriteDWORD(cntData, cnt) + savaData
    
    # ´ÓÊý¾Ý¿âÔØÈëÊý¾Ý
    def LoadPyGameData(self, datas, pos, dataslen):
        cnt, pos = CommFunc.ReadDWORD(datas, pos)
        GameWorld.Log("Load DBPyMarry count :%s" % cnt)
        
        for _ in xrange(cnt):
            coupleData = PyGameDataStruct.tagDBPyCouple()
            coupleData.clear()
            pos += coupleData.readData(datas, pos, dataslen)
            
            playerIDA = coupleData.PlayerIDA
            playerIDB = coupleData.PlayerIDB
            
            couple = self.AddCouple(playerIDA, playerIDB, coupleData)
            if couple.GetBreakRequestTime() > 0:
                PyGameData.g_marryBreakInfo[(playerIDA, playerIDB)] = couple
                
        SortMarryBreak()
        return pos
    
class DBPyUnNotifyLoveGiftRecManager(object):
    ## Î´Í¨ÖªµÄÔùËÍÀñÎï¼Ç¼¹ÜÀí
    
    def __init__(self):
        self.unNotifyLoveGiftDict = {} # {playerID:[PyGameDataStruct.tagDBPyUnNotifyLoveGiftRec, ...], ...}
        return
    
    def AddUnNotifyGiftRec(self, receivePlayerID, givePlayerID, giftNum, giftCount, sendTime):
        ''' Ìí¼Óδ֪ͨµÄÔùËÍÀñÎï¼Ç¼
        @param receivePlayerID: Î´Í¨ÖªµÄÊÜÔù·½Íæ¼ÒID
        @param givePlayerID: ÔùËÍ·½Íæ¼ÒID
        '''
        recData = PyGameDataStruct.tagDBPyUnNotifyLoveGiftRec()
        recData.PlayerID = receivePlayerID
        recData.GivePlayerID = givePlayerID
        recData.GiftNum = giftNum
        recData.GiftCount = giftCount
        recData.SendTime = sendTime
        
        if receivePlayerID not in self.unNotifyLoveGiftDict:
            self.unNotifyLoveGiftDict[receivePlayerID] = []
        giftList = self.unNotifyLoveGiftDict[receivePlayerID]
        giftList.append(recData)
        return
    
    def LoginNotify(self, curPlayer):
        receivePlayerID = curPlayer.GetPlayerID()
        if receivePlayerID not in self.unNotifyLoveGiftDict:
            return
        giftList = self.unNotifyLoveGiftDict.pop(receivePlayerID, [])
        
        sendGiftList = []
        for recData in giftList:
            giftOK = ChPyNetSendPack.tagGCSendGiftsOK()
            giftOK.PlayerID = recData.GivePlayerID
            giftOK.Name = PlayerSocial.GetSocialPlayerName(recData.GivePlayerID)
            giftOK.NameLen = len(giftOK.Name)
            giftOK.GiftNum = recData.GiftNum
            giftOK.GiftCount = recData.GiftCount
            giftOK.SendTime = recData.SendTime
            sendGiftList.append(giftOK)
            
        clientPack = ChPyNetSendPack.tagGCSendGiftsOKList()
        clientPack.SendGiftsOKList = sendGiftList
        clientPack.Count = len(clientPack.SendGiftsOKList)
        NetPackCommon.SendFakePack(curPlayer, clientPack)
        return
    
    # ±£´æÊý¾Ý ´æÊý¾Ý¿âºÍrealtimebackup
    def GetSaveData(self):
        savaData = ""
        cntData = ""
        cnt = 0
        
        for recDataList in self.unNotifyLoveGiftDict.values():
            for recData in recDataList:
                cnt += 1
                savaData += recData.getBuffer()
                
        GameWorld.Log("Save DBPyUnNotifyLoveGiftRec count :%s len=%s" % (cnt, len(savaData)))
        return CommFunc.WriteDWORD(cntData, cnt) + savaData
    
    # ´ÓÊý¾Ý¿âÔØÈëÊý¾Ý
    def LoadPyGameData(self, datas, pos, dataslen):
        cnt, pos = CommFunc.ReadDWORD(datas, pos)
        GameWorld.Log("Load DBPyUnNotifyLoveGiftRec count :%s" % cnt)
        
        for _ in xrange(cnt):
            recData = PyGameDataStruct.tagDBPyUnNotifyLoveGiftRec()
            recData.clear()
            pos += recData.readData(datas, pos, dataslen)
            
            playerID = recData.PlayerID
            
            if playerID not in self.unNotifyLoveGiftDict:
                self.unNotifyLoveGiftDict[playerID] = []
            recDataList = self.unNotifyLoveGiftDict[playerID]
            recDataList.append(recData)
            
        return pos
    
def AddProsperity(candyObj, addValue):
    candyObj.prosperity += addValue
    
    succProsperityStrList = []
    # ·±ÈÙ¶ÈÈ«·þºì°ü
    redpackDict = IpyGameDataPY.GetFuncEvalCfg("LoveCandyAward", 1, {})
    for prosperityStr, redPackID in redpackDict.items():
        if candyObj.prosperity < int(prosperityStr):
            continue
        if prosperityStr in candyObj.prosperitySuccessList:
            continue
        succProsperityStrList.append(prosperityStr)
        PlayerFamilyRedPacket.CreateSystemRedPacket(redPackID)
        
    # ·±ÈٶȶîÍâ½±Àø
    itemInfoDict = IpyGameDataPY.GetFuncEvalCfg("LoveCandyAward", 2, {})
    for prosperityStr, itemList in itemInfoDict.items():
        if candyObj.prosperity < int(prosperityStr):
            continue
        if prosperityStr in candyObj.prosperitySuccessList:
            continue
        succProsperityStrList.append(prosperityStr)
        
        playerIDList = [candyObj.playerIDA, candyObj.playerIDB]
        paramList = [candyObj.playerNameA, candyObj.playerNameB, prosperityStr]
        PlayerCompensation.SendMailByKey("MarryCandyProsperity", playerIDList, itemList, paramList)
        
    for prosperityStr in succProsperityStrList:
        if prosperityStr not in candyObj.prosperitySuccessList:
            candyObj.prosperitySuccessList.append(prosperityStr)
            
    return
 
def OnServerClose():
    
    for candyObj in PyGameData.g_marryCandySortList:
        __DoMarryCandyOver(candyObj)
        
    return
 
def DoOnDay():
    
    # ÖØÖÃÿÈÕÆ¸Àñ״̬
    syncPlayerIDList = []
    coupleMgr = PyDataManager.GetDBPyCoupleManager()
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetMarryCount()):
        ipyData = ipyDataMgr.GetMarryByIndex(index)
        if not ipyData.GetIsDayReset():
            continue
        bridePriceID = ipyData.GetBridePriceID()
        
        for couple in coupleMgr.coupleDict.values():
            bridePriceState = couple.GetBridePriceState()
            buyCount = couple.GetBridePriceBuyCount(bridePriceID)
            if not buyCount:
                continue
            coupleIDInfo = [couple.coupleData.PlayerIDA, couple.coupleData.PlayerIDB]
            updBridePriceState = couple.SetBridePriceBuyCount(bridePriceID, 0)
            GameWorld.DebugLog("ÖØÖÃÿÈÕÆ¸Àñ´ÎÊý: coupleIDInfo=%s,bridePriceState=%s,bridePriceID=%s,updBridePriceState=%s" 
                               % (coupleIDInfo, bridePriceState, bridePriceID, updBridePriceState))
            syncPlayerIDList.extend(coupleIDInfo)
            
    if syncPlayerIDList:
        playerMgr = GameWorld.GetPlayerManager()
        syncPlayerIDList = list(set(syncPlayerIDList))
        for playerID in syncPlayerIDList:
            curPlayer = playerMgr.FindPlayerByID(playerID)
            if not curPlayer or PlayerControl.GetIsTJG(curPlayer):
                continue
            Sync_CoupleInfo(curPlayer)
            
    return
 
def OnPlayerLogin(curPlayer):
    PyDataManager.GetDBPyUnNotifyLoveGiftRecManager().LoginNotify(curPlayer)
    Sync_CoupleInfo(curPlayer)
    Sync_CandyList(curPlayer)
    return
 
def OnTimeProcess(curTime, tick):
    ## Ã¿Ãë´¥·¢Ò»´Î
    
    # ¼ì²é½áËãϲÌÇ
    doCount = len(PyGameData.g_marryCandySortList)
    while doCount > 0 and PyGameData.g_marryCandySortList:
        doCount -= 1
        candyObj = PyGameData.g_marryCandySortList[0]
        if curTime <= candyObj.endTime:
            break
        
        PyGameData.g_marryCandySortList.pop(0)
        PyGameData.g_marryCandyInfo.pop((candyObj.playerIDA, candyObj.playerIDB), None)
        
        __DoMarryCandyOver(candyObj)
        
    # ¼ì²éºÍÀë
    breakWaitTimes = IpyGameDataPY.GetFuncCfg("LoveMarryBreak", 5)
    doCount = len(PyGameData.g_marryBreakSortList)
    while doCount > 0 and PyGameData.g_marryBreakSortList:
        doCount -= 1
        couple = PyGameData.g_marryBreakSortList[0]
        if curTime <= (couple.GetBreakRequestTime() + breakWaitTimes):
            break
        playerIDA, playerIDB = couple.coupleData.PlayerIDA, couple.coupleData.PlayerIDB
        PyGameData.g_marryBreakSortList.pop(0)
        PyGameData.g_marryBreakInfo.pop((playerIDA, playerIDB), None)
        
        GameWorld.Log("ºÍÀëÌá½»ÇëÇóµ½ÆÚ£¬ÏµÍ³×Ô¶¯ºÍÀë! playerIDA=%s,playerIDB=%s, len(g_marryBreakSortList)=%s" 
                      % (playerIDA, playerIDB, len(PyGameData.g_marryBreakSortList)))
        __DoMarryBreakLogic(couple, 0)
        
    return
 
def __DoMarryCandyOver(candyObj):
    playerIDA, playerIDB, prosperity = candyObj.playerIDA, candyObj.playerIDB, candyObj.prosperity
    GameWorld.Log("½áËã»éÀñϲÌÇÑç»á: playerIDA=%s,playerIDB=%s,prosperity=%s" % (playerIDA, playerIDB, prosperity))
    
    transformItemInfo = IpyGameDataPY.GetFuncEvalCfg("LoveCandyAward", 3)
    if len(transformItemInfo) != 2:
        return
    unitProsperity, itemID = transformItemInfo
    itemCount = int(math.ceil(prosperity / float(unitProsperity)))
    remainSeconds = candyObj.endTime - int(time.time())
    GameWorld.Log("ϲÑç·±ÈÙ¶Èת»¯½±Àø: playerIDA=%s,playerIDB=%s,prosperity=%s,itemID=%s,itemCount=%s,marryTime=%s,endTime=%s,remainSeconds=%s" 
                  % (playerIDA, playerIDB, prosperity, itemID, itemCount,
                     GameWorld.ChangeTimeNumToStr(candyObj.marryTime),
                     GameWorld.ChangeTimeNumToStr(candyObj.endTime), remainSeconds
                     ))
    if not itemID or not itemCount:
        return
    playerIDList = [playerIDA, playerIDB]
    itemList = [[itemID, itemCount, 0]]
    paramList = [candyObj.playerNameA, candyObj.playerNameB, prosperity]
    PlayerCompensation.SendMailByKey("MarryCandyOver", playerIDList, itemList, paramList)
    return
 
#// B3 12 ÌáÇ×»ØÓ¦ #tagCGMarryResponse
#
#struct    tagCGMarryResponse
#{
#    tagHead        Head;
#    DWORD        ReqPlayerID;    // ÌáÇ×µÄÍæ¼ÒID
#    BYTE        IsOK;    // ÊÇ·ñͬÒ⣬0-·ñ£¬1-ÊÇ
#};
def OnMarryResponse(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    reqPlayerID = clientData.ReqPlayerID
    isOK = clientData.IsOK
    
    reqPlayer = GameWorld.GetPlayerManager().FindPlayerByID(reqPlayerID)
    if not __MarryCheckComm(curPlayer, reqPlayer, reqPlayerID, False):
        return
    
    playerID = curPlayer.GetPlayerID()
    if reqPlayerID not in PyGameData.g_marryReqInfo:
        GameWorld.DebugLog("ÌáÇ×ÇëÇó²»´æÔÚ! reqPlayerID=%s" % reqPlayerID, playerID)
        PlayerControl.NotifyCode(curPlayer, "MarryReqInvalid")
        return
    reqData = PyGameData.g_marryReqInfo[reqPlayerID]
    
    if reqData.playerIDB != playerID:
        GameWorld.DebugLog("·ÇĿǰÌáÇ×¶ÔÏó! reqPlayerID=%s, playerIDB(%s) != playerID(%s)" 
                           % (reqPlayerID, reqData.playerIDB, playerID), playerID)
        PlayerControl.NotifyCode(curPlayer, "MarryReqInvalid")
        return
    
    if __CheckMarryReqTimeout(reqData):
        GameWorld.DebugLog("ÌáÇ×ÇëÇóÒѳ¬Ê±! reqPlayerID=%s" % reqPlayerID, playerID)
        PlayerControl.NotifyCode(curPlayer, "MarryReqInvalid")
        PyGameData.g_marryReqInfo.pop(reqPlayerID, None)
        return
    
    __DoMarryResponse(curPlayer, reqPlayer, reqPlayerID, isOK)
    return
 
def __DoMarryResponse(curPlayer, reqPlayer, reqPlayerID, isOK):
    ''' ÌáÇ×»ØÓ¦
    @param curPlayer: »ØÓ¦Íæ¼Ò
    @param reqPlayer: ÌáÇ×Íæ¼Ò
    @param isOK: ÊÇ·ñͳһ
    '''
    reqData = PyGameData.g_marryReqInfo.pop(reqPlayerID, None)
    if not reqData:
        return
    bridePriceID = reqData.bridePriceID
    ipyData = IpyGameDataPY.GetIpyGameData("Marry", bridePriceID)
    if not ipyData:
        return
    
    playerID = curPlayer.GetPlayerID()
    reqPlayerName = reqPlayer.GetName() if reqPlayer else PlayerSocial.GetSocialPlayerName(reqPlayerID)
    playerName = curPlayer.GetName()
    
    responsePack = ChPyNetSendPack.tagGCMarryResponseRet()
    responsePack.PlayerIDA = reqPlayerID
    responsePack.PlayerNameA = reqPlayerName
    responsePack.NameALen = len(responsePack.PlayerNameA)
    responsePack.PlayerIDB = playerID
    responsePack.PlayerNameB = playerName
    responsePack.NameBLen = len(responsePack.PlayerNameB)
    responsePack.IsOK = isOK
    if reqPlayer:
        NetPackCommon.SendFakePack(reqPlayer, responsePack) # ±Ø»Ø¸´ÌáÇ×·½
    # ¾Ü¾ø
    if not isOK:
        return
    NetPackCommon.SendFakePack(curPlayer, responsePack) # »ØÓ¦·½½öͬÒâʱͬ²½
    
    # ===================== ÒÔÏÂÖ´ÐгÉÇ×Âß¼­ ===================== 
    GameWorld.Log("Ö´ÐгÉÇ×: reqPlayerID=%s,playerID=%s,bridePriceID=%s" % (reqPlayerID, playerID, bridePriceID), playerID)
    
    curTime = int(time.time())
    prosperity = ipyData.GetProsperity()
    candyTimes = ipyData.GetCandyTimes()
    brideGiftItemInfo = ipyData.GetBrideGiftItemInfo()
    worldNotifyKey = ipyData.GetWorldNotifyKey()
    if worldNotifyKey:
        paramList = [reqPlayerName, playerName]
        for itemID, itemCount, _ in brideGiftItemInfo:
            paramList.extend([itemID, itemCount])
        PlayerControl.WorldNotify(0, worldNotifyKey, paramList)
        
    coupleMgr = PyDataManager.GetDBPyCoupleManager()
    couple = coupleMgr.GetCouple(playerID)
    if not couple:
        GameWorld.Log("    Ð»é: reqPlayerID=%s,playerID=%s,bridePriceID=%s" % (reqPlayerID, playerID, bridePriceID), playerID)
        coupleData = PyGameDataStruct.tagDBPyCouple()
        coupleData.PlayerIDA = reqPlayerID
        coupleData.PlayerNameA = reqPlayerName
        coupleData.PlayerIDB = playerID
        coupleData.PlayerNameB = playerName
        coupleData.NewMarryTime = curTime
        couple = coupleMgr.AddCouple(reqPlayerID, playerID, coupleData)
        
        # Í¨Öª¸øÏà¹ØÉç½»ÈËÔ±
        PlayerSocial.NotifySocialCoupleChange(reqPlayerID, playerID)
        PlayerSocial.NotifySocialCoupleChange(playerID, reqPlayerID)
        
        # Í¨ÖªµØÍ¼È«¾Ö°éÂÂÐÅÏ¢
        PyDataManager.GetDBPyCoupleManager().SendMapServerCoupleInfo([playerID, reqPlayerID])
    else:
        GameWorld.Log("    Òѻ飬ÔÙ´ÎÌáÇ×: PlayerIDA=%s,PlayerIDB=%s, cur reqPlayerID=%s,playerID=%s,bridePriceID=%s" 
                      % (couple.coupleData.PlayerIDA, couple.coupleData.PlayerIDB, reqPlayerID, playerID, bridePriceID), playerID)
        
    couple.coupleData.MarryTime = curTime
    updBuyCountValue = couple.SetBridePriceBuyCount(bridePriceID, couple.GetBridePriceBuyCount(bridePriceID) + 1)
    GameWorld.Log("    updBuyCountValue=%s" % updBuyCountValue, playerID)
    
    if bridePriceID > couple.BridePriceMaxID:
        couple.BridePriceMaxID = bridePriceID
        GameWorld.Log("    update BridePriceMaxID=%s" % couple.BridePriceMaxID, playerID)
        
    # Í¨ÖªÍæ¼Ò
    for player in [reqPlayer, curPlayer]:
        if not player:
            continue   
        mapServerCoupleInfo = couple.GetSendMapServerCoupleInfo(player.GetPlayerID())
        dataMsg = [reqPlayerID, bridePriceID, mapServerCoupleInfo]
        MapServer_QueryPlayer_DoLogic_Love(player, "MarrySuccess", dataMsg, playerID)
        Sync_CoupleInfo(player)
        
    # Æ¸Àñ½±Àø·¢Óʼþ
    playerIDList = [reqPlayerID, playerID]
    paramList = [reqPlayerName, playerName]
    PlayerCompensation.SendMailByKey("MarrySuccess", playerIDList, brideGiftItemInfo, paramList)
    
    # ÐÂÔöϲÌÇ
    candyObj = MarryCandy()
    candyObj.playerIDA = reqPlayerID
    candyObj.playerNameA = reqPlayerName
    candyObj.playerIDB = playerID
    candyObj.playerNameB = playerName
    candyObj.bridePriceID = bridePriceID
    candyObj.marryTime = curTime
    candyObj.endTime = curTime + candyTimes
    AddProsperity(candyObj, prosperity)
    
    PyGameData.g_marryCandyInfo[(reqPlayerID, playerID)] = candyObj
    __SortCandy()
    Sync_CandyList(None, [candyObj])
    
    PyGameData.g_marryReqInfo.pop(playerID, None) # ¿ÉÄÜ´æÔÚÏ໥ÌáÇ×µÄÇé¿ö£¬³¢ÊÔ˳±ã°Ñ×ÔÉíµÄÌáÇ×ÇëÇóɾ³ý£¬ÒòΪÒѾ­ÎÞÓÃÁË
    return True
 
def __SortCandy():
    PyGameData.g_marryCandySortList = PyGameData.g_marryCandyInfo.values()
    PyGameData.g_marryCandySortList.sort(key=operator.attrgetter("endTime"))
    return
 
def SortMarryBreak():
    PyGameData.g_marryBreakSortList = PyGameData.g_marryBreakInfo.values()
    PyGameData.g_marryBreakSortList.sort(key=operator.attrgetter("coupleData.BreakRequestTime"))
    #GameWorld.DebugLog("SortMarryBreak count=%s" % len(PyGameData.g_marryBreakSortList))
    return
 
def __CheckMarryReqTimeout(reqData):
    ## ¼ì²éÌáÇ×ÊÇ·ñ³¬Ê±
    curTime = int(time.time())
    passSeconds = curTime - reqData.reqTime
    reqSecondCD = IpyGameDataPY.GetFuncCfg("LoveMarry", 1)
    return passSeconds > reqSecondCD
 
#// B3 16 ºÍƽÀë»é»ØÓ¦ #tagGCMarryBreakResponse
#
#struct    tagGCMarryBreakResponse
#{
#    tagHead        Head;
#    BYTE        IsOK;    // ÊÇ·ñͬÒ⣬0-·ñ£¬1-ÊÇ
#};
def OnMarryBreakResponse(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    isOK = clientData.IsOK
    
    playerID = curPlayer.GetPlayerID()
    couple = PyDataManager.GetDBPyCoupleManager().GetCouple(playerID)
    if not couple:
        GameWorld.Log("ûÓа飬ÎÞ·¨»ØÓ¦ºÍÀë! ", playerID)
        return
    coupleID = couple.GetCoupleID(playerID)
    breakRequestID = couple.GetBreakRequestID()
    if not breakRequestID or coupleID != breakRequestID:
        GameWorld.Log("°éÂÂûÓÐÌá³öºÍÀ룬ÎÞ·¨»ØÓ¦ºÍÀë! coupleID=%s,breakRequestID=%s" 
                      % (coupleID, breakRequestID), playerID)
        return
    
    playerIDA, playerIDB = couple.coupleData.PlayerIDA, couple.coupleData.PlayerIDB
    if (playerIDA, playerIDB) in PyGameData.g_marryBreakInfo:
        PyGameData.g_marryBreakInfo.pop((playerIDA, playerIDB), None)
        SortMarryBreak()
        
    if not isOK:
        GameWorld.Log("¾Ü¾øºÍÀë! coupleID=%s" % coupleID, playerID)
        couple.SetBreakRequestID(0) # Çå³ýºÍÀëÇëÇóID
        
        Sync_CoupleInfo(curPlayer)
        tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(coupleID)
        if tagPlayer and not PlayerControl.GetIsTJG(tagPlayer):
            Sync_CoupleInfo(tagPlayer)
        PlayerCompensation.SendMailByKey("MarryBreakRefuse", [coupleID], [], [curPlayer.GetName()])
        return
    
    GameWorld.Log("ͬÒâºÍÀë: coupleID=%s" % coupleID, playerID)
    
    __DoMarryBreakLogic(couple, playerID)
    return
 
def __DoMarryBreakLogic(couple, playerID=0):
    ## Ö´ÐÐÀë»é 
    
    if not couple:
        return
    
    playerIDA = couple.coupleData.PlayerIDA
    playerIDB = couple.coupleData.PlayerIDB
    
    coupleMgr = PyDataManager.GetDBPyCoupleManager()
    
    # Ç×ÃܶȼõÉÙ
    decIntimacyPer = IpyGameDataPY.GetFuncCfg("LoveMarryBreak", 4)
    if decIntimacyPer:
        PyDataManager.GetIntimacyManager().DelIntimacyBothPer(playerIDA, playerIDB, decIntimacyPer)
        
    # Óʼþ֪ͨÀë»é
    for pid in [playerIDA, playerIDB]:
        coupleName = couple.GetCoupleName(pid)
        playerIDList = [pid]
        paramList = [coupleName]
        PlayerCompensation.SendMailByKey("MarryBreakOK", playerIDList, [], paramList)
        
    coupleMgr.DelCouple(playerIDA, playerIDB)
    # Í¨ÖªµØÍ¼È«¾Ö°éÂÂÐÅÏ¢
    PyDataManager.GetDBPyCoupleManager().SendMapServerCoupleInfo([playerIDA, playerIDB])
    
    # Í¨ÖªÍæ¼Ò
    dataMsg = []
    for pid in [playerIDA, playerIDB]:
        tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(pid)
        if tagPlayer and not PlayerControl.GetIsTJG(tagPlayer):
            MapServer_QueryPlayer_DoLogic_Love(tagPlayer, "ClearCoupleSocial", dataMsg, playerID)
            Sync_CoupleInfo(tagPlayer)
            
    # Í¨Öª¸øÏà¹ØÉç½»ÈËÔ±
    PlayerSocial.NotifySocialCoupleChange(playerIDA, 0)
    PlayerSocial.NotifySocialCoupleChange(playerIDB, 0)
    
    if (playerIDA, playerIDB) in PyGameData.g_marryCandyInfo:
        GameWorld.Log("Àë»éʱͬ²½Çå³ýϲÌÇÑç»á: playerIDA=%s, playerIDB=%s" % (playerIDA, playerIDB), playerID)
        PyGameData.g_marryCandyInfo.pop((playerIDA, playerIDB))
        __SortCandy()
        Sync_CandyList(None)
        
    if (playerIDA, playerIDB) in PyGameData.g_marryBreakInfo:
        GameWorld.Log("Àë»éʱͬ²½Çå³ýºÍÀëÇëÇó: playerIDA=%s, playerIDB=%s" % (playerIDA, playerIDB), playerID)
        PyGameData.g_marryBreakInfo.pop((playerIDA, playerIDB), None)
        SortMarryBreak()
        
    return True
 
def MapServer_Love(curPlayer, msgList):
    mapID = curPlayer.GetRealMapID()
    GameWorld.Log("MapServer_Love mapID=%s,msgList=%s" % (mapID, msgList), curPlayer.GetPlayerID())
    if not msgList:
        return
    
    msgType, dataMsg = msgList
    
    # ËÍÀñÎïÇëÇó
    if msgType == "SendGiftsReq":
        ret = __SendGiftsReq(curPlayer, dataMsg)
        
    # ËÍÀñÎï
    elif msgType == "SendGiftsOK":
        __DoSendGiftsOK(curPlayer, dataMsg)
        return
    
    # ÌáÇ×
    elif msgType == "MarryReq":
        __DoMarryReq(curPlayer, dataMsg)
        return
    
    # ³ÔϲÌÇ
    elif msgType == "MarryEatCandy":
        ret = __DoMarryEatCandy(curPlayer, dataMsg)
        
    # ¹ºÂòϲÌÇÑÌ»¨
    elif msgType == "MarryBuyFireworks":
        ret = __DoMarryBuyFireworks(curPlayer, dataMsg)
    
    # Àë»é
    elif msgType == "MarryBreakReq":
        ret = __DoMarryBreakReq(curPlayer, dataMsg)
        
    if ret == None:
        return
    return msgList + [ret]
 
def __SendGiftsReq(curPlayer, dataMsg):
    ## ËÍÀñÎïÇëÇó
    tagPlayerID = dataMsg[0]
    playerID = curPlayer.GetPlayerID()
    
    # ºÚÃûµ¥¼ì²é
    if PyDataManager.GetBlacklistManager().CheckBlacklistBoth(playerID, tagPlayerID, curPlayer):
        return
    
    return True
 
def __DoSendGiftsOK(curPlayer, dataMsg):
    ## ËÍÀñÎï
    
    playerID = curPlayer.GetPlayerID()
    playerName = curPlayer.GetName()
    
    tagPlayerID, giftNum, giftItemID, giftCount, isAutoBuy = dataMsg
    
    ipyData = IpyGameDataPY.GetIpyGameData("LoveGift", giftNum)
    if not ipyData:
        return
    
    addCharmSelf = ipyData.GetAddCharmSelf() * giftCount
    addCharmTag = ipyData.GetAddCharmTag() * giftCount
    addIntimacy = ipyData.GetAddIntimacy() * giftCount
    worldNotifyKey = ipyData.GetWorldNotifyKey()
    
    GameWorld.Log("ÔùËÍÀñÎï: tagPlayerID=%s,giftNum=%s,giftItemID=%s,giftCount=%s,addCharmSelf=%s,addCharmTag=%s,addIntimacy=%s,isAutoBuy=%s" 
                  % (tagPlayerID, giftNum, giftItemID, giftCount, addCharmSelf, addCharmTag, addIntimacy, isAutoBuy), playerID)
    
    tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(tagPlayerID)
    
    PyDataManager.GetIntimacyManager().AddIntimacyBoth(playerID, tagPlayerID, addIntimacy)
    PlayerCharm.AddCharm(curPlayer, playerID, playerID, addCharmSelf)
    PlayerCharm.AddCharm(tagPlayer, tagPlayerID, playerID, addCharmTag)
    
    tagPlayerName = ""
    isOnline = tagPlayer and not PlayerControl.GetIsTJG(tagPlayer)
    if isOnline:
        tagPlayerName = tagPlayer.GetName()
    else:
        tagPlayerName = PlayerSocial.GetSocialPlayerName(tagPlayerID)
        
    if worldNotifyKey:
        PlayerControl.WorldNotify(0, worldNotifyKey, [playerName, tagPlayerName, giftItemID, giftCount])
        
    sendTime = int(time.time())
    if not isOnline:
        PyDataManager.GetDBPyUnNotifyLoveGiftRecManager().AddUnNotifyGiftRec(tagPlayerID, playerID, giftNum, giftCount, sendTime)
        return
    
    # Í¨ÖªÄ¿±êǰ¶ËËÍ»¨³É¹¦
    giftOK = ChPyNetSendPack.tagGCSendGiftsOK()
    giftOK.PlayerID = playerID
    giftOK.Name = playerName
    giftOK.NameLen = len(giftOK.Name)
    giftOK.GiftNum = giftNum
    giftOK.GiftCount = giftCount
    giftOK.SendTime = sendTime
    
    clientPack = ChPyNetSendPack.tagGCSendGiftsOKList()
    clientPack.SendGiftsOKList = [giftOK]
    clientPack.Count = len(clientPack.SendGiftsOKList)
    NetPackCommon.SendFakePack(tagPlayer, clientPack)
    return
 
def MapServer_QueryPlayer_DoLogic_Love(tagPlayer, msgType, dataMsg, playerID=0):
    ## Í¨ÖªÄ¿±êÍæ¼ÒµØÍ¼Ö´ÐРDoLogic
    tagPlayerID = tagPlayer.GetPlayerID()
    tagMapID = tagPlayer.GetRealMapID()
    if tagMapID:
        cmdStr = str([msgType, dataMsg])
        GameWorld.Log("MapServer_QueryPlayer_DoLogic_Love: msgType=%s,tagPlayerID=%s,tagMapID=%s,dataMsg=%s" 
                      % (msgType, tagPlayerID, tagMapID, dataMsg), playerID)
        GameWorld.GetPlayerManager().MapServer_QueryPlayer(0, 0, tagPlayer.GetPlayerID(), tagMapID, "Love",
                                                           cmdStr, len(cmdStr), tagPlayer.GetRouteServerIndex())
    return
 
def __MarryCheckComm(curPlayer, tagPlayer, tagPlayerID, checkIntimacy):
    ## ³ÉÇ×ͨÓüì²é
    
    playerID = curPlayer.GetPlayerID()
    
    # ºÚÃûµ¥¼ì²é
    if PyDataManager.GetBlacklistManager().CheckBlacklistBoth(playerID, tagPlayerID, curPlayer):
        return
    
    if not tagPlayer or PlayerControl.GetIsTJG(tagPlayer):
        PlayerControl.NotifyCode(curPlayer, "LoveOffline") # ÀëÏß
        return
    
    curCouple = PyDataManager.GetDBPyCoupleManager().GetCouple(playerID)
    if curCouple and curCouple.GetCoupleID(playerID) != tagPlayerID:
        PlayerControl.NotifyCode(curPlayer, "HaveCouple") # ÒѾ­ÓÐÆäËû°éÂÂÁË
        return
    
    tagCouple = PyDataManager.GetDBPyCoupleManager().GetCouple(tagPlayerID)
    if tagCouple and tagCouple.GetCoupleID(tagPlayerID) != playerID:
        PlayerControl.NotifyCode(curPlayer, "TagHaveCouple") # ¶Ô·½ÒѾ­ÓÐÆäËû°éÂÂÁË
        return
    
    # »ØÓ¦·½¿É²»¼ì²éÇ×ÃܶÈ
    if checkIntimacy:
        needIntimacy = IpyGameDataPY.GetFuncCfg("LoveMarry", 2)
        curIntimacys = PyDataManager.GetIntimacyManager().GetIntimacys(playerID)
        if not curIntimacys or curIntimacys.GetTagIntimacy(tagPlayerID) < needIntimacy:
            PlayerControl.NotifyCode(curPlayer, "IntimacyLack", [needIntimacy]) # Ç×ÃܶȲ»×ã
            return
        
    return True
 
def __DoMarryReq(curPlayer, dataMsg):
    ## ÌáÇ×
    
    tagPlayerID, bridePriceID = dataMsg
    
    tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(tagPlayerID)
    
    if not __MarryCheckComm(curPlayer, tagPlayer, tagPlayerID, True):
        return
    
    playerID = curPlayer.GetPlayerID()
    
    if (playerID, tagPlayerID) in PyGameData.g_marryCandyInfo or (tagPlayerID, playerID) in PyGameData.g_marryCandyInfo:
        PlayerControl.NotifyCode(curPlayer, "MarryReqLimitByCandy") # Ï²ÑçÖÐÎÞ·¨²Ù×÷
        return
    
    couple = PyDataManager.GetDBPyCoupleManager().GetCouple(playerID)
    if couple:
        coupleID = couple.GetCoupleID(playerID)
        if coupleID != tagPlayerID:
            GameWorld.Log("ÒѳÉÇ×°éÂÂID²»Ò»Ö£¬ÎÞ·¨ÌáÇ×! tagPlayerID(%s) != coupleID(%s)" % (tagPlayerID, coupleID), playerID)
            return
        
        ipyData = IpyGameDataPY.GetIpyGameData("Marry", bridePriceID)
        if not ipyData:
            return
        
        canBuyMax = ipyData.GetCanBuyCount()
        buyCount = couple.GetBridePriceBuyCount(bridePriceID)
        GameWorld.DebugLog("bridePriceID=%s,buyCount=%s,canBuyMax=%s %s" % (bridePriceID, buyCount, canBuyMax, couple.coupleData.BridePriceState))
        if canBuyMax and buyCount >= canBuyMax:
            GameWorld.Log("ƸÀñÌáÇ×´ÎÊý²»×㣬ÎÞ·¨ÌáÇ×! bridePriceID=%s,buyCount(%s) >= canBuyMax(%s)" 
                          % (bridePriceID, buyCount, canBuyMax), playerID)
            return
                
    curTime = int(time.time())
    if tagPlayerID in PyGameData.g_marryReqInfo:
        tagReqData = PyGameData.g_marryReqInfo[tagPlayerID]
        tagBridePriceID = tagReqData.bridePriceID
        if playerID == tagReqData.playerIDB and not __CheckMarryReqTimeout(tagReqData):
            if tagBridePriceID < bridePriceID:
                GameWorld.Log("Íæ¼ÒÌáÇ×ʱ£¬Ä¿±ê¸ÕºÃÒѾ­ÏÈÌá¹ýÇ×£¬ÇÒÔÚÓÐЧÆÚÄÚ£¬Ö±½Ó³ÉÇ×£¡Ê¹Óõ±Ç°ÌáÇ×Íæ¼Ò½Ï¸ßƸÀñIDΪ׼! tagPlayerID=%s,tagBridePriceID=%s < bridePriceID=%s" 
                              % (tagPlayerID, tagBridePriceID, bridePriceID), playerID)
                reqData = MarryReq()
                reqData.playerIDA = playerID
                reqData.playerIDB = tagPlayerID
                reqData.bridePriceID = bridePriceID
                reqData.reqTime = curTime
                PyGameData.g_marryReqInfo[playerID] = reqData
                if __DoMarryResponse(tagPlayer, curPlayer, playerID, 1):
                    return
            GameWorld.Log("Íæ¼ÒÌáÇ×ʱ£¬Ä¿±ê¸ÕºÃÒѾ­ÏÈÌá¹ýÇ×£¬ÇÒÔÚÓÐЧÆÚÄÚ£¬Ö±½Ó³ÉÇ×£¡tagPlayerID=%s,tagBridePriceID=%s,bridePriceID=%s" 
                          % (tagPlayerID, tagBridePriceID, bridePriceID), playerID)
            if __DoMarryResponse(curPlayer, tagPlayer, tagPlayerID, 1):
                return
        else:
            GameWorld.DebugLog("¶Ô·½ÓÐÌáÇ×£¬µ«ÊǶÔÏó²»Ò»Ñù»òÒѳ¬Ê±£¡ tagPlayerID=%s, timeout=%s" % (tagReqData.playerIDB, __CheckMarryReqTimeout(tagReqData)), playerID)
            
    if playerID not in PyGameData.g_marryReqInfo:
        reqData = MarryReq()
        PyGameData.g_marryReqInfo[playerID] = reqData
    else:
        reqData = PyGameData.g_marryReqInfo[playerID]
        
    # Ìáǰ²»ÑéÖ¤£¬Ö±½Ó¸²¸Ç£¬·ÅÔÚ»ØÓ¦ÖÐÑéÖ¤
    reqData.playerIDA = playerID
    reqData.playerIDB = tagPlayerID
    reqData.bridePriceID = bridePriceID
    reqData.reqTime = curTime
    
    # Í¨Öª×Ô¼ºÇëÇó³É¹¦
    NetPackCommon.SendFakePack(curPlayer, ChPyNetSendPack.tagGCMarryReqOK())
    
    # Í¨Öª¶Ô·½
    clientPack = ChPyNetSendPack.tagGCMarryReqInfo()
    clientPack.PlayerID = playerID
    clientPack.PlayerName = curPlayer.GetName()
    clientPack.NameLen = len(clientPack.PlayerName)
    clientPack.BridePriceID = bridePriceID
    NetPackCommon.SendFakePack(tagPlayer, clientPack)
    return
 
def __DoMarryEatCandy(curPlayer, dataMsg):
    ## ³ÔϲÌÇ
    playerIDA, playerIDB, playerID, costMoneyType, costMoneyValue, playerMoneyValue = dataMsg
    
    coupleIDInfo = (playerIDA, playerIDB)
    
    if coupleIDInfo not in PyGameData.g_marryCandyInfo:
        GameWorld.ErrLog("²»´æÔڸûéÀñϲÌÇÑç»á! playerIDA=%s, playerIDB=%s" % (playerIDA, playerIDB))
        return
    candyObj = PyGameData.g_marryCandyInfo[coupleIDInfo]
    
    bridePriceID = candyObj.bridePriceID
    ipyData = IpyGameDataPY.GetIpyGameData("Marry", bridePriceID)
    if not ipyData:
        return
    candyItemInfo = []
    candyItemWeightInfo = ipyData.GetCandyItemWeightInfo()
    candyNotifyItemInfo = ipyData.GetCandyNotifyItemInfo()
    
    playerFreeEatCount = candyObj.playerFreeEatCountDict.get(playerID, 0)
    playerFireworksCount = candyObj.fireworksCountDict.get(playerID, 0)
    
    candyFreeCount = IpyGameDataPY.GetFuncCfg("LoveCandy", 1) # Ãâ·ÑϲÌÇ´ÎÊý
    fireworksCandyCount = IpyGameDataPY.GetFuncCfg("LoveCandyFire", 3) # ¹ºÂòÒ»´ÎÑÌ»¨ÔùËÍϲÌÇ´ÎÊý
    
    totalFreeCount = candyFreeCount + fireworksCandyCount * playerFireworksCount
    isFree = (playerFreeEatCount < totalFreeCount)
    
    canBuy = isFree or (playerMoneyValue >= costMoneyValue)
    GameWorld.Log("³ÔϲÌÇ: coupleIDInfo=%s,costMoneyType=%s,costMoneyValue=%s,playerMoneyValue=%s,playerFireworksCount=%s,playerFreeEatCount=%s,totalFreeCount=%s,isFree=%s,canBuy=%s" 
                  % (coupleIDInfo, costMoneyType, costMoneyValue, playerMoneyValue, playerFireworksCount, playerFreeEatCount, totalFreeCount, isFree, canBuy), playerID)
    if canBuy:
        addProsperityValue = IpyGameDataPY.GetFuncCfg("LoveCandy", 3) # Ï²ÌÇÿ´ÎÔö¼Ó·±ÈÙ¶È
        AddProsperity(candyObj, addProsperityValue)
        if isFree:
            candyObj.playerFreeEatCountDict[playerID] = playerFreeEatCount + 1
        Sync_CandyList(None, [candyObj])
        
        updProsperity = candyObj.prosperity
        updPlayerFreeEatCount = candyObj.playerFreeEatCountDict.get(playerID, 0)
        
        getCandyItemInfo = GameWorld.GetResultByWeightList(candyItemWeightInfo, [])
        if getCandyItemInfo:
            candyItemInfo.append(getCandyItemInfo)
            itemID, itemCount = getCandyItemInfo[:2]
            if itemID in candyNotifyItemInfo:
                PlayerControl.WorldNotify(0, "EatCandyItemNotify", [curPlayer.GetName(), itemID, itemCount])
        GameWorld.Log("¸üÐÂϲÌÇÑç»á: updProsperity=%s,updPlayerFreeEatCount=%s,getCandyItemInfo=%s" 
                      % (updProsperity, updPlayerFreeEatCount, getCandyItemInfo), playerID)
        
    return canBuy, isFree, costMoneyType, costMoneyValue, candyItemInfo
 
def __DoMarryBuyFireworks(curPlayer, dataMsg):
    ## ¹ºÂòϲÌÇÑÌ»¨
    playerIDA, playerIDB, playerID, costMoneyType, costMoneyValue, playerMoneyValue = dataMsg
    
    coupleIDInfo = (playerIDA, playerIDB)
    
    if coupleIDInfo not in PyGameData.g_marryCandyInfo:
        GameWorld.ErrLog("²»´æÔڸûéÀñϲÌÇÑç»áÑÌ»¨! playerIDA=%s, playerIDB=%s" % (playerIDA, playerIDB))
        return
    candyObj = PyGameData.g_marryCandyInfo[coupleIDInfo]
    
    fireworksTotalBuyCount = sum(candyObj.fireworksCountDict.values())
    totalBuyCountLimit = IpyGameDataPY.GetFuncCfg("LoveCandyFire", 1)
    if fireworksTotalBuyCount >= totalBuyCountLimit:
        PlayerControl.NotifyCode(curPlayer, "MarryFireworksSoldout")
        return
    
    addProsperityValue = IpyGameDataPY.GetFuncCfg("LoveCandyFire", 4) # ÑÌ»¨Ï²ÌÇÔùËÍ·±ÈÙ¶È
    
    GameWorld.Log("¹ºÂò»éÀñÑÌ»¨: coupleIDInfo=%s,costMoneyType=%s,costMoneyValue=%s,playerMoneyValue=%s,fireworksCountDict=%s" 
                  % (coupleIDInfo, costMoneyType, costMoneyValue, playerMoneyValue, candyObj.fireworksCountDict), playerID)
        
    AddProsperity(candyObj, addProsperityValue)
    candyObj.fireworksCountDict[playerID] = candyObj.fireworksCountDict.get(playerID, 0) + 1
    Sync_CandyList(None, [candyObj])
    
    GameWorld.Log("¸üлéÀñÑÌ»¨: updProsperity=%s,fireworksCountDict=%s" % (candyObj.prosperity, candyObj.fireworksCountDict), playerID)
    return costMoneyType, costMoneyValue
 
def __DoMarryBreakReq(curPlayer, dataMsg):
    ## Àë»éÇëÇó
    playerID, breakType, moneyType, moneyValue = dataMsg
    
    couple = PyDataManager.GetDBPyCoupleManager().GetCouple(playerID)
    if not couple:
        GameWorld.Log("ûÓа飬²»ÐèÒªÀë»é! ", playerID)
        return
    coupleID = couple.GetCoupleID(playerID)
    
    curTime = int(time.time())
    
    # ¹«¹²CD
    marryTime = couple.GetMarryTime()
    passTime = curTime - marryTime
    marryBreakCD = IpyGameDataPY.GetFuncCfg("LoveMarryBreak", 1)
    if marryBreakCD and passTime < marryBreakCD:
        GameWorld.Log("¾àÀë×î½üÒ»´Î³ÉÇ×Àë»éµÈ´ýʱ¼äδµ½£¬ÎÞ·¨ÇëÇóÀë»é! marryTime=%s,passTime(%s) < %s" 
                      % (GameWorld.ChangeTimeNumToStr(marryTime), passTime, marryBreakCD), playerID)
        return
    
    # ºÍÀë¶îÍâÏÞÖÆ¸öÈËCD
    playerBreakRequestTime = couple.GetPlayerBreakRequestTime(playerID)
    if breakType == 0 and playerBreakRequestTime:
        passTime = curTime - playerBreakRequestTime
        breakReqCD = IpyGameDataPY.GetFuncCfg("LoveMarryBreak", 2)
        if breakReqCD and passTime < breakReqCD:
            GameWorld.Log("¾àÀë×î½üÒ»´ÎÇëÇóºÍÀëµÈ´ýʱ¼äδµ½£¬ÎÞ·¨ÇëÇóÀë»é! playerBreakRequestTime=%s,passTime(%s) < %s" 
                          % (GameWorld.ChangeTimeNumToStr(playerBreakRequestTime), passTime, breakReqCD), playerID)
            return
        
    if couple.GetBreakRequestID() == coupleID:
        GameWorld.Log("ÇëÇóÀë»éʱ¶Ô·½ÒѾ­Ìá³öºÍÀëÁË£¬Ö±½ÓÀë»é! coupleID=%s,breakRequestID=%s" 
                      % (coupleID, couple.GetBreakRequestID()), playerID)        
        __DoMarryBreakLogic(couple, playerID)
        return
    
    # 0-ºÍƽÀë»é£»1-Ç¿ÖÆÀë»é
    if breakType == 0:
        if couple.GetBreakRequestID() != playerID:
            playerIDA, playerIDB = couple.coupleData.PlayerIDA, couple.coupleData.PlayerIDB
            GameWorld.Log("ÐÂÔöÌá½»ºÍÀë! coupleID=%s" % coupleID, playerID)
            couple.SetBreakRequestID(playerID)
            PyGameData.g_marryBreakInfo[(playerIDA, playerIDB)] = couple
            SortMarryBreak()
            playerBreakRequestTime = couple.GetPlayerBreakRequestTime(playerID)
        else:
            GameWorld.Log("ÖØ¸´Ìá½»ºÍÀë! coupleID=%s" % coupleID, playerID)
            
        Sync_CoupleInfo(curPlayer)
        tagPlayer = GameWorld.GetPlayerManager().FindPlayerByID(coupleID)
        if tagPlayer and not PlayerControl.GetIsTJG(tagPlayer):
            Sync_CoupleInfo(tagPlayer)
        return
    
    GameWorld.Log("Ç¿ÖÆÀë»é: coupleID=%s" % coupleID, playerID)
    __DoMarryBreakLogic(couple, playerID)
    
    return moneyType, moneyValue
 
def Sync_CoupleInfo(curPlayer):
    ## Í¬²½°éÂÂÐÅÏ¢
    playerID = curPlayer.GetPlayerID()
    clientPack = ChPyNetSendPack.tagGCCoupleInfo()
    curCouple = PyDataManager.GetDBPyCoupleManager().GetCouple(playerID)
    if curCouple:
        clientPack.CoupleID = curCouple.GetCoupleID(playerID)
        clientPack.CoupleName = curCouple.GetCoupleName(playerID)
        clientPack.NameLen = len(clientPack.CoupleName)
        clientPack.NewMarryTime = curCouple.GetNewMarryTime()
        clientPack.MarryTime = curCouple.GetMarryTime()
        clientPack.BridePriceState = curCouple.GetBridePriceState()
        clientPack.BreakRequestID = curCouple.GetBreakRequestID()
        clientPack.BreakRequestTime = curCouple.GetBreakRequestTime()
        clientPack.PlayerBreakRequestTime = curCouple.GetPlayerBreakRequestTime(playerID)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def Sync_CandyList(curPlayer, syncCandyList=None):
    if syncCandyList == None:
        syncCandyList = PyGameData.g_marryCandySortList
        
    if not syncCandyList:
        return
    
    clientPack = ChPyNetSendPack.tagGCCandyList()
    clientPack.CandyInfoList = []
    for candyObj in PyGameData.g_marryCandySortList:
        candyInfo = ChPyNetSendPack.tagGCCandyInfo()
        candyInfo.PlayerIDA = candyObj.playerIDA
        candyInfo.PlayerNameA = candyObj.playerNameA
        candyInfo.NameALen = len(candyInfo.PlayerNameA)
        candyInfo.PlayerIDB = candyObj.playerIDB
        candyInfo.PlayerNameB = candyObj.playerNameB
        candyInfo.NameBLen = len(candyInfo.PlayerNameB)
        candyInfo.BridePriceID = candyObj.bridePriceID
        candyInfo.MarryTime = candyObj.marryTime
        candyInfo.EndTime = candyObj.endTime
        candyInfo.Prosperity = candyObj.prosperity
        candyInfo.FireworksTotalBuyCount = sum(candyObj.fireworksCountDict.values())
        
        if curPlayer:
            candyInfo.FireworksPlayerBuyCount = candyObj.fireworksCountDict.get(curPlayer.GetPlayerID(), 0)
            candyInfo.PlayerFreeEatCandyCount = candyObj.playerFreeEatCountDict.get(curPlayer.GetPlayerID(), 0)
            
        clientPack.CandyInfoList.append(candyInfo)
    clientPack.CandyCount = len(clientPack.CandyInfoList)
    
    if not curPlayer:
        playerManager = GameWorld.GetPlayerManager()
        for i in xrange(playerManager.GetActivePlayerCount()):
            curPlayer = playerManager.GetActivePlayerAt(i)
            if curPlayer == None:
                continue
            if PlayerControl.GetIsTJG(curPlayer):
                continue
            
            for candyInfo in clientPack.CandyInfoList:
                candyInfo.FireworksPlayerBuyCount = candyObj.fireworksCountDict.get(curPlayer.GetPlayerID(), 0)
                candyInfo.PlayerFreeEatCandyCount = candyObj.playerFreeEatCountDict.get(curPlayer.GetPlayerID(), 0)
                
            NetPackCommon.SendFakePack(curPlayer, clientPack)
    else:
        if PlayerControl.GetIsTJG(curPlayer):
            return
        NetPackCommon.SendFakePack(curPlayer, clientPack)
    return