| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package GameWorldLogic.FBProcess.GameLogic_Love  | 
| #  | 
| # @todo:ÇéÔµ¸±±¾  | 
| # @author hxp  | 
| # @date 2021-11-24  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ÇéÔµ¸±±¾  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2021-11-24 16:30"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import FBCommon  | 
| import NPCCommon  | 
| import ReadChConfig  | 
| import IPY_GameWorld  | 
| import PlayerControl  | 
| import GameWorldProcess  | 
| import ItemControler  | 
| import IpyGameDataPY  | 
| import PyGameData  | 
| import GameWorld  | 
| import ChConfig  | 
|   | 
| (  | 
| Def_Time_MapPrepare, # ×¼±¸Ê±¼ä, Ãë  | 
| Def_Time_Fight, # Õ½¶·Ê±¼ä, Ãë  | 
| Def_Time_PickupItem, # Ê°È¡ÎïÆ·Ê±¼ä, Ãë  | 
| Def_Time_Leave, # ½áÊøÊ±¼ä, Ãë  | 
| ) = range(4)  | 
|   | 
| #µ±Ç°¸±±¾µØÍ¼µÄ״̬  | 
| (  | 
| FB_Step_Open, # µØÍ¼¿ªÆô  | 
| FB_Step_MapPrepare, # µØÍ¼×¼±¸  | 
| FB_Step_Fighting, # Õ½¶·ÖÐ  | 
| FB_Step_PickupItem, # Ê°È¡ÎïÆ·  | 
| FB_Step_LeaveTime, # ×ÔÓÉÍ˳öʱ¼ä  | 
| FB_Step_Over, # ¸±±¾¹Ø±Õ  | 
| ) = range(6)  | 
|   | 
| FB_CostTime = 'FB_CostTime'   # ¹ý¹ØºÄʱ  | 
| FBPlayerDict_EnterState = "FBPlayerDict_EnterState" # ÒѽøÈëµÄÍæ¼Ò£¬²ÎÊý  | 
|   | 
| TDRefreshNPCFileNum = ChConfig.Def_FBMapID_Love  | 
|   | 
| Def_Devil_TimeType = IPY_GameWorld.tttLeaveFamilyWar  | 
|   | 
| def OnOpenFB(tick):  | 
|     ##¿ªÆô¸±±¾  | 
|     return  | 
|   | 
| def OnCloseFB(tick):  | 
|     ##¹Ø±Õ¸±±¾  | 
|     return  | 
|   | 
| def OnEnterFBEvent(curPlayer, mapID, lineID, tick):  | 
|     onlyDoubleTeam = IpyGameDataPY.GetFuncCfg("LoveFB", 1)  | 
|     if onlyDoubleTeam:  | 
|         if not curPlayer.GetTeamID():  | 
|             PlayerControl.NotifyCode(curPlayer, "OnlyTwoMemTeamCanEnter", [mapID])  | 
|             return False  | 
|     return True  | 
|   | 
| def GetPlayerResetWorldPosFBMsg(curPlayer, lineId):  | 
|     ## »ñÈ¡È볡Я´øÐÅÏ¢  | 
|     return ""  | 
|   | 
| def OnChangeMapAsk(ask, tick):  | 
|     ##²éѯÊÇ·ñ¿ÉÒÔ½øÈëµØÍ¼  | 
|     return IPY_GameWorld.cmeAccept  | 
|   | 
| def OnGetFBEnterPos(curPlayer, mapID, lineId, ipyEnterPosInfo, tick):  | 
|     ##¸±±¾Íæ¼Ò½øÈëµã  | 
|     return ipyEnterPosInfo  | 
|   | 
| def DoEnterFB(curPlayer, tick):  | 
|           | 
|     gameFB = GameWorld.GetGameFB()  | 
|     fbStep = gameFB.GetFBStep()  | 
|     playerID = curPlayer.GetPlayerID()  | 
|       | 
|     GameWorld.Log("DoEnterFB...", playerID)  | 
|     hadDelTicket = FBCommon.GetHadDelTicket(curPlayer)  | 
|     if not hadDelTicket:  | 
|         mapID = GameWorld.GetGameWorld().GetMapID()  | 
|         delResult = FBCommon.DelFBEnterTicket(curPlayer, mapID)  | 
|         isOK = delResult[0]  | 
|         #hasBind = delResult[1]  | 
|         if not isOK:  | 
|             PlayerControl.PlayerLeaveFB(curPlayer)  | 
|             return  | 
|         FBCommon.SetHadDelTicket(curPlayer)  | 
|         FBCommon.AddEnterFBCount(curPlayer, ChConfig.Def_FBMapID_Love)  | 
|         PyGameData.g_fbPickUpItemDict.pop(playerID, 0)  | 
|         gameFB.SetPlayerGameFBDict(playerID, FBPlayerDict_EnterState, 1)  | 
|           | 
|     if fbStep == FB_Step_Open:  | 
|         FBCommon.SetFBStep(FB_Step_MapPrepare, tick)  | 
|           | 
|     if fbStep <= FB_Step_MapPrepare:  | 
|         mapID = GameWorld.GetMap().GetMapID()  | 
|         notify_tick = FBCommon.GetFBLineStepTime(mapID)[Def_Time_MapPrepare] * 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_Fighting:  | 
|         mapID = GameWorld.GetMap().GetMapID()  | 
|         notify_tick = FBCommon.GetFBLineStepTime(mapID)[Def_Time_Fight] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick())  | 
|         curPlayer.Sync_TimeTick(IPY_GameWorld.tttTowerTake, 0, max(notify_tick, 0), True)  | 
|           | 
|     DoFBHelp(curPlayer, tick)  | 
|     return  | 
|   | 
| def DoExitFB(curPlayer, tick):  | 
|     ##Íæ¼ÒÍ˳ö¸±±¾  | 
|     return  | 
|   | 
| def DoPlayerLeaveFB(curPlayer, tick):  | 
|     ##Íæ¼ÒÖ÷¶¯À뿪¸±±¾.  | 
|     return  | 
|   | 
| def DoFBHelp(curPlayer, tick):  | 
|     wheelNum = None  | 
|     movePointDict = ReadChConfig.GetEvalChConfig('TD_%s_Move' % TDRefreshNPCFileNum)  | 
|     rMarkList = movePointDict.keys()  | 
|     gameFB = GameWorld.GetGameFB()  | 
|     for rMark in rMarkList:  | 
|         if wheelNum == None:  | 
|             wheelNum = gameFB.GetGameFBDictByKey(ChConfig.Map_TDNPC_RefreshBigWheelNum % rMark) + 1  | 
|               | 
|     #¸±±¾°ïÖú(֪ͨ¿Í»§¶ËÏÔʾ)  | 
|     wheelTotal = len(ReadChConfig.GetEvalChConfig('TD_%s_Cfg' % TDRefreshNPCFileNum))  | 
|     fbHelpDict = {FBCommon.Help_wheel:wheelNum, FBCommon.Help_wheelTotal:wheelTotal}  | 
|     GameWorld.DebugLog("DoFBHelp: %s" % fbHelpDict, curPlayer.GetPlayerID())  | 
|     FBCommon.Notify_FBHelp(curPlayer, fbHelpDict)  | 
|     return  | 
|   | 
| ##¸±±¾¶¨Ê±Æ÷  | 
| # @param tick Ê±¼ä´Á  | 
| # @return ·µ»ØÖµÎÞÒâÒå  | 
| # @remarks ¸±±¾¶¨Ê±Æ÷  | 
| def OnProcess(tick):  | 
|       | 
|     fbStep = GameWorld.GetGameFB().GetFBStep()  | 
|       | 
|     if fbStep == FB_Step_MapPrepare:  | 
|         __DoLogic_MapPrepare(tick)  | 
|     elif fbStep == FB_Step_Fighting:  | 
|         __DoLogic_MapFighting(tick)  | 
|     elif fbStep == FB_Step_PickupItem:  | 
|         __DoLogic_PickupItem(tick)  | 
|     elif fbStep == FB_Step_LeaveTime:  | 
|         __DoLogic_MapLeave(tick)  | 
|           | 
|     return  | 
|   | 
| def __DoLogic_MapPrepare(tick):  | 
|     mapID = GameWorld.GetMap().GetMapID()  | 
|     timeInfo = FBCommon.GetFBLineStepTime(mapID)  | 
|     if tick - GameWorld.GetGameFB().GetFBStepTick() < timeInfo[Def_Time_MapPrepare] * 1000:  | 
|         return  | 
|       | 
|     FBCommon.SetFBStep(FB_Step_Fighting, tick)  | 
|       | 
|     movePointDict = ReadChConfig.GetEvalChConfig('TD_%s_Move' % TDRefreshNPCFileNum)  | 
|     rMarkList = movePointDict.keys()  | 
|     isNotify = True  | 
|     for rMark in rMarkList:  | 
|         FBCommon.OpenTDNPCRefresh(rMark, TDRefreshNPCFileNum, 0, tick, isNotify)  | 
|         if isNotify:  | 
|             isNotify = False  | 
|               | 
|     FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0) # Ç¿ÖÆÍ¬²½Ò»´Î  | 
|     # Í¨Öª¿ªÊ¼  | 
|     FBCommon.Sync_Player_TimeTick(IPY_GameWorld.tttTowerTake, timeInfo[Def_Time_Fight] * 1000)  | 
|     return  | 
|   | 
| def __DoLogic_MapFighting(tick):  | 
|       | 
|     mapID = GameWorld.GetMap().GetMapID()  | 
|     timeInfo = FBCommon.GetFBLineStepTime(mapID)  | 
|     # ¼ä¸ôδµ½  | 
|     if tick - GameWorld.GetGameFB().GetFBStepTick() < timeInfo[Def_Time_Fight] * 1000:  | 
|         #FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 5000)  | 
|         return  | 
|       | 
|     __DoOver(tick)  | 
|     return  | 
|   | 
| def __DoLogic_PickupItem(tick):  | 
|     mapItemCount = GameWorld.GetMapItemManager().GetMapItemCount()  | 
|     mapID = GameWorld.GetMap().GetMapID()  | 
|     timeInfo = FBCommon.GetFBLineStepTime(mapID)  | 
|     if mapItemCount and tick - GameWorld.GetGameFB().GetFBStepTick() < timeInfo[Def_Time_PickupItem] * 1000:  | 
|         return  | 
|     FBCommon.SetFBStep(FB_Step_LeaveTime, tick)  | 
|       | 
|     copyMapPlayerManager = GameWorld.GetMapCopyPlayerManager()  | 
|     for i in xrange(copyMapPlayerManager.GetPlayerCount()):  | 
|         curPlayer = copyMapPlayerManager.GetPlayerByIndex(i)  | 
|         if curPlayer == None or curPlayer.IsEmpty():  | 
|             continue  | 
|         DoOverToLeave(curPlayer, tick)  | 
|           | 
|     return  | 
|   | 
| def __DoLogic_MapLeave(tick):  | 
|     mapID = GameWorld.GetMap().GetMapID()  | 
|     timeInfo = FBCommon.GetFBLineStepTime(mapID)  | 
|     if tick - GameWorld.GetGameFB().GetFBStepTick() < timeInfo[Def_Time_Leave] * 1000:  | 
|         return  | 
|     FBCommon.SetFBStep(FB_Step_Over, tick)  | 
|       | 
|     # Ê±¼äµ½£¬Ìß³ö»¹ÔÚ¸±±¾µÄÍæ¼ÒµÈ...  | 
|     FBCommon.DoLogic_FBKickAllPlayer()  | 
|     #GameWorld.GetGameWorld().SetPropertyID(0)  | 
|     GameWorldProcess.CloseFB(tick)  | 
|     return  | 
|   | 
| def DoFBRebornNPC(curNPC, tick):  | 
|     ##¸±±¾ÓÐNPCÕÙ³ö  | 
|     fromRefreshValue = curNPC.GetDictByKey(ChConfig.Def_NPC_Dict_FromRefreshValue)  | 
|       | 
|     if fromRefreshValue == TDRefreshNPCFileNum:  | 
|         curNPC.SetIsNeedProcess(True)  | 
|         FBCommon.UpdTDNPCCnt(curNPC, 1)  | 
|           | 
|     return  | 
|   | 
| def OnTDCurWheelOver(refreshMark, tick):  | 
|     movePointDict = ReadChConfig.GetEvalChConfig('TD_%s_Move' % TDRefreshNPCFileNum)  | 
|     rMarkList = movePointDict.keys()  | 
|     isWheelRefreshOver = FBCommon.IsTDWheelRefreshOver(rMarkList) # ±¾´ó²¨ËùÓеãË¢¹ÖÍê±Ï  | 
|     if isWheelRefreshOver:  | 
|         GameWorld.DebugLog("±¾´ó²¨ËùÓеãË¢Íê, Ç¿ÖÆÍ¬²½Ò»´Î¹ÖÎïÊý")  | 
|         FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0) # Ç¿ÖÆÍ¬²½Ò»´Î  | 
|           | 
|     return  | 
|   | 
| def OnTDNPCReachTheGoal(curNPC, tick):  | 
|     #GameWorld.DebugLog("µ½´ïÖÕµã...")  | 
|     curNPC.SetVisible(False)  | 
|     NPCCommon.SetDeadEx(curNPC)  | 
|     return  | 
|   | 
| def GetFBEveryoneDropInfo(curNPC):  | 
|     ## »ñÈ¡¸±±¾Ã¿È˵ôÂäÉèÖÃÐÅÏ¢  | 
|     # @return: None or [ownerPlayerList, isOnlySelfSee]  | 
|           | 
|     isOnlySelfSee = True  | 
|     ownerPlayerList = []  | 
|     playerManager = GameWorld.GetMapCopyPlayerManager()  | 
|     for index in xrange(playerManager.GetPlayerCount()):  | 
|         curPlayer = playerManager.GetPlayerByIndex(index)  | 
|         if not curPlayer:  | 
|             continue  | 
|         ownerPlayerList.append(curPlayer)  | 
|           | 
|     return ownerPlayerList, isOnlySelfSee  | 
|   | 
| #def DoFB_Npc_KillNPC(attacker, curNPC, tick):  | 
| #    __DoOnNPCKilled(attacker, curNPC, tick)  | 
| #    return  | 
| #  | 
| #def DoFB_Player_KillNPC(curPlayer, curNPC, tick):  | 
| #    __DoOnNPCKilled(curPlayer, curNPC, tick)  | 
| #    return  | 
|   | 
| def DoFB_NPCDead(curNPC):  | 
|       | 
|     fbStep = GameWorld.GetGameFB().GetFBStep()  | 
|     if fbStep != FB_Step_Fighting:  | 
|         return  | 
|       | 
|     fromRefreshValue = curNPC.GetDictByKey(ChConfig.Def_NPC_Dict_FromRefreshValue)  | 
|     # ÈëÇÖ¹Ö  | 
|     if fromRefreshValue != TDRefreshNPCFileNum:  | 
|         return  | 
|       | 
|     FBCommon.UpdTDNPCCnt(curNPC, -1) # ¹ÖÎïÊý-1  | 
|       | 
|     tick = GameWorld.GetGameWorld().GetTick()  | 
|     movePointDict = ReadChConfig.GetEvalChConfig('TD_%s_Move' % TDRefreshNPCFileNum)  | 
|     rMarkList = movePointDict.keys()  | 
|     isAllRefresh = FBCommon.IsTDNPCRefreshOver(rMarkList) # ËùÓйÖÊÇ·ñÈ«²¿Ë¢Íê  | 
|     isAllKilled = FBCommon.IsTDNPCCurWheelAllKilled(rMarkList) # ±¾²¨¹ÖÊÇ·ñÈ«²¿±»»÷ɱ  | 
|       | 
|     if isAllRefresh and isAllKilled:  | 
|         GameWorld.DebugLog("È«²¿¹ÖË¢ÐÂÍê±ÏÇÒÒѱ»É±Íê, ´¦Àí½áÊøÂß¼")  | 
|         __DoOver(tick)  | 
|           | 
|     elif isAllKilled:  | 
|         GameWorld.DebugLog("±¾²¨¹ÖÈ«²¿É±Í꣬½øÈëÏÂÒ»²¨£¡")  | 
|         for index, rMark in enumerate(rMarkList):  | 
|             FBCommon.SetEnterTDNextWheel(rMark, tick, index == 0)  | 
|             #if index == 0:  | 
|             #    FBCommon.Sync_TDNextWheelTick(None, rMark, Def_Devil_TimeType, tick)  | 
|               | 
|         FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0) # ²¨ÊýÇл»Ç¿ÖÆÍ¬²½Ò»´Î  | 
|           | 
|     return  | 
|   | 
| def __DoOver(tick):  | 
|     # ¸±±¾½áÊøÂß¼  | 
|     GameWorld.DebugLog("´¦Àí¸±±¾½áÊøÂß¼")  | 
|     costTime = tick - GameWorld.GetGameFB().GetFBStepTick()  | 
|     gameFB = GameWorld.GetGameFB()  | 
|     gameFB.SetGameFBDict(FB_CostTime, costTime)  | 
|       | 
|     FBCommon.SetFBStep(FB_Step_PickupItem, tick)  | 
|       | 
|     # Çå¹Ö  | 
|     FBCommon.ClearFBNPC()  | 
|     FBCommon.NotifyCopyMapPlayerFBHelp(tick, DoFBHelp, 0) # ¸±±¾½áÊøÇ¿ÖÆÍ¬²½Ò»´Î  | 
|       | 
|     movePointDict = ReadChConfig.GetEvalChConfig('TD_%s_Move' % TDRefreshNPCFileNum)  | 
|     rMarkList = movePointDict.keys()  | 
|     # ¹Ø±ÕËùÓÐË¢¹Öµã  | 
|     for rMark in rMarkList:  | 
|         FBCommon.CloseTDNPCRefresh(rMark, True)  | 
|     return  | 
|   | 
| def OnPickUpItem(curPlayer, curItem, tick):  | 
|     FBCommon.OnPickUpItem(curPlayer, curItem, tick, None)  | 
|     return  | 
|   | 
| def DoOverToLeave(curPlayer, tick):  | 
|     isPass = 1  | 
|     playerID = curPlayer.GetPlayerID()  | 
|     mapID = GameWorld.GetMap().GetMapID()  | 
|     gameFB = GameWorld.GetGameFB()  | 
|     leaveTick = FBCommon.GetFBLineStepTime(mapID)[Def_Time_Leave] * 1000  | 
|     curPlayer.Sync_TimeTick(IPY_GameWorld.tttLeaveMap, 0, leaveTick, True)  | 
|       | 
|     costTime = gameFB.GetGameFBDictByKey(FB_CostTime)  | 
|       | 
|     pickupItemList = PyGameData.g_fbPickUpItemDict.get(playerID, [])  | 
|     coupleID = PlayerControl.GetCoupleID(curPlayer)  | 
|     coupleEnterState = gameFB.GetPlayerGameFBDictByKey(coupleID, FBPlayerDict_EnterState) if coupleID else 0  | 
|     if coupleEnterState:  | 
|         coupleAwardListEx = IpyGameDataPY.GetFuncEvalCfg("LoveFB", 2)  | 
|         ItemControler.GivePlayerItemOrMail(curPlayer, coupleAwardListEx)  | 
|         pickupItemList.extend(coupleAwardListEx)  | 
|           | 
|     overDict = {FBCommon.Over_dataMapID:mapID, FBCommon.Over_isPass:isPass, FBCommon.Over_costTime:costTime,   | 
|                 FBCommon.Over_itemInfo:FBCommon.GetJsonItemList(pickupItemList)}  | 
|     FBCommon.Notify_FB_Over(curPlayer, overDict)  | 
|     GameWorld.Log("½áËã: coupleID=%s,coupleEnterState=%s,overDict=%s" % (coupleID, coupleEnterState, overDict), playerID)  | 
|     return  | 
|   | 
|   |