xdh
2019-03-02 0f297a5b66b91751d8342624db871efeca7ed94e
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerMagicWeapon
#
# @todo:·¨±¦ÏµÍ³
# @author xdh
# @date 2017-05-18
# @version 1.0
#
# ÏêϸÃèÊö: ·¨±¦ÏµÍ³
#
#-------------------------------------------------------------------------------
#"""Version = 2017-05-18 12:00"""
#-------------------------------------------------------------------------------
 
import ItemCommon
import ShareDefine
import NetPackCommon
import DataRecordPack
import ChPyNetSendPack
import PlayerControl
import IPY_GameWorld
import SkillCommon
import GameWorld
import ChConfig
import IpyGameDataPY
import SkillShell
import GameFuncComm
import PlayerSuccess
import EventShell
import PassiveBuffEffMng
import ItemControler
import PlayerActivity
import ChEquip
import PlayerVip
 
import random
 
g_succInfoDict = {}
g_potentialsSkillDict = {}
##µÇ¼´¦Àí
# @param curPlayer Íæ¼Ò
# @return None
def PlayerMagicWeaponLogin(curPlayer):
    NotifyMagicWeapon(curPlayer, True)
    SyncXBXZAwardRecord(curPlayer)
    Sycn_MagicWeaponLV(curPlayer)
    Sycn_MWPrivilegeData(curPlayer)
    return
 
def OnDay(curPlayer):
    #ÖØÖ÷¨±¦Ö®»êÿÈÕÁìÈ¡¼Ç¼
    for privilege in ChConfig.MWPrivilegeList:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWSoulGotItemState % privilege, 0)
    Sycn_MWPrivilegeData(curPlayer, isForce=True)
    return
 
def DoMagicWeaponOpen(curPlayer):
    ## ·¨±¦¹¦ÄÜ¿ªÆô ¼¤»îµÚÒ»¸ö·¨±¦
#    ipyData = IpyGameDataPY.IPY_Data().GetTreasureByIndex(0)
#    mwID = ipyData.GetID()
#    GameWorld.DebugLog("·¨±¦¹¦ÄÜ¿ªÆô ¼¤»îµÚÒ»¸ö·¨±¦ mwID=%s"%mwID)
#    DoActiveMW(curPlayer, mwID)
#    NotifyMagicWeapon(curPlayer)
    return True
 
def GetIsActiveMagicWeapon(curPlayer, mwID, lv=0):
    #»ñÈ¡·¨±¦ÊÇ·ñ¼¤»î
    #ͨ¹ýÍæ¼Ò×ÖµäÖµ¿ÉÖ±½ÓÅжÏÊÇ·ñÒѾ­¼¤»î£¬ÕâÀï¿É²»ÑéÖ¤·¨±¦IDÊÇ·ñ´æÔÚ£¬¼´Ê¹´«Èë²»´æÔÚµÄÒ²ÊÇ·µ»ØÎ´¼¤»î
    #if not GetWMIpyData(mwID):
    #    return False
    if lv:
        curMWLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % mwID)
        return curMWLV >= lv
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsActive, mwID % 100, True, [mwID / 100])
 
def SetMagicWeaponActiveState(curPlayer, mwID, isActive=True):
    #ÉèÖ÷¨±¦¼¤»î״̬
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsActive, mwID % 100, isActive, True, [mwID / 100])
    return
 
def ActiveMagicWeapon(curPlayer, succID):
    ##¼¤»î·¨±¦
    mwID = GetMWIDBySuccID(succID)
    if mwID == None:
        return
    
    isActive = GetIsActiveMagicWeapon(curPlayer, mwID)
    if isActive:
        return
    succIDList = GetNeedSuccIDByMWID(mwID)
    needExp = len(succIDList)
    curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponExp % mwID)
    
    if curExp >= needExp:
        return
    
    newExp = min(needExp, curExp + 1)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponExp % mwID, newExp)
    DataRecordPack.DR_MagicWeaponExp(curPlayer, mwID, succID, newExp, needExp)
    ipyData = GetWMIpyData(mwID)
    needItemDict = ipyData.GetNeedItem()
    #GameWorld.DebugLog('    ¼¤»î·¨±¦ mwID=%s,curExp=%s,succIDList=%s' % (mwID, newExp,succIDList))
    if newExp >= needExp and not needItemDict:
        #³É¾ÍÌõ¼þ´ï³É ¼¤»î·¨±¦
        DoActiveMW(curPlayer, mwID)
        
    return
 
def DoActiveMW(curPlayer, mwID, mwLV=0):
    if not GetWMIpyData(mwID):
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponLV % mwID, mwLV)
    if mwLV == 0:
        SetMagicWeaponActiveState(curPlayer, mwID)
        #֪ͨ
        NotifyMagicWeapon(curPlayer)
        
        
        if mwID in IpyGameDataPY.GetFuncEvalCfg('UnblockTreasure'):
            PlayerControl.NotifyCode(curPlayer, 'UnblockTreasure', [curPlayer.GetName(), mwID])
        else:
            sysMark = IpyGameDataPY.GetFuncEvalCfg('UnblockTreasure', 2, {}).get(mwID, 'UnblockTreasure')
            PlayerControl.WorldNotify(0, sysMark, [curPlayer.GetName(), mwID])
        
        #ÈÎÎñ
        EventShell.EventRespons_OnActiveMagicWeapon(curPlayer, mwID)
    else:
        
        #֪ͨ¿Í»§¶ËµÈ¼¶
        Sycn_MagicWeaponLV(curPlayer, mwID)
        EventShell.EventRespons_MagicWeaponLV(curPlayer, mwID, mwLV)
    #³É¾Í
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_GetMagicWeapon, 1, [mwID, mwLV])
 
    #½âËø¼¼ÄÜ
    upIpyData = IpyGameDataPY.GetIpyGameData('TreasureUp', mwID, mwLV)
    if not upIpyData:
        return
    skillIDList = upIpyData.GetUnLockSkill()
    for skillID in skillIDList:
        GiveSkill(curPlayer, skillID, GameWorld.GetGameWorld().GetTick())
    #ÎïÆ·½±Àø
    itemAward = upIpyData.GetItemAward()
    if itemAward:
        itemID, itemCnt, isBind = itemAward
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, 1)
        if 1 > packSpace:
            PlayerControl.SendMailByKey('TreasureWakeUp', [curPlayer.GetID()], [itemAward])
        else:
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, isBind,
                                             [IPY_GameWorld.rptItem], True, showSysInfo=True, event=["MWAward", False, {"mwID":mwID}])
    activeMWID = upIpyData.GetActiveMWID()
    if activeMWID == mwID:
        GameWorld.ErrLog('    TreasureUp.txt ÅäÖÃÒì³£ ²»¿É¼¤»î×ÔÉí·¨±¦ mwID=%s'%mwID)
    elif activeMWID:
        DoActiveMW(curPlayer, activeMWID)
    
    #¼¤»î»ê
    activeSoulID = upIpyData.GetActiveSoulID()
    if activeSoulID:
        __DoActiveMWSoul(curPlayer, activeSoulID, False)
    
    CalcMagicWeaponAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    GameWorld.DebugLog('    ¼¤»î·¨±¦ mwID=%s,mwLV=%s' % (mwID, mwLV))
    
    vipAddAtkMWID = IpyGameDataPY.GetFuncCfg("VIPAddAtkEXP", 2) # VIPɱ¹Ö¼ÓÊôÐÔËùÐ輤»î·¨±¦
    if mwID == vipAddAtkMWID:
        PlayerVip.RefreshVIPAttr(curPlayer)
        
    #½âËø¹¦ÄÜ
    GameFuncComm.DoFuncOpenLogic(curPlayer)
    DataRecordPack.DR_MagicWeaponActive(curPlayer, mwID, mwLV)
    return True
 
def GetWMIpyData(mwID):return IpyGameDataPY.GetIpyGameData('Treasure', mwID)
 
def GetNeedSuccIDByMWID(mwID, ipyData=None):
    ##»ñÈ¡·¨±¦ID¿ªÆôÐèÒªÍê³ÉµÄ³É¾ÍID
    if not ipyData:
        ipyData = GetWMIpyData(mwID)
        if not ipyData:
            return []
    succIDList = list(ipyData.GetSuccID())
    return succIDList
 
def GetMWIDBySuccID(succID):
    global g_succInfoDict
    
    if not g_succInfoDict:
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetTreasureCount()):
            ipyData = ipyDataMgr.GetTreasureByIndex(i)
            mwID = ipyData.GetID()
            succIDList = GetNeedSuccIDByMWID(mwID, ipyData)
            for succid in succIDList:
                if succid in g_succInfoDict:
                    GameWorld.ErrLog('    ´æÔÚÏàͬ³É¾Í¼¤»îÌõ¼þµÄ·¨±¦ %s ºÍ %s' % (mwID, g_succInfoDict[succid]))
                g_succInfoDict[succid] = mwID
    return g_succInfoDict.get(succID)
 
def GetMWActiveCntTotal(curPlayer):
    ## »ñÈ¡¼¤»îµÄ·¨±¦×ܸöÊý
    activeCnt = 0
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetTreasureCount()):
        ipyData = ipyDataMgr.GetTreasureByIndex(i)
        magicWeaponID = ipyData.GetID()
        if GetIsActiveMagicWeapon(curPlayer, magicWeaponID):
            activeCnt += 1
    return activeCnt
 
def GetMWActiveCntByType(curPlayer, mwType):
    ## ¸ù¾Ý·¨±¦ÀàÐÍ»ñÈ¡ÒѼ¤»îÊýÁ¿
    dataList = IpyGameDataPY.GetIpyGameDataByCondition('Treasure', {'TreasureType':mwType}, True, False)
    if not dataList:
        return 0
    activeCnt = 0
    for ipydata in dataList:
        isActive = GetIsActiveMagicWeapon(curPlayer, ipydata.GetID())
        if isActive:
            activeCnt += 1
    return activeCnt
 
## ¸ø¼¼ÄÜ
#  @param curPlayer
#  @param skillResID ¼¼ÄÜÔ´ID
#  @param tick Ê±¼ä´Á
#  @return None
def GiveSkill(curPlayer, skillResID, tick, isShowSys=True):
    
    skillData = GameWorld.GetGameData().FindSkillByType(skillResID, 1)
    if skillData == None:
        GameWorld.DebugLog("__GiveSkill() hasn't find skill(%s)" % skillResID)
        return
    if not SkillCommon.CheckSkillJob(curPlayer, skillData):
        return
    if not SkillShell.CheckLearnSkillCondition(curPlayer, skillData):
        GameWorld.DebugLog("__GiveSkill() learn skill(%s) condition isn't enough" % skillResID)
        return
    skillManager = curPlayer.GetSkillManager()
    if skillManager.FindSkillBySkillTypeID(skillResID):
        GameWorld.DebugLog("__GiveSkill() have learned skill(%s)" % skillResID)
        return
    GameWorld.DebugLog('    ¼¤»î·¨±¦ ¼¤»î¼¼ÄÜ skillResID=%s' % (skillResID))
    skillManager.LVUpSkillBySkillTypeID(skillResID)
    if isShowSys:
        PlayerControl.NotifyCode(curPlayer, "GetSkillInfo", [skillResID])
    
    DataRecordPack.DR_LearnORUPSkill(curPlayer, skillResID, 0)
    #·¨±¦±»¶¯¼¼ÄÜÐè×°±¸²ÅÉúЧ
    if skillData.GetFuncType() != ChConfig.Def_SkillFuncType_FbPassiveSkill:
        PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPlayer, skillResID)    
        if SkillCommon.isPassiveAttr(skillData):
            curControl = PlayerControl.PlayerControl(curPlayer)
            curControl.RefreshPlayerAttrState()
    
    PlayerControl.PlayerControl(curPlayer).RefreshSkillFightPowerEx(skillResID, 0)
    return
 
 
def NotifyMagicWeapon(curPlayer, isLogin=False):
    #֪ͨ·¨±¦ÐÅÏ¢
    packData = ChPyNetSendPack.tagMCMagicWeaponData()
    packData.Clear()
    packData.MagicWeaponID = []
 
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetTreasureCount()):
        ipyData = ipyDataMgr.GetTreasureByIndex(i)
        magicWeaponID = ipyData.GetID()
        isActive = GetIsActiveMagicWeapon(curPlayer, magicWeaponID)
        if not isActive:
            continue
        packData.MagicWeaponID.append(magicWeaponID)
        
    packData.Num = len(packData.MagicWeaponID)
    if packData.Num or isLogin:
        NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
 
##--------------------------------------------------------------------------------------------------
def GetMWRefineIpyData(treasureID, treasureLV):
    #»ñÈ¡·¨±¦µÈ¼¶ÐÅÏ¢
    return IpyGameDataPY.GetIpyGameDataNotLog("TreasureRefine", treasureID, treasureLV)
 
def CalcMagicWeaponAttr(curPlayer):
    ## ¼ÆËã·¨±¦ÊôÐÔ
    allAttrList1 = [{} for _ in range(4)] #ÈË×å·¨±¦
    allAttrList2 = [{} for _ in range(4)] #ħ×å·¨±¦
    allAttrList3 = [{} for _ in range(4)] #ÏÉ×å·¨±¦
    allAttrList4 = [{} for _ in range(4)] #ÍõÕß·¨±¦
    mwTypeMfpTypeDict = {1:ShareDefine.Def_MFPType_MagicWeapon1,
                         2:ShareDefine.Def_MFPType_MagicWeapon2,
                         3:ShareDefine.Def_MFPType_MagicWeapon3,
                         4:ShareDefine.Def_MFPType_MagicWeapon4}
    addPowerDict = {} #¶îÍâÕ½Á¦
    signDayMWID = IpyGameDataPY.GetFuncCfg('MWSignDayAttr', 2)
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyDataMgr.GetTreasureCount()):
        treasureIpyData = ipyDataMgr.GetTreasureByIndex(i)
        magicWeaponID = treasureIpyData.GetID()
        isActive = GetIsActiveMagicWeapon(curPlayer, magicWeaponID)
#        if not isActive:
#            continue
        allAttrDict = {}
        #=======================================================================
        # #ÖýÁ¶ÊôÐÔ
        # mwRefineLv = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponRefineLV % magicWeaponID)
        # refineipyData = GetMWRefineIpyData(magicWeaponID, mwRefineLv)
        # if refineipyData:  
        #    attrDict = refineipyData.GetTreasureAttr()
        #    GameWorld.AddDictValue(allAttrDict, attrDict)
        #=======================================================================
        treasureType = treasureIpyData.GetTreasureType()
        if isActive:
            mfpType = mwTypeMfpTypeDict.get(treasureType, ShareDefine.Def_MFPType_Role)
            #µÈ¼¶ÊôÐÔ
            curMWLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % magicWeaponID)
            for lv in xrange(curMWLV+1):
                upIpyData = IpyGameDataPY.GetIpyGameDataNotLog('TreasureUp', magicWeaponID, lv)
                if upIpyData:
                    attrDict = upIpyData.GetAddAttr()
                    GameWorld.AddDictValue(allAttrDict, attrDict)
                    addPowerDict[mfpType] = addPowerDict.get(mfpType, 0) + upIpyData.GetPowerEx()
                    
            if magicWeaponID == signDayMWID:
                #Ç©µ½ÊôÐÔ
                totalSignNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TotalSignNum) # ×ÜÇ©µ½ÌìÊý
                addAttr = {}
                for attid, attnum in IpyGameDataPY.GetFuncEvalCfg('MWSignDayAttr', 1, {}).items():
                    addAttr[int(attid)] = attnum * totalSignNum
                GameWorld.AddDictValue(allAttrDict, addAttr)
            #ÍõÕß·¨±¦ÊôÐÔ
            seasonID = IpyGameDataPY.GetFuncEvalCfg('MagicWeaponOfKing', 1, {}).get(magicWeaponID, 0)
            kingAwardLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CrossPK_SeasonAwardLV % seasonID)
            kingMWIpyData = IpyGameDataPY.GetIpyGameDataNotLog('MagicWeaponOfKing', magicWeaponID, kingAwardLV)
            if kingMWIpyData and GetIsWearMagicWeapon(curPlayer, magicWeaponID):
                attrDict = kingMWIpyData.GetAddAttr()
                GameWorld.AddDictValue(allAttrDict, attrDict)
        
        fbpasslv = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWFBPassLevel % magicWeaponID)
        #ÀϺÅÒѼ¤»îµÄħ×å·¨±¦Ã»Óйؿ¨ÊôÐÔ£¬Ö±½ÓÉèÖÃÂú¹Ø¿¨
        if isActive and not fbpasslv:
            ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('MagicWeaponFB', {'MWID':magicWeaponID}, True, False)
            if ipyDataList:
                maxLevel = ipyDataList[-1].GetLevel()
                fbpasslv = maxLevel
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWFBPassLevel % magicWeaponID, maxLevel)
                GameWorld.Log('ÀϺÅÒѼ¤»îµÄħ×å·¨±¦Ã»Óйؿ¨ÊôÐÔ£¬Ö±½ÓÉèÖÃÂú¹Ø¿¨ magicWeaponID=%s,maxLevel=%s'%(magicWeaponID, maxLevel), curPlayer.GetID())
        if fbpasslv: #¸±±¾¹Ø¿¨ÊôÐÔ
            fbipyData = IpyGameDataPY.GetIpyGameData('MagicWeaponFB', magicWeaponID, fbpasslv)
            if fbipyData:
                attrDict = fbipyData.GetAttrDict()
                for effID, value in attrDict.items():
                    effID = int(effID)
                    allAttrDict[effID] = allAttrDict.get(effID, 0) + value
                
                
        for effID, value in allAttrDict.items():
            if treasureType == 1:
                PlayerControl.CalcAttrDict_Type(effID, value, allAttrList1)
            elif treasureType == 2:
                PlayerControl.CalcAttrDict_Type(effID, value, allAttrList2)
            elif treasureType == 3:
                PlayerControl.CalcAttrDict_Type(effID, value, allAttrList3)
            elif treasureType == 4:
                PlayerControl.CalcAttrDict_Type(effID, value, allAttrList4)
            else:
                GameWorld.ErrLog("δ֪·¨±¦ÊôÐÔ, magicWeaponID=%s,treasureType=%s,effID=%s,value=%s" 
                                 % (magicWeaponID, treasureType, effID, value), curPlayer.GetPlayerID())
    
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_MagicWeapon1, allAttrList1)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_MagicWeapon2, allAttrList2)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_MagicWeapon3, allAttrList3)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_MagicWeapon4, allAttrList4)
    return
 
 
#// A5 0E ¿ªÆô·¨±¦ #tagCMOpenMagicWeapon
#
#struct    tagCMOpenMagicWeapon
#
#{
#    tagHead        Head;
#    DWORD        MWID;
#};
def OnOpenMagicWeapon(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    mwID = clientData.MWID
    isActive = GetIsActiveMagicWeapon(curPlayer, mwID)
    if isActive:
        GameWorld.DebugLog('    ¸Ã·¨±¦ÒÑ¿ªÆô£¡ mwID=%s' % mwID)
        return
    succIDList = GetNeedSuccIDByMWID(mwID)
    curExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponExp % mwID)
    if curExp < len(succIDList):
        GameWorld.DebugLog('    ¸Ã·¨±¦ËùÐè³É¾ÍδÍê³É£¡ mwID=%s£¬ curExp=%s, succIDList=%s' % (mwID, curExp, succIDList))
        return
    #ÏûºÄÎïÆ·ÅжÏ
    ipyData = GetWMIpyData(mwID)
    needItemDict = ipyData.GetNeedItem()
    if needItemDict:
        #ͨ¹ý´Ë;¾¶½âËø·¨±¦ ±ØÐëÒªÅäÏûºÄÎïÆ·
        
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
        lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemDict, itemPack, False)
        if lackItemDict:
            GameWorld.DebugLog("    ¿ªÆô·¨±¦ ²ÄÁϲ»×㣡mwID=%s,needItemDict=%s,lackItemDict=%s,delInfoDict=%s" 
                               % (mwID, needItemDict, lackItemDict, delInfoDict))
            return
        
        #¿ÛÏûºÄ
        ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, ChConfig.ItemDel_MagicWeapon)
    else:
        ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('XBXZ', {'MWID':mwID}, True, False)
        if not ipyDataList:
            return
        for ipyData in ipyDataList:
            if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_XBXZAwardRecord, ipyData.GetID()):
                return
            
    
    DoActiveMW(curPlayer, mwID)
    return
 
#-------------------------------------------------------------------------------
 
def OnGetXBXZAward(curPlayer, index):
    ##Ïɱ¦Ñ°Ö÷Áì½±
    ipyData = IpyGameDataPY.GetIpyGameData('XBXZ', index)
    if not ipyData:
        return
    if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_XBXZAwardRecord, index):
        GameWorld.DebugLog('    Ïɱ¦Ñ°Ö÷Áì½± ÒÑÁìÈ¡£¡ index=%s' % index)
        return
    
    curType = ipyData.GetType()
    conditionList = ipyData.GetCondition()
    cnt = 0
    if curType == 1:
        #½ÇÉ«·ÀÓùµ½XX
        cnt = PlayerControl.GetFuncDef(curPlayer)
        
    elif curType == 2:
        #´©´÷Èý½×³ÈÉ«1ÐÇ»òËĽ××ÏÉ«1ÐÇÒÔÉÏÍ·¿ø
        playerEquip = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
        SamboSpecialUnlock = IpyGameDataPY.GetFuncEvalCfg('SamboSpecialUnlock')
        for equipIndex in xrange(playerEquip.GetCount()):
            curEquip = playerEquip.GetAt(equipIndex)
            if curEquip.IsEmpty():
                continue
            curClassLV = ItemCommon.GetItemClassLV(curEquip)
            itemColor = curEquip.GetItemColor()
            itemQuality = curEquip.GetItemQuality()
            itemID = curEquip.GetItemTypeID()
            for classlv, color, star, place in conditionList:
                if equipIndex is place and itemID in SamboSpecialUnlock:
                    cnt = 1
                    break
                if equipIndex is place and curClassLV >= classlv and itemColor >= color and itemQuality >= star:
                    cnt = 1
                    break
            if cnt:
                break
#    elif curType == 3:
#        #È«Éí×°±¸XÐÇ
#        cnt = ChEquip.GetTotalEquipStars(curPlayer)
        
    elif curType == 4:
        #X½×ÆÕͨ¡¢Ç¿»¯Ì××°
        suiteCntDict = {}
        playerEquip = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptEquip)
        for equipIndex in xrange(playerEquip.GetCount()):
            curEquip = playerEquip.GetAt(equipIndex)
            if curEquip.IsEmpty():
                continue
            suiteInfo = ChEquip.GetSuiteInfoByPlace(curPlayer, equipIndex, curEquip)
            for suitelv, suiteType in conditionList:
                if suiteInfo.get(suiteType, 0) >= suitelv:
                    suiteCntDict[suiteType] = suiteCntDict.get(suiteType, 0)+1
        cnt = max(suiteCntDict.values()) if suiteCntDict else 0
        
    else:
        return
    if cnt < ipyData.GetNeedCnt():
        GameWorld.DebugLog('    Ïɱ¦Ñ°Ö÷Áì½± , Ìõ¼þ²»Âú×ã ID=%s, cnt=%s,NeedCnt=%s' % (index, cnt, ipyData.GetNeedCnt()))
        return
    
    # ¼ì²é±³°ü
    awardItemList = ipyData.GetAwardItem()
    if awardItemList:
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem)
        needSpace = len(awardItemList)
        if needSpace > packSpace:
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
            return
    
    # ¸üÐÂÁì½±¼Ç¼
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_XBXZAwardRecord, index, 1)
    
    # ¸øÎïÆ·
    if awardItemList:
        for itemID, itemCnt in awardItemList:
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 1, [IPY_GameWorld.rptItem], True)
       
    #¸øÇ®
    for moneyType, value in ipyData.GetMoney():
        PlayerControl.GiveMoney(curPlayer, moneyType, value)
    SyncXBXZAwardRecord(curPlayer,[index])
    #³É¾Í
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_XBXZ, 1, [ipyData.GetMWID()])
    GameWorld.DebugLog('    Ïɱ¦Ñ°Ö÷Áì½±OK, ID=%s, cnt=%s' % (index, cnt))
    return
 
 
## Í¨ÖªÏɱ¦Ñ°Ö÷¶ÔÓ¦½±ÀøÁì½±¼Ç¼
#  @param None
#  @return
def SyncXBXZAwardRecord(curPlayer, syncIDList=[]):
    if syncIDList:
        recordIndexList = []
        for succID in syncIDList:
            recordIndexList.append(succID / 31)
    else:
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        succCnt = ipyDataMgr.GetXBXZCount()
        if not succCnt:
            return
        maxSuccid = ipyDataMgr.GetXBXZByIndex(succCnt-1).GetID()
        recordIndexList = range(maxSuccid / 31+1)
            
    succFARPack = ChPyNetSendPack.tagMCXBXZAwardRecordList()
    succFARPack.Clear()
    succFARPack.RecordList = []
    for i in recordIndexList:
        awardRecord=curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_XBXZAwardRecord%i)
        if not awardRecord:
            continue
        recordInfo = ChPyNetSendPack.tagMCXBXZAwardRecord()
        recordInfo.RecordIndex = i
        recordInfo.Record = awardRecord
        succFARPack.RecordList.append(recordInfo)
   
    succFARPack.RecordCnt = len(succFARPack.RecordList)
    NetPackCommon.SendFakePack(curPlayer, succFARPack)
    return
 
#-------------------------------------------------------------------------------
#// A5 15 ÌáÉý·¨±¦µÈ¼¶ #tagCMMagicWeaponUp
#
#struct    tagCMMagicWeaponUp
#
#{
#    tagHead        Head;
#    DWORD        WMID;    //·¨±¦ID
#};
def OnMagicWeaponUp(index, clientData, tick):
    #·¨±¦Éý¼¶
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    mwID = clientData.MWID
    curMWLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % mwID)
    nextMWLV = curMWLV+1
    nextIpyData = IpyGameDataPY.GetIpyGameData('TreasureUp', mwID, nextMWLV)
    if not nextIpyData:
        return
    needExp = nextIpyData.GetNeedExp()
    curUpExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponUpExp % mwID)
    if curUpExp < needExp:
        GameWorld.DebugLog('·¨±¦Éý¼¶¾­Ñé²»×ã%s'%needExp)
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponUpExp % mwID, curUpExp-needExp)
    
    DoActiveMW(curPlayer, mwID, nextMWLV)
    
    return
 
def AddMagicWeaponUpExp(curPlayer, mwID, addExp):
    #Ôö¼Ó·¨±¦Éý¼¶¾­Ñé
    GameWorld.DebugLog('Ôö¼Ó·¨±¦Éý¼¶¾­Ñé mwID=%s,addExp=%s'%(mwID, addExp))
    curUpExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponUpExp % mwID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponUpExp % mwID, curUpExp+addExp)
    Sycn_MagicWeaponLV(curPlayer, mwID)
    # Ã¿Èջ
    ipyData = GetWMIpyData(mwID)
    mwType = ipyData.GetTreasureType() if ipyData else 0
    if mwType == 1:
        PlayerActivity.AddDailyActionFinishCnt(curPlayer, ShareDefine.DailyActionID_MagicWeapon)
    return
 
def Sycn_MagicWeaponLV(curPlayer, mwID= -1):
    #֪ͨ·¨±¦µÈ¼¶ÐÅÏ¢
    if mwID == -1:
        isAll = True
        needCalList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetTreasureCount()):
            ipyData = ipyDataMgr.GetTreasureByIndex(i)
            needCalList.append(ipyData.GetID())
    else:
        isAll = False
        needCalList = [mwID]
    sendPack = ChPyNetSendPack.tagMCMagicWeaponLVInfo()
    sendPack.InfoList = []
    for mwID in needCalList:
        mwLv = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponLV % mwID)
        curUpExp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponUpExp % mwID)
        state = GetIsClickMagicWeapon(curPlayer, mwID)
        FBPassLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWFBPassLevel % mwID)
        isWear = GetIsWearMagicWeapon(curPlayer, mwID)
        if isAll and not mwLv and not curUpExp and not state and not FBPassLV and not isWear:
            continue
        pack = ChPyNetSendPack.tagMCMagicWeaponInfo()
        pack.MWID = mwID
        pack.LV = mwLv
        pack.Exp = curUpExp
        pack.State = state
        pack.FBPassLV = FBPassLV
        pack.IsWear = isWear
        sendPack.InfoList.append(pack)
    sendPack.Count = len(sendPack.InfoList)
    if sendPack.Count:
        NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
def GetMagicWeaponPrivilege(curPlayer, privilege):
    #·¨±¦µÈ¼¶È¨ÏÞ
    if not GetIsActiveMWSoul(curPlayer, privilege):
        return 0
    privilegeIpyData = IpyGameDataPY.GetIpyGameDataNotLog('TreasurePrivilege', privilege)
    if not privilegeIpyData:
        return 0
    return privilegeIpyData
 
def GetMagicWeaponPrivilegeAttr(curPlayer, privilege):
    #»ñÈ¡·¨±¦ÌØÈ¨Ôö¼ÓµÄÊôÐÔ
    addAttr = {}
    privilegeIpyData = IpyGameDataPY.GetIpyGameDataNotLog('TreasurePrivilege', privilege)
    if not privilegeIpyData:
        return addAttr
    attrInfo = privilegeIpyData.GetAddAttr()
    if not attrInfo:
        attrInfo = {}
    singleValue = privilegeIpyData.GetSingleValue()
    
    if privilege == ChConfig.MWPrivilege_EquipPlus:
        #Ç¿»¯¼Ó³É
        addAttr = ChEquip.CalcAllEquipAllPlusLVAttr(curPlayer)
    else: 
        multiple = 1 #±¶Êý
        if singleValue:
            gotValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulGotValue % privilege)
            maxValue = privilegeIpyData.GetMaxValue()
            if maxValue:
                gotValue = min(maxValue, gotValue)
            multiple = gotValue/singleValue
        for attid, attnum in attrInfo.items():
            addAttr[int(attid)] = attnum * multiple
    
    GameWorld.DebugLog('    »ñÈ¡·¨±¦ÌØÈ¨Ôö¼ÓµÄÊôÐÔ privilege=%s,addAttr=%s' % (privilege,addAttr), curPlayer.GetID())
    return addAttr
 
def SetMWPrivilegeData(curPlayer, privilege, data, isAdd=False):
    ##ÉèÖ÷¨±¦ÌØÈ¨Ïà¹ØÊý¾Ý
    privilegeIpyData = IpyGameDataPY.GetIpyGameDataNotLog('TreasurePrivilege', privilege)
    if not privilegeIpyData:
        return
    curGotValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulGotValue % privilege)
    singleValue = privilegeIpyData.GetSingleValue()
    if singleValue and curGotValue % singleValue:
        fixGotValue = curGotValue/singleValue*singleValue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWSoulGotValue % privilege, fixGotValue)
        GameWorld.Log('Íæ¼Ò·¨±¦Ö®»êÒÑÁìµÄÊý¾Ý²»Êǵ¥´Î½ø¶ÈµÄ±¶Êý£¬ÐÞ¸´! privilege=%s,curGotValue=%s, fixGotValue=%s'%(privilege, curGotValue, fixGotValue))
    
    curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulCurValue % privilege)
    newData = curValue + data if isAdd else data
    maxValue = privilegeIpyData.GetMaxValue()
    if maxValue:
        newData = min(maxValue, newData)
    if curValue != newData:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWSoulCurValue % privilege, newData)
 
        Sycn_MWPrivilegeData(curPlayer, privilege)
    GameWorld.Log('    privilege=%s,data=%s,curValue=%s,newData=%s'%(privilege, data,curValue,newData))
    return
 
def GetMWSoulAward(curPlayer, privilege):
    #ÁìÈ¡·¨±¦Ö®»ê½±Àø
    ipyData = GetMagicWeaponPrivilege(curPlayer, privilege)
    if not ipyData:
        GameWorld.DebugLog('ÁìÈ¡·¨±¦Ö®»ê½±Àø£¬¶ÔÓ¦·¨±¦Ö®»êδ¼¤»î£¬»òδÅäÖàprivilege=%s'%privilege)
        return
    singleValue = ipyData.GetSingleValue()
    maxValue = ipyData.GetMaxValue()
    if singleValue:
        #´ïµ½½ø¶ÈÔò¿ÉÁìÈ¡ÊôÐÔ
        curValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulCurValue % privilege)
        gotValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulGotValue % privilege)
        if gotValue >= curValue:
            return
        canGetCnt = (curValue - gotValue) / singleValue
        if canGetCnt <= 0 and maxValue and curValue >= maxValue:
            canGetCnt = 1 #ÒÑ´ïµ½´ÎÊýÉÏÏÞ£¬×îºóÒ»´Î²»¹ÜÊÇ·ñÂú×ã¶¼ÈÃÁì(Ò»°ãÊÇÒòΪÅäÖôíÎó»òÕß±ä¸üµ¼ÖÂ)
        if canGetCnt <= 0:
            return
        updGotCnt = min(maxValue, gotValue+canGetCnt*singleValue) if maxValue else gotValue+canGetCnt*singleValue
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWSoulGotValue % privilege, updGotCnt)
        CalcMagicWeaponSoulAttr(curPlayer)
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
        
        
    itemList = ipyData.GetItemAward()
    if itemList:
        #ÿÈÕÎïÆ·½±Àø
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulGotItemState % privilege):
            GameWorld.Log('    ÁìÈ¡·¨±¦Ö®»ê½±Àø ½ñÈÕÒÑÁìÈ¡ privilege=%s'%privilege)
            return
        needSpace = len(itemList)
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
        if needSpace > packSpace:
            PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_676165", [IPY_GameWorld.rptItem])
            return
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWSoulGotItemState % privilege, 1)
        for itemid, cnt, isBind in itemList:
            ItemControler.GivePlayerItem(curPlayer, int(itemid), int(cnt), isBind,
                                         [IPY_GameWorld.rptItem], True, showSysInfo=True, event=["MWSoulAward", False, {"privilege":privilege}])
    
    #֪ͨ
    Sycn_MWPrivilegeData(curPlayer, privilege)
    return
 
def Sycn_MWPrivilegeData(curPlayer, privilegeID= -1, isForce=False):
    #֪ͨ·¨±¦ÌØÈ¨ÐÅÏ¢
    if privilegeID == -1:
        needCalList = ChConfig.MWPrivilegeList
    else:
        needCalList = [privilegeID]
    sendPack = ChPyNetSendPack.tagMCMWPrivilegeDataInfo()
    sendPack.InfoList = []
    for priID in needCalList:
        pack = ChPyNetSendPack.tagMCMWPrivilegeData()
        pack.CurValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulCurValue % priID)
        pack.GotValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulGotValue % priID)
        pack.ItemAwardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MWSoulGotItemState % priID)
        pack.State = GetIsActiveMWSoul(curPlayer, priID)
        if not isForce and max([pack.CurValue, pack.GotValue, pack.ItemAwardState, pack.State]) == 0:
            continue
        pack.PriID = priID
        sendPack.InfoList.append(pack)
    sendPack.Count = len(sendPack.InfoList)
    if sendPack.Count:
        NetPackCommon.SendFakePack(curPlayer, sendPack)
    return
 
#// A5 16 ·¨±¦×´Ì¬¼Ç¼ #tagCMMagicWeaponState
#
#struct    tagCMMagicWeaponState
#
#{
#    tagHead        Head;
#    DWORD        MWID;    //·¨±¦ID
#};
def SaveMagicWeaponState(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    mwID = clientData.MWID
    if GetIsClickMagicWeapon(curPlayer, mwID):
        return
    SetMagicWeaponClickState(curPlayer, mwID)
    Sycn_MagicWeaponLV(curPlayer, mwID)
    return
 
def GetIsClickMagicWeapon(curPlayer, mwID):
    #»ñÈ¡·¨±¦ÊÇ·ñµã»÷ÈÏÖ÷
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsClick, mwID % 100, True, [mwID / 100])
 
def SetMagicWeaponClickState(curPlayer, mwID, state=1):
    #ÉèÖ÷¨±¦ÊÇ·ñµã»÷ÈÏÖ÷״̬
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsClick, mwID % 100, state, True, [mwID / 100])
    return
 
#// A5 1D ·¨±¦Åå´÷ #tagCMWearMagicWeapon
#
#struct    tagCMWearMagicWeapon
#
#{
#    tagHead        Head;
#    DWORD        MWID;    //·¨±¦ID
#    BYTE        State;        //0-жÏ 1-Åå´÷
#};
def OnWearMagicWeapon(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    mwID = clientData.MWID
    if not GetIsActiveMagicWeapon(curPlayer, mwID):
        return
    isWear = clientData.State
    if isWear:
        maxCnt = IpyGameDataPY.GetFuncCfg('MagicWeaponOfKing', 2)
        hasWearCnt = 0
        for mid in IpyGameDataPY.GetFuncEvalCfg('MagicWeaponOfKing', 1, {}):
            if hasWearCnt >= maxCnt:
                return
            if GetIsWearMagicWeapon(curPlayer, mid):
                hasWearCnt +=1
                
    SetMagicWeaponWearState(curPlayer, mwID, isWear)
    CalcMagicWeaponAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    Sycn_MagicWeaponLV(curPlayer, mwID)
    return
 
def GetIsWearMagicWeapon(curPlayer, mwID):
    #»ñÈ¡·¨±¦ÊÇ·ñÅå´÷
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsWear, mwID % 100, True, [mwID / 100])
 
def SetMagicWeaponWearState(curPlayer, mwID, state):
    #ÉèÖ÷¨±¦ÊÇ·ñÅå´÷
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_MagicWeaponIsWear, mwID % 100, state, True, [mwID / 100])
    return
 
#// A5 12 ¼¤»î·¨±¦Ö®»ê #tagCMActiveMWSoul
#
#struct    tagCMActiveMWSoul
#
#{
#    tagHead        Head;
#    BYTE        ID;    //±àºÅ
#};
def OnActiveMWSoul(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    soulID = clientData.ID
    ipyData = IpyGameDataPY.GetIpyGameData('TreasurePrivilege', soulID)
    if not ipyData:
        return
    if GetIsActiveMWSoul(curPlayer, soulID):
        GameWorld.Log('    ¸Ã·¨±¦Ö®»êÒѾ­¼¤»î£¡£¡ soulID=%s'%soulID)
        return
    #¼ì²é³É¾Í
    succList = ipyData.GetSuccessList()
    for succID in succList:
        if not PlayerSuccess.GetSuccHasGot(curPlayer, succID):
            GameWorld.DebugLog('    ¼¤»î·¨±¦Ö®»ê ³É¾ÍδÍê³É  soulID=%s,succID=%s'%(soulID, succID))
            return
    
    __DoActiveMWSoul(curPlayer, soulID)
    return
 
def __DoActiveMWSoul(curPlayer, soulID, isRefreshAttr=True):
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_MWSoulActiveState, soulID, 1, True)
    #ÈÎÎñ
    EventShell.EventRespons_MWSoulActive(curPlayer, soulID)
    
    CalcMagicWeaponSoulAttr(curPlayer)
    if isRefreshAttr:
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    
    #֪ͨ
    Sycn_MWPrivilegeData(curPlayer, soulID)
    return
 
 
def GetIsActiveMWSoul(curPlayer, soulID):
    #»ñÈ¡·¨±¦Ö®»êÊÇ·ñÒѼ¤»î
    return GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_MWSoulActiveState, soulID)
 
def CalcMagicWeaponSoulAttr(curPlayer):
    #·¨±¦Ö®»êÊôÐÔË¢ÐÂ
    allAttrList = [{} for _ in range(4)]
    allAttrDict = {}
    ipyMgr = IpyGameDataPY.IPY_Data()
    for i in xrange(ipyMgr.GetTreasurePrivilegeCount()):
        ipyData = ipyMgr.GetTreasurePrivilegeByIndex(i)
        soulID = ipyData.GetPrivilegeID()
        if not GetIsActiveMWSoul(curPlayer, soulID):
            continue
        attrDict = GetMagicWeaponPrivilegeAttr(curPlayer, soulID)
        GameWorld.AddDictValue(allAttrDict, attrDict)
        
    for attrID, attrValue in allAttrDict.items():
        PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_MagicWeaponSoul, allAttrList)
    return
 
def UptateMWFBPasslv(curPlayer, mwID, passLV):
    GameWorld.Log('¸üйؿ¨ mwID=%s,level=%s'%(mwID, passLV), curPlayer.GetID())
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MWFBPassLevel % mwID, passLV)
    CalcMagicWeaponAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    Sycn_MagicWeaponLV(curPlayer, mwID)
    
    EventShell.EventRespons_MagicWeaponFBPassLV(curPlayer, mwID, passLV)
    return