xdh
2019-04-13 10a2b69436a1ebb09fa49a339655e150bfda70a8
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package GameWorldLogic.FBProcess.GameLogic_FairyTreasure
#
# @todo:çÎ翱¦²Ø
# @author xdh
# @date 2019-04-09
# @version 1.0
# ÏêϸÃèÊö: çÎ翱¦²Ø
#
#---------------------------------------------------------------------
#"""Version = 2019-04-09 11:00"""
#---------------------------------------------------------------------
 
import FBCommon
import GameWorld
import IPY_GameWorld
import NPCCustomRefresh
import IpyGameDataPY
import PlayerControl
import PlayerFairyDomain
import GameWorldProcess
import ItemControler
import NPCCommon
import ChConfig
import ChPlayer
import EventReport
import ChNPC
 
 
FBPlayerDict_CurStep = 'FBPlayerDict_CurStep'   # µ±Ç°½×¶Î
# ¸±±¾Í¨ÓÃÅäÖÃ
(
Def_PrepareTime, # ×¼±¸Ê±¼ä£¬Ãë
Def_FightTime, # Õ½¶·Ê±¼ä£¬Ãë
Def_LeaveTime, # Í˳öʱ¼ä, Ãë
Def_CollectTime, # ²É¼¯Ê±¼ä, Ãë
Def_RefreshBossMark, # Ë¢¹Ö±êʶµã
) = range(5)
 
 
#µ±Ç°¸±±¾µØÍ¼µÄ״̬
(
FB_Step_Open,  # ¸±±¾¿ªÆô
FB_Step_Prepare,  # ¸±±¾µÈ´ý
FB_Step_Fighting,  # ¸±±¾½øÐÐÖÐ
#FB_Step_Collect,  # ¸±±¾²É¼¯ÖÐ
#FB_Step_PickItem, # Ê°È¡ÎïÆ·ÖÐ
FB_Step_Over,  # ¸±±¾½áÊø
FB_Step_Close,  # ¸±±¾¹Ø±Õ
) = range(5)
 
def __GetFBTimeCfg(lineID=0):
    if not lineID:
        lineID = FBCommon.GetFBPropertyMark()
    return FBCommon.GetFBLineStepTime(ChConfig.Def_FBMapID_FairyTreasure, lineID)
 
## ÊÇ·ñ¿É½øÈë
#  @param curPlayer
#  @param mapID µØÍ¼ID
#  @param lineId ·ÖÏßID
#  @param tick
#  @return ÊÇ·ñ¿É½øÈë
def OnEnterFBEvent(curPlayer, mapID, lineId, tick):
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'MapID':mapID, 'LineID':lineId})
    if not ipyData:
        return
    fdeventID = ipyData.GetID()
    if not PlayerFairyDomain.SetFairyDomainEventState(curPlayer, fdeventID, PlayerFairyDomain.FDEventState_Visiting):
        return
    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 ÇëÇóÐÅÏ¢
#  @param tick
#  @return »Ø¸´ÊÇ·ñͨ¹ýÇëÇó
def OnChangeMapAsk(ask, tick):
    return IPY_GameWorld.cmeAccept
 
## ½ø¸±±¾
#  @param curPlayer
#  @param tick
#  @return None
def DoEnterFB(curPlayer, tick):
    mapID = GameWorld.GetMap().GetMapID()
    mapID = FBCommon.GetRecordMapID(mapID)
    gameFB = GameWorld.GetGameFB()
    lineID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ReqFBFuncLine)
    playerID = curPlayer.GetID()
    hadDelTicket = FBCommon.GetHadDelTicket(curPlayer)
    if not hadDelTicket:
        FBCommon.SetHadDelTicket(curPlayer)
        FBCommon.SetFBPropertyMark(lineID)
    
    if not hadDelTicket \
        and IpyGameDataPY.GetIpyGameDataByCondition("NPCShow", {"MapID":mapID, "LineID":lineID}, isLogNone=False):
        GameWorld.DebugLog("¸Õ½øÈëʱ²»Ö±½Ó¿ªÊ¼£¬ÐèµÈǰ¶Ë֪ͨ¿ªÊ¼²Å¿ªÊ¼!", playerID)  # µôÏßÖØÉÏÇ¿ÖÆ¿ªÊ¼
        return
    
    fbStep = gameFB.GetFBStep()
 
    if fbStep < FB_Step_Prepare:
        FBCommon.SetFBStep(FB_Step_Prepare, tick)
        
    if fbStep <= FB_Step_Prepare:
        notify_tick = __GetFBTimeCfg(lineID)[Def_PrepareTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttWaitStart, 0, max(notify_tick, 0), True)
        
    elif fbStep == FB_Step_Fighting:
        notify_tick = __GetFBTimeCfg(lineID)[Def_FightTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttTowerTake, 0, max(notify_tick, 0), True)
    else:
        PlayerControl.PlayerLeaveFB(curPlayer)
        return
    DoFBHelp(curPlayer, tick)
    return
 
 
 
## ¿Í»§¶Ë·¢ËÍ¿ªÊ¼¸±±¾
def OnClientStartFB(curPlayer, tick):
    gameFB = GameWorld.GetGameFB()
    fbStep = gameFB.GetFBStep()
    if fbStep >= FB_Step_Prepare:
        GameWorld.ErrLog("ǰ¶ËÇëÇóÕýʽ¿ªÊ¼¸±±¾, µ«¸±±¾ÒѾ­¿ªÊ¼ÁË£¬²»¿ÉÖØ¸´¿ªÊ¼!", curPlayer.GetPlayerID())
        return
    
    lineID = FBCommon.GetFBPropertyMark()
    GameWorld.DebugLog("ǰ¶Ë³¡¾°ÐãÒѲ¥·ÅÍê±Ï£¬ÇëÇóÕýʽ¿ªÊ¼¸±±¾!lineID=%s" % lineID, curPlayer.GetPlayerID())
    FBCommon.SetFBStep(FB_Step_Prepare, tick)
    notify_tick = __GetFBTimeCfg(lineID)[Def_PrepareTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())
    curPlayer.Sync_TimeTick(IPY_GameWorld.tttWaitStart, 0, max(notify_tick, 0), True)
    DoFBHelp(curPlayer, tick)
    return
 
 
## ¸±±¾Ê±¼äµ½¹Ø±Õ
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def OnCloseFB(tick):
    return
 
 
## »ñµÃ¸±±¾°ïÖúÐÅÏ¢
#  @param curPlayer µ±Ç°Íæ¼Ò£¨±»Í¨Öª¶ÔÏó£©
#  @param tick µ±Ç°Ê±¼ä
#  @return None
def DoFBHelp(curPlayer, tick):
    gameFB = GameWorld.GetGameFB()
    
    curStep = gameFB.GetGameFBDictByKey(FBPlayerDict_CurStep) + 1
    helpDict = {FBCommon.Help_step:curStep}
    GameWorld.DebugLog("DoFBHelp %s" % str(helpDict))
    FBCommon.Notify_FBHelp(curPlayer, helpDict)
    return
 
##Íæ¼ÒÍ˳ö¸±±¾.
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ·µ»ØÖµÎÞÒâÒå
# @remarks Íæ¼ÒÖ÷¶¯À뿪¸±±¾.
def DoExitFB(curPlayer, tick):
    # Íæ¼ÒÍ˳öĬÈϹرո±±¾
    #GameWorldProcess.CloseFB(tick)
    return
 
 
##¸±±¾×ÜÂß¼­¼ÆÊ±Æ÷
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks ¸±±¾×ÜÂß¼­¼ÆÊ±Æ÷
def OnProcess(tick):
    gameFB = GameWorld.GetGameFB()
    fbStep = gameFB.GetFBStep()
    # ¸±±¾×¼±¸
    if fbStep == FB_Step_Prepare:
        __DoLogic_FB_Prepare(tick)    
    # ¸±±¾½øÐÐÖÐ
    elif fbStep == FB_Step_Fighting:
        __DoLogic_FB_Fighting(tick)
#    # ¸±±¾Ê°È¡ÖÐ
#    elif fbStep == FB_Step_PickItem:
#        __DoLogic_FB_PickItem(tick)
    # ¸±±¾½áÊø
    elif fbStep == FB_Step_Over:
        __DoLogic_FB_Over(tick)
    
    return
 
 
##Õ½¶·×¼±¸Ê±¼ä
# @param tick  Ê±ÖÓ
# @return ÎÞÒâÒå
def __DoLogic_FB_Prepare(tick):
    gameFB = GameWorld.GetGameFB()
    mapID = GameWorld.GetMap().GetMapID()
    lineID = FBCommon.GetFBPropertyMark()
    trialCfg = __GetFBTimeCfg(lineID)
    if tick - gameFB.GetFBStepTick() < trialCfg[Def_PrepareTime] * 1000:
        return
    FBCommon.Sync_Player_TimeTick(IPY_GameWorld.tttTowerTake, trialCfg[Def_FightTime] * 1000)
    bossID = FBCommon.GetFBLineRefreshNPC(mapID, lineID)[0]
    NPCCustomRefresh.SetNPCRefresh(trialCfg[Def_RefreshBossMark], [bossID])
    #תÈëÕ½¶·
    FBCommon.SetFBStep(FB_Step_Fighting, tick)
    return
 
 
##Õ½¶·Ê±¼ä
# @param tick  Ê±ÖÓ
# @return ÎÞÒâÒå
def __DoLogic_FB_Fighting(tick):
    gameFB = GameWorld.GetGameFB()
    #ÅжÏʱ¼ä½áÊø
    if tick - gameFB.GetFBStepTick() < __GetFBTimeCfg()[Def_FightTime] * 1000:
        return
    
    #ÓÎÏ·½áÊø
    FBCommon.SetFBStep(FB_Step_Over, tick)
    return
 
 
        
##¸±±¾¹Ø±ÕÖÐ
# @param tick:ʱ¼ä´Á
# @return ÎÞÒâÒå
# @remarks ¸±±¾¹Ø±ÕÖÐ
def __DoLogic_FB_Over(tick):
    # ¼ä¸ôδµ½
    if tick - GameWorld.GetGameFB().GetFBStepTick() < __GetFBTimeCfg()[Def_LeaveTime] * 1000:
        return
    
    #¸±±¾¹Ø±Õ
    GameWorldProcess.CloseFB(tick)
    FBCommon.SetFBStep(FB_Step_Close, tick)
    return
 
 
## É±¹Ö
#  @param curPlayer
#  @param curNPC ±»É±µÄ¹Ö
#  @param tick
#  @return None
def DoFB_Player_KillNPC(curPlayer, curNPC, tick):
    mapID = GameWorld.GetMap().GetMapID()
    lineID = FBCommon.GetFBPropertyMark()
    bossID, boxID = FBCommon.GetFBLineRefreshNPC(mapID, lineID)
    if bossID != curNPC.GetNPCID():
        return
    #Ë¢±¦Ïä½øÈë²É¼¯½×¶Î
    GameWorld.GetGameFB().SetGameFBDict(FBPlayerDict_CurStep, 1)
    DoFBHelp(curPlayer, tick)
    #FBCommon.SetFBStep(FB_Step_Collect, tick)
    NPCCustomRefresh.SetNPCRefresh(__GetFBTimeCfg()[Def_RefreshBossMark], [boxID])
    return
 
## ¼ì²éÊÇ·ñ¿É¹¥»÷£¬ Ö÷Åж¨²»¿É¹¥»÷µÄÇé¿ö£¬ÆäËûÂß¼­ÓÉÍâ²ã¾ö¶¨
#  @param attacker ¹¥»÷·½
#  @param defender ·ÀÊØ·½
#  @return bool
def CheckCanAttackTagObjInFB(attacker, defender):
    gameFB = GameWorld.GetGameFB()
    if gameFB.GetFBStep() != FB_Step_Fighting:
        return False
    return True
 
 
##ÊÇ·ñ¿ÉÒԲɼ¯
# @param curPlayer Íæ¼ÒʵÀý
# @param curNPC NPCʵÀý
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks
def OnCanCollect(curPlayer, curNPC, tick):
    return True
 
 
##¸±±¾ÖÐ,²É¼¯ÎïÐèÒªLoadingʱ¼ä.
# @param curPlayer Íæ¼ÒʵÀý
# @param curNPC NPCʵÀý
# @return ·µ»ØÖµ, Loadingʱ¼ä
# @remarks ¸±±¾ÖÐ,²É¼¯ÎïÐèÒªLoadingʱ¼ä
def GetFBPrepareTime(curPlayer, curNPC):
    return __GetFBTimeCfg()[Def_CollectTime] * 1000
 
 
##Íæ¼ÒÊÕ¼¯³É¹¦(Ëþ, Æì)
# @param curPlayer Íæ¼ÒʵÀý
# @param tick Ê±¼ä´Á
# @return ÎÞÒâÒå
# @remarks
def OnCollectOK(curPlayer, npcID, tick):
    playerID = curPlayer.GetID()
    tagObj = curPlayer.GetActionObj()
    if not tagObj:
        return
    if tagObj.GetGameObjType() != IPY_GameWorld.gotNPC:
        return
    
    curNPC = GameWorld.GetNPCManager().GetNPCByIndex(tagObj.GetIndex())
    if not curNPC:
        return
    dropPosX, dropPosY = curNPC.GetPosX(), curNPC.GetPosY()
    
    ChNPC.OnCollectEnd(curPlayer, curNPC)
    GameWorld.DebugLog('    ²É¼¯³É¹¦£¡', playerID)
    
    #DoFBHelp(curPlayer, 0)
    #µôÂ䏸½±Àø
    DoFairyTreasureOver(curPlayer, tick, dropPosX, dropPosY)
    
    
    return
 
def DoFairyTreasureOver(curPlayer, tick, dropPosX, dropPosY):
    #[[(4000,[141,1,1])],[(4000,[141,1,1])]]
    FBCommon.SetFBStep(FB_Step_Over, tick)
    
    lineID = FBCommon.GetFBPropertyMark()
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'MapID':ChConfig.Def_FBMapID_FairyTreasure, 'LineID':lineID})
    fdeventID = ipyData.GetID()
    giveItemList = PlayerFairyDomain.GetFairyAppointAward(curPlayer, fdeventID)
    if not giveItemList:
        awardCfg = FBCommon.GetFBLineReward(ChConfig.Def_FBMapID_FairyTreasure, lineID)
        curAlchemyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyLV)
        giveItemList = []
        dropItemList = []
        for awardRateList in awardCfg:
            newItemInfoList = []
            for itemInfo in awardRateList:
                itemID = itemInfo[1][0]
                itemData = GameWorld.GetGameData().GetItemByTypeID(itemID)
                if not itemData:
                    return
                if curAlchemyLV < itemData.GetLV() - 1:
                    #µ¤Â¯µÈ¼¶²»×ã
                    continue
    
                newItemInfoList.append(itemInfo)
            if not newItemInfoList:
                continue
            randomitem = GameWorld.GetResultByWeightList(newItemInfoList)
            giveItemList.append(randomitem)
            for _ in randomitem[1]:
                dropItemList.append([randomitem[0],1,randomitem[2]])
        
    if giveItemList:
        NPCCommon.DoVirtualItemDrop(curPlayer, dropItemList, dropPosX, dropPosY)
        ItemControler.GivePlayerItemOrMail(curPlayer, giveItemList)
        leaveTick = __GetFBTimeCfg(lineID)[Def_LeaveTime] * 1000
        curPlayer.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, leaveTick, True)
        overDict = {FBCommon.Over_itemInfo:FBCommon.GetJsonItemList(giveItemList)}
        FBCommon.NotifyFBOver(curPlayer, ChConfig.Def_FBMapID_FairyTreasure, lineID, 1, overDict)
    
    PlayerFairyDomain.SetFairyDomainEventState(curPlayer, fdeventID, PlayerFairyDomain.FDEventState_Visited)
    return
 
 
## ÊÇ·ñ¸±±¾¸´»î
#  @param None
#  @return ÊÇ·ñ¸±±¾¸´»î
def OnPlayerReborn():
    return True
 
## ¸±±¾ÐÐΪ
#  @param curPlayer Íæ¼Ò
#  @param actionType ÐÐΪÀàÐÍ
#  @param actionInfo ÐÐΪÐÅÏ¢
#  @param tick µ±Ç°Ê±¼ä
#  @return None
def DoFBAction(curPlayer, actionType, actionInfo, tick):
    
    return