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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GameWorldLogic.FBProcess.GameLogic_KillDevil
#
# @todo:ÌÖ·¥Ñýħ
# @author hxp
# @date 2020-01-07
# @version 1.0
#
# ÏêϸÃèÊö: ÌÖ·¥Ñýħ£¬×é¶Ó/µ¥ÈË
#
#-------------------------------------------------------------------------------
#"""Version = 2020-01-07 19:00"""
#-------------------------------------------------------------------------------
 
import FBCommon
import NPCCommon
import PyGameData
import PlayerAssist
import IpyGameDataPY
import ItemControler
import GameWorldProcess
import PlayerFairyDomain
import NPCCustomRefresh
import IPY_GameWorld
import ItemCommon
import GameWorld
import ChConfig
 
(
Def_PrepareTime, # ×¼±¸Ê±¼ä, Ãë
Def_FightTime, # ¸±±¾Ê±¼ä, Ãë
Def_ExitTime, # Í˳öʱ¼ä, Ãë
) = range(3)
 
# ¸±±¾×´Ì¬
(
FB_Step_Open, #¿ªÆô
FB_Step_Prepare, #×¼±¸ÖÐ
FB_Step_Fight, # Õ½¶·ÖÐ
FB_Step_Over, # ½áÊøµÈ´ý
FB_Step_Close, # ¹Ø±ÕÖÐ
) = range(5)
 
FBDict_FBBossID = "FBBossID" # ¸±±¾bossID
FBDict_KillNPCCount = "KillNPCCount_%s" # ÒÑ»÷ɱNPCÊý£¬²ÎÊýnpcID
 
## ¿ªÆô¸±±¾
def OnOpenFB(tick):
    return
 
## ÊÇ·ñÄܹ»Í¨¹ý»î¶¯²éѯ½øÈë
def OnEnterFBEvent(curPlayer, mapID, lineID, tick):
    teamID = curPlayer.GetTeamID()
    if teamID:
        if curPlayer.GetTeamLV() != IPY_GameWorld.tmlLeader:
            return True
        
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'MapID':mapID, 'LineID':lineID})
    if not ipyData:
        return
    fdeventID = ipyData.GetID()
    if not PlayerFairyDomain.SetFairyDomainEventState(curPlayer, fdeventID, PlayerFairyDomain.FDEventState_Visiting):
        GameWorld.DebugLog("ÉèÖÃʼþѰ·ÃÖÐʧ°Ü£¬¿ÉÄÜûÓиÃʼþ! fdeventID=%s" % fdeventID)
        return
    
    return True
 
## ¸±±¾Íæ¼Ò½øÈëµã
def OnGetFBEnterPos(curPlayer, mapID, lineID, ipyEnterPosInfo, tick):
    return ipyEnterPosInfo
 
## ÊÇ·ñ¿ÉÒÔ½øÈë
def OnChangeMapAsk(ask, tick):
    return IPY_GameWorld.cmeAccept
 
## Íæ¼Ò½øÈ븱±¾
def DoEnterFB(curPlayer, tick):
    mapID = GameWorld.GetGameWorld().GetMapID()
    mapID = FBCommon.GetRecordMapID(mapID)
    gameFB = GameWorld.GetGameFB()
    
    lineTimeCfg = FBCommon.GetFBLineStepTime(mapID)
        
    fbStep = gameFB.GetFBStep()
    if fbStep == FB_Step_Open:
        FBCommon.SetFBStep(FB_Step_Prepare, tick)
        bossID = FBCommon.GetFBLineRefreshNPC(mapID)[1]
        gameFB.SetGameFBDict(FBDict_FBBossID, bossID)
        
    if fbStep <= FB_Step_Prepare:
        PyGameData.g_fbPickUpItemDict.pop(curPlayer.GetPlayerID(), 0)
        notify_tick = lineTimeCfg[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 = lineTimeCfg[Def_FightTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttTowerTake, 0, max(notify_tick, 0), True)
        
    DoFBHelp(curPlayer, tick)
    return
 
## ¸±±¾°ïÖúÐÅÏ¢
def DoFBHelp(curPlayer, tick):
    playerID = curPlayer.GetPlayerID()
    gameFB = GameWorld.GetGameFB()
    npcID = gameFB.GetGameFBDictByKey(FBDict_FBBossID)
    killCount = gameFB.GetGameFBDictByKey(FBDict_KillNPCCount % npcID)
    #fbHelpDict = {FBCommon.Help_npcTotal:killCount}
    fbHelpDict = {FBCommon.Help_npc:FBCommon.GetJsonNPCKillList({npcID:killCount})}
    FBCommon.Notify_FBHelp(curPlayer, fbHelpDict)
    GameWorld.DebugLog("DoFBHelp %s" % str(fbHelpDict), playerID)
    return
 
## Íæ¼ÒÍ˳ö¸±±¾.
def DoExitFB(curPlayer, tick):
    return
 
## Íæ¼ÒÖ÷¶¯À뿪¸±±¾.
def DoPlayerLeaveFB(curPlayer, tick):
    return
 
## ¹Ø±Õ¸±±¾
def OnCloseFB(tick):
    return
 
## Íæ¼Ò¸±±¾¸´»î
def DoFBOnReborn(curPlayer, rebornType, tick):
    return
 
## ¸±±¾¶¨Ê±Æ÷
def OnProcess(tick):
    fbStep = GameWorld.GetGameFB().GetFBStep()
 
    # ¸±±¾×¼±¸
    if fbStep == FB_Step_Prepare:
        __DoLogic_FB_Prepare(tick)
    elif fbStep == FB_Step_Fight:
        __ProcessFight(tick)
    elif fbStep == FB_Step_Over:
        __ProcessCloseFB(tick)
        
    return
 
## ¸±±¾×¼±¸
def __DoLogic_FB_Prepare(tick):
    #gameFB = GameWorld.GetGameFB()
    mapID = GameWorld.GetMap().GetMapID()
    fbCfg = FBCommon.GetFBLineStepTime(mapID)
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameFB().GetFBStepTick() < fbCfg[Def_PrepareTime] * 1000:
        return
    
    gameFB = GameWorld.GetGameFB()
    mapID = GameWorld.GetMap().GetMapID()
    refreshMark, bossID = FBCommon.GetFBLineRefreshNPC(mapID)
    gameFB.SetGameFBDict(FBDict_FBBossID, bossID)
    
    NPCCustomRefresh.SetNPCRefresh(refreshMark, [bossID])
    NPCCustomRefresh.ProcessAllNPCRefresh(tick) # Á¢¼´³ö·¢Ò»´Î±êʶµãË¢ÐÂ
    
    FBCommon.SetFBStep(FB_Step_Fight, tick)
    FBCommon.Sync_Player_TimeTick(IPY_GameWorld.tttTowerTake, fbCfg[Def_FightTime] * 1000)
    return
 
## ¸±±¾Õ½¶·
def __ProcessFight(tick):
    mapID = GameWorld.GetMap().GetMapID()
    fbCfg = FBCommon.GetFBLineStepTime(mapID)
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameFB().GetFBStepTick() < fbCfg[Def_FightTime] * 1000:
        return
    
    __DoKillDevilOver(tick)
    return
    
## ¸±±¾¹Ø±Õ
def __ProcessCloseFB(tick):
    mapID = GameWorld.GetMap().GetMapID()
    fbCfg = FBCommon.GetFBLineStepTime(mapID)
    closeTime = ChConfig.Def_FBPickupItemTime + fbCfg[Def_ExitTime] * 1000
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameFB().GetFBStepTick() < closeTime:
        return
    
    GameWorldProcess.CloseFB(tick)
    FBCommon.SetFBStep(FB_Step_Close, tick)
    return
 
## Íæ¼ÒɱËÀNPC
def DoFB_Player_KillNPC(curPlayer, curNPC, tick):
    npcID = curNPC.GetNPCID()
    gameFB = GameWorld.GetGameFB()
    fbBossID = gameFB.GetGameFBDictByKey(FBDict_FBBossID)
    if npcID != fbBossID:
        return
    gameFB.SetGameFBDict(FBDict_KillNPCCount % npcID, gameFB.GetGameFBDictByKey(FBDict_KillNPCCount % npcID) + 1)
    FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0)
    
    __DoKillDevilOver(tick, curNPC)
    return
 
def __DoKillDevilOver(tick, curNPC=None):
    # Õ½¶·³¬Ê±
    gameFB = GameWorld.GetGameFB()
    if gameFB.GetFBStep() == FB_Step_Over:
        return
    FBCommon.SetFBStep(FB_Step_Over, tick)
    
    isPass = curNPC != None
    lineID = 0
    mapID = FBCommon.GetRecordMapID(GameWorld.GetMap().GetMapID())
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'MapID':mapID, 'LineID':lineID})
    fdeventID = ipyData.GetID() if ipyData else 0
    GameWorld.DebugLog("¸±±¾½áËã: isPass=%s" % (isPass))
    
    noAssistPlayerID, assistMoneyType, assistPlayerMoneyDict = PlayerAssist.OnFBAssistOver(isPass, mapID)
    exitTime = FBCommon.GetFBLineStepTime(mapID)[Def_ExitTime] * 1000
    rewardInfo = FBCommon.GetFBLineReward(mapID, 0)
    assistItemList = [] if not rewardInfo else rewardInfo
    
    playerManager = GameWorld.GetMapCopyPlayerManager()
    playerCount = playerManager.GetPlayerCount()
    for index in xrange(playerCount):
        curPlayer = playerManager.GetPlayerByIndex(index)
        if not curPlayer:
            continue
        
        playerID = curPlayer.GetPlayerID()
        overDict = {}
        if isPass and noAssistPlayerID:
            if playerID == noAssistPlayerID:
                bossID = curNPC.GetNPCID()
                dropPosX, dropPosY = curNPC.GetPosX(), curNPC.GetPosY()
                isOnlySelfSee = False
                isDropDisperse = True
                dropItemMapInfo = [dropPosX, dropPosY, isOnlySelfSee, isDropDisperse]
                jsonItemList, totalExp, totalMoney = NPCCommon.GiveKillNPCDropPrize(curPlayer, mapID, {bossID:1}, dropItemMapInfo=dropItemMapInfo)
                if not jsonItemList:
                    # Ã»ÓеôÂäʱֱ½Ó֪ͨ½áË㣬·ÀÖ¹¿¨¸±±¾
                    curPlayer.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, exitTime, True)
                    FBCommon.NotifyFBOver(curPlayer, mapID, lineID, isPass, overDict)
                else:
                    PlayerFairyDomain.SetFairyDomainEventState(curPlayer, fdeventID, PlayerFairyDomain.FDEventState_Visited)
                    curPlayer.Sync_TimeTick(ChConfig.tttPickupItem, 0, ChConfig.Def_FBPickupItemTime, True)
                continue
                    
            elif playerID in assistPlayerMoneyDict:
                addAssistMoney = assistPlayerMoneyDict[playerID]
                overDict.update({FBCommon.Over_isAssist:1, FBCommon.Over_itemInfo:FBCommon.GetJsonItemList(assistItemList),
                                 FBCommon.Over_money:FBCommon.GetJsonMoneyList({assistMoneyType:addAssistMoney})})
                ItemControler.GivePlayerItemOrMail(curPlayer, assistItemList)
            
            else:
                pass
            
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, exitTime, True)
        FBCommon.NotifyFBOver(curPlayer, mapID, lineID, isPass, overDict)
        
    return
 
def OnPickUpItem(curPlayer, curItem, tick):
    mapItemType = curItem.GetType()
    if mapItemType == ChConfig.Def_ItemType_Money:
        return
    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]
    
    playerItemCount = 0
    mapItemManager = GameWorld.GetMapItemManager()
    for index in xrange(mapItemManager.GetMapItemCount()):
        mapItem = mapItemManager.GetMapItemByIndex(index)
        if not mapItem or mapItem.IsEmpty():
            continue
        
        # »¹ÓÐÊôÓÚ×Ô¼ºµÄ¶«Î÷û¼ñ²»Í¨Öª½áÊø
        if mapItem.GetOwnerID() == curPlayer.GetPlayerID():
            playerItemCount += 1
        
    isItemAllPickUp = (playerItemCount <= 1)
    if not isItemAllPickUp:
        return
    
    isPass = 1
    lineID = 0
    mapID = FBCommon.GetRecordMapID(GameWorld.GetMap().GetMapID())
    leaveTick = FBCommon.GetFBLineStepTime(mapID)[Def_ExitTime] * 1000
    jsonItemList = PyGameData.g_fbPickUpItemDict.get(playerID, [])
    curPlayer.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, leaveTick, True)
    overDict = {FBCommon.Over_itemInfo:jsonItemList}
    FBCommon.NotifyFBOver(curPlayer, mapID, lineID, isPass, overDict)
    return
 
## ¼ì²éÊÇ·ñ¿É¹¥»÷£¬ Ö÷Åж¨²»¿É¹¥»÷µÄÇé¿ö£¬ÆäËûÂß¼­ÓÉÍâ²ã¾ö¶¨
def CheckCanAttackTagObjInFB(attacker, defender):
    return GameWorld.GetGameFB().GetFBStep() == FB_Step_Fight
 
## ¿É·ñɨµ´
def OnPlayerFBSweepAsk(curPlayer, mapID, lineID, sweepCnt, isFinish, dataEx):
    curState = PlayerFairyDomain.GetFairyDomainFBEventState(curPlayer, mapID, lineID)
    if curState not in [PlayerFairyDomain.FDEventState_CanVisit, PlayerFairyDomain.FDEventState_Visiting]:
        GameWorld.DebugLog("çÎç¿ÎÞ·¨É¨µ´! ²»´æÔÚ¸Ãʼþ»òÎÞ·¨½øÈ룡 mapID=%s,lineID=%s,curState=%s" % (mapID, lineID, curState))
        return False
    return True
 
## É¨µ´½á¹û
def OnPlayerFBSweepResult(curPlayer, mapID, lineID, sweepCnt, isFinish, dataEx):
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'MapID':mapID, 'LineID':lineID})
    if ipyData:
        fdeventID = ipyData.GetID()
        PlayerFairyDomain.SetFairyDomainEventState(curPlayer, fdeventID, PlayerFairyDomain.FDEventState_Visited)
    
    isPass = 1
    _, bossID = FBCommon.GetFBLineRefreshNPC(ChConfig.Def_FBMapID_KillDevil)
    jsonItemList, totalExp, totalMoney = NPCCommon.GiveKillNPCDropPrize(curPlayer, mapID, {bossID:1})
    overDict = {FBCommon.Over_itemInfo:jsonItemList, FBCommon.Over_isSweep:1}
    FBCommon.NotifyFBOver(curPlayer, mapID, lineID, isPass, overDict)
    return