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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GameWorldLogic.FBProcess.GameLogic_GatherSoul
#
# @todo:¾Û»ê¸±±¾
# @author xdh
# @date 2018-12-12
# @version 1.0
#
# ÏêϸÃèÊö: ¾Û»ê¸±±¾
#
#-------------------------------------------------------------------------------
#"""Version = 2018-12-12 21:00"""
#-------------------------------------------------------------------------------
 
import FBCommon
import GameWorld
import ItemCommon
import IPY_GameWorld
import GameWorldProcess
import PyGameData
import NPCCustomRefresh
import ChConfig
import ShareDefine
import EventReport
import PlayerControl
import ItemControler
import ChNPC
 
#---¸±±¾ÅäÖöÔÓ¦keyÖµ---
(
Def_FightTime,  # ½øÐÐʱ¼ä(Ãë)
Def_LeaveTime,  # Í˳öʱ¼ä(Ãë)
Def_BuildNPCID,  # ½¨ÔìµãNPCID
Def_BuildCnt,  # ½¨ÔìµãÊýÁ¿
Def_BuildMark,  # ½¨Ôìµã±êʶµã
Def_BuildTime,  # ½¨Ôìʱ¼äºÁÃë
Def_GuardInfo,  #{ÊØÎÀnpcid:×î´óÊýÁ¿}
Def_BossID,  # »Æ½ðBOSSID
Def_BossCostMoney,  # ÕÙ»½»Æ½ðBOSSÐèÒª½ðÇ®
Def_NPCRefreshMark,  # ¹ÖÎïˢбêʶµã
Def_NPCRefreshCD,  # Ð¡¹Ö¼ä¸ôʱ¼äºÁÃë
Def_WheelRefreshCD,  # Ã¿²¨¼ä¸ôʱ¼äºÁÃë
) = range(12)
 
#µ±Ç°¸±±¾µØÍ¼µÄ״̬
(
FB_Step_Open,  # ¸±±¾¿ªÆô
FB_Step_Prepare,  # ½¨ÔìÊØÎÀ
FB_Step_Fighting,  # Ë¢¹ÖÖÐ
FB_Step_Over,  # ¸±±¾½áÊø
FB_Step_Close,  # ¸±±¾¹Ø±Õ
) = range(5)
 
 
FBPlayerDict_GuardNPCID = 'FBPlayerDict_GuardNPCID'  # ÐèˢеÄÊØÎÀID
FBPlayerDict_GuardNPCCnt = 'FBPlayerDict_GuardNPCCnt%s'  # ÊØÎÀÒÑË¢ÐÂÊýÁ¿
FBPlayerDict_CurWheel = 'FBPlayerDict_CurWheel'  # µ±Ç°µÚ¼¸²¨¹Ö
FBPlayerDict_NPCIndex = 'FBPlayerDict_NPCIndex'  # ±¾²¨¹ÖµÚ¼¸Ö»
FBPlayerDict_LastWheelEndTime = 'FBPlayerDict_LastWheelEndTime'  # ÉÏÒ»²¨½áÊøÊ±¼ä
FBPlayerDict_LastNPCRTime = 'FBPlayerDict_LastNPCRTime'  # ÉÏÒ»Ö»¹ÖÎïË¢ÐÂʱ¼ä
FBPlayerDict_HasRefreshBoss = 'FBPlayerDict_HasRefreshBoss'  # ±¾²¨ÊÇ·ñÒÑË¢»Æ½ðBOSS
FBPlayerDict_AutoBoss = 'FBPlayerDict_AutoBoss'  # ÊÇ·ñ×Ô¶¯Ë¢»Æ½ðboss
FBPlayerDict_NPCRemainCnt = 'FBPlayerDict_NPCRemainCnt'  # NPCÊ£ÓàÊýÁ¿
 
 
##---»ñµÃ¸±±¾ÅäÖÃ---
#  @param None
#  @return ÅäÖÃÐÅÏ¢
def GetGatherSoulFBCfg():
    return FBCommon.GetFBLineStepTime(ChConfig.Def_FBMapID_GatherSoul, 0)
 
 
def GetGatherSoulNPCCfg():
    return FBCommon.GetFBLineRefreshNPC(ChConfig.Def_FBMapID_GatherSoul)
 
 
## ÊÇ·ñÄܹ»Í¨¹ý»î¶¯²éѯ½øÈë
#  @param curPlayer Íæ¼ÒʵÀý
#  @param mapID µØÍ¼ID
#  @param lineID Ïß·id
#  @param tick Ê±¼ä´Á
#  @return ²¼¶ûÖµ
def OnEnterFBEvent(curPlayer, mapID, lineID, tick):
    return True
 
 
##¸±±¾Íæ¼Ò½øÈëµã
# @param curPlayer Íæ¼ÒʵÀý
# @param mapID µØÍ¼ID
# @param lineId ·ÖÏßID
# @param ipyEnterPosInfo ¹¦ÄÜÏß·IPYÅäÖÃ×ø±êÐÅÏ¢
# @param tick Ê±¼ä´Á
# @return posX, posY, Ëæ»ú°ë¾¶(¿ÉÑ¡)
def OnGetFBEnterPos(curPlayer, mapID, lineId, ipyEnterPosInfo, tick):
    return ipyEnterPosInfo
 
 
##²éѯÊÇ·ñ¿ÉÒÔ½øÈëµØÍ¼
# @param ask:ÇëÇó½á¹¹Ìå(IPY_BMChangeMapAsk)
# @param tick:ʱ¼ä´Á
# @return IPY_GameWorld.cme Ã¶¾Ù
def OnChangeMapAsk(ask, tick):
    return IPY_GameWorld.cmeAccept
 
 
##¿ªÆô¸±±¾
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks ¿ªÆô¸±±¾
def OnOpenFB(tick):
    #Ë¢½¨Ôìµã
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    NPCCustomRefresh.SetNPCRefresh(gatherSoulFBCfg[Def_BuildMark], [(gatherSoulFBCfg[Def_BuildNPCID], 1)], 1, gatherSoulFBCfg[Def_BuildCnt])
    return
 
##¹Ø±Õ¸±±¾
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks 
def OnCloseFB(tick):
    __DoGatherSoulOver()
    return
 
## ½ø¸±±¾
#  @param curPlayer
#  @param tick
#  @return None
def DoEnterFB(curPlayer, tick):
    PlayerControl.SetSight(curPlayer, ChConfig.Def_PlayerSight_Default * 3)
    playerID = curPlayer.GetPlayerID()
    playerLV = curPlayer.GetLV()
    mapID = GameWorld.GetMap().GetMapID()
    mapID = FBCommon.GetRecordMapID(mapID)
    gameFB = GameWorld.GetGameFB()
    lineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ReqFBFuncLine)
    GameWorld.DebugLog("DoEnterFB...lineID=%s,playerLV=%s" % (lineID, playerLV), playerID)
    hadDelTicket = FBCommon.GetHadDelTicket(curPlayer)
    if not hadDelTicket:
        FBCommon.SetHadDelTicket(curPlayer)
        FBCommon.SetFBPropertyMark(lineID)
        EventReport.WriteEvent_FB(curPlayer, ChConfig.Def_FBMapID_GatherSoul, 0, ChConfig.CME_Log_Start)
    
    fbStep = gameFB.GetFBStep()
    if fbStep < FB_Step_Prepare:
        FBCommon.SetFBStep(FB_Step_Prepare, tick)
        
    if fbStep < FB_Step_Over:
        notify_tick = GetGatherSoulFBCfg()[Def_FightTime] * 1000 - (tick - GameWorld.GetGameWorld().GetOpenFBTick())
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttTowerTake, 0, max(notify_tick, 0), True)
    else:
        return
    DoFBHelp(curPlayer, tick)
    curPlayer.SetFaction(ShareDefine.CampType_Justice)
    return
 
 
##Íæ¼ÒÍ˳ö¸±±¾
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
def DoExitFB(curPlayer, tick):
    PlayerControl.SetSight(curPlayer, ChConfig.Def_PlayerSight_Default)
    fbStep = GameWorld.GetGameFB().GetFBStep()
    if fbStep >= FB_Step_Over:
        GameWorldProcess.CloseFB(tick)
    return
 
 
##Íæ¼ÒÖ÷¶¯À뿪¸±±¾.
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
def DoPlayerLeaveFB(curPlayer, tick):
    __DoGatherSoulOver()
    GameWorldProcess.CloseFB(tick)
    return  
 
 
## »ñµÃ¸±±¾°ïÖúÐÅÏ¢
#  @param curPlayer µ±Ç°Íæ¼Ò£¨±»Í¨Öª¶ÔÏó£©
#  @param tick µ±Ç°Ê±¼ä
#  @return None
def DoFBHelp(curPlayer, tick):
    gameFB = GameWorld.GetGameFB()
    fbStep = gameFB.GetFBStep()
    if fbStep > FB_Step_Fighting:
        return
    curWheel = gameFB.GetGameFBDictByKey(FBPlayerDict_CurWheel)
    maxWheel = len(GetGatherSoulNPCCfg())
    curWheel = 0 if fbStep == FB_Step_Prepare else min(curWheel+1, maxWheel)
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    guardDict = {}
    for npcid in gatherSoulFBCfg[Def_GuardInfo]:
        guardDict[npcid] = gameFB.GetGameFBDictByKey(FBPlayerDict_GuardNPCCnt%npcid)
    hasRefreshBoss = gameFB.GetGameFBDictByKey(FBPlayerDict_HasRefreshBoss)
    isAutoBoss = gameFB.GetGameFBDictByKey(FBPlayerDict_AutoBoss)
    lineID = GameWorld.GetGameWorld().GetLineID()
    itemDict = PyGameData.g_gathersoulfbAwardDict.get(lineID, {})
    helpItemInfo = {}
    for wheel, itemList in itemDict.items():
        helpItemInfo[str(wheel)] = FBCommon.GetJsonItemList(itemList)
    helpDict = {FBCommon.Help_wheel:curWheel, 
                FBCommon.Help_step:fbStep, 
                FBCommon.Help_npc:FBCommon.GetJsonNPCKillList(guardDict),
                FBCommon.Help_isAuto:isAutoBoss,
                FBCommon.Help_hasRefreshBoss:hasRefreshBoss,
                FBCommon.Help_gsItemInfo:helpItemInfo,
                }
    #¸±±¾°ïÖú
    GameWorld.DebugLog("DoFBHelp %s" % str(helpDict))
    FBCommon.Notify_FBHelp(curPlayer, helpDict)
    return
 
 
##---¸±±¾×ÜÂß¼­¼ÆÊ±Æ÷---
# @param tick:ʱ¼ä´Á
# @return ÎÞÒâÒå
# @remarks ¸±±¾×ÜÂß¼­¼ÆÊ±Æ÷
def OnProcess(tick):
    fbStep = GameWorld.GetGameFB().GetFBStep()
    
    # ¸±±¾½øÐÐÖÐ
    if fbStep == FB_Step_Fighting:
        __DoLogic_FB_Fighting(tick)
    # ¸±±¾½áÊø
    elif fbStep == FB_Step_Over:
        __DoLogic_FB_Over(tick)
    
    return
 
 
def __CheckNPCRefresh(tick):
    gameFB = GameWorld.GetGameFB()
    
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    
    lastWheelEndTime = gameFB.GetGameFBDictByKey(FBPlayerDict_LastWheelEndTime)
    if lastWheelEndTime and tick - lastWheelEndTime < gatherSoulFBCfg[Def_WheelRefreshCD]:
        return
    lastNPCRTime = gameFB.GetGameFBDictByKey(FBPlayerDict_LastNPCRTime)
    if lastNPCRTime and tick - lastNPCRTime < gatherSoulFBCfg[Def_NPCRefreshCD]:
        return
    
    curWheel = gameFB.GetGameFBDictByKey(FBPlayerDict_CurWheel)
    curNPCIndex = gameFB.GetGameFBDictByKey(FBPlayerDict_NPCIndex)
    npcRereshList = GetGatherSoulNPCCfg()  #[[npcid,npcid,],[],[]]
    if curWheel >= len(npcRereshList):
        return
    npcList = npcRereshList[curWheel]
    if curNPCIndex >= len(npcList):
        return
    
    GameWorld.DebugLog('    ¿ªÊ¼Ë¢µÚ%s²¨µÚ%sÖ»¹Ö£¡' % (curWheel + 1, curNPCIndex + 1))
    
    refreshNPCid = npcList[curNPCIndex]  #±¾´ÎҪˢеÄNPC
#    npcCntDict = {}  #±êʶµã¶ÔÓ¦ÊýÁ¿
    
#    gameNPC = GameWorld.GetNPCManager()
#    for i in xrange(gameNPC.GetCustomNPCRefreshCount()):
#        npcRefresh = gameNPC.GetCustomNPCRefreshAt(i)
#        rmark = npcRefresh.GetRefreshMark()
#        npcCntDict[rmark] = npcCntDict.get(rmark, npcRefresh.GetCount())
    __RefreshNPC(refreshNPCid)
    
    if curNPCIndex + 1 >= len(npcList):
        if curWheel + 1 >= len(npcRereshList):
            GameWorld.DebugLog('    È«²¿Ð¡¹ÖË¢Í꣡')
 
    gameFB.SetGameFBDict(FBPlayerDict_NPCIndex, curNPCIndex + 1)
    gameFB.SetGameFBDict(FBPlayerDict_LastNPCRTime, tick)
    
    curPlayer = FBCommon.GetCurSingleFBPlayer()
    if curPlayer:
        DoFBHelp(curPlayer, tick)
    return
 
def __RefreshNPC(refreshNPCid):
    #Ë¢1Ö»¹ÖÎï
    gameFB = GameWorld.GetGameFB()
    curRemainCnt = gameFB.GetGameFBDictByKey(FBPlayerDict_NPCRemainCnt)
    curMaxCnt = curRemainCnt + 1
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    refreshMark = gatherSoulFBCfg[Def_NPCRefreshMark]
    NPCCustomRefresh.SetNPCRefresh(refreshMark, [refreshNPCid], curMaxCnt, 1)
    gameFB.SetGameFBDict(FBPlayerDict_NPCRemainCnt, curMaxCnt)
    return
 
## ¸±±¾½øÐÐÖÐ
#  @param tick:ʱ¼ä´Á
#  @return ÎÞÒâÒå
def __DoLogic_FB_Fighting(tick):
    __CheckNPCRefresh(tick)
    __CheckAutoRefreshGoldBoss(tick)
    
    fbCfg = GetGatherSoulNPCCfg()
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameWorld().GetOpenFBTick() < fbCfg[Def_FightTime] * 1000:
        return
    
    __DoGatherSoulOver()
    return
 
        
##¸±±¾¹Ø±ÕÖÐ
# @param tick:ʱ¼ä´Á
# @return ÎÞÒâÒå
# @remarks ¸±±¾¹Ø±ÕÖÐ
def __DoLogic_FB_Over(tick):
 
    #gameFB = GameWorld.GetGameFB()
    fbCfg = GetGatherSoulNPCCfg()
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameFB().GetFBStepTick() < fbCfg[Def_LeaveTime] * 1000:
        return
    
    #¸±±¾¹Ø±Õ
    GameWorldProcess.CloseFB(tick)
    FBCommon.SetFBStep(FB_Step_Close, tick)
    return
 
def DoFB_NPCDead(curNPC):
    npcRereshList = GetGatherSoulNPCCfg()
    npcidlist = [GetGatherSoulFBCfg()[Def_BossID]]
    for nlist in npcRereshList:
        npcidlist += nlist
    if curNPC.GetNPCID() not in npcidlist:
        return
    
    gameFB = GameWorld.GetGameFB()
    curRemainCnt = gameFB.GetGameFBDictByKey(FBPlayerDict_NPCRemainCnt)
    newRemainCnt = max(0, curRemainCnt - 1)
    gameFB.SetGameFBDict(FBPlayerDict_NPCRemainCnt, newRemainCnt)
    
    curWheel = gameFB.GetGameFBDictByKey(FBPlayerDict_CurWheel)
    curNPCIndex = gameFB.GetGameFBDictByKey(FBPlayerDict_NPCIndex)
    
    if newRemainCnt <= 0 and curNPCIndex >= len(npcRereshList[curWheel]):
        #±¾²¨µÄ¹Ö¶¼ËÀµôÁË
        gameFB.SetGameFBDict(FBPlayerDict_CurWheel, curWheel + 1)
        gameFB.SetGameFBDict(FBPlayerDict_HasRefreshBoss, 0)
        curPlayer = FBCommon.GetCurSingleFBPlayer()
        if curPlayer:
            DoFBHelp(curPlayer, GameWorld.GetGameWorld().GetTick())
        if curWheel + 1>=len(npcRereshList):
            #ËùÓв¨µÄ¹Ö¶¼ËÀÁË£¬½áÊø
            __DoGatherSoulOver()
        else:
            #½øÈëÏÂÒ»²¨
            gameFB.SetGameFBDict(FBPlayerDict_NPCIndex, 0)
            gameFB.SetGameFBDict(FBPlayerDict_LastWheelEndTime, GameWorld.GetGameWorld().GetTick())
            gameFB.SetGameFBDict(FBPlayerDict_LastNPCRTime, 0)
            if curPlayer:
                curPlayer.Sync_TimeTick(IPY_GameWorld.tttLeaveFamilyWar, 0, GetGatherSoulFBCfg()[Def_WheelRefreshCD], True)
                    
    return
 
##ÊÇ·ñ¿ÉÒÔ¶áÆì
# @param curPlayer Íæ¼ÒʵÀý
# @param curNPC NPCʵÀý
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks
def OnCanCollect(curPlayer, curNPC, tick):
    gameFB = GameWorld.GetGameFB()
    guardNPCID = gameFB.GetGameFBDictByKey(FBPlayerDict_GuardNPCID)
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    guardMaxCntDict = gatherSoulFBCfg[Def_GuardInfo]
    if guardNPCID not in guardMaxCntDict:
        return False
    curCnt = gameFB.GetGameFBDictByKey(FBPlayerDict_GuardNPCCnt % guardNPCID)
    if curCnt >= guardMaxCntDict[guardNPCID]:
        GameWorld.Log('    ¸ÃÊØÎÀÒÑÂú£¬²»¿ÉÔÙ½¨Ôì guardNPCID=%s,curCnt=%s' % (guardNPCID, curCnt))
        return False
    return True
 
 
##¸±±¾ÖÐ,Õ¼ÁìNPCµÄLoadingʱ¼ä.
# @param curPlayer Íæ¼ÒʵÀý
# @param curNPC NPCʵÀý
# @return ·µ»ØÖµ, Loadingʱ¼ä
# @remarks ¸±±¾ÖÐ,Õ¼ÁìNPCµÄLoadingʱ¼ä
def GetFBPrepareTime(curPlayer, curNPC):
    return GetGatherSoulFBCfg()[Def_BuildTime]
 
 
##Íæ¼ÒÊÕ¼¯³É¹¦(Ëþ, Æì)
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks
def OnCollectOK(curPlayer, npcID, tick):
    tagObj = curPlayer.GetActionObj()
    if not tagObj:
        return
    if tagObj.GetGameObjType() != IPY_GameWorld.gotNPC:
        return
    
    curNPC = GameWorld.GetNPCManager().GetNPCByIndex(tagObj.GetIndex())
    if not curNPC:
        return
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    if curNPC.GetNPCID() != gatherSoulFBCfg[Def_BuildNPCID]:
        return
    gameFB = GameWorld.GetGameFB()
    guardNPCID = gameFB.GetGameFBDictByKey(FBPlayerDict_GuardNPCID)
    if not guardNPCID:
        GameWorld.ErrLog('²É¼¯Ç°Î´Ö¸¶¨Òª½¨ÔìNPCID', curPlayer.GetID())
        return
    ChNPC.OnCollectEnd(curPlayer, curNPC)
    #Ë¢ÊØÎÀ
    NPCCustomRefresh.SetNPCRefresh(gatherSoulFBCfg[Def_BuildMark], [(guardNPCID, 1)], 1, 1)
    key = FBPlayerDict_GuardNPCCnt % guardNPCID
    gameFB.SetGameFBDict(key, gameFB.GetGameFBDictByKey(key) + 1)
    gameFB.SetGameFBDict(FBPlayerDict_GuardNPCID, 0)
    DoFBHelp(curPlayer, tick)
    return
 
 
## ¸±±¾ÐÐΪ
#  @param curPlayer Íæ¼Ò
#  @param actionType ÐÐΪÀàÐÍ
#  @param actionInfo ÐÐΪÐÅÏ¢
#  @param tick µ±Ç°Ê±¼ä
#  @return None
def DoFBAction(curPlayer, actionType, actionInfo, tick):
    gameFB = GameWorld.GetGameFB()
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    fbStep = gameFB.GetFBStep()
    if actionType == 0:  #½¨ÔìÊØÎÀ 
        if actionInfo not in gatherSoulFBCfg[Def_GuardInfo]:
            return
        gameFB.SetGameFBDict(FBPlayerDict_GuardNPCID, actionInfo)
        
    elif actionType == 1:  #¿ªÊ¼Ë¢¹Ö 
        if fbStep != FB_Step_Prepare:
            return
        FBCommon.SetFBStep(FB_Step_Fighting, tick)
        FBCommon.AddEnterFBCount(curPlayer, ChConfig.Def_FBMapID_GatherSoul)
    elif actionType == 2:  #ÕÙ»½»Æ½ðBOSS actionInfo 0-ÕÙ»½1´Î 1-×Ô¶¯ÕÙ»½ 2-È¡Ïû×Ô¶¯ÕÙ»½
        if fbStep != FB_Step_Fighting:
            return
        if actionInfo == 0:
            if gameFB.GetGameFBDictByKey(FBPlayerDict_HasRefreshBoss):
                #±¾²¨ÒÑË¢»Æ½ðBOSS
                PlayerControl.NotifyCode(curPlayer, 'JHCallForBoss1')
                return
            #ÅжÏÇ®
            costMoney = gatherSoulFBCfg[Def_BossCostMoney]
            costMoneyList = PlayerControl.HaveMoneyEx(curPlayer, ShareDefine.TYPE_Price_Gold_Paper_Money, costMoney)
            if not costMoneyList:
                return
            for moneyType, moneyCnt in costMoneyList:
                PlayerControl.PayMoney(curPlayer, moneyType, moneyCnt, ChConfig.Def_Cost_FBGatherSoulBoss)
            #Á¢¼´Ë¢
            __RefreshNPC(gatherSoulFBCfg[Def_BossID])
            gameFB.SetGameFBDict(FBPlayerDict_HasRefreshBoss, 1)
        elif actionInfo == 1:
            if gameFB.GetGameFBDictByKey(FBPlayerDict_AutoBoss):
                GameWorld.DebugLog('ÒѾ­ÊÇ×Ô¶¯ÕÙ»½BOSS״̬£¡')
                return
            gameFB.SetGameFBDict(FBPlayerDict_AutoBoss, 1)
        elif actionInfo == 2:
            if not gameFB.GetGameFBDictByKey(FBPlayerDict_AutoBoss):
                GameWorld.DebugLog('²»ÊÇ×Ô¶¯ÕÙ»½BOSS״̬£¬²»ÐèҪȡÏû£¡')
                return
            gameFB.SetGameFBDict(FBPlayerDict_AutoBoss, 0)
            
    DoFBHelp(curPlayer, tick)
    return
 
def __CheckAutoRefreshGoldBoss(tick):
    ##×Ô¶¯ÕÙ»½»Æ½ðBOSS
    gameFB = GameWorld.GetGameFB()
    if not gameFB.GetGameFBDictByKey(FBPlayerDict_AutoBoss):
        return
    curPlayer = FBCommon.GetCurSingleFBPlayer()
    if not curPlayer:
        gameFB.SetGameFBDict(FBPlayerDict_AutoBoss, 0)
        return
    fbStep = gameFB.GetFBStep()
    if fbStep != FB_Step_Fighting:
        gameFB.SetGameFBDict(FBPlayerDict_AutoBoss, 0)
        return
    if gameFB.GetGameFBDictByKey(FBPlayerDict_HasRefreshBoss):
        #±¾²¨ÒÑË¢»Æ½ðBOSS
        return
    gatherSoulFBCfg = GetGatherSoulFBCfg()
    lastWheelEndTime = gameFB.GetGameFBDictByKey(FBPlayerDict_LastWheelEndTime)
    if lastWheelEndTime and tick - lastWheelEndTime < gatherSoulFBCfg[Def_WheelRefreshCD]:
        return
    
    
    costMoney = gatherSoulFBCfg[Def_BossCostMoney]
    costMoneyList = PlayerControl.HaveMoneyEx(curPlayer, ShareDefine.TYPE_Price_Gold_Paper_Money, costMoney, False)
    if not costMoneyList:
        PlayerControl.NotifyCode(curPlayer, 'JHCallForBoss2')
        gameFB.SetGameFBDict(FBPlayerDict_AutoBoss, 0)
    else:
        for moneyType, moneyCnt in costMoneyList:
            PlayerControl.PayMoney(curPlayer, moneyType, moneyCnt, ChConfig.Def_Cost_FBGatherSoulBoss)
        #Á¢¼´Ë¢
        __RefreshNPC(gatherSoulFBCfg[Def_BossID])
        
        gameFB.SetGameFBDict(FBPlayerDict_HasRefreshBoss, 1)
    DoFBHelp(curPlayer, tick)
    return
 
 
## ÊÇ·ñ¸±±¾¸´»î
#  @param None
#  @return ÊÇ·ñ¸±±¾¸´»î
def OnPlayerReborn():
    return True
 
 
##Íæ¼ÒËÀÍö.
# @param curPlayer:ËÀÍöµÄÍæ¼Ò 
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Íæ¼ÒÖ÷¶¯À뿪¸±±¾.
def DoPlayerDead(curPlayer):
    
    return
 
 
## ¼ì²éÊÇ·ñ¿É¹¥»÷£¬ Ö÷Åж¨²»¿É¹¥»÷µÄÇé¿ö£¬ÆäËûÂß¼­ÓÉÍâ²ã¾ö¶¨
#  @param attacker ¹¥»÷·½
#  @param defender ·ÀÊØ·½
#  @return bool
def CheckCanAttackTagObjInFB(attacker, defender):
    gameFB = GameWorld.GetGameFB()
    if gameFB.GetFBStep() != FB_Step_Fighting:
        return False
    return True
 
def KillGatherSoulNPCDropAward(itemID, itemCnt, isBind):
    ##µôÂä½±Àø {wheel:[[itemid,itemCnt,isBind]]}
    gameFB = GameWorld.GetGameFB()
    curWheel = gameFB.GetGameFBDictByKey(FBPlayerDict_CurWheel) + 1
    #ownerID = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_SingleFBPlayerID)
    lineID = GameWorld.GetGameWorld().GetLineID()
    if lineID not in PyGameData.g_gathersoulfbAwardDict:
        PyGameData.g_gathersoulfbAwardDict[lineID] = {}
    if curWheel not in PyGameData.g_gathersoulfbAwardDict[lineID]:
        PyGameData.g_gathersoulfbAwardDict[lineID][curWheel] = []
    PyGameData.g_gathersoulfbAwardDict[lineID][curWheel].append([itemID, itemCnt, isBind])
    curPlayer = FBCommon.GetCurSingleFBPlayer()
    if curPlayer:
        DoFBHelp(curPlayer, 0)
    return
 
## ¸±±¾½áÊø´¦Àí
def __DoGatherSoulOver():
    gameFB = GameWorld.GetGameFB()
    if gameFB.GetFBStep() == FB_Step_Over:
        return
    
    tick = GameWorld.GetGameWorld().GetTick()
    # ½øÈëÀ뿪½×¶Î
    FBCommon.SetFBStep(FB_Step_Over, tick)
    ownerID = gameFB.GetGameFBDictByKey(ChConfig.Def_FB_SingleFBPlayerID)
    lineID = GameWorld.GetGameWorld().GetLineID()
    itemDict = PyGameData.g_gathersoulfbAwardDict.pop(lineID, {})
    totalItemList = []
    for itemList in itemDict.values():
        totalItemList += itemList
    GameWorld.Log('   ¸±±¾½áÊø´¦Àí  itemDict=%s'%itemDict, ownerID)
    curPlayer = FBCommon.GetCurSingleFBPlayer()
    if not curPlayer:
        #½±ÀøÖ±½Ó·¢Óʼþ
        if totalItemList:
            PlayerControl.SendMailByKey('JHBagFull2', [ownerID], totalItemList)
        
        GameWorldProcess.CloseFB(tick)
        return
    if totalItemList:
        needPackSpaceDict = {}
        for itemID, itemCnt, isBind in totalItemList:
            curItem = GameWorld.GetGameData().GetItemByTypeID(itemID)
            if not curItem:
                return
            packType = ChConfig.GetItemPackType(curItem)
            needSpace = ItemControler.GetItemNeedPackCount(packType, curItem, itemCnt)
            needPackSpaceDict[packType] = needPackSpaceDict.get(packType, 0) + needSpace
            
        isSendMail = False #ÊÇ·ñ±³°ü²»×ã
        for packType, needSpace in needPackSpaceDict.items():
            if needSpace > ItemCommon.GetItemPackSpace(curPlayer, packType, needSpace):
                isSendMail = True
                break
    
        if isSendMail:
            PlayerControl.SendMailByKey('JHBagFull2', [curPlayer.GetPlayerID()], totalItemList)
            GameWorld.DebugLog("±³°ü¿Õ¼ä²»¹»£¬·¢ËÍÓʼþ: mailItemList=%s" % str(totalItemList), curPlayer.GetPlayerID())
        else:
            for itemID, itemCnt, isBind in totalItemList:
                ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [],
                                                event=["GatherSoulFB", False, {}])
            
    fbCfg = GetGatherSoulFBCfg()
    costTime = tick - GameWorld.GetGameWorld().GetOpenFBTick()
 
    itemInfo = FBCommon.GetJsonItemList(totalItemList)
    __SendOverInfo(curPlayer, {FBCommon.Over_isPass:1, FBCommon.Over_costTime:costTime, FBCommon.Over_itemInfo:itemInfo})
    
    FBCommon.Sync_Player_TimeTick(IPY_GameWorld.tttLeaveMap, fbCfg[Def_LeaveTime] * 1000)
    return
 
 
## ·¢ËÍÌôÕ½½á¹ûÐÅÏ¢
def __SendOverInfo(curPlayer, overDict):
    overDict[FBCommon.Over_dataMapID] = ChConfig.Def_FBMapID_GatherSoul
    #overDict[FBCommon.Over_lineID] = FBCommon.GetFBPropertyMark()
    GameWorld.DebugLog("__SendOverInfo overDict=%s" % (str(overDict)), curPlayer.GetPlayerID())
    FBCommon.Notify_FB_Over(curPlayer, overDict)
    return