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
#!/usr/bin/python
# -*- coding: GBK -*-
#
# @todo: 
#
# @author: Alee
# @date 2017-11-23 ÏÂÎç01:56:11
# @version 1.0
#
# @note: 
#
#---------------------------------------------------------------------
import GameWorld
import IPY_GameWorld
import SkillCommon
import PlayerControl
import NPCCommon
import GameBuffs
import ChConfig
import FBLogic
import SkillShell
import PassiveBuffEffMng
import ChNetSendPack
import PlayerTJG
import OperControlManager
import GameObj
import CrossPlayerData
import AttackCommon
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
## Ö´ÐÐÌí¼ÓBuff²¢Ë¢ÐÂÊôÐÔ
#  @param curObj µ±Ç°¶ÔÏó
#  @param buffType buffÀàÐÍ
#  @param curSkill µ±Ç°¼¼ÄÜ
#  @param tick µ±Ç°Ê±¼ä
#  @param value Buff×ÜÖµ->ÓÃÓÚ³ÖÐøÀ༼ÄÜ
#  @param buffOwner BuffÓµÓÐÕß
#  @param addForce ´ú±íÊÇ·ñÒ»¶¨Ìí¼Óbuff£¬±ÜÃ⻥Ïà·´µ¯buff
def DoAddBuff( curObj, buffType, curSkill, tick, addBuffValueList = [], buffOwner = None, addForce = False ):
    if curObj == None:
        # ±ÜÃâÅä±í´íÎóµ¼Ö±¨´í
        return False
 
    if GameWorld.GetMap().GetMapID() == ChConfig.Def_FBMapID_GatherSoul and curObj.GetGameObjType() == IPY_GameWorld.gotNPC:
        if curSkill.GetSkillTypeID() != 23052:
            #GameWorld.DebugLog('¾Û»ê¸±±¾Íæ¼Ò²»ÄܶԹÖÎïÉÏbuff curSkill=%s,buffOwner=%s'%(curSkill.GetSkillTypeID(),buffOwner.GetID()))
            return True
        #GameWorld.DebugLog('¾Û»ê¸±±¾¶Ô¹ÖÎïÉÏbuff curSkill=%s,buffOwner=%s'%(curSkill.GetSkillTypeID(),buffOwner.GetID()))
        
    if curObj.GetGameObjType() == IPY_GameWorld.gotNPC and curObj.GetIsBoss() not in ChConfig.Def_SkillAttack_NPCIsBoss \
    and SkillCommon.GetSkillBattleType(curSkill) == ChConfig.Def_BattleRelationType_CommNoBoss and SkillShell.IsNPCSkillResist(curObj):
        # Êͷźó ¶ÔÖ¸¶¨BOSSÎÞЧµÄ¼¼ÄÜ
        return True
    
    buffOwner = AttackCommon.ElfChangeAttacker(buffOwner)  # ElfÁéÎªÌæÉí¹¥»÷£¬ÒªÈ¡Íæ¼ÒµÄÊôÐÔ
    
    result = AddBuffNoRefreshState(curObj, buffType, curSkill, tick, addBuffValueList, buffOwner, addForce)
    
    if result is not 0:
        # ±»µÖÏûµÄbuff ²»´¦Àí
        #ÏÈË¢ÐÐΪBUFF³É¹¦Ôò²»Ë¢ ÊôÐÔ
        __AddActBuffRefreshState(curObj, curSkill, buffType)
    
    if result:
        #Ë¢ÐÂÊôÐÔ
        curObjType = curObj.GetGameObjType()
        #Íæ¼Ò
        if curObjType == IPY_GameWorld.gotPlayer:
            #Ë¢ÐÂÍæ¼ÒÊôÐÔ
            playerControl = PlayerControl.PlayerControl(curObj)
            #playerControl.CalcPassiveBuffAttr()
            playerControl.RefreshPlayerAttrByBuff()
        #NPC
        elif curObjType == IPY_GameWorld.gotNPC:
            npcControl = NPCCommon.NPCControl(curObj)
            npcControl.RefreshNPCAttrState()
        #Òì³£
        else:
            GameWorld.Log("Ìí¼ÓbuffË¢ÐÂʧ°Ü curObjType = %s"%(curObjType))
    
    return result
 
 
# ¿ì½ÝËÑË÷ CanRepeatTime×Ö¶Î
# buffʱ¼ä´¦ÀíÀàÐÍ£¬¸öλÊý
def GetBuffRepeatTimeType(curSkill):
    return curSkill.GetCanRepeatTime()%10
 
# buffÌæ»»Âß¼­£¬Ê®Î»Êý
def GetBuffReplaceType(curSkill):
    return curSkill.GetCanRepeatTime()/10%10
 
# buff¸ù¾ÝÊÍ·ÅÕß²»Í¬ÅжÏÊÇ·ñ¹²´æbuff£¬°ÙλÊý Def_Buff_NoCoexist 
def GetBuffCoexistType(curSkill):
    return curSkill.GetCanRepeatTime()/100
 
def GetBuffMaxLayer(curSkill):
    layerMaxCnt = 0
    hasEffect = SkillCommon.GetSkillEffectByEffectID(curSkill, ChConfig.Def_Skill_Effect_LayerCnt)
    if hasEffect:
        layerMaxCnt = hasEffect.GetEffectValue(0)   # Äܵþ¼ÓµÄ×î´óÉÏÏÞ
 
    return layerMaxCnt
 
def IsLayerPlusAttr(curBuff):
    ## ÊÇ·ñµþ¼ÓÊôÐԲ㼶buff£¬¿Éµþ¼Óʱ£¬ÊôÐÔ=µ¥²ãÊôÐÔ*²ã¼¶£¬Ä¬Èϵþ¼Ó
    hasEffect = SkillCommon.GetSkillEffectByEffectID(curBuff.GetSkill(), ChConfig.Def_Skill_Effect_LayerCnt)
    if not hasEffect:
        return False
    if hasEffect.GetEffectValue(1)/10 == 1:
        # ÅäÖò»µþ¼Ó£¬Ö±½Ó·µ»ØFalse
        return False
    return True
 
# ¸Ä±äBUFF³ÖÐøÊ±¼ä
def ChangeLastTime(attacker, curSkill):
    buffTime = curSkill.GetLastTime() 
    if not attacker:
        return buffTime 
    if curSkill.GetEffect(0).GetEffectID() == ChConfig.Def_Skill_Effect_Burn:
        # ×ÆÉÕµÄʱ¼äÌØÊâ´¦Àí
        buffTime = buffTime*(ChConfig.Def_MaxRateValue + PlayerControl.GetBurnTimePer(attacker))/ChConfig.Def_MaxRateValue
    
    buffTime += PassiveBuffEffMng.GetPassiveSkillValueByTriggerType(attacker, None, curSkill, ChConfig.TriggerType_BuffTime)
    return buffTime
    
 
#---------------------------------------------------------------------
## Ôö¼ÓBUFF ¼õÉÙBUFF(²ÎÊý -> µ±Ç°¶ÔÏó,buffÀàÐÍ,µ±Ç°¼¼ÄÜ,µ±Ç°Ê±¼ä,Buff×ÜÖµ->ÓÃÓÚ³ÖÐøÀ༼ÄÜ , BuffÓµÓÐÕß)
#  buffµÄeffectÔÚÌí¼ÓºÍɾ³ýµÄʱºò´¦Àí£¬buff¹²´æÓÉbuff±¾Éí¾ö¶¨¶ø²»ÊÇeffect»¥³â£¬²»ÔÙͳһµ÷ÓÃRefreshPlayerBuffOnAttrAddEffect
#  plusValueList ¸ÄΪbuff valueÁÐ±í µÚÒ»¸öΪÔö¼ÓÊýÖµ£¬ÆäËû×Ô¶¨Òå
#  addForce ±íʾÊÇ·ñÒ»¶¨»áÔö¼Óbuff£¬±ÜÃ⻥Ïà·´µ¯buff
#  ·µ»ØÖµ ·µ»ØÕæË¢ÊôÐÔ£¬·µ»Ø0 ´ú±í±»µÖÏûbuff
def AddBuffNoRefreshState( curObj, buffType, curSkill, tick, plusValueList=[], buffOwner = None, addForce = False):
    if not SkillCommon.IsBuff(curSkill):
        GameWorld.ErrLog("%s ²»ÄܼÓÕâ¸öbuff, ÒòΪËüÊǹ¥»÷¼¼ÄÜ! %s-->TypeID = %d"%(curObj.GetName(), curSkill.GetSkillName(), curSkill.GetSkillType()))
        return False
 
    buffTuple = SkillCommon.GetBuffManagerByBuffType( curObj, buffType )
    #ͨ¹ýÀàÐÍ»ñȡĿ±êµÄbuff¹ÜÀíÆ÷Ϊ¿Õ£¬ÔòÌø³ö
    if buffTuple == ():
        return False
    
    if not addForce and curSkill.GetSkillType() in ChConfig.Def_Debuff_List:
        if PassiveBuffEffMng.OnPassiveSkillHappen(curObj, buffOwner, curSkill, ChConfig.TriggerType_DebuffOff, tick):
            # ´Ë´¦±ØÐë·µ»Ø0 ÓÃÓÚÍâ²ãÅжϱ»µÖÏû
            return 0
        
        if PassiveBuffEffMng.OnPassiveBuffHappen(curObj, buffOwner, curSkill, ChConfig.TriggerType_DebuffOff, tick):
            # ±»¶¯ÀàbuffµÖÏû
            # ´Ë´¦±ØÐë·µ»Ø0 ÓÃÓÚÍâ²ãÅжϱ»µÖÏû
            return 0
 
    buffState = buffTuple[0]
    maxBuffCount = buffTuple[1]
    buffCount = buffState.GetBuffCount()
    #¼¼ÄÜID
    curSkillID = curSkill.GetSkillID()
    #¼¼ÄÜÀàÐÍID
    curSkillTypeID = curSkill.GetSkillTypeID()
    #µ±Ç°¼¼ÄܳÖÐøÊ±¼ä
    curSkillLastTime = ChangeLastTime(buffOwner, curSkill)
    #µ±Ç°¼¼Äܵȼ¶
    curSkillLV = curSkill.GetSkillLV()
    #Ìæ»»Ä£Ê½
    buffReplaceType = GetBuffReplaceType(curSkill)
    #¹²´æÄ£Ê½ 
    buffCoexistType = GetBuffCoexistType(curSkill)
    #ʱ¼ä´¦ÀíÀàÐÍ
    buffRepeatTimeType = GetBuffRepeatTimeType(curSkill) 
    #ÓÃÓÚBUFFÂúµÄʱºò´¦ÀíË¢ÐÂÂß¼­
    isDelRefresh = False
    
    #valueÖµÏÞÖÆ²»³¬¹ý20E
    for i in range(len(plusValueList)):
        plusValueList[i] = min(plusValueList[i], ChConfig.Def_UpperLimit_DWord)
        
    # Ïò¿ç·þ·¢ËÍÊý¾Ý
    CrossPlayerData.SendMergeData_Buff(curObj, curSkillID, plusValueList)
    
    # buff²ã¼¶
    layerMaxCnt = 0
    layerCalc = 0
    hasEffect = SkillCommon.GetSkillEffectByEffectID(curSkill, ChConfig.Def_Skill_Effect_LayerCnt)
    if hasEffect:
        layerMaxCnt = hasEffect.GetEffectValue(0)   # Äܵþ¼ÓµÄ×î´óÉÏÏÞ
        layerCalc = hasEffect.GetEffectValue(1)%10     # Ôö¼Ó²ã¼¶»¹ÊǼõÉٲ㼶 Def_BuffLayer_Add
 
    
    #1 ¼ì²éÊÇ·ñÓÐÏàͬµÄBUFF£¬Èç¹ûÓÐÏàͬµÄ¾ÍË¢ÐÂʱ¼ä
    for i in range( 0, buffCount ):
        curBuff = buffState.GetBuff(i)
        if not curBuff:
            continue
        
        #ÅжÏÊÇ·ñÓµÓÐͬһÀàÐ͵ļ¼ÄÜ
        buffSkill = curBuff.GetSkill()
        if buffSkill.GetSkillTypeID() != curSkillTypeID:
            continue
        
        if buffCoexistType == ChConfig.Def_Buff_Coexist and buffOwner:
            #¿Éͬʱ´æÔÚµÄbuff£¬ÅжÏÊÍ·ÅÕßÊÇ·ñ²»Ò»Ñù
            if curBuff.GetOwnerID() != buffOwner.GetID() or curBuff.GetOwnerType() != buffOwner.GetGameObjType():
                continue
        
        #--------------¼¼ÄÜÀàÐÍIDÏàͬ
        #buff¼¼Äܵȼ¶
        buffSkillLV = buffSkill.GetSkillLV()
        #buff¼¼ÄÜID
        buffSkillID = buffSkill.GetSkillID()
        buffValue = curBuff.GetValue() # µ±Ç°ÒÑÓÐÈÝÁ¿
        
        if buffReplaceType == ChConfig.Def_Buff_Replace_Better:
            if buffSkillLV > curSkillLV:
                # Ö»È¡×îºÃµÄ, ²»¿É¼ÓÖ±½ÓÍ˳ö
                return False
        
        resultTime = -1 #²»¸Ä±äʱ¼äµÄÇé¿ö
        if buffRepeatTimeType == ChConfig.Def_BuffTime_Reset:
            # ÖØÖÃʱ¼ä
            resultTime = curSkillLastTime
        elif buffRepeatTimeType == ChConfig.Def_BuffTime_Add:
            # ÑÓ³¤Ê±¼ä
            curBuffRemainTime = curBuff.GetRemainTime()
            resultTime = min(curSkillLastTime + curBuffRemainTime, ChConfig.Def_Max_Buff_RemainTime)
            #__NotifyMsg_MaxLastTime( curObj, buffSkillID, buffSkillLV ) ¿Í»§¶ËÌáʾ
        elif buffRepeatTimeType == ChConfig.Def_BuffTime_Keep_AddValue:
            # Ê±¼ä²»¶¯Ôö¼ÓÖµ
            if len(plusValueList) > 0:
                plusValueList[0] = min(buffValue + plusValueList[0], ChConfig.Def_UpperLimit_DWord)
                
        if buffSkillLV == curSkillLV:
            changeLayer = False
            if layerMaxCnt and curBuff.GetLayer() < layerMaxCnt:
                if layerCalc == ChConfig.Def_BuffLayer_Add:
                    curBuff.SetLayer(curBuff.GetLayer() + 1)
                    #BUFF²ã¼¶±ä»¯´¥·¢±»¶¯
                    if buffOwner:
                        curObj.SetDict(ChConfig.Def_PlayerKey_AddBuffLayer, curBuff.GetLayer())
                        PassiveBuffEffMng.OnPassiveSkillTrigger(buffOwner, curObj, curSkill, ChConfig.TriggerType_AddLayer, tick)
                        PassiveBuffEffMng.OnPassiveBuffTrigger(buffOwner, curObj, curSkill, ChConfig.TriggerType_AddLayer, tick)
                        curObj.SetDict(ChConfig.Def_PlayerKey_AddBuffLayer, 0)
                else:
                    curBuff.SetLayer(layerMaxCnt)
                changeLayer = True
                    
            # Def_Buff_Replace_NewºÍDef_Buff_Recharge ¾ù¿É×ßµ½´ËÂß¼­
            __BuffCanRemain(curObj, buffState, curBuff, i, resultTime, plusValueList, buffOwner)
 
            return changeLayer
        else:
            if buffReplaceType == ChConfig.Def_Buff_Recharge:
                # ³äÄÜÐÍ
                __BuffCanRemain(curObj, buffState, curBuff, i, resultTime, plusValueList, buffOwner)
                return
            
            processInterval = curBuff.GetProcessInterval()
            ownerID, ownerType = curBuff.GetOwnerID(), curBuff.GetOwnerType()
            buffState.DeleteBuffByIndex(i)
            SkillShell.ClearBuffEffectBySkillID(curObj, buffSkillID, ownerID, ownerType)
            return __AddBuff(curObj, buffState, curSkill, plusValueList, buffOwner, isDelRefresh, 
                             tick, curSkillLastTime, processInterval, layerMaxCnt, layerCalc)
        
        #ÒѾ­ÕÒµ½Í¬Ò»ÀàÐ͵ļ¼ÄÜ£¬Á¢¼´Í˳ö²»È»»áµ¼Ö´íÂÒ
        return False
        
    
    #2 ¼ì²éBUFFÊÇ·ñÒѾ­ÂúÁË£¬Èç¹ûÒѾ­ÂúÁ˾ͰÑ×îÔçµÄBUFF³åµô
    while buffState.GetBuffCount() >= maxBuffCount: 
        curBuff = buffState.GetBuff(0)
        ownerID, ownerType = curBuff.GetOwnerID(), curBuff.GetOwnerType()
        DoBuffDisApper( curObj, curBuff, tick )
        #ɾ³ý×îÔç¼ÓÉϵÄBuff
        buffState.DeleteBuffByIndex(0)
        SkillShell.ClearBuffEffectBySkillID(curObj, buffSkillID, ownerID, ownerType)
        #ɾ³ýδ֪BUFF£¬Ë¢ÐÂÊôÐÔ
        isDelRefresh = True
    
    return __AddBuff(curObj, buffState, curSkill, plusValueList, buffOwner, isDelRefresh, 
                     tick, curSkillLastTime, 0, layerMaxCnt, layerCalc)
 
 
## ÊÇ·ñѪ°ü/À¶°übuff
# @param curSkill
# @return 
def __IsMPHPPackageBuff(curSkill):
    for i in range(0, curSkill.GetEffectCount()):
        curEffect = curSkill.GetEffect(i)
        curEffectID = curEffect.GetEffectID()
        
        if not curEffectID:
            continue
        
        if curEffectID in [ChConfig.Def_Skill_Effect_HPPackage, ChConfig.Def_Skill_Effect_MPPackage, 
                           ChConfig.Def_Skill_Effect_PetHPPackage]:
            return True
        
    return False
 
# Í¬²½ÎªÖ÷´ÓbuffµÄʱ¼ä
def SyncMasterBuffTime(curObj, curBuff, curSkill):
    curObjType = curObj.GetGameObjType()
    #Íæ¼Ò
    if curObjType != IPY_GameWorld.gotPlayer:
        return
    findEffect = SkillCommon.GetSkillEffectByEffectID(curSkill, ChConfig.Def_Skill_Effect_MasterBuff)
    if not findEffect:
        return
    
    masterSkillTypeID = findEffect.GetEffectValue(0)
    if not masterSkillTypeID:
        return
    
    findSkill = GameWorld.GetGameData().GetSkillBySkillID(masterSkillTypeID)
    if not findSkill:
        return
    
    buffType = SkillCommon.GetBuffType(findSkill)
    buffTuple = SkillCommon.GetBuffManagerByBuffType(curObj, buffType)
    if buffTuple == ():
        return
    
    buffManager = buffTuple[0]
    findBuff = buffManager.FindBuff(masterSkillTypeID)
    if not findBuff:
        return
    
    #GameWorld.DebugLog("SyncMasterBuffTime----SetRemainTime--%s"%curSkill.GetSkillID())
    curBuff.SetRemainTime(findBuff.GetRemainTime())
 
##Ìí¼ÓBUFF, Ñ¹Èëbuffvalue, ¾ßÌåBUFF·ÖÖ§´¦Àí£¬¹ýÂËË¢ÐÂ
# @param curObj ÊÜЧ¹ûÕß
# @param buffState buff¹ÜÀíÆ÷
# @param curSkill ¼¼ÄÜʵÀý
# @param value Ñ¹ÈëbuffµÄÖµ
# @param buffOwner buffµÄÊÍ·ÅÕß
# @param isDelRefresh Íâ½çɾ³ýBUFFÊÇ·ñË¢ÐÂ
# @param tick Ê±¼ä´Á
# @return ÊÇ·ñË¢ÐÂÍæ¼ÒÊôÐÔ
def __AddBuff(curObj, buffState, curSkill, plusValueList, buffOwner, isDelRefresh, tick,
              curSkillLastTime, updProcessInterval, layerMaxCnt, layerCalc):
    skillID = curSkill.GetSkillID()
 
    #ÊÇ·ñÐèҪ֪ͨ¿Í»§¶Ë
    isNotify = True if curSkill.GetClientEffectType() != 0 else False
    # Ôö¼ÓµÚËĸö²ÎÊýÊÇ·ñÁ¢¼´¹ã²¥
    addBuff = buffState.AddBuff(skillID, tick, isNotify, False)
    
    if updProcessInterval > 0:
        # ¼Ì³ÐÉÏÒ»¸öbuffµÄÑ­»·¼Ç¼
        addBuff.SetProcessInterval(updProcessInterval)
        
    #ÉèÖÃbuffÊôÐÔ
    __SetBuffValue(addBuff , plusValueList , buffOwner)
    
    # ²ã¼¶
    if layerMaxCnt:
        if layerCalc == ChConfig.Def_BuffLayer_Add:
            addBuff.SetLayer(1)
        else:
            addBuff.SetLayer(layerMaxCnt)
 
    addBuff.SetRemainTime(curSkillLastTime)
    
    # Í¬²½Ö÷´Ó¼¼ÄÜʱ¼ä
    SyncMasterBuffTime(curObj, addBuff, curSkill)
    
    passiveEff = None
    onwerID = 0
    onwerType = 0
    isRefresh = False # ÊÇ·ñË¢ÊôÐÔ
    
    if buffOwner:
        onwerID, onwerType = buffOwner.GetID(), buffOwner.GetGameObjType()
    # buffЧ¹û¼ÓÈë
    for effectIndex in range(0, curSkill.GetEffectCount()):
        curEffect = curSkill.GetEffect(effectIndex)
        effectID = curEffect.GetEffectID()
        if effectID == 0:
            continue
        
        # »ñµÃbuffЧ¹ûµÄ¼ÆËãÄ£¿éÎļþºó׺, Èç¹ûÄÜÕÒµ½ËµÃ÷ÐèҪˢÊôÐÔ
        moduleSuffix = SkillShell.GetBuffModuleSuffix(curEffect) 
        calcTypeFunc = GameWorld.GetExecFunc(GameBuffs, "Buff_%s.%s"%(moduleSuffix, "GetCalcType"))
        if calcTypeFunc:
            isRefresh = True
        
        # Ö¸¶¨µÄЧ¹ûID²Å¼Ç¼£¬Ë¢ÊôÐÔÒѾ­²»ÔÙͨ¹ý±éÀúЧ¹û¶ÓÁиijɱéÀúbuff
        if effectID in ChConfig.Def_BuffManager_EffectsID:
            buffState.AddEffect(curEffect, addBuff.GetValue(), skillID, onwerID, onwerType)
            
        triggerType = PassiveBuffEffMng.GetBuffTriggerTypeByEffectID(effectID)
        if triggerType == -1:
            continue
        passiveEff = PassiveBuffEffMng.GetPassiveEffManager().InitObjPassiveEff(curObj)
        passiveEff.AddBuffInfoByEffect(curEffect, skillID, onwerID, onwerType)
        
    # Í¨Öª¿Í»§¶Ë
    #buffState.Sync_AddBuffEx()
    if isNotify:
        PYSync_RefreshBuff(curObj, addBuff, SkillCommon.GetBuffType(curSkill), notifyAll=False, owner = buffOwner, errSkillID=skillID)
        
    #Ìí¼ÓBUFFºóµÄÌØÊâ´¦Àí
    DoAddBuffOver(curObj, curSkill, addBuff, buffOwner, tick)
 
    #¼ì²éÊÇ·ñÊôÓÚË¢ÐÂBUFF
    #===========================================================================
    # if not CheckBuffRefresh(curSkill, isDelRefresh):
    #    return False
    #===========================================================================
    
    return isRefresh
 
 
##buff¼ÓÉÏÖ®ºóµÄ´¦Àí£¬ÕâÀï»á¶ÔBUFFValue´¦Àí£¬´ËǰҪÏÈÉèÖúÃ
# @param curObj ÊÜЧ¹û·½
# @param curSkill buff¼¼ÄÜÊý¾Ý
# @param addBuff Íæ¼ÒÉíÉϵÄBUFFʵÀý
# @param tick Ê±¼ä´Á
# @return None 
def DoAddBuffOver(curObj, curSkill, addBuff, buffOwner, tick):
    #´¥·¢±»¶¯¼¼ÄÜ
    if buffOwner:
        PassiveBuffEffMng.OnPassiveSkillTrigger(buffOwner, curObj, curSkill, ChConfig.TriggerType_AddBuffOver, tick)
        # ´Ë´¦²»ÄÜ´«¼¼ÄÜcurSkill ÆÁ±Î±»¶¯´¥·¢±»¶¯ÏÞÖÆ
        # ÔÝÇÒÌØÊâ´¦Àí¿ØÖÆÀàbuff²Å´¥·¢
        if SkillCommon.GetBuffType(curSkill) == IPY_GameWorld.bfActionBuff:
            PassiveBuffEffMng.GetValueByPassiveBuffTriggerType(curObj, buffOwner, curSkill, ChConfig.TriggerType_AddBuffOver, False)
        
    #ÊÇ·ñÊdzÖÐøÐÔ¼¼ÄÜ
    isLstSkill = curSkill.GetSkillType() in ChConfig.Def_LstBuff_List
    
    #buff¼ÓÉϺóµÄÌØÊâ´¦Àí
    for effectIndex in range(0, curSkill.GetEffectCount()):
        curEffect = curSkill.GetEffect(effectIndex)
        effectID = curEffect.GetEffectID()
        
        if not effectID:
            continue
        
        if isLstSkill:
            callFunc = GameWorld.GetExecFunc(GameBuffs, "BuffProcess_%d.%s"%(effectID, "DoAddBuffOver"))
            if not callFunc:
                callFunc = GameWorld.GetExecFunc(GameBuffs, "Buff_%d.%s"%(effectID, "DoAddBuffOver"))
        else:        
            callFunc = GameWorld.GetExecFunc(GameBuffs, "Buff_%d.%s"%(effectID, "DoAddBuffOver"))
        
        if not callFunc:
            continue
        
        callFunc(curObj, addBuff, curEffect, tick, buffOwner)
    
    return
 
 
##Ìí¼ÓBUFF¹ýÂËË¢ÐÂ
# @param curSkill
# @param isDelRefresh Íâ½çɾ³ýBUFFÊÇ·ñË¢ÐÂ
# @return ÊÇ·ñË¢ÐÂÍæ¼ÒÊôÐÔ
def CheckBuffRefresh(curSkill, isDelRefresh):
    #===========================================================================
    # skillType, skillTypeID = curSkill.GetSkillType(), curSkill.GetSkillTypeID()
    # #³ÖÐøÐÔBUFF²»Ë¢ÐÂÊôÐÔ
    # if skillType in ChConfig.Def_LstBuff_List:
    #    return False
    #===========================================================================
    
    #¶¥ÌæBUFFÖ±½ÓˢУ¬²»×öÏêϸÅж¨
    if isDelRefresh:
        return True
    
    isRefresh = False
    for effectIndex in range(0, curSkill.GetEffectCount()):
        curEffect = curSkill.GetEffect(effectIndex)
        effectID = curEffect.GetEffectID()
        if effectID == 0:
            continue
        
        # »ñµÃbuffЧ¹ûµÄ¼ÆËãÄ£¿éÎļþºó׺
        moduleSuffix = SkillShell.GetBuffModuleSuffix(curEffect) 
        calcTypeFunc = GameWorld.GetExecFunc(GameBuffs, "Buff_%s.%s"%(moduleSuffix, "GetCalcType"))
        if calcTypeFunc:
            isRefresh = True
            break
 
    return isRefresh
 
 
## Ìí¼ÓBUFF Ë¢ÐÂÐÐΪ״̬
#  @param curObj µ±Ç°¶ÔÏó
#  @param curSkill µ±Ç°¼¼ÄÜ
#  @param buffType buffÀàÐÍ
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.AddBuffNoRefreshStateÖÐʹÓÃ
def __AddActBuffRefreshState(curObj, curSkill, buffType):
    #Ë¢ÐÂÐÐΪ״̬£¬
    if buffType != IPY_GameWorld.bfActionBuff:
        return False
 
    #Ë¢ÐÂÊôÐÔ
    curObjType = curObj.GetGameObjType()
    # Ìí¼Ó¿ØÖÆBUFF²»ÓÃÈ«²¿Ë¢ÐÂ
    #Íæ¼Ò
    if curObjType == IPY_GameWorld.gotPlayer:
        #Ë¢ÐÂËùÓÐ״̬
        #playerControl = PlayerControl.PlayerControl(curObj)
        #playerControl.RefreshPlayerActionState()
        OperControlManager.SetObjActState(curObj, curSkill)
    #NPC
    elif curObjType == IPY_GameWorld.gotNPC:
        #npcControl = NPCCommon.NPCControl(curObj)
        #npcControl.RefreshNPCActionState()
        OperControlManager.SetObjActState(curObj, curSkill)
    #Òì³£
    else:
        GameWorld.Log("Ìí¼ÓÐÐΪbuffË¢ÐÂʧ°Ü curObjType = %s"%(curObjType))
        return False
    
    return True
#---------------------------------------------------------------------
## µ±Buffʱ¼äÂúµÄʱºò, Êä³öϵͳÌáʾ²¢¼Ç¼Á÷Ïò
#  @param curObj Ä¿±ê
#  @param skillID ¼¼ÄÜID
#  @param skillLV ¼¼Äܵȼ¶
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __NotifyMsg_MaxLastTime( curObj, skillID, skillLV ):
    curObjID = curObj.GetID()
    curObjType = curObj.GetGameObjType()
    
    #Ö»´¦ÀíÍæ¼Ò
    if curObjType != IPY_GameWorld.gotPlayer:
        return
    
    curPlayer = GameWorld.GetObj( curObjID, curObjType )
    
    if not curPlayer:
        GameWorld.Log('###__NotifyMsg_MaxLastTime Err ( %s , %s )'%( curObjID, curObjType ) )
        return
    
    #¶Ô²»Æð£¬ÄúÉíÉÏÀÛ»ýµÄҩˮʱ¼äÒÑ´ïÉÏÏÞ,ÎÞ·¨¼ÌÐøµþ¼Ó!
    #F607977B-0A57-4B68-A5CDB2C5DAEF4D18Ìæ»»ÎªGeRen_chenxin_60292
    PlayerControl.NotifyCode( curPlayer, "GeRen_chenxin_60292" )
    
    return
#---------------------------------------------------------------------
## ÅжÏÕâ¸öbuffÊÇ·ñ¿ÉÒÔµþ¼Ó
#  @param curSkill µ±Ç°¼¼ÄÜ
#  @param buffState buff״̬
#  @param curBuff µ±Ç°buff
#  @param buffIndex buffË÷Òý
#  @param curSkillLastTime µ±Ç°¼¼ÄܳÖÐøÊ±¼ä
#  @param sumTime ÀÛ¼Óʱ¼ä
#  @param value Buff×ÜÖµ->ÓÃÓÚ³ÖÐøÀ༼ÄÜ
#  @param buffOwner buffÓµÓÐÕß
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __BuffCanRemain(curObj, buffState, curBuff, buffIndex, resultTime, plusValueList, buffOwner):
    if resultTime != -1:
        curBuff.SetRemainTime(resultTime)
    #ÖØÖÃbuff×ÜÖµ
    __SetBuffValue(curBuff , plusValueList , buffOwner)
 
    buffState.Sync_RefreshBuff(buffIndex, curBuff.GetRemainTime())
    
    DoAddBuffOver(curObj, curBuff.GetSkill(), curBuff, buffOwner, GameWorld.GetGameWorld().GetTick())  
    return
 
#---------------------------------------------------------------------
## ´Ó¹ÜÀíÆ÷ÖÐÈ¡µÃBUFFʵÀýºÍË÷Òý
#  @param buffManager Buff¹ÜÀíÆ÷
#  @param skillTypeID ¼¼ÄÜÀàÐÍID
#  @return BUFFʵÀýºÍË÷Òý
#  @remarks ´Ó¹ÜÀíÆ÷ÖÐÈ¡µÃBUFFʵÀýºÍË÷Òý
def GetBuffAndIndexInManager(buffManager, skillTypeID):
    for i in range(0, buffManager.GetBuffCount()):
        curBuff = buffManager.GetBuff(i)
        
        if not curBuff:
            continue
        
        #ÅжÏÊÇ·ñÓµÓÐͬһÀàÐ͵ļ¼ÄÜ
        if curBuff.GetSkill().GetSkillTypeID() != skillTypeID:
            continue
        
        return curBuff, i
    
    return None, 0
 
 
#---------------------------------------------------------------------
## Ë¢ÐÂBUFFµÄʱ¼ä
#  @param curBuff µ±Ç°BUFF
#  @param buffManager BUFF¹ÜÀíÆ÷
#  @param buffIndex buffË÷Òý
#  @param sumTime BUFF³ÖÐøÊ±¼ä
#  @return None
#  @remarks Ë¢ÐÂBUFFµÄʱ¼ä£¨²»°üÀ¨ÓÀ¾ÃBUFF£©
def Add_SyncBuffTime(curBuff, buffManager, buffIndex, addTime):
    #·À·¶Ê±¼äΪ0£¨´ú±íÓÀ¾Ã£©
    remainTime =curBuff.GetRemainTime()
    if remainTime == 0:
        GameWorld.ErrLog("²»¿É¸Ä±ä³ÖÐøÊ±¼ä£¬¸ÃBUFFΪÓÀ¾ÃÐÔBUFF %s"%curBuff.GetBuffID())
        return
    
    sumTime = remainTime + addTime
    if sumTime <= 0:
        GameWorld.ErrLog("BUFFʱ¼äÀÛ¼ÓÒì³£ %s = %s + %s"%(sumTime, remainTime, addTime))
        return
    
    curBuff.SetRemainTime(sumTime)
    #֪ͨ¿Í»§¶Ë
    buffManager.Sync_RefreshBuff(buffIndex, sumTime)
    
#---------------------------------------------------------------------                
## ÉèÖÃbuffµÄÊôÐÔ
#  @param buff buff
#  @param value buffÖµ
#  @param buffOwner buffÓµÓÐÕß
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __SetBuffValue(buff , valueList , buffOwner):
    #Ìí¼ÓBuffÉèÖÃ
    for i in range(len(valueList)):
        if i == 0:
            buff.SetValue(valueList[0])
        elif i == 1:
            buff.SetValue1(valueList[1])
        elif i == 2:
            buff.SetValue2(valueList[2])
            
    #if hasattr(curTime, callObj) != True:
    if buffOwner != None :
        buff.SetOwnerID(buffOwner.GetID())
        buff.SetOwnerType(buffOwner.GetGameObjType())
        
    return
#---------------------------------------------------------------------
## Ë¢ÐÂBuff
#  @param curObj  µ±Ç°¶ÔÏó
#  @param buffState buff״̬
#  @param tick µ±Ç°Ê±¼ä
#  @return True or False
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def RefreshBuff( curObj, buffState, tick ):
    #º¯ÊýÌå·µ»ØÖµ,ÊÇ·ñ³åË¢ÊôÐÔ
    isRefresh = False  # É¾³ýµÄbuffÊÇ·ñË¢ÊôÐÔ
    delResult = False     # É¾³ýµÄbuffÊÇ·ñË¢¿ØÖÆ
    
    # Èç¹ûÔÚbuffˢйý³ÌÖе¼ÖÂÍæ¼ÒËÀÍö£¬²¢ÇÒÒòËÀÍöÌáǰµ¼ÖÂbuff±»ÇåÀíÔò»áµ¼Ö±¨´í
    # µ«¿ÉÒÔÔÚË¢ÐÂǰ¾ÍÒѾ­ËÀÍöµÄ£¬Ôò¿ÉÒÔË¢ÐÂbuff
    beforeHP = GameObj.GetHP(curObj)
    
    index = 0
    isPlayerTJG = (curObj.GetGameObjType() == IPY_GameWorld.gotPlayer and PlayerTJG.GetIsTJG(curObj))
    
    skillIDListInDelBuff = []   # buffÏûʧÖÐÐèÒª´¦ÀíÌí¼Óbuff£¬Íâ²ã´¦Àí±ÜÃâ´íÂÒ
    
    while index < buffState.GetBuffCount():
        curBuff = buffState.GetBuff( index )
        if not curBuff:
            index += 1
            GameWorld.Log( "###Ë¢ÐÂBuffÒì³£ , ¶ÔÏó = %s"%( curObj.GetID() ) )
            continue
        curBuffRemainTime = curBuff.GetRemainTime()
        curSkill = curBuff.GetSkill()
        #Ìî±í,³ÖÐøÊ±¼äΪ0µÄBuffΪÓÀ¾ÃBuff
        if not curSkill.GetLastTime() and not curBuffRemainTime:
            index += 1
            continue
        
        if isPlayerTJG and curSkill.GetSkillTypeID() in ChConfig.TJGStateNotRefreshTimeBuff:
            curBuff.SetCalcStartTick( tick ) 
            index += 1
            #GameWorld.DebugLog("ÍÑ»ú¹Ò״̬ϲ»Ë¢ÐÂbuffʱ¼ä: skillTypeID=%s" % curSkill.GetSkillTypeID())
            continue
        
        remainTime = curBuffRemainTime - ( tick - curBuff.GetCalcStartTick() )
        #»¹ÓÐÊ£Óàʱ¼ä
        if remainTime > 0:
            curBuff.SetCalcStartTick( tick ) 
            curBuff.SetRemainTime( remainTime )
            index += 1
            continue
        #-------------------ÎÞÊ£Óàʱ¼äÁË
        curBuff.SetRemainTime(0)
 
        ownerID, ownerType = curBuff.GetOwnerID(), curBuff.GetOwnerType()
        #Õâ¸öº¯ÊýÀïÃæ²»ÄÜ×öBuffÌí¼ÓºÍɾ³ýÂß¼­!!!!!²»È»Ö¸Õë»á´íÂÒ
        DoBuffDisApper( curObj, curBuff, tick )
        
        if beforeHP != 0 and GameObj.GetHP(curObj) == 0:
            # Ë¢ÐÂǰÓÐѪÁ¿£¬Ë¢ÐºóËÀÍöÔòÍ˳ö£¬´ýÏÂÒ»´ÎˢУ¬±ØÐëËÀÍöÌáǰɾbuffµ¼Ö±¨´í
            return False, False
        
        #±ê¼Çɾ³ý±ê¼Ç
        if not isRefresh and CheckBuffRefresh(curSkill, False):
            # ÊôÐÔÀà
            isRefresh = True
 
        if not delResult:
            # ÓÃÓÚ¿ØÖÆÀàÅжÏ
            delResult = True
        buffState.DeleteBuffByIndex( index )
        SkillShell.ClearBuffEffectBySkillID(curObj, curSkill.GetSkillID(), ownerID, ownerType)
        
        addSkillID = curObj.GetDictByKey(ChConfig.Def_PlayerKey_SkillInDelBuff) 
        if addSkillID:
            skillInfo = [addSkillID, ownerID, ownerType]
            if skillInfo not in skillIDListInDelBuff:
                skillIDListInDelBuff.append(skillInfo)
            curObj.SetDict(ChConfig.Def_PlayerKey_SkillInDelBuff, 0) 
            
    OnSkillAfterBuffDisappear(curObj, skillIDListInDelBuff, tick)
    
    #Ö´ÐÐDoBuffDisApperÖÐ,±ê¼ÇµÄÍæ¼Ò´¦ÀíÒªÇó
    __DoBuffDisApperByKey( curObj , tick )
        
    return isRefresh, delResult
 
 
# DoBuffDisApper²»ÄÜ×öBuffÌí¼ÓºÍɾ³ýÂß¼­!!!!!²»È»Ö¸Õë»á´íÂÒ, ¹ÊÔÚÍâ²ã´¦Àí
def OnSkillAfterBuffDisappear(curObj, skillIDListInDelBuff, tick):
    posX, posY = curObj.GetPosX(), curObj.GetPosY()
    for skillInfo in skillIDListInDelBuff:
        attacker = GameWorld.GetObj(skillInfo[1], skillInfo[2])
        if not attacker:
            attacker = curObj
        skillData = GameWorld.GetGameData().GetSkillBySkillID(skillInfo[0])
        if not skillData:
            continue
        
        SkillShell.Trigger_UseSkill(attacker, curObj, skillData, tick, posX, posY)
    return
 
#---------------------------------------------------------------------
## Ö´ÐÐbuffÏûʧ´¥·¢Âß¼­
#  @param curObj µ±Ç°OBj
#  @param curBuff µ±Ç°buff
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def DoBuffDisApper( curObj, curBuff, tick ):
    #Õâ¸öº¯ÊýÀïÃæ²»ÄÜ×öBuffÌí¼ÓºÍɾ³ýÂß¼­!!!!!²»È»Ö¸Õë»á´íÂÒ
    curSkill = curBuff.GetSkill()
 
    curObjType = curObj.GetGameObjType()
    skillData = GameWorld.GetGameData().GetSkillBySkillID(curSkill.GetSkillID())
    
    #ÊÇ·ñÊdzÖÐøÐÔ¼¼ÄÜ
    isLstSkill = curSkill.GetSkillType() in ChConfig.Def_LstBuff_List
    
    PassiveBuffEffMng.OnPassiveSkillTrigger(curObj, None, curSkill, ChConfig.TriggerType_BuffDisappear, tick)
    
    #buffÏûʧµÄ´¥·¢
    for effectIndex in range( 0, curSkill.GetEffectCount() ):
        curEffect = curSkill.GetEffect( effectIndex )
        effectID = curEffect.GetEffectID()
        
        if not effectID:
            continue
        
        if isLstSkill:
            callFunc = GameWorld.GetExecFunc( GameBuffs, "BuffProcess_%d.%s"%( effectID, "OnBuffDisappear") )
            if not callFunc:
                callFunc = GameWorld.GetExecFunc( GameBuffs, "Buff_%d.%s"%( effectID, "OnBuffDisappear") )
        else:        
            callFunc = GameWorld.GetExecFunc( GameBuffs, "Buff_%d.%s"%( effectID, "OnBuffDisappear") )
        
        if not callFunc:
            continue
        
        callFunc( curObj, curSkill, curBuff, curEffect, tick )
        
        #=======================================================================
        # if curObjType == IPY_GameWorld.gotPlayer and curSkillTypeID in ChConfig.Ded_ComboBuffProcessSkillIDList:
        #    curObj.SetDict(ChConfig.Def_PlayerKey_ComboBuffProcessState, 0)
        #    #GameWorld.DebugLog("Á¬»÷buffÏûʧ£¬ÖØÖô¦Àí״̬£¡%s" % curSkillTypeID)
        #=======================================================================
            
    passiveEff = PassiveBuffEffMng.GetPassiveEffManager().GetPassiveEff(curObj)
    if passiveEff:
        passiveEff.DelBuffInfo(skillData)
    return
 
 
#---------------------------------------------------------------------
## Ö´ÐÐbuffÏûʧ´¥·¢Âß¼­£¬²»´¦ÀíbuffµÄ¹¦ÄÜÂß¼­£¬Ö»´¦ÀíÐèÒªµÄ±ØÐë״̬Âß¼­
#  Èç²»´¦ÀíbuffµÄ É˺¦£¬±¬Õ¨µÈ£¬µ«±ØÐë´¦Àí»Ö¸´Ñ£ÔÎ״̬µÈ
def DoBuffDisApperEx( curObj, curBuff, tick ):
    #Õâ¸öº¯ÊýÀïÃæ²»ÄÜ×öBuffÌí¼ÓºÍɾ³ýÂß¼­!!!!!²»È»Ö¸Õë»á´íÂÒ
    curSkill = curBuff.GetSkill()
 
    skillData = GameWorld.GetGameData().GetSkillBySkillID(curSkill.GetSkillID())
    
    #ÊÇ·ñÊdzÖÐøÐÔ¼¼ÄÜ
    isLstSkill = curSkill.GetSkillType() in ChConfig.Def_LstBuff_List
    
    PassiveBuffEffMng.OnPassiveSkillTrigger(curObj, None, curSkill, ChConfig.TriggerType_BuffDisappear, tick)
    
    #buffÏûʧµÄ´¥·¢
    for effectIndex in range( 0, curSkill.GetEffectCount() ):
        curEffect = curSkill.GetEffect( effectIndex )
        effectID = curEffect.GetEffectID()
        
        if not effectID:
            continue
        
        if isLstSkill:
            callFunc = GameWorld.GetExecFunc( GameBuffs, "BuffProcess_%d.%s"%( effectID, "OnBuffDisappearEx") )
            if not callFunc:
                callFunc = GameWorld.GetExecFunc( GameBuffs, "Buff_%d.%s"%( effectID, "OnBuffDisappearEx") )
        else:        
            callFunc = GameWorld.GetExecFunc( GameBuffs, "Buff_%d.%s"%( effectID, "OnBuffDisappearEx") )
        
        if not callFunc:
            continue
        
        callFunc( curObj, curSkill, curBuff, curEffect, tick )
            
    passiveEff = PassiveBuffEffMng.GetPassiveEffManager().GetPassiveEff(curObj)
    if passiveEff:
        passiveEff.DelBuffInfo(skillData)
    return
 
#---------------------------------------------------------------------
## buffÏûʧ
#  @param curObj µ±Ç°Ä¿±ê
#  @param µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __DoBuffDisApperByKey( curObj, tick ):
    
    #2012-06-13 jiang Ð޸ĺìÃûbuffÏûʧʱֱ½ÓÇå³ýpkÖµ
    #===========================================================================
    # if curObj.GetDictByKey(ChConfig.Def_Player_DelBuff_PncRed):
    #    #Ê£ÓàPKÖµ²»Îª0,Ìí¼ÓºìÃûBuff
    #    if curObj.GetPKValue() > 0:
    #        curObj.SetPKValue(0)
    #    
    #    #Çå¿Õ×ÖµäÖµ
    #    curObj.SetDict( ChConfig.Def_Player_DelBuff_PncRed , 0 )
    #===========================================================================
    
    #-------------¸±±¾µØÍ¼Âß¼­´¦Àí
    if GameWorld.GetMap().GetMapFBType() == IPY_GameWorld.fbtNull:
        return
    
    #FB BUFFÏûʧÂß¼­
    FBLogic.DoBuffDisAppear( curObj, tick )
    return
 
#---------------------------------------------------------------------
##ͨ¹ý¼¼ÄÜIDɾ³ý¶ÔÏóBuff£¬ Íâ²ãË¢ÐÂÊôÐÔ
# @param curPlayer Íæ¼ÒʵÀý
# @param skillID ¼¼ÄÜID
# @param tick Ê±¼ä´Á
# @return ²¼¶ûÖµ
def DelBuffBySkillID(curObj, skillID, tick, disappearTrigger=True, buffOwner=None):
    buffSkill = GameWorld.GetGameData().GetSkillBySkillID(skillID)
    
    #Òì³£´íÎó
    if not buffSkill:
        #GameWorld.Log("²éÕÒBuffÒì³£ = %s "%(ChConfig.Def_SkillID_JoinExam) , curPlayer.GetPlayerID())
        return False
    
    buffType = SkillCommon.GetBuffType(buffSkill)
    buffTuple = SkillCommon.GetBuffManagerByBuffType(curObj, buffType)
    #ͨ¹ýÀàÐÍ»ñȡĿ±êµÄbuff¹ÜÀíÆ÷Ϊ¿Õ£¬ÔòÌø³ö
    if buffTuple == ():
        return False
    
    buffMgr = buffTuple[0]
    #ÅжÏÊÇ·ñ´æÔÚµÄBUFF
    buffSkillTypeID = buffSkill.GetSkillTypeID()
    curBuff = buffMgr.FindBuff(buffSkillTypeID)
    if not curBuff:
        #Buff²»´æÔÚ
        return False
    
    ownerID, ownerType = curBuff.GetOwnerID(), curBuff.GetOwnerType()
    if buffOwner:
        if buffOwner.GetGameObjType() != ownerType or buffOwner.GetID() != ownerID:
            #GameWorld.DebugLog("buff¹éÊô²»Í¬£¬²»ÄÜÇå³ý£¡skillID=%s" % skillID, curObj.GetID())
            return False
    if disappearTrigger:
        #ɾ³ýBuff
        DoBuffDisApper(curObj, curBuff, tick)
    buffMgr.DeleteBuffByTypeID(buffSkillTypeID)
    
    SkillShell.ClearBuffEffectBySkillID(curObj, skillID, ownerID, ownerType)
    #ÕâÀïֻˢÐÂBUFFЧ¹ûÊý£¬Íâ²ã¾ö¶¨ÊÇ·ñË¢ÐÂÊôÐÔ
    #if refresh:
    #    SkillShell.RefreshPlayerBuffOnAttrAddEffect(curPlayer, buffType)
        
    # É¾³ýbuffÒ²ÐèÒª¿¼ÂÇÊÇ·ñÒòbuff×öË¢ÐÂÊôÐÔ ÈçÎÞÊôÐÔbuffºÍ¹¥ËÙ£¬Òƶ¯ËÙ¶È
    return True
 
 
# Í¨¹ý¼¼ÄÜtypeidɾ³ýbuff
def DelBuffBySkillTypeID(curPlayer, skillTypeID, tick, disappearTrigger=True):
    buffSkill = GameWorld.GetGameData().GetSkillBySkillID(skillTypeID)
    
    #Òì³£´íÎó
    if not buffSkill:
        #GameWorld.Log("²éÕÒBuffÒì³£ = %s "%(ChConfig.Def_SkillID_JoinExam) , curPlayer.GetPlayerID())
        return False
    
    buffType = SkillCommon.GetBuffType(buffSkill)
    buffTuple = SkillCommon.GetBuffManagerByBuffType(curPlayer, buffType)
    #ͨ¹ýÀàÐÍ»ñȡĿ±êµÄbuff¹ÜÀíÆ÷Ϊ¿Õ£¬ÔòÌø³ö
    if buffTuple == ():
        return False
    
    buffMgr = buffTuple[0]
    #ÅжÏÊÇ·ñ´æÔÚµÄBUFF
    buffSkillTypeID = buffSkill.GetSkillTypeID()
    curBuff = buffMgr.FindBuff(buffSkillTypeID)
    if not curBuff:
        #Buff²»´æÔÚ
        return False
    
    ownerID, ownerType = curBuff.GetOwnerID(), curBuff.GetOwnerType()
    #ɾ³ýBuff
    if disappearTrigger:
        DoBuffDisApper(curPlayer, curBuff, tick)
    buffMgr.DeleteBuffByTypeID(buffSkillTypeID)
    
    SkillShell.ClearBuffEffectBySkillTypeID(curPlayer, skillTypeID, ownerID, ownerType) 
    
    # É¾³ýbuffÒ²ÐèÒª¿¼ÂÇÊÇ·ñÒòbuff×öË¢ÐÂÊôÐÔ ÈçÎÞÊôÐÔbuffºÍ¹¥ËÙ£¬Òƶ¯ËÙ¶È
    return True
 
 
# µ±²ã¼¶Îª0µÄʱºòɾ³ý´Ëbuff
def SetBuffLayer(gameObj, buff, layer, delBuff=True, skillTypeID=0, disappearTrigger=True, isSync=False):
    buff.SetLayer(layer)
    if layer == 0 and delBuff:
        tick = GameWorld.GetGameWorld().GetTick()
        DelBuffBySkillTypeID(gameObj, skillTypeID, tick, disappearTrigger)
        
        curObjType = gameObj.GetGameObjType()
        #Íæ¼Ò
        if curObjType == IPY_GameWorld.gotPlayer:
            #Ë¢ÐÂÍæ¼ÒÊôÐÔ
            playerControl = PlayerControl.PlayerControl(gameObj)
            #playerControl.CalcPassiveBuffAttr()
            playerControl.RefreshPlayerAttrByBuff()
        #NPC
        elif curObjType == IPY_GameWorld.gotNPC:
            npcControl = NPCCommon.NPCControl(gameObj)
            npcControl.RefreshNPCAttrState()
    else:
        curObjType = gameObj.GetGameObjType()
        if isSync and curObjType == IPY_GameWorld.gotPlayer:
            buffType = SkillCommon.GetBuffType(buff.GetSkill())
            PYSync_RefreshBuff(gameObj, buff, buffType)
    return
 
def ReduceBuffLayer(gameObj, buff, skillTypeID, delLayerCnt=1):
    ## ¼õÉÙbuffµÄValueÖµ
    #GameWorld.DebugLog("ReduceBuffLayer: skillTypeID=%s,delLayerCnt=%s %s" % (skillTypeID, delLayerCnt, buff))
    if not buff and not skillTypeID:
        return
    
    if not buff:
        buff = SkillCommon.FindBuffByID(gameObj, skillTypeID)[0]
        
    if not buff or buff.GetLayer() <= 0:
        return
    
    SetBuffLayer(gameObj, buff, max(0, buff.GetLayer() - delLayerCnt), skillTypeID=skillTypeID, isSync=True)
    return
 
## ÊôÐÔbuffЧ¹ûid¶ÔÓ¦¼ÆËãÄ£¿é×Öµä{Ч¹ûid:(¼ÆËãÄ£¿éÃûºó׺, [ÊôÐÔÀàÐÍ])}
#  ´øÊôÐÔµÄbuff Ä¬ÈÏÒÔÊôÐÔÀàÐÍΪЧ¹ûID
def FindBuffAttrByEffectID(effect):
    """
    buffЧ¹ûID¶¨Òå
    1.»ù´¡ÊôÐÔÒÔ TYPE_Calc_AttrList µÄÀàÐÍΪID£¬AֵΪ¾ßÌåÖµ£¬BֵΪÏßÐÔ£¨¼ÆË㣩ÀàÐÍ£¬ÒÔ¶àЧ¹ûµÄ·½Ê½Ö§³ÖÅäÖöàÊôÐÔ
    2.·Ç»ù´¡ÊôÐÔ»ò¶àÊôÐÔ¿ÉÅäÖÃÔÚ Def_Skill_BuffEffectDict ÖÐ
    3.ÆäËûÌØ¶¨Ð§¹ûΪ¾ßÌå×ö·¨
    """
    effectID = effect.GetEffectID()
    if effectID in ChConfig.TYPE_Calc_AttrList:
        # ´Ë´¦IDΪDef_Calc_AllAttrType_MAXÖеÄÀàÐÍ
        return ChConfig.EffCalcTypeDict.get(effect.GetEffectValue(1), ""), [effectID]
 
    return ChConfig.Def_Skill_BuffEffectDict.get(effectID, ("", []))
 
 
# Ê¹ÓÃÀà FindEffect º¯Êý£¬Í¨¹ýЧ¹ûIDÕÒÉíÉϵÄbuffЧ¹û
def FindBuffEffectPlusByEffectID(buffState, effectID):
    #gameObj.GetBuffState().FindEffect(ChConfig)
    for i in range(buffState.GetEffectCount()):
        effect = buffState.GetEffect(i)
        if not effect:
            continue
        if effect.GetEffectID() != effectID:
            continue
        
        return effect, buffState.GetEffectPlusValue(i), buffState.GetEffectFromSkillID(i)
    return None, None, None
 
 
# Ê¹ÓÃÀà FindEffect º¯Êý£¬Í¨¹ýЧ¹ûIDºÍÓµÓÐÕßÕÒÉíÉϵÄbuffЧ¹û
def FindBuffEffectByOwnertID(buffState, effectID, ownerID, ownerType):
    #gameObj.GetBuffState().FindEffect(ChConfig)
    for i in range(buffState.GetEffectCount()):
        effect = buffState.GetEffect(i)
        if not effect:
            continue
        if effect.GetEffectID() != effectID:
            continue
        
        if buffState.GetEffectOwnerID(i) != ownerID:
            continue
        if buffState.GetEffectOwnerType(i) != ownerType:
            continue
 
        return effect, buffState.GetEffectPlusValue(i), buffState.GetEffectFromSkillID(i)
    return None, None, None
 
 
def DeleteBuffByEffectID(curObj, buffState, effectID, tick):
    curEffect, plusValue, skillID = FindBuffEffectPlusByEffectID(buffState, effectID)
    if not curEffect:
        return
    
    return DelBuffBySkillID(curObj, skillID, tick)
 
def PYSync_RefreshBuff(gameObj, curBuff, buffType, notifyAll=True, owner = None, errSkillID=None):
    try:
        sendPack = ChNetSendPack.tagObjAddBuff()
        if not curBuff:
            return
        if not hasattr(curBuff, "GetSkill"):
            return
        curSkill = curBuff.GetSkill()
        if not curSkill or not hasattr(curSkill, "GetSkillID"):
            return
        skillID = curSkill.GetSkillID()
        if GameObj.GetHP(gameObj) <= 0 or AttackCommon.GetIsDead(gameObj):
            return
        sendPack.ObjType = gameObj.GetGameObjType()
        sendPack.ObjID = gameObj.GetID();
        sendPack.SkillID = skillID;
        sendPack.LastTime = curBuff.GetRemainTime();
        sendPack.BuffType = buffType;
        sendPack.Value = curBuff.GetValue();
        sendPack.Value1 = curBuff.GetValue1();
        sendPack.Value2 = curBuff.GetValue2();
        sendPack.Layer = curBuff.GetLayer();
        if owner:
            sendPack.OwnerID = owner.GetID()
            sendPack.OwnerType = owner.GetGameObjType()
        if notifyAll or gameObj.GetGameObjType() != IPY_GameWorld.gotPlayer:
            gameObj.NotifyAll(sendPack.GetBuffer(), sendPack.GetLength());
        else:
            PlayerControl.PyNotifyAll(gameObj, sendPack, notifySelf=True, notifyCnt=-1)
    except:
        GameWorld.RaiseException("PYSync_RefreshBuff error errSkillID=%s" % errSkillID)
        return