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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package GameWorldLogic.FBProcess.GameLogic_MunekadoTrial
#
# @todo:×ÚÃÅÊÔÁ¶
# @author xdh
# @date 2017-11-29 11:00
# @version 1.0
#
#
# ÏêϸÃèÊö: ×ÚÃÅÊÔÁ¶
#
#---------------------------------------------------------------------
#"""Version = 2017-11-29 11:00"""
#---------------------------------------------------------------------
 
import FBCommon
import IPY_GameWorld
import GameWorldProcess
import GameWorld
import ShareDefine
import NPCCustomRefresh
import ItemControler
import ChConfig
import PlayerSuccess
import IpyGameDataPY
import PlayerControl
import ItemCommon
import EventReport
import PyGameData
import EventShell
import NPCCommon
import FBHelpBattle
import PlayerActLogin
 
import math
 
 
(
Def_PrepareTime, # ×¼±¸Ê±¼ä, Ãë
Def_FightTime, # ¸±±¾Ê±¼ä, Ãë
Def_PickItemTime, # Ê°È¡Ê±¼ä, Ãë
Def_ExitTime, # Í˳öʱ¼ä, Ãë
) = range(4)
 
 
 
 
# ¸±±¾×´Ì¬
(
FB_Step_CallHelp, # ÖúÕ½ÕÙ»½
FB_Step_Prepare, #×¼±¸ÖÐ
FB_Step_Fight, # Õ½¶·ÖÐ
FB_Step_PickItem, # Ê°È¡ÎïÆ·ÖÐ
FB_Step_Over, # ½áÊøµÈ´ý
FB_Step_Close, # ¹Ø±ÕÖÐ
) = range(6)
 
#ZMSL_GameStep = "ZMSL_GameStep"   # µ±Ç°¹Ø¿¨
ZMSL_FBNextRefreshStep = 'ZMSL_FBNextRefreshStep'   # Ë¢¹Ö½×¶ÎÊý
ZMSL_FBNPCCnt = 'ZMSL_FBNPCCnt'   # ¸±±¾Ê£Óà¹ÖÎïÊý
ZMSL_FBNPCNeedRefreshCnt = 'ZMSL_FBNPCNeedRefreshCnt'   # »¹ÐèˢеĹÖÎïÊý
ZMSL_FBNPCRefreshCnt = 'ZMSL_FBNPCRefreshCnt'   # µ±ÂÖˢеĹÖÎïÊý
ZMSL_FBStepStartTick = 'ZMSL_FBStepStartTick'   # ½×¶Î¿ªÊ¼µÄʱ¼ä
 
ZMSL_FBStepStar = 'ZMSL_FBStepStar'   # ¸±±¾½×¶Î½áÊøÊ±ÐǼ¶
ZMSL_CostTime = 'ZMSL_CostTime'   # ¹ý¹ØºÄʱ
 
 
 
 
## OnDay´¦Àí
#  @param curPlayer
#  @return None
def OnFBPlayerOnDay(curPlayer):
    curPlayerMapID = FBCommon.GetRecordMapID(curPlayer.GetMapID())
    if curPlayerMapID == ChConfig.Def_FBMapID_MunekadoTrial:
        GameWorld.DebugLog("ZMSLOnDay curPlayerMapID=%s,SetDict IsInFBOnDay 1" % curPlayerMapID)
        curPlayer.SetDict(ChConfig.Def_PlayerKey_IsInFBOnDay, 1)
    return
 
##---»ñµÃ¸±±¾Ë¢¹ÖÅäÖÃ---
#  @param None
#  @return ÅäÖÃÐÅÏ¢
def __GetZMSLnpcCfg(lineID, mapID=0):
    if not mapID:
        mapID = GameWorld.GetMap().GetMapID()
    return FBCommon.GetFBLineRefreshNPC(mapID, lineID)
 
def GetMTFBLineStepTime(lineID=-1):
    mapID = GameWorld.GetMap().GetMapID()
    if lineID == -1:
        lineID=FBCommon.GetFBPropertyMark()
    return FBCommon.GetFBLineStepTime(mapID, lineID)
 
##¿ªÆô¸±±¾
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¿ªÆô¸±±¾
def OnOpenFB(tick):
    return
 
 
##¹Ø±Õ¸±±¾
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks 
def OnCloseFB(tick):
    return
 
## ÊÇ·ñÄܹ»Í¨¹ý»î¶¯²éѯ½øÈë
#  @param curPlayer Íæ¼ÒʵÀý
#  @param mapID µØÍ¼ID
#  @param lineID Ïß·id
#  @param tick Ê±¼ä´Á
#  @return ²¼¶ûÖµ
def OnEnterFBEvent(curPlayer, mapID, lineID, tick):
    if lineID != 0:
        historyStar = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_PlayerFBStar_MapId, lineID-1, False, [mapID])
        needStar = IpyGameDataPY.GetFuncCfg('MunekadoLockLimit')
        if historyStar < needStar:
            GameWorld.DebugLog('    ÉÏÒ»²ãÆÀ¼¶Î´´ïµ½%s£¬ÎÞ·¨ÌôÕ½±¾²ã£¡' % needStar)
            return False
    return True
 
 
 
##¸±±¾Íæ¼Ò½øÈëµã
# @param curPlayer Íæ¼ÒʵÀý
# @param mapID µØÍ¼ID
# @param lineId ·ÖÏßID
# @param tick Ê±¼ä´Á
# @return ×ø±êÁбí(X,Y)
# @remarks ¸±±¾Íæ¼Ò½øÈëµã
def OnGetFBEnterPos(curPlayer, mapID, lineId, ipyEnterPosInfo, tick):
    return ipyEnterPosInfo
 
 
##ÊÇ·ñ¿ÉÒÔ½øÈë
# @param ask ÇëÇó½á¹¹Ìå
# @param tick Ê±¼ä´Á
# @return TChangeMapError
# @remarks ÑéÖ¤¼Ò×åÊÇ·ñÔÚ½ñÌìµÄ¼Ò×åÕ½±í
def OnChangeMapAsk(ask, tick):
    return IPY_GameWorld.cmeAccept
 
 
##Íæ¼Ò½øÈ븱±¾
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks Íæ¼Ò½øÈ븱±¾
def DoEnterFB(curPlayer, tick):
    mapID = GameWorld.GetGameWorld().GetMapID()
    mapID = FBCommon.GetRecordMapID(mapID)
    gameFB = GameWorld.GetGameFB()
    
    # ÉèÖø±±¾¹«¹²ÊôÐԵĵ¥¶À´¦Àí£¬·ÀÖ¹¶ÓÔ±½øÈëºó±»ÐÞ¸Ä
    if not FBCommon.GetHadSetFBPropertyMark():
        lineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ReqFBFuncLine)
        FBCommon.SetFBPropertyMark(lineID)
#        if gameFB.GetFBStep() == FB_Step_Open:
#            FBCommon.SetFBStep(FB_Step_Prepare, tick)
#            gameFB.SetGameFBDict(ZMSL_FBNextRefreshStep, 0)
#            gameFB.SetGameFBDict(ZMSL_FBNPCCnt, 0)
#            gameFB.SetGameFBDict(ZMSL_FBNPCRefreshCnt, 0)
    
    lineID = FBCommon.GetFBPropertyMark()
    GameWorld.DebugLog("ZMSL DoEnterFB lineID=%s£¡" % lineID, curPlayer.GetID())
    # ½øÈëÏûºÄ´¦Àí
    if not FBCommon.GetHadDelTicket(curPlayer):
        FBCommon.SetHadDelTicket(curPlayer)
        PyGameData.g_fbPickUpItemDict.pop(curPlayer.GetPlayerID(), 0)
        curPlayer.SetDict(ChConfig.Def_PlayerKey_IsInFBOnDay, 0)
#        isHelpFight = False
#        if FBCommon.SetIsHelpFight(curPlayer):
#            isHelpFight = True
#            GameWorld.DebugLog("ZMSL ÖúÕ½½øÈ븱±¾£¡", curPlayer.GetID())
#        joinType = FBCommon.GetFBJoinType(curPlayer, isHelpFight)
#        EventReport.WriteEvent_FB(curPlayer, mapID, lineID, ChConfig.CME_Log_Start, joinType)
    if gameFB.GetFBStep() == FB_Step_CallHelp:
        FBHelpBattle.SendGameServer_RefreshHelpBattlePlayer(curPlayer, mapID, lineID)
        return
    ZMSLCfg = GetMTFBLineStepTime()
    fbStep = gameFB.GetFBStep()
    if fbStep <= FB_Step_Prepare:
        notify_tick = ZMSLCfg[Def_PrepareTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttAddUpTime, 0, max(notify_tick, 0), True)
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttWaitStart, 0, max(notify_tick, 0), True)
        
    elif fbStep == FB_Step_Fight:
        notify_tick = ZMSLCfg[Def_FightTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttTowerTake, 0, max(notify_tick, 0), True)
        
        __UpdZMSLFBStar(tick, True, curPlayer)
    DoFBHelp(curPlayer, tick)
    return
 
## ÕÙ»½ÖúÕ½Íê³É
def OnCallHelpBattleOK(curPlayer, tick):
    ZMSLCfg = GetMTFBLineStepTime()
    FBCommon.SetFBStep(FB_Step_Prepare, tick)
    notify_tick = ZMSLCfg[Def_PrepareTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())
    curPlayer.Sync_TimeTick(IPY_GameWorld.tttWaitStart, 0, max(notify_tick, 0), True)
    lineID = FBCommon.GetFBPropertyMark()
    EventReport.WriteEvent_FB(curPlayer, ChConfig.Def_FBMapID_MunekadoTrial, lineID, ChConfig.CME_Log_Start)    
    return
 
## Ë¢¹Ö
# @return: True-ÒÑͨ¹Ø
def __RefreshZMSLNextNPC(tick):
    gameFB = GameWorld.GetGameFB()
    
    npcCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCCnt)
    needRefreshCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCNeedRefreshCnt)
    # »¹Óй֠or »¹Ã»Ë¢Í꣬²»Ö´ÐÐÏÂÒ»²¨Ë¢ÐÂ
    if npcCnt > 0 or needRefreshCnt > 0:
        return
    
    refreshStep = gameFB.GetGameFBDictByKey(ZMSL_FBNextRefreshStep)
    lineID = FBCommon.GetFBPropertyMark()
    
    refreshNPCList, rMarkList = __GetZMSLnpcCfg(lineID)
    
    if refreshStep >= len(refreshNPCList) or refreshStep >= len(rMarkList):
        # ÒÑÊÇ×îºóÒ»²¨, Í¨¹Ø
        GameWorld.DebugLog("ÒÑÊÇ×îºóÒ»²¨, Í¨¹Ø")
        return True
    rMark = rMarkList[refreshStep]
    rNPCList = refreshNPCList[refreshStep]
    needRefreshCnt = 0
    for rNPCInfo in rNPCList:
        needRefreshCnt += rNPCInfo[1]
        
    gameFB.SetGameFBDict(ZMSL_FBNPCRefreshCnt, needRefreshCnt)
    gameFB.SetGameFBDict(ZMSL_FBNPCNeedRefreshCnt, needRefreshCnt)
    NPCCustomRefresh.SetNPCRefresh(rMark, rNPCList, needRefreshCnt, needRefreshCnt)
    
    # ¸üÐÂÏÂÒ»²¨½×¶ÎÖµ
    gameFB.SetGameFBDict(ZMSL_FBNextRefreshStep, refreshStep + 1)
    gameFB.SetGameFBDict(ZMSL_FBStepStartTick, tick)
    gameFB.SetGameFBDict(ZMSL_FBStepStar, gameFB.GetGameFBDictByKey(ChConfig.Def_FB_Grade))
 
    return
 
 
##Íæ¼ÒÍ˳ö¸±±¾.
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
def DoExitFB(curPlayer, tick):
    GameWorld.DebugLog("ZMSL DoExitFB...", curPlayer.GetPlayerID())
    
    if GameWorld.GetMapCopyPlayerManager().GetPlayerCount() == 1:
        GameWorld.DebugLog("¸±±¾ÖÐֻʣÏÂÒ»¸öÈË£¬¹Ø±Õ¸±±¾!")
        gameFB = GameWorld.GetGameFB()
        gameFB.SetIsSafeClose(1)
    return
 
##Íæ¼ÒÖ÷¶¯À뿪¸±±¾.
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
def DoPlayerLeaveFB(curPlayer, tick):
    GameWorld.DebugLog("ZMSL DoPlayerLeaveFB...", curPlayer.GetPlayerID())
    
    return
 
##Íæ¼Ò¸±±¾¸´»î
# @param curPlayer Íæ¼ÒʵÀý
# @param rebornType
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
def OnPlayerReborn():
    
    return True
 
## »ñÈ¡È볡Я´øÐÅÏ¢
#  @param curPlayer
#  @param lineId ·ÖÏß
#  @return ×Ö·ûÐÍ ½øÈëÐéÄâ·ÖÏßID
def GetPlayerResetWorldPosFBMsg(curPlayer, lineId):
    
    return ""
 
##¸±±¾¶¨Ê±Æ÷
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¸±±¾¶¨Ê±Æ÷
def OnProcess(tick):
    fbStep = GameWorld.GetGameFB().GetFBStep()
 
    # ¸±±¾×¼±¸
    if fbStep == FB_Step_Prepare:
        __DoLogic_FB_Prepare(tick)
    elif fbStep == FB_Step_Fight:
        __UpdZMSLFBStar(tick)
        __ProcessOverFight(tick)
    elif fbStep == FB_Step_PickItem:
        __DoLogic_FB_PickItem(tick)
    elif fbStep == FB_Step_Over:
        __ProcessCloseFB(tick)
        
    return
 
 
## ¸±±¾×¼±¸Âß¼­
#  @param tick:ʱ¼ä´Á
#  @return ÎÞÒâÒå
def __DoLogic_FB_Prepare(tick):
    #gameFB = GameWorld.GetGameFB()
    fbCfg = GetMTFBLineStepTime()
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameFB().GetFBStepTick() < fbCfg[Def_PrepareTime] * 1000:
        return
    __RefreshZMSLNextNPC(tick)
    playerManager = GameWorld.GetMapCopyPlayerManager()
    for i in range(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(i)
        if not curPlayer:
            continue
        DoFBHelp(curPlayer, tick)
    
    FBCommon.SetFBStep(FB_Step_Fight, tick)
    FBCommon.Sync_Player_TimeTick(IPY_GameWorld.tttTowerTake, fbCfg[Def_FightTime] * 1000)
    return
 
## É±¹Ö½áÊø
#  @param tick
#  @return None
def __ProcessOverFight(tick):
    
    FightTime = GetMTFBLineStepTime()[Def_FightTime]
    openTick = GameWorld.GetGameWorld().GetOpenFBTick()
    if max(0, FightTime * 1000 - (tick - openTick)) > 0:
        return
 
    __DoZMSLOver(False, tick)        
    return
 
## ¸±±¾Ê°È¡
#  @param tick:ʱ¼ä´Á
#  @return ÎÞÒâÒå
def __DoLogic_FB_PickItem(tick):
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameFB().GetFBStepTick() < GetMTFBLineStepTime()[Def_PickItemTime] * 1000:
        return
    FBCommon.SetFBStep(FB_Step_Over, tick)
    return
 
## ¸±±¾¹Ø±Õ
#  @param tick
#  @return None
def __ProcessCloseFB(tick):
    gameFB = GameWorld.GetGameFB()
    
    if tick - gameFB.GetFBStepTick() < GetMTFBLineStepTime()[Def_ExitTime] * 1000:
        return
    
    FBCommon.DoLogic_FBKickAllPlayer()
    GameWorldProcess.CloseFB(tick)
    FBCommon.SetFBStep(FB_Step_Close, tick)
    return
 
def GetCanDropPlayerList():
    dropPlayerList = []
    playerManager = GameWorld.GetMapCopyPlayerManager()
    for index in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not curPlayer:
            continue
        if FBCommon.GetIsHelpFight(curPlayer):
            continue
        dropPlayerList.append(curPlayer)
    return dropPlayerList
 
def __DoZMSLOver(isPass, tick, killNPCID=0):
    # Õ½¶·³¬Ê±
    costTime = tick - GameWorld.GetGameFB().GetFBStepTick()
    gameFB = GameWorld.GetGameFB()
    gameFB.SetGameFBDict(ZMSL_CostTime, costTime)
    star = GameWorld.GetGameFB().GetGameFBDictByKey(ChConfig.Def_FB_Grade)
    GameWorld.DebugLog("__DoZMSLOver isPass=%s,killNPCID=%s,star=%s" % (isPass, killNPCID, star))
    #===============================================================================================
    # canDropPlayerList = GetCanDropPlayerList()
    # if isPass and canDropPlayerList:
    #    FBCommon.SetFBStep(FB_Step_PickItem, tick)
    #    leaveTime = GetMTFBLineStepTime()[Def_PickItemTime] * 1000
    # else:
    #    FBCommon.SetFBStep(FB_Step_Over, tick)
    #    leaveTime = GetMTFBLineStepTime()[Def_ExitTime] * 1000
    #===============================================================================================
    FBCommon.SetFBStep(FB_Step_Over, tick)
    leaveTime = GetMTFBLineStepTime()[Def_ExitTime] * 1000
    mapID = GameWorld.GetMap().GetMapID()
    mapID = FBCommon.GetRecordMapID(mapID)
    lineID = FBCommon.GetFBPropertyMark()
    
    #awardDict = FBCommon.GetFBLineReward(mapID, lineID)
    #prizeItemList = awardDict.get(star, [])
    overDict = {FBCommon.Over_grade:star,FBCommon.Over_dataMapID:mapID,FBCommon.Over_isPass:int(isPass), FBCommon.Over_costTime:costTime}
    playerManager = GameWorld.GetMapCopyPlayerManager()
    playerCount = playerManager.GetPlayerCount()
    for index in xrange(playerCount):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not curPlayer:
            continue
        
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, leaveTime, True)
        if not isPass:
            FBCommon.Notify_FB_Over(curPlayer, overDict)
            continue
        if lineID+1 > curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_FBHistoryMaxLine % mapID):
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_FBHistoryMaxLine % mapID, lineID+1)
        needSyncFBData = False
        #¸üÐÂÀúÊ·ÆÀ¼¶
        historyStar = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_PlayerFBStar_MapId, lineID, False, [mapID])
        if star > historyStar:
            GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_PlayerFBStar_MapId, lineID, star, False, [mapID])
            needSyncFBData = True
        isInFBOnDay = curPlayer.GetDictByKey(ChConfig.Def_PlayerKey_IsInFBOnDay)
             
        if star == 5:
            EventReport.WriteEvent_FB(curPlayer, mapID, lineID, ChConfig.CME_Log_End, 0, 1)
        EventShell.EventRespons_FBEvent(curPlayer, "zmsl_%s_%s" % (lineID, star))
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MunekadoTrial, 1, [playerCount, star, lineID+1])
        EventShell.EventRespons_FBEvent(curPlayer, "passzmsl")
        # Èç¹ûÔÚ¸±±¾ÖйýÌ죬ÔòÖ»¸øÎïÆ·½±Àø£¬²»±ä¸ü¹ý¹ØÐÅÏ¢
        if not isInFBOnDay:
            FBCommon.AddEnterFBCount(curPlayer, mapID, 1)
            needSyncFBData = False
        else:
            curPlayer.SetDict(ChConfig.Def_PlayerKey_IsInFBOnDay, 0)
        FBHelpBattle.DoFBHelpBattleFinish(curPlayer, mapID, lineID)
        PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MunekadoTrialEx, 1)
        PlayerActLogin.AddLoginAwardActionCnt(curPlayer, ChConfig.Def_LoginAct_MunekadoTrial, 1)
            #=======================================================================================
            # #¸ø½±Àø
            # needSpace = len(prizeItemList)
            # emptySpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
            # isSendMail = int(needSpace > emptySpace) # ÊÇ·ñ·¢ËÍÓʼþ
            # if isSendMail:
            #    PlayerControl.SendMailByKey("", [curPlayer.GetPlayerID()], prizeItemList)
            #    GameWorld.DebugLog("±³°ü¿Õ¼ä²»¹»£¬·¢ËÍÓʼþ: mailItemList=%s" % str(prizeItemList), curPlayer.GetPlayerID())
            # else:
            #    for itemID, itemCnt, isBind in prizeItemList:
            #        ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem], event=["MunekadoTrial", False, {}])
            #overDict[FBCommon.Over_itemInfo] = FBCommon.GetJsonItemList(prizeItemList)
            #=======================================================================================
            
        jsonItemList, totalExp, totalMoney = NPCCommon.GiveKillNPCDropPrize(curPlayer, ChConfig.Def_FBMapID_MunekadoTrial, {killNPCID:1})
        # Í¨Öª½á¹û
        overDict[FBCommon.Over_itemInfo] = jsonItemList
            
        if needSyncFBData:
            FBCommon.Sync_FBPlayerFBInfoData(curPlayer, mapID)
            
#        if not canDropPlayerList:
#            FBCommon.Notify_FB_Over(curPlayer, overDict)
        GameWorld.DebugLog('    overDict=%s'%overDict, curPlayer.GetID())
        FBCommon.Notify_FB_Over(curPlayer, overDict)
    return
 
## ¿É·ñɨµ´
def OnPlayerFBSweepAsk(curPlayer, mapID, lineID, sweepCnt, isFinish, dataEx):
    if mapID != ChConfig.Def_FBMapID_MunekadoTrial:
        return
    # ÔÝдËÀ£¬Ç°Á½²ã²»ÄÜɨ
    #if lineID < 2:        
    #    GameWorld.DebugLog("ǰÁ½²ã²»ÄÜɨµ´!")
    #    return
    historyStar = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_PlayerFBStar_MapId, lineID, False, [mapID])
    if historyStar < 5:
        GameWorld.DebugLog("ûÓÐS¼¶²»ÄÜɨµ´!")
        return
    
    return True
 
## Öúսɨµ´½á¹û
def OnPlayerFBHelpBattleSweepResult(curPlayer, mapID, lineID, helpBattlePlayerDict):
    #¿ÛÃÅÆ±ÒªÔÚ¹«¹²Âß¼­ÖÐÍê³É
    
    refreshNPCList = __GetZMSLnpcCfg(lineID, mapID)[0]
    if not refreshNPCList:
        return
    lastNPCList = refreshNPCList[-1]
    if not lastNPCList:
        return
    killNPCID = lastNPCList[0][0] # Ä¬ÈÏ×îºóÒ»²¨µÄNPCIDΪͨ¹Øboss½±ÀøID
    GameWorld.DebugLog("ɨµ´×ÚÃÅÊÔÁ¶: killNPCID=%s,helpBattlePlayerDict=%s" 
                       % (killNPCID, helpBattlePlayerDict))
    
    star = 5
    EventReport.WriteEvent_FB(curPlayer, mapID, lineID, ChConfig.CME_Log_End, 0, 1)
    
    EventShell.EventRespons_FBEvent(curPlayer, "zmsl_%s_%s" % (lineID, star))
    EventShell.EventRespons_FBEvent(curPlayer, "passzmsl")
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MunekadoTrialEx, 1)
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_MunekadoTrial, 1, [1, star, lineID+1])
    PlayerActLogin.AddLoginAwardActionCnt(curPlayer, ChConfig.Def_LoginAct_MunekadoTrial, 1)
    jsonItemList, totalExp, totalMoney = NPCCommon.GiveKillNPCDropPrize(curPlayer, ChConfig.Def_FBMapID_MunekadoTrial, {killNPCID:1}, curGrade=star)
    
    # Í¨Öª½á¹û
    overDict = {FBCommon.Over_grade:star,FBCommon.Over_dataMapID:mapID,FBCommon.Over_isPass:1, FBCommon.Over_isSweep:1}
    overDict[FBCommon.Over_helpPlayer] = helpBattlePlayerDict
    overDict[FBCommon.Over_itemInfo] = jsonItemList
    GameWorld.DebugLog("×ÚÃÅɨµ´½á¹û: overDict=%s" % overDict)
    FBCommon.Notify_FB_Over(curPlayer, overDict)
    return True
 
## ¼ì²éÊÇ·ñ¿É¹¥»÷£¬ Ö÷Åж¨²»¿É¹¥»÷µÄÇé¿ö£¬ÆäËûÂß¼­ÓÉÍâ²ã¾ö¶¨
#  @param attacker ¹¥»÷·½
#  @param defender ·ÀÊØ·½
#  @return bool
def CheckCanAttackTagObjInFB(attacker, defender):
    gameFB = GameWorld.GetGameFB()
    if gameFB.GetFBStep() != FB_Step_Fight:
        return False
    return True
    
##¸±±¾ÓÐNPCÕÙ³ö
# @param curNPC:
# @param tick:tick
# @return None
def DoFBRebornNPC(curNPC, tick):
    if curNPC.GetNPCID() not in __GetAllNPCIDList():
        return
    gameFB = GameWorld.GetGameFB()
    npcCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCCnt)
    needRefreshCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCNeedRefreshCnt)
    
    npcCnt += 1
    needRefreshCnt -= 1
    gameFB.SetGameFBDict(ZMSL_FBNPCCnt, npcCnt)
    gameFB.SetGameFBDict(ZMSL_FBNPCNeedRefreshCnt, needRefreshCnt)
    GameWorld.DebugLog("DoFBRebornNPC, npcID=%s,ZMSL_FBNPCCnt=%s,needRefreshCnt=%s" % (curNPC.GetNPCID(), npcCnt, needRefreshCnt))
    if needRefreshCnt <= 0:
        GameWorld.DebugLog("±¾²¨¹ÖÎïË¢ÐÂÍê±Ï£¡npcCnt=%s" % npcCnt)
    return
 
 
def __GetAllNPCIDList():
    lineID = FBCommon.GetFBPropertyMark()
    refreshNPCList = __GetZMSLnpcCfg(lineID)[0]
    npcIDList = []
    for rList in refreshNPCList:
        for npcid, npccnt in rList:
            npcIDList.append(npcid)
    return npcIDList
 
def DoFB_Npc_KillNPC(attacker, curNPC, tick):
    __FBNPCOnKilled(curNPC, tick)
    return
 
##Íæ¼ÒɱËÀNPC
# @param curPlayer:Íæ¼ÒʵÀý
# @param curNPC:µ±Ç°±»É±ËÀµÄNPC
# @param tick:ʱ¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Íæ¼ÒÖ÷¶¯À뿪¸±±¾.
def DoFB_Player_KillNPC(curPlayer, curNPC, tick):
    __FBNPCOnKilled(curNPC, tick)
    return
 
def __FBNPCOnKilled(curNPC, tick):
    if curNPC.GetNPCID() not in __GetAllNPCIDList():
        return
    gameFB = GameWorld.GetGameFB()
    npcCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCCnt)
    needRefreshCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCNeedRefreshCnt)
    
    npcCnt -= 1
    gameFB.SetGameFBDict(ZMSL_FBNPCCnt, npcCnt)
    
    GameWorld.DebugLog("DoFB_Player_KillNPC, npcID=%s,ZMSL_FBNPCCnt=%s,needRefreshCnt=%s" 
                       % (curNPC.GetNPCID(), npcCnt, needRefreshCnt))
    
    if npcCnt <= 0 and needRefreshCnt <= 0:
        GameWorld.DebugLog("±¾²¨ËùÓйÖÎïÒѱ»»÷ɱ£¡")
        isAllKilled = __RefreshZMSLNextNPC(tick)
        if isAllKilled:
            __DoZMSLOver(True, tick, curNPC.GetNPCID())
    
    FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0)
    return
 
def OnPickUpItem(curPlayer, curItem, tick):
    mapItemType = curItem.GetType()
    if mapItemType != ChConfig.Def_ItemType_Money:
        playerID = curPlayer.GetID()
        isEquip = ItemCommon.CheckItemIsEquip(curItem)
        jsonItem = ItemCommon.GetJsonItem(curItem)
        if playerID in PyGameData.g_fbPickUpItemDict:
            if isEquip:
                PyGameData.g_fbPickUpItemDict[playerID].append(jsonItem)
            else:
                isIn = False
                for itemInfo in PyGameData.g_fbPickUpItemDict[playerID]:
                    if itemInfo["ItemID"] == jsonItem["ItemID"] and itemInfo.get("IsBind") == jsonItem.get("IsBind"):
                        itemInfo["Count"] = itemInfo.get("Count", 1)+ jsonItem.get("Count", 1)
                        isIn = True
                        break
                if not isIn:
                    PyGameData.g_fbPickUpItemDict[playerID].append(jsonItem)
        else:
            PyGameData.g_fbPickUpItemDict[playerID] = [jsonItem]
    
    isItemAllPickUp = (GameWorld.GetMapItemManager().GetMapItemCount() <= 1)
    if isItemAllPickUp and GameWorld.GetGameFB().GetFBStep() == FB_Step_PickItem:
        #__DoIceLodeOver(True)
        FBCommon.SetFBStep(FB_Step_Over, tick)
        leaveTime = GetMTFBLineStepTime()[Def_ExitTime] * 1000
        
        mapID = GameWorld.GetMap().GetMapID()
        mapID = FBCommon.GetRecordMapID(mapID)
        gameFB = GameWorld.GetGameFB()
        star = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_Grade)
        costTime = gameFB.GetGameFBDictByKey(ZMSL_CostTime)
        
        playerManager = GameWorld.GetMapCopyPlayerManager()
        for index in xrange(playerManager.GetPlayerCount()):
            player = playerManager.GetPlayerByIndex(index)
            if not player:
                continue
            player.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, leaveTime, True)
            jsonItemList = PyGameData.g_fbPickUpItemDict.get(player.GetPlayerID(), [])
            overDict = {FBCommon.Over_grade:star,FBCommon.Over_dataMapID:mapID,FBCommon.Over_isPass:1, 
                        FBCommon.Over_costTime:costTime, FBCommon.Over_itemInfo:jsonItemList}
            GameWorld.DebugLog("PickItemOver: %s" % overDict, player.GetPlayerID())
            FBCommon.Notify_FB_Over(player, overDict)
            
    return
 
## Íæ¼Ò¹¥»÷Íæ¼ÒÊÇ·ñÓгͷ£
#  @param atkPlayer: ¹¥»÷·½
#  @param defPlayer: ·ÀÊØ·½
#  @return Íæ¼Ò¹¥»÷Íæ¼ÒÊÇ·ñÓгͷ£
def DoFBAttackHasPunish(atkPlayer, defPlayer):
    return True
 
## ¸üе±Ç°¸±±¾ÐǼ¶
def __UpdZMSLFBStar(tick, isEnter=False, curPlayer=None):
    lineID = FBCommon.GetFBPropertyMark()
    FBCommon.UpdateFBGrade(tick, FBCommon.GetFBLineGrade(GameWorld.GetGameWorld().GetMapID(), lineID), curPlayer)
    return
    #1-D 2-C 3-B 4-A 5-S
#    gameFB = GameWorld.GetGameFB()
#    curStar = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_Grade)
#    if curStar == 1:
#        return curStar
#    stepStartTick = gameFB.GetGameFBDictByKey(ZMSL_FBStepStartTick)
#    if not stepStartTick:
#        return curStar
#    useSecond = int(math.ceil((tick - stepStartTick) / 1000.0))
#    lineID = FBCommon.GetFBPropertyMark()
#    starTimeList = IpyGameDataPY.GetFuncEvalCfg('MunekadoTrialStarTime').get(lineID,[])
#    wheelNum = gameFB.GetGameFBDictByKey(ZMSL_FBNextRefreshStep)
#    if wheelNum > len(starTimeList):
#        GameWorld.DebugLog("    MunekadoTrialStarTime ÅäÖôíÎó Ó벨Êý²»µÈ")
#        return
#    stepStar = gameFB.GetGameFBDictByKey(ZMSL_FBStepStar)
#    starTimeInfo = starTimeList[wheelNum-1]
#    updStar = stepStar if stepStar else 5
#    totalStarTime = 0
#    for starTime in starTimeInfo:
#        if updStar == 1:
#            break
#        totalStarTime +=starTime
#        if useSecond >= totalStarTime:
#            updStar = max(1, updStar-1)
#        else:
#            break
#
#    diffSecond =max(0, totalStarTime -useSecond)
#    
#    if curStar == updStar and not isEnter:
#        return curStar
#        
#    gameFB.SetGameFBDict(ChConfig.Def_FB_Grade, updStar)
#    
#    GameWorld.DebugLog("__UpdFBStar useSecond=%s,curStar=%s,updStar=%s, diffSecond=%s" 
#                       % (useSecond, curStar, updStar, diffSecond))
#    
#    if curPlayer:
#        DoFBHelp(curPlayer, tick)
#        if updStar != 1:
#            curPlayer.Sync_TimeTick(IPY_GameWorld.tttFlagTake, 0, diffSecond * 1000, True)
#    else:
#        playerManager = GameWorld.GetMapCopyPlayerManager()
#        for index in xrange(playerManager.GetPlayerCount()):
#            curPlayer = playerManager.GetPlayerByIndex(index)
#            if not curPlayer:
#                continue
#            DoFBHelp(curPlayer, tick)
#            if updStar != 1:
#                curPlayer.Sync_TimeTick(IPY_GameWorld.tttFlagTake, 0, diffSecond * 1000, True)
#            
#            
#    return updStar
 
##¸±±¾°ïÖúÐÅÏ¢
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks ÓÃÓÚ֪ͨÕóÓª±È·ÖÌõ
def DoFBHelp(curPlayer, tick):
    gameFB = GameWorld.GetGameFB()
    star = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_Grade)
    wheelNum = gameFB.GetGameFBDictByKey(ZMSL_FBNextRefreshStep)
    needKillCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCRefreshCnt)
    remainNPCCnt = gameFB.GetGameFBDictByKey(ZMSL_FBNPCCnt)
    KillNPCCnt = max(0, needKillCnt - remainNPCCnt)
    data = [KillNPCCnt, needKillCnt]
    lineID = FBCommon.GetFBPropertyMark()
    fbHelpDict = {FBCommon.Help_step:wheelNum, FBCommon.Help_grade:star, FBCommon.Help_npcTotal:KillNPCCnt, FBCommon.Help_lineID:lineID}
    
    FBCommon.Notify_FBHelp(curPlayer, fbHelpDict)
    return
 
 
 
## ¸±±¾ÐÐΪ
#  @param curPlayer Íæ¼Ò
#  @param actionType ÐÐΪÀàÐÍ
#  @param actionInfo ÐÐΪÐÅÏ¢
#  @param tick µ±Ç°Ê±¼ä
#  @return None
def DoFBAction(curPlayer, actionType, actionInfo, tick):
  
    return
 
 
## ÖØÖø±±¾¸´»îÍæ¼Ò×ø±êµã
# @param None
# @return ÎÞÒâÒå
def OnResetFBRebornPlacePos(curPlayer, rebornPlace, tick):
    lineID = FBCommon.GetFBPropertyMark()
    ipyEnterPosInfo = FBCommon.GetFBLineEnterPosInfo(ChConfig.Def_FBMapID_MunekadoTrial, lineID)
    posX, posY = ipyEnterPosInfo[:2]
    curPlayer.ResetPos(posX, posY)
    return
 
#// A3 2F ×ÚÃÅÊÔÁ¶¶Ò»» #tagCMTrialExchange
#
#struct    tagCMTrialExchange
#{
#    tagHead        Head;
#    DWORD        ID;  //¶Ò»»ID
#}; 
def OnTrialExange(playerIndex, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(playerIndex)
    exchangeID = clientData.ID
    ipyData = IpyGameDataPY.GetIpyGameData("TrialExchange", exchangeID)
    if not ipyData:
        return
    playerID = curPlayer.GetPlayerID()
    
    exchangeItemIDList = ipyData.GetExchangeItemIDList()
    if not exchangeItemIDList:
        return
    if len(exchangeItemIDList) > 1:
        jobIndex = curPlayer.GetJob() - 1
        if jobIndex < 0 or jobIndex >= len(exchangeItemIDList):
            return
        exchangeItemID = exchangeItemIDList[jobIndex]
    else:
        exchangeItemID = exchangeItemIDList[0]
    exchangeItemCount = ipyData.GetExchangeItemCount()
    exchangeItemIsBind = ipyData.GetExchangeItemIsBind()
    costItemID = ipyData.GetCostItemID()
    costItemCount = ipyData.GetCostItemCount()
    if not exchangeItemID or not exchangeItemCount or not costItemID or not costItemCount:
        return
    
    if not ItemCommon.CheckPackHasSpace(curPlayer, IPY_GameWorld.rptItem, True):
        return
    
    costItemDict = {costItemID:costItemCount}
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    lackItemDict, delInfoDict = ItemCommon.GetCostItemIndexList(costItemDict, itemPack)
    if lackItemDict:
        GameWorld.DebugLog("¶Ò»»ÏûºÄÎïÆ·²»×㣡exchangeID=%s,costItemID=%s,costItemCount=%s,lackItemDict=%s" 
                           % (exchangeID, costItemID, costItemCount, lackItemDict), playerID)
        return
    
    #¿ÛÏûºÄ
    ItemCommon.DelCostItem(curPlayer, itemPack, delInfoDict)
    
    #¸øÎïÆ·
    ItemControler.GivePlayerItem(curPlayer, exchangeItemID, exchangeItemCount, 0, [IPY_GameWorld.rptItem], 
                                 event=[ChConfig.ItemGive_TrialExchange, False, {}])
    #ÈÎÎñ
    EventShell.EventRespons_TrialExchange(curPlayer, costItemID)
    
    GameWorld.DebugLog("×ÚÃŶһ»³É¹¦£¡exchangeID=%s,costItemID=%s,costItemCount=%s,delInfoDict=%s" 
                           % (exchangeID, costItemID, costItemCount, delInfoDict), playerID)
    return