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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerLove
#
# @todo:ÇéԵϵͳ
# @author hxp
# @date 2021-11-09
# @version 1.0
#
# ÏêϸÃèÊö: ÇéԵϵͳ
#
#-------------------------------------------------------------------------------
#"""Version = 2021-11-09 20:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import ItemCommon
import PlayerControl
import IpyGameDataPY
import ChPyNetSendPack
import FunctionNPCCommon
import IPY_GameWorld
import ItemControler
import NetPackCommon
import ChConfig
import SkillCommon
import BuffSkill
import PyGameData
 
def DoPlayerOnDay(curPlayer):
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveEatCandyToday):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveEatCandyToday, 0)
        Sync_LoveInfo(curPlayer)
    return
 
def DoPlayerLogin(curPlayer):
    Sync_LoveInfo(curPlayer)
    Sync_LoveRingInfo(curPlayer)
    return
 
#// B3 10 ËÍÀñÎï #tagCMSendGifts
#
#struct    tagCMSendGifts
#{
#    tagHead        Head;
#    DWORD        TagPlayerID;    // Ä¿±êÍæ¼ÒID
#    WORD        GiftNum;        // ÔùËÍÀñÎï±àºÅ
#    DWORD        GiftCount;    // ÔùËÍÀñÎïÊýÁ¿
#    BYTE        IsAutoBuy;    // ÊÇ·ñ×Ô¶¯¹ºÂò
#};
def OnSendGifts(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    tagPlayerID = clientData.TagPlayerID
    giftNum = clientData.GiftNum
    giftCount = clientData.GiftCount
    isAutoBuy = clientData.IsAutoBuy
    
    if giftNum <= 0 or giftCount <= 0:
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("LoveGift", giftNum)
    if not ipyData:
        return
    
    giftItemID = ipyData.GetGiftItemID()
    if not ipyData.GetAllowBatch():
        giftCount = 1 # ²»ÔÊÐíÅúÁ¿ÔùË͵ÄĬÈÏÔùËÍ1¸ö
        
    _, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, giftItemID, giftCount)
    lackCnt = giftCount - bindCnt - unBindCnt
    if lackCnt > 0:
        if not isAutoBuy:
            GameWorld.DebugLog("ÀñÎïµÀ¾ß²»×㣬ÎÞ·¨ÔùËÍ! giftItemID=%s,giftCount=%s,bindCnt=%s,unBindCnt=%s,lackCnt=%s" 
                               % (giftItemID, giftCount, bindCnt, unBindCnt, lackCnt))
            return
        
        moneyType = IpyGameDataPY.GetFuncCfg("LoveGift", 1)
        infoDict = {ChConfig.Def_Cost_Reason_SonKey:giftItemID}
        if not FunctionNPCCommon.PayAutoBuyItem(curPlayer, {giftItemID:lackCnt}, moneyType, ChConfig.Def_Cost_Love, infoDict, isCheck=True):
            return
        
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_Love, tick):
        PlayerControl.NotifyCode(curPlayer, "RequestLater")
        return
    
    dataMsg = [tagPlayerID, giftNum, giftItemID, giftCount, isAutoBuy]
    SendToGameServer_Love(curPlayer, "SendGiftsReq", dataMsg)
    return
 
#// B3 11 ÌáÇ× #tagCMMarryReq
#
#struct    tagCMMarryReq
#{
#    tagHead        Head;
#    DWORD        TagPlayerID;    // Ä¿±êÍæ¼ÒID
#    BYTE        BridePriceID;    // Æ¸ÀñID
#};
def OnMarryReq(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    tagPlayerID = clientData.TagPlayerID
    bridePriceID = clientData.BridePriceID
    
    ipyData = IpyGameDataPY.GetIpyGameData("Marry", bridePriceID)
    if not ipyData:
        return
    costMoneyInfo = ipyData.GetCostMoneyInfo()
    if len(costMoneyInfo) != 2:
        return
    moneyType, moneyValue = costMoneyInfo
    
    if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyValue):
        return
    
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_Love, tick):
        PlayerControl.NotifyCode(curPlayer, "RequestLater")
        return
    
    dataMsg = [tagPlayerID, bridePriceID]
    SendToGameServer_Love(curPlayer, "MarryReq", dataMsg)
    return
 
#// B3 13 ³ÔϲÌÇ #tagCMMarryEatCandy
#
#struct    tagCMMarryEatCandy
#{
#    tagHead        Head;
#    DWORD        PlayerIDA;    // Ï²ÌÇËùÊôÍæ¼ÒIDA
#    DWORD        PlayerIDB;    // Ï²ÌÇËùÊôÍæ¼ÒIDB
#};
def OnMarryEatCandy(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    playerIDA = clientData.PlayerIDA
    playerIDB = clientData.PlayerIDB
    
    playerID = curPlayer.GetPlayerID()
    
    EatCandyMax = IpyGameDataPY.GetFuncCfg("LoveCandy", 4)
    if EatCandyMax:
        eatCandyToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveEatCandyToday)
        if eatCandyToday >= EatCandyMax:
            GameWorld.DebugLog("ÒÑ´ï½ñÈÕ³ÔϲÌÇ´ÎÊýÉÏÏÞ. eatCandyToday=%s >= %s" % (eatCandyToday, EatCandyMax), playerID)
            return
        
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_Love, tick):
        PlayerControl.NotifyCode(curPlayer, "RequestLater")
        return
    
    costMoneyType, costMoneyValue = IpyGameDataPY.GetFuncEvalCfg("LoveCandy", 2)
    playerMoneyValue = PlayerControl.GetMoney(curPlayer, costMoneyType)
    
    dataMsg = [playerIDA, playerIDB, playerID, costMoneyType, costMoneyValue, playerMoneyValue]
    SendToGameServer_Love(curPlayer, "MarryEatCandy", dataMsg)
    return
 
 
#// B3 14 ¹ºÂò»éÀñÑÌ»¨ #tagCMMarryBuyFireworks
#
#struct    tagCMMarryBuyFireworks
#{
#    tagHead        Head;
#    DWORD        PlayerIDA;    // Ï²ÌÇËùÊôÍæ¼ÒIDA
#    DWORD        PlayerIDB;    // Ï²ÌÇËùÊôÍæ¼ÒIDB
#};
def OnMarryBuyFireworks(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    playerIDA = clientData.PlayerIDA
    playerIDB = clientData.PlayerIDB
    
    playerID = curPlayer.GetPlayerID()
    
    costMoneyType, costMoneyValue = IpyGameDataPY.GetFuncEvalCfg("LoveCandyFire", 2)
    if not PlayerControl.HaveMoney(curPlayer, costMoneyType, costMoneyValue):
        return
    playerMoneyValue = PlayerControl.GetMoney(curPlayer, costMoneyType)    
    
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_Love, tick):
        PlayerControl.NotifyCode(curPlayer, "RequestLater")
        return
    
    dataMsg = [playerIDA, playerIDB, playerID, costMoneyType, costMoneyValue, playerMoneyValue]
    SendToGameServer_Love(curPlayer, "MarryBuyFireworks", dataMsg)
    return
 
#// B3 15 Àë»é #tagCMMarryBreak
#
#struct    tagCMMarryBreak
#{
#    tagHead        Head;
#    BYTE        BreakType;    // 0-ºÍƽÀë»é£»1-Ç¿ÖÆÀë»é
#};
def OnMarryBreak(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    breakType = clientData.BreakType
    playerID = curPlayer.GetPlayerID()
    
    moneyType, moneyValue = 0, 0
    if breakType == 1:
        costMoneyInfo = IpyGameDataPY.GetFuncEvalCfg("LoveMarryBreak", 3)
        if len(costMoneyInfo) != 2:
            return
        moneyType, moneyValue = costMoneyInfo
        
        if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyValue):
            return
        
    if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_Love, tick):
        PlayerControl.NotifyCode(curPlayer, "RequestLater")
        return
    
    dataMsg = [playerID, breakType, moneyType, moneyValue]
    SendToGameServer_Love(curPlayer, "MarryBreakReq", dataMsg)
    return
 
def SendToGameServer_Love(curPlayer, msgType, dataMsg):
    ## ·¢ËÍÐÅÏ¢µ½¿ç·þ·þÎñÆ÷
    msgList = str([msgType, dataMsg])
    GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetPlayerID(), 0, 0, "Love", msgList, len(msgList))
    GameWorld.Log("ÇéÔµ·¢ËÍGameServer: %s, %s" % (msgType, dataMsg), curPlayer.GetPlayerID())
    return
 
def GameServer_Love_DoLogic(curPlayer, msgData):
    
    msgType, dataMsg = msgData[:2]
    
    ## ½á»é³É¹¦
    if msgType == "MarrySuccess":
        __DoMarrySuccess(curPlayer, dataMsg)
    
    ## Àë»é³É¹¦
    elif msgType == "ClearCoupleSocial":
        __ClearCoupleSocial(curPlayer, dataMsg)
    
    ## Í¬²½Ç×ÃܶÈ
    elif msgType == "SyncMapServerIntimacy":
        SyncMapServerIntimacy(curPlayer, dataMsg)
        
    return
 
def GameServer_Love_DoResult(curPlayer, msgData):
    
    msgType, dataMsg, ret = msgData
    
    ## ËÍÀñÎïÇëÇó·µ»Ø
    if msgType == "SendGiftsReq":
        if not ret:
            return
        __DoSendGiftsReq(curPlayer, dataMsg)
        
    ## ³ÔϲÌÇ·µ»Ø
    elif msgType == "MarryEatCandy":
        if not ret:
            return
        __DoMarryEatCandy(curPlayer, ret)
        
    ## ¹ºÂò»éÀñÑÌ»¨·µ»Ø
    elif msgType == "MarryBuyFireworks":
        if not ret:
            return
        __DoMarryBuyFireworks(curPlayer, ret)
        
    ## Àë»éÇëÇó·µ»Ø
    elif msgType == "MarryBreakReq":
        if not ret:
            return
        __DoMarryBreakReq(curPlayer, ret)
        
    return
 
def __DoSendGiftsReq(curPlayer, dataMsg):
    ## ËÍÀñÎï·½´¦Àí
    
    playerID = curPlayer.GetPlayerID()
    tagPlayerID, giftNum, giftItemID, giftCount, isAutoBuy = dataMsg
    
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, giftItemID, giftCount)
    lackCnt = giftCount - bindCnt - unBindCnt
    delCnt = giftCount
    if lackCnt > 0:
        if not isAutoBuy:
            GameWorld.ErrLog("ÀñÎïµÀ¾ß²»×㣬ÎÞ·¨ÔùËÍ! giftItemID=%s,giftCount=%s,bindCnt=%s,unBindCnt=%s,lackCnt=%s" 
                             % (giftItemID, giftCount, bindCnt, unBindCnt, lackCnt))
            return
        
        moneyType = IpyGameDataPY.GetFuncCfg("LoveGift", 1)
        infoDict = {ChConfig.Def_Cost_Reason_SonKey:giftItemID}
        if not FunctionNPCCommon.PayAutoBuyItem(curPlayer, {giftItemID:lackCnt}, moneyType, ChConfig.Def_Cost_Love, infoDict):
            return
        delCnt -= lackCnt
        
    GameWorld.Log("ÔùËÍÀñÎï: tagPlayerID=%s,giftNum=%s,giftItemID=%s,giftCount=%s,isAutoBuy=%s" 
                  % (tagPlayerID, giftNum, giftItemID, giftCount, isAutoBuy), playerID)
    
    # ¿Û³ýÏûºÄ
    if delCnt > 0:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delCnt, "Love")
        
    SendToGameServer_Love(curPlayer, "SendGiftsOK", dataMsg)
    return
 
def __DoMarryEatCandy(curPlayer, retInfo):
    ## Ö´ÐгÔϲÌǽá¹û
    
    canBuy, isFree, costMoneyType, costMoneyValue, candyItemInfo = retInfo
    
    if not isFree:
        if not PlayerControl.HaveMoney(curPlayer, costMoneyType, costMoneyValue):
            return
        
    if not canBuy:
        return
    
    updEatCandyToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveEatCandyToday) + 1
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveEatCandyToday, updEatCandyToday)
    Sync_LoveInfo(curPlayer)
    
    GameWorld.Log("³ÔϲÌǽá¹û: isFree=%s,updEatCandyToday=%s" % (isFree, updEatCandyToday), curPlayer.GetPlayerID())
    
    if not isFree:
        infoDict = {ChConfig.Def_Cost_Reason_SonKey:"EatCandy"}
        PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, ChConfig.Def_Cost_Love, infoDict, isMinus=True)
        
    ItemControler.GivePlayerItemOrMail(curPlayer, candyItemInfo)
    return
    
def __DoMarryBuyFireworks(curPlayer, retInfo):
    ## Ö´ÐйºÂò»éÀñÑÌ»¨½á¹û
    
    costMoneyType, costMoneyValue = retInfo
    GameWorld.Log("Ö´ÐйºÂò»éÀñÑÌ»¨½á¹û: costMoneyType=%s, costMoneyValue=%s" % (costMoneyType, costMoneyValue), curPlayer.GetPlayerID())
    
    infoDict = {ChConfig.Def_Cost_Reason_SonKey:"MarryBuyFireworks"}
    PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, ChConfig.Def_Cost_Love, infoDict, isMinus=True)
    return
    
def __DoMarryBreakReq(curPlayer, retInfo):
    ## Àë»éÇëÇó½á¹û·µ»Ø
    
    costMoneyType, costMoneyValue = retInfo
    GameWorld.Log("Ö´ÐÐÇ¿ÖÆÀë»éÇëÇó½á¹û: costMoneyType=%s, costMoneyValue=%s" % (costMoneyType, costMoneyValue), curPlayer.GetPlayerID())
    
    infoDict = {ChConfig.Def_Cost_Reason_SonKey:"MarryBreak"}
    PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, ChConfig.Def_Cost_Love, infoDict, isMinus=True)
    return
 
def __DoMarrySuccess(curPlayer, dataMsg):
    ## Ö´ÐгÉÇ׳ɹ¦
    reqPlayerID, bridePriceID, mapServerCoupleInfo, coupleIntimacy = dataMsg
    playerID = curPlayer.GetPlayerID()
    PlayerControl.SetCoupleInfo(playerID, mapServerCoupleInfo)
    
    GameWorld.Log("Ö´ÐгÉÇ׳ɹ¦! reqPlayerID=%s,bridePriceID=%s,coupleIntimacy=%s" % (reqPlayerID, bridePriceID, coupleIntimacy), playerID)
    
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingClassLV) == 0:
        GameWorld.DebugLog("¼¤»îÇé½ä!")
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingClassLV, 1)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingStarLV, 1)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingEatCount, 0)
        Sync_LoveRingInfo(curPlayer)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveCoupleIntimacy, coupleIntimacy)
    RefreshCoupleTeamBuff(curPlayer)
    
    # ÌáÇ×µÄÍæ¼Ò¿Û³ýÏûºÄ
    if playerID == reqPlayerID:
        ipyData = IpyGameDataPY.GetIpyGameData("Marry", bridePriceID)
        if ipyData:
            moneyType, moneyValue = ipyData.GetCostMoneyInfo()
            infoDict = {ChConfig.Def_Cost_Reason_SonKey:"MarrySuccess", "bridePriceID":bridePriceID}
            PlayerControl.PayMoney(curPlayer, moneyType, moneyValue, ChConfig.Def_Cost_Love, infoDict, isMinus=True)
            
    RefreshLoveAttr(curPlayer)
    return
 
def __ClearCoupleSocial(curPlayer, dataMsg):
    ## Àë»é - Çå³ý°é¹Øϵ
    
    playerID = curPlayer.GetPlayerID()
    
    coupleID = PlayerControl.GetCoupleID(curPlayer)
    PlayerControl.SetCoupleInfo(playerID, None)
    
    GameWorld.Log("Çå³ý°é¹Øϵ³É¹¦! coupleID=%s" % (coupleID), playerID)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveCoupleIntimacy, 0)
    RefreshCoupleTeamBuff(curPlayer)
    
    RefreshLoveAttr(curPlayer)
    return
 
#// B3 17 Çé½ä½âËø #tagCMLoveRingUnlock
#
#struct    tagCMLoveRingUnlock
#{
#    tagHead        Head;
#};
def OnLoveRingUnlock(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    unlockItemID = IpyGameDataPY.GetFuncCfg("LoveRing", 1)
    
    unlockItem = ItemCommon.FindItemInPackByItemID(curPlayer, unlockItemID, IPY_GameWorld.rptItem)
    if not ItemCommon.CheckItemCanUse(unlockItem):
        GameWorld.DebugLog("ÎïÆ·½âËøÇé½äȱÉÙµÀ¾ß! unlockItemID=%s" % unlockItemID, playerID)
        return
    ItemCommon.DelItem(curPlayer, unlockItem, 1)
    
    classLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingClassLV)
    if classLV < 1:
        GameWorld.DebugLog("ÎïÆ·½âËøÇé½ä!", playerID)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingClassLV, 1)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingStarLV, 1)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingEatCount, 0)
        Sync_LoveRingInfo(curPlayer)
        RefreshLoveAttr(curPlayer)
        
    NetPackCommon.SendFakePack(curPlayer, ChPyNetSendPack.tagMCLoveRingUnlockOK())
    return
 
#// B3 18 Çé½äÉý¼¶ #tagCMLoveRingUp
#
#struct    tagCMLoveRingUp
#{
#    tagHead        Head;
#    DWORD        UseItemCnt;        //ÏûºÄ²ÄÁϸöÊý
#};
def OnLoveRingUp(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    costItemCount = clientData.UseItemCnt # ÏûºÄ²ÄÁϸöÊý
    #isAutoBuy = False # ±¾¹¦ÄÜÔݲ»Ìṩ×Ô¶¯¹ºÂò
    playerID = curPlayer.GetPlayerID()
    
    classLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingClassLV)
    if not classLV:
        GameWorld.DebugLog("Çé½äδ½âËø!", playerID)
        return
    
    starLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingStarLV)
    curEatItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingEatCount)
    
    ringIpyData = IpyGameDataPY.GetIpyGameData("LoveRing", classLV, starLV)
    if not ringIpyData:
        return
    needEatCount = ringIpyData.GetNeedEatCount()
    
    if not needEatCount:
        GameWorld.DebugLog("Çé½äÒÑÂú¼¶£¡classLV=%s,starLV=%s" % (classLV, starLV), playerID)
        return
    
    costItemID = IpyGameDataPY.GetFuncCfg("LoveRing", 2)
    if not costItemID or costItemCount <= 0:
        return
    
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, costItemID, costItemCount)
    lackCnt = costItemCount - bindCnt - unBindCnt
    if lackCnt > 0:
        GameWorld.DebugLog("ÏûºÄµÀ¾ß²»×㣬ÎÞ·¨Éý¼¶Çé½ä! costItemID=%s,costItemCount=%s,bindCnt=%s,unBindCnt=%s,lackCnt=%s" 
                           % (costItemID, costItemCount, bindCnt, unBindCnt, lackCnt), playerID)
        return
    delCnt = costItemCount
    
    updClassLV, updStarLV = classLV, starLV
    updEatItemCount = curEatItemCount + costItemCount
    GameWorld.DebugLog("Çé½äÉý¼¶: classLV=%s,starLV=%s,curEatItemCount=%s,costItemCount=%s,updEatItemCount=%s,needEatCount=%s" 
                       % (classLV, starLV, curEatItemCount, costItemCount, updEatItemCount, needEatCount), playerID)
    
    ringUpType = ""
    if updEatItemCount >= needEatCount:
        ringUpType = "starUp"
        updStarLV += 1
        nextRingIpyData = IpyGameDataPY.GetIpyGameDataNotLog("LoveRing", updClassLV, updStarLV)
        if not nextRingIpyData:
            updClassLV += 1
            updStarLV = 1
            nextRingIpyData = IpyGameDataPY.GetIpyGameData("LoveRing", updClassLV, updStarLV)
            if not nextRingIpyData:
                GameWorld.ErrLog("Çé½äÉý¼¶Êý¾ÝÒì³£: classLV=%s,starLV=%s,curEatItemCount=%s,costItemCount=%s,updEatItemCount=%s,needEatCount=%s" 
                       % (classLV, starLV, curEatItemCount, costItemCount, updEatItemCount, needEatCount), playerID)
                return
            ringUpType = "classUp"
        updEatItemCount -= needEatCount
        
    # ¿Û³ýÏûºÄ
    if delCnt:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delCnt, "Love")
        
    # ÉýÐÇ
    if ringUpType == "starUp":
        GameWorld.DebugLog("    ÉýÐÇ: updClassLV=%s,updStarLV=%s,updEatItemCount=%s" % (updClassLV, updStarLV, updEatItemCount), playerID)
        
    # Éý½×
    elif ringUpType == "classUp":
        GameWorld.DebugLog("    Éý½×: updClassLV=%s,updStarLV=%s,updEatItemCount=%s" % (updClassLV, updStarLV, updEatItemCount), playerID)
        
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingClassLV, updClassLV)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingStarLV, updStarLV)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveRingEatCount, updEatItemCount)
    
    Sync_LoveRingInfo(curPlayer)
    RefreshLoveAttr(curPlayer)
    return
 
def RefreshLoveAttr(curPlayer):
    CalcLoveAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    return
 
def CalcLoveAttr(curPlayer):
    
    classLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingClassLV)
    starLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingStarLV)
    
    coupleID = PlayerControl.GetCoupleID(curPlayer)
    
    allAttrList = [{} for _ in range(4)]
    allAttrListCouple = [{} for _ in range(4)]
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in xrange(ipyDataMgr.GetLoveRingCount()):
        ringIpyData = ipyDataMgr.GetLoveRingByIndex(index)
        dataClassLV = ringIpyData.GetRingClassLV()
        dataStarLV = ringIpyData.GetRingStarLV()
        if dataClassLV > classLV or (dataClassLV == classLV and dataStarLV > starLV):
            break
        elif dataClassLV == classLV and dataStarLV == starLV:
            upItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingEatCount)
        else:
            upItemCount = ringIpyData.GetNeedEatCount()
            
        # ½×ÐÇÊôÐÔ
        starAttrTypeList = ringIpyData.GetStarAttrType()
        starAttrValueList = ringIpyData.GetStarAttrValue()
        for i, attrID in enumerate(starAttrTypeList):
            attrValue = starAttrValueList[i]
            PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList)
        
        # Éý¼¶¸öÊýÊôÐÔ
        upItemPerCount = ringIpyData.GetUpEatItemPerCount()
        if upItemCount and upItemPerCount:
            upItemAttrTypeList = ringIpyData.GetUpItemAttrType()
            upItemAttrValueList = ringIpyData.GetUpItemAttrValue()
            attrMultiple = upItemCount / upItemPerCount
            for i, attrID in enumerate(upItemAttrTypeList):
                attrValue = upItemAttrValueList[i]
                PlayerControl.CalcAttrDict_Type(attrID, attrValue * attrMultiple, allAttrList)
                
        # ÏÉÂÂÊôÐÔ
        if coupleID:
            coupleAttrTypeList = ringIpyData.GetCoupleAttrType()
            coupleAttrValueList = ringIpyData.GetCoupleAttrValue()
            for i, attrID in enumerate(coupleAttrTypeList):
                attrValue = coupleAttrValueList[i]
                PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrListCouple)
                
    #GameWorld.DebugLog("Çé½ä»ù´¡ÊôÐÔ: classLV=%s,starLV=%s,allAttrList=%s" % (classLV, starLV, allAttrList))
    #GameWorld.DebugLog("Çé½äÏÉÂÂÊôÐÔ: classLV=%s,starLV=%s,allAttrListCouple=%s" % (classLV, starLV, allAttrListCouple))
    
    # ±£´æ¼ÆËãÖµ
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_LoveRing, allAttrList)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_LoveRingCouple, allAttrListCouple)
    return
 
def Sync_LoveRingInfo(curPlayer):
    ## Í¬²½Çé½äÐÅÏ¢
    clientPack = ChPyNetSendPack.tagMCLoveRingInfo()
    clientPack.ClassLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingClassLV)
    clientPack.StarLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingStarLV)
    clientPack.EatCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveRingEatCount)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def Sync_LoveInfo(curPlayer):
    ## Í¬²½ÇéÔµÏà¹ØÐÅÏ¢
    clientPack = ChPyNetSendPack.tagMCLoveInfo()
    clientPack.EatCandyToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveEatCandyToday)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return
 
def SyncMapServerIntimacy(curPlayer, dataMsg):
    tagID, intimacyValue = dataMsg
    coupleID = PlayerControl.GetCoupleID(curPlayer)
    if coupleID == tagID:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LoveCoupleIntimacy, intimacyValue)
        RefreshCoupleTeamBuff(curPlayer)
    return
 
def RefreshCoupleTeamBuff(curPlayer):
    ## Ë¢Ð°éÂÂ×é¶Óbuff
    
    teamID = curPlayer.GetTeamID()
    playerID = curPlayer.GetPlayerID()
    cupleID = PlayerControl.GetCoupleID(curPlayer)
    teamPlayerInfoDict = PyGameData.g_teamPlayerInfoDict.get(teamID, {}) if teamID else {}
    teamPlayerIDList = teamPlayerInfoDict.keys()
    skillLV = 0
    skillTypeID = IpyGameDataPY.GetFuncCfg("IntimacyBuff", 2)
    coupleIntimacy = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LoveCoupleIntimacy)
    if cupleID and cupleID in teamPlayerIDList:
        skillLVIntimacyList = IpyGameDataPY.GetFuncEvalCfg("IntimacyBuff", 1)
        for lv, lvIntimacy in enumerate(skillLVIntimacyList, 1):
            if coupleIntimacy >= lvIntimacy:
                skillLV = lv
            else:
                break
            
    GameWorld.DebugLog("ˢаéÂÂ×é¶ÓBuff: cupleID=%s,coupleIntimacy=%s,teamID=%s,teamPlayerIDList=%s,skillTypeID=%s,skillLV=%s" 
                       % (cupleID, coupleIntimacy, teamID, teamPlayerIDList, skillTypeID, skillLV), playerID)
    tick = GameWorld.GetGameWorld().GetTick()
    if skillLV > 0:
        findBuff = SkillCommon.FindBuffByID(curPlayer, skillTypeID)[0]
        if findBuff:
            if skillLV == findBuff.GetSkill().GetSkillLV():
                return
            BuffSkill.DelBuffBySkillID(curPlayer, skillTypeID, tick)
        SkillCommon.AddBuffBySkillType(curPlayer, skillTypeID, tick, skillLV)
    else:
        if BuffSkill.DelBuffBySkillID(curPlayer, skillTypeID, tick):
            #ͳһˢÐÂ״̬
            playerControl = PlayerControl.PlayerControl(curPlayer)
            playerControl.RefreshPlayerAttrByBuff()
            
    return