xdh
2018-11-12 9884f7248cae1b51d22e59b61d1c2af21141101d
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
#!/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)
    Sycn_MagicWeaponRefineLV(curPlayer)
    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
 
def GetPotentialsSkillInfo(curPlayer):
    #ͨ¹ýDZÁ¦¼¼ÄÜID»ñÈ¡¶ÔÓ¦µÄÏÂÒ»¸ö¼¼ÄÜID {skillUseType:{skillid:[skilllv,nextSkillid,addPower,]}}
    global g_potentialsSkillDict
 
    if not g_potentialsSkillDict:
        g_potentialsSkillDict = {}
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetTreasureCount()):
            ipyData = ipyDataMgr.GetTreasureByIndex(i)
            mwID = ipyData.GetID()
            skillIDList = ipyData.GetPotentials()
            addPowerList = ipyData.GetSkillPower()
            lastSkillUseType = 0
            for curSkillID in skillIDList:
                skillData = GameWorld.GetGameData().FindSkillByType(curSkillID, 1)
                if skillData == None:
                    GameWorld.DebugLog("GetPotentialsSkillInfo() hasn't find skill(%s)" % curSkillID)
                    continue
                if lastSkillUseType != skillData.GetUseType():
                    index = 0
                else:
                    index +=1
                lastSkillUseType = skillData.GetUseType()
                addPower = addPowerList[index]
 
                preSkillID = skillData.GetLearnSkillReq()
                if not preSkillID:
                    continue
                skillUseType = skillData.GetUseType()
                preSkilllv = skillData.GetLearnSkillLV()
                if skillUseType not in g_potentialsSkillDict:
                    g_potentialsSkillDict[skillUseType] = {}
                g_potentialsSkillDict[skillUseType][preSkillID] = [preSkilllv, curSkillID, addPower]
    curskillUseType = pow(2, curPlayer.GetJob())
    
    return g_potentialsSkillDict.get(curskillUseType, {})
 
## ¸ø¼¼ÄÜ
#  @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
 
 
 
#// A5 0D Éý¼¶·¨±¦¼¼ÄÜ #tagCMMagicWeaponSkillUp
#
#struct    tagCMMagicWeaponSkillUp
#{
#    tagHead        Head;
#    WORD        SkillTypeID;
#    BYTE        CostIndex;
#};
def OnMagicWeaponSkillUp(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    skillTypeID = clientData.SkillTypeID
    costIndex = clientData.CostIndex #0´ú±íδѡÖР1´ú±íµÚÒ»¸ö
    
    curSkillType = None
    SPSkillTypeDict = IpyGameDataPY.GetFuncEvalCfg('SPSkillType')
    for skillType, skillIDList in SPSkillTypeDict.items():
        if skillTypeID in skillIDList:
            curSkillType = int(skillType)
            break
    if curSkillType == None:
        #²»ÊÇ·¨±¦¼¼ÄÜ
        return
    
    #»ñµÃÍæ¼Ò¼¼ÄܹÜÀíÆ÷
    skillManager = curPlayer.GetSkillManager()
    #»ñµÃ¼¼ÄÜ
    curSkill = skillManager.FindSkillBySkillTypeID(skillTypeID)
    if curSkill == None:
        curSkillLV = 0
        beforeFightPower = 0
    else:
        curSkillLV = curSkill.GetSkillLV()
        beforeFightPower = curSkill.GetFightPower()
        if curSkillLV == curSkill.GetSkillMaxLV():
            #ÒѾ­ÊÇ×î¸ßµÈ¼¶
            PlayerControl.NotifyCode(curPlayer, "UseMagicLost16")
            return
    
    upSkillLv = curSkillLV + 1
    curSkillID = skillTypeID if not curSkill else curSkill.GetSkillID()
    upSkill = GameWorld.GetGameData().FindSkillByType(skillTypeID, upSkillLv)
    if not upSkill:
        GameWorld.DebugLog("¼¼ÄÜÉý¼¶Åä±í´íÎó ID=%s lv=%s"%(skillTypeID, upSkillLv))
        return
    
    if not SkillShell.CheckLearnSkillCondition(curPlayer, upSkill):
        return
    
    #Éý¼¶¼¼ÄÜÏûºÄ
    ipyData = IpyGameDataPY.GetIpyGameData('TreasureSkill', curSkillType, upSkillLv)
    if not ipyData:
        return
    
    needSP = ipyData.GetNeedPoint()
    if PlayerControl.GetZhenQi(curPlayer) < needSP:
        GameWorld.DebugLog("·¨±¦sp²»×㣬ÎÞ·¨Éý¼¶¼¼ÄÜ£¡needSP=%s,skillTypeID=%s" % (needSP, skillTypeID), curPlayer.GetPlayerID())
        return
    
    initRate = ipyData.GetInitRate() #³õʼ¸ÅÂÊ
    itemIndexList = []
    
    if initRate != ShareDefine.Def_MaxRateValue and costIndex > 0:
        #Âú¸ÅÂʲ»ÏûºÄµÀ¾ß
        needItemIDList = ipyData.GetNeedItemID()
        needItemCntList = ipyData.GetNeedItemCnt()
        maxRateList = ipyData.GetMaxRate()
        if costIndex - 1 >= len(needItemIDList):
            GameWorld.Log("·¨±¦¼¼ÄÜÉý¼¶£¬costIndex=%s ´íÎó" % costIndex)
            return
        needItemID, needItemCnt, initRate = needItemIDList[costIndex - 1], needItemCntList[costIndex - 1], maxRateList[costIndex - 1]
        itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
        isEnough, itemIndexList = ItemCommon.GetItem_FromPack_ByID(needItemID, itemPack, needItemCnt)
        if not isEnough:
            GameWorld.DebugLog("Éý¼¶·¨±¦¼¼ÄÜ() up skill(%s) item(%s) no enough" \
                               % (upSkill.GetSkillID(), needItemID))
            return
        
    
    #¿ÛÎïÆ·
    if itemIndexList:
        ItemCommon.ReduceItem(curPlayer, itemPack, itemIndexList, needItemCnt, False, ChConfig.ItemDel_MagicWeapon, 
                              {"SkillTypeID":skillTypeID, "SkillLV":curSkillLV})
    
    #¸¶Ç®
    #infoDict = {"SkillID":skillTypeID, "SkillLV":upSkillLv, ChConfig.Def_Cost_Reason_SonKey:upSkill.GetSkillName()}
    if not PlayerControl.PlayerLostZhenQi(curPlayer, needSP):
        return
    playerID = curPlayer.GetPlayerID()
    maxRateValue = ShareDefine.Def_MaxRateValue
    randValue = random.randint(0, maxRateValue-1)
    canHappen = randValue < initRate
    GameWorld.DebugLog("canHappen=%s,randValue=%s,initRate=%s,maxRateValue=%s" 
                       % (canHappen, randValue, initRate, maxRateValue), playerID)
    # ²»Êǰٷְٳɹ¦µÄ¼Ç¼ºÏ³ÉÁ÷Ïò
    if initRate != maxRateValue:
        drDict = {"PlayerID":playerID, "AccID":curPlayer.GetAccID(), "skillTypeID":skillTypeID, "IsSuccess":canHappen,
                  "initRate":initRate, "randValue":randValue, "maxRateValue":maxRateValue}
 
        DataRecordPack.SendEventPack("MagicWeaponSkillUp", drDict, curPlayer)
 
    if not canHappen:
        GameWorld.DebugLog("·¨±¦¼¼ÄÜÉý¼¶£¬curSkillID=%s, maxRate=%s Éý¼¶Ê§°Ü" % (curSkillID, initRate))
        curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitMagicWeaponSkillUp, 0)
        return
    curControl = PlayerControl.PlayerControl(curPlayer)
    skillManager.LVUPSkillByID(curSkillID)
    #´¥·¢Ñ§Ï°Ð¼¼ÄÜ
    newSkillIsPassive = False
    potentialSkillLearnDict = IpyGameDataPY.GetFuncEvalCfg('PotentialSkillLearn')
    if str(skillTypeID) in potentialSkillLearnDict:
        needSkllLV, newSkillID = potentialSkillLearnDict[str(skillTypeID)]
        if upSkillLv == needSkllLV:
            if not skillManager.FindSkillBySkillTypeID(newSkillID):
                newSkill = GameWorld.GetGameData().FindSkillByType(newSkillID, 1)
                if newSkill:
                    skillManager.LVUPSkillByID(newSkillID)
                    GameWorld.DebugLog('    ·¨±¦¼¼ÄÜÉý¼¶ skillTypeID=%s, upSkillLv=%s, ´¥·¢Ñ§Ï°¼¼ÄÜ%s' % (skillTypeID, upSkillLv, newSkillID))
                    curControl.RefreshSkillFightPowerEx(newSkillID, 0)
                    PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPlayer, newSkillID)
                    if SkillCommon.isPassiveAttr(newSkill):
                        newSkillIsPassive = True
                    PlayerControl.WorldNotify(0, 'SkillPotential2', [curPlayer.GetName(), skillTypeID, upSkillLv, newSkillID])
            
    
    #֪ͨ¼¼ÄÜÒÑÉý¼¶³É¹¦
    hasUnlockSkill = False
    nextSkillDict = GetPotentialsSkillInfo(curPlayer)
    if skillTypeID in nextSkillDict:
        needSkilllv,nextSkillID = nextSkillDict[skillTypeID][:2]
        if upSkillLv == needSkilllv:
            PlayerControl.WorldNotify(0, 'SkillPotential1', [curPlayer.GetName(), skillTypeID, upSkillLv, nextSkillID])
            CalcMagicWeaponAttr(curPlayer)
            hasUnlockSkill = True
            
    maxLV = upSkill.GetSkillMaxLV()
    if upSkillLv == maxLV:
        PlayerControl.WorldNotify(0, 'SkillPotential3', [curPlayer.GetName(), skillTypeID, maxLV])
    
    if SkillCommon.isPassiveAttr(upSkill) or newSkillIsPassive or hasUnlockSkill:
        curControl.RefreshPlayerAttrState()
        
    curControl.RefreshSkillFightPowerEx(upSkill.GetSkillID(), beforeFightPower)
    PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPlayer, upSkill.GetSkillID())
    
    #»ñµÃ¼¼Äܵȼ¶
    #curSkillLV = curSkill.GetSkillLV()
    GameWorld.DebugLog('    ·¨±¦¼¼ÄÜÉý¼¶ skillTypeID=%s, upSkillLv=%s' % (skillTypeID, upSkillLv))
    DataRecordPack.DR_LearnORUPSkill(curPlayer, skillTypeID, upSkillLv)
    
    curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitMagicWeaponSkillUp, 1)
    
    SetMWPrivilegeData(curPlayer, ChConfig.MWPrivilege_MWSkillUp, GetSPSkillTotalLV(curPlayer))
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MWSkillUp, 1, [skillTypeID])
    EventShell.EventRespons_MWSkillUp(curPlayer)
    return
 
def GetSPSkillTotalLV(curPlayer):
    #DZÁ¦¼¼ÄÜ×ܵȼ¶
    totalLV = 0
    skillManager = curPlayer.GetSkillManager()
    for i in xrange(skillManager.GetSkillCount()):
        curSkill = skillManager.GetSkillByIndex(i)
        if curSkill.GetFuncType() != ChConfig.Def_SkillFuncType_FbSPSkill:
            continue
        totalLV += curSkill.GetSkillLV()
    return totalLV
 
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)] #ÏÉ×å·¨±¦
 
    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()
        #µÈ¼¶ÊôÐÔ
        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)
                
        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)
        
        
        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)
            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)
    #¼¼ÄܽâËøÕ½Á¦
    nextSkillDict = GetPotentialsSkillInfo(curPlayer)
    addPowerDict = {}
    for skillID, info in nextSkillDict.items():
        needSkilllv, nextSkillID, addPower = info
        skillManager = curPlayer.GetSkillManager()
        curSkill = skillManager.FindSkillBySkillTypeID(skillID)
        if not curSkill:
            continue
        curSkillLV = curSkill.GetSkillLV()
        if curSkillLV < needSkilllv:
            continue
        mfpType = ChConfig.Def_SkillFuncType_MFPType.get(curSkill.GetFuncType(), ShareDefine.Def_MFPType_Role)
        addPowerDict[mfpType] = addPowerDict.get(mfpType, 0) + addPower
    
    for mfpType, addPower in addPowerDict.items():
        curPlayer.SetDict(ChConfig.Def_PlayerKey_MFPEx % mfpType, addPower)
    return
 
#// A5 77 Íæ¼Ò¾«Á¶·¨±¦ #tagCMMWRefine
#
#struct tagCMMWRefine
#{
#    tagHead    Head;
#    DWORD    MWID;    // ·¨±¦ID
#    DWORD   MaterialID; //²ÄÁÏID
#};
def PlayerMWRefine(index, clientPack, tick):
    mwID = clientPack.MWID # ·¨±¦ID
    materialID = clientPack.MaterialID # ÌáÉý¸ÅÂÊÎïÆ·ID
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    playerID = curPlayer.GetPlayerID()
    allTreasureItemIDList = IpyGameDataPY.GetFuncEvalCfg("TreasureUpRateItem")
    if mwID not in allTreasureItemIDList:
        GameWorld.DebugLog("¸Ã·¨±¦²»ÄÜÖýÁ¶-·¨±¦ID:%s" % mwID, playerID)
        return
    
    isActive = GetIsActiveMagicWeapon(curPlayer, mwID)
    if not isActive:
        GameWorld.DebugLog("·¨±¦Î´¼¤»î£¬²»ÄÜÖýÁ¶-·¨±¦ID:%s" % mwID, playerID)
        return
    
    nextRefineLv = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponRefineLV % mwID) + 1
    mwRefineIpyData = GetMWRefineIpyData(mwID, nextRefineLv)
    if not mwRefineIpyData:
        GameWorld.DebugLog("·¨±¦ÒÑÂú¼¶£¬²»ÄÜÖýÁ¶-·¨±¦ID:%s, nextRefineLv=%s" % (mwID, nextRefineLv), playerID)
        return
    
    # ËùÐèÁ¶µ¤Â¯µÈ¼¶
    alchemyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyLV)
    if alchemyLV < mwRefineIpyData.GetNeedAlchemyLV():
        GameWorld.DebugLog("Á¶µ¤Â¯µÈ¼¶²»×㣬ÎÞ·¨ÖýÁ¶·¨±¦-·¨±¦ID:%s, nextRefineLv=%s,alchemyLV=%s,NeedAlchemyLV=%s" 
                           % (mwID, nextRefineLv, alchemyLV, mwRefineIpyData.GetNeedAlchemyLV()), playerID)
        return
    
    # ËùÐèËùÓз¨±¦µÈ¼¶
    needAllTreasureLV = mwRefineIpyData.GetNeedAllTreasureLV()
    for tID in allTreasureItemIDList:
        if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponRefineLV % tID) < needAllTreasureLV:
            GameWorld.DebugLog("ËùÓз¨±¦Ðè´ïµ½¶ÔÓ¦µÈ¼¶ºó²Å¿É¼ÌÐøÖýÁ¶! needAllTreasureLV=%s" % needAllTreasureLV, playerID)
            return
        
    needItemDict = mwRefineIpyData.GetMaterial()
    
    fujiaRate = 0
    if materialID:
        treasureUpRateItem = IpyGameDataPY.GetFuncEvalCfg("TreasureUpRateItem", 2)
        if materialID not in treasureUpRateItem:
            GameWorld.ErrLog("¸ÃÎïÆ·IDÎÞ·¨ÓÃÓÚÌáÉý·¨±¦ÖýÁ¶¸ÅÂÊ£¡itemID=%s" % (materialID), playerID)
            return
        rateItemData = GameWorld.GetGameData().GetItemByTypeID(materialID)
        if not rateItemData:
            return
        fujiaRate = rateItemData.GetEffectByIndex(0).GetEffectValue(0)
        needItemDict[materialID] = 1
        
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(needItemDict, itemPack)
    if lackItemDict:
        GameWorld.DebugLog("·¨±¦ÖýÁ¶²ÄÁϲ»×㣡·¨±¦ID:%s, nextRefineLv=%s,needItemDict=%s,lackItemDict=%s,hasItemDict=%s" 
                           % (mwID, nextRefineLv, needItemDict, lackItemDict, delInfoDict), playerID)
        return
    ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict, ChConfig.ItemDel_MagicWeapon)
    
    successRate = mwRefineIpyData.GetSuccessRate() + fujiaRate
    if GameWorld.CanHappen(successRate):
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponRefineLV % mwID, nextRefineLv)
        skillID = mwRefineIpyData.GetOpenSkill()
        if skillID:
            GiveSkill(curPlayer, skillID, tick)
        CalcMagicWeaponAttr(curPlayer)
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
        #֪ͨ¿Í»§¶Ë    
        Sycn_MagicWeaponRefineLV(curPlayer, mwID)
        curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitMWUpLevel, ChConfig.Def_ComposeState_Sucess)
        GameWorld.DebugLog("·¨±¦ÖýÁ¶³É¹¦! ·¨±¦ID:%s, upRefineLv=%s,successRate=%s" % (mwID, nextRefineLv, successRate), playerID)
    else:
        curPlayer.Sync_MakeItemAnswer(ShareDefine.Def_mitMWUpLevel, ChConfig.Def_ComposeState_Fail)
        GameWorld.DebugLog("·¨±¦ÖýÁ¶Ê§°Ü! ·¨±¦ID:%s, nextRefineLv=%s,successRate=%s" % (mwID, nextRefineLv, successRate), playerID)
        
    return
 
def Sycn_MagicWeaponRefineLV(curPlayer, mwID= -1):
    if mwID == -1:
        needCalList = IpyGameDataPY.GetFuncEvalCfg("TreasureUpRateItem")
    else:
        needCalList = [mwID]
    sendPack = ChPyNetSendPack.tagMCMagicWeaponMsg()
    sendPack.MWInfo = []
    for mwID in needCalList:
        mwRefineLv = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_MagicWeaponRefineLV % mwID)
        if not mwRefineLv:
            continue
        pack = ChPyNetSendPack.tagMCMagicWeaponLV()
        pack.MWID = mwID
        pack.MWLV = mwRefineLv
        sendPack.MWInfo.append(pack)
    sendPack.Count = len(sendPack.MWInfo)
    if sendPack.Count:
        NetPackCommon.SendFakePack(curPlayer, sendPack)
    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:
        needCalList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetTreasureCount()):
            ipyData = ipyDataMgr.GetTreasureByIndex(i)
            needCalList.append(ipyData.GetID())
    else:
        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)
        if not mwLv and not curUpExp and not state:
            continue
        pack = ChPyNetSendPack.tagMCMagicWeaponInfo()
        pack.MWID = mwID
        pack.LV = mwLv
        pack.Exp = curUpExp
        pack.State = state
        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
    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 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