#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package GameWorldLogic.FBProcess.GameLogic_ClearDevil # # @todo:³ýħÎÀµÀ # @author xdh # @date 2017-09-12 # @version 1.0 # # ÏêϸÃèÊö: ³ýħÎÀµÀ # #------------------------------------------------------------------------------- #"""Version = 2017-09-12 21:00""" #------------------------------------------------------------------------------- import FBCommon import GameWorld import IpyGameDataPY import IPY_GameWorld import GameWorldProcess import EventShell import NPCCustomRefresh import ChConfig import ShareDefine import EventReport import PlayerControl import QuestCommon #---¸±±¾ÅäÖöÔÓ¦keyÖµ--- ( Def_IsPointType, #ÊÇ·ñ»ý·ÖÀั±¾ Def_PrepareTime, # ¸±±¾×¼±¸Ê±¼ä(Ãë) Def_FightTime, # ½øÐÐʱ¼ä(Ãë) Def_LeaveTime, # Í˳öʱ¼ä(Ãë) ) = range(4) ( DL_RefreshMark, # Ë¢¹Ö±êʶµã DL_NPCID, # NPCID DL_SingleNPCCnt, # µ¥´ÎË¢NPC¸öÊý DL_maxCnt, #µ±Ç°µã×î´ó¹ÖÎïÊý DL_TotalNPCCnt, # ÀÛ¼ÆË¢NPC×ܸöÊý DL_NeedKillCnt, # ÐèÒª»÷ɱÊýÁ¿ DL_RefreshCD, # ˢмä¸ô ) = range(7) #µ±Ç°¸±±¾µØÍ¼µÄ״̬ ( FB_Step_Open, # ¸±±¾¿ªÆô FB_Step_Prepare, # ¸±±¾µÈ´ý FB_Step_Fighting, # ¸±±¾½øÐÐÖÐ FB_Step_Over, # ¸±±¾½áÊø FB_Step_Close, # ¸±±¾¹Ø±Õ ) = range(5) FBPlayerDict_MissionID = 'FBPlayerDict_MissionID' #¸±±¾ÈÎÎñID FBPlayerDict_MissionType = 'FBPlayerDict_MissionType' #¸±±¾ÈÎÎñÀàÐÍ FBPlayerDict_CostTime = 'FBPlayerDict_CostTime' #¸±±¾ºÄʱ FBPlayerDict_TotalPoint = 'FBPlayerDict_TotalPoint' # »ñµÃµÄ×Ü»ý·Ö FBPlayerDict_NPCRemainCnt = 'FBPlayerDict_NPCRemainCnt_%s' # NPCÊ£ÓàÊýÁ¿ FBPlayerDict_TotalExp = 'FBPlayerDict_TotalExp' # »ñµÃµÄ×ܾ­Ñé FBPlayerDict_TotalExpPoint = 'FBPlayerDict_TotalExpPoint' # »ñµÃµÄ×ܾ­Ñéµã ##---»ñµÃ¸±±¾ÅäÖÃ--- # @param None # @return ÅäÖÃÐÅÏ¢ def GetClearDevilTimeCfg(lineID=None): if lineID == None: lineID = FBCommon.GetFBPropertyMark() mapID = GameWorld.GetMap().GetMapID() return FBCommon.GetFBLineStepTime(mapID, lineID) def GetClearDevilNPCCfg(lineID): mapID = GameWorld.GetMap().GetMapID() return FBCommon.GetFBLineRefreshNPC(mapID, lineID) def GetPointByNPCID(npcid): '''ͨ¹ýNPCID»ñÈ¡¶ÔÓ¦µÄ»ý·Ö''' npcPointDict = IpyGameDataPY.GetFuncEvalCfg('ClearDevilPoint', 2) return npcPointDict.get(npcid, 0) def GetIsPointFBType(lineID): #ÊÇ·ñ»ý·ÖÀั±¾ FBLineStepTimeCfg = GetClearDevilTimeCfg(lineID) if not FBLineStepTimeCfg: return return FBLineStepTimeCfg[Def_IsPointType] ## ÊÇ·ñÄܹ»Í¨¹ý»î¶¯²éѯ½øÈë # @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 curPlayer # @param tick # @return None def DoEnterFB(curPlayer, tick): 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_ClearDevil, 0, ChConfig.CME_Log_Start) fbMissionID = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ReqFBMissionID) if fbMissionID: fbMissionType = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_ReqFBMissionType) gameFB.SetGameFBDict(FBPlayerDict_MissionID, fbMissionID) gameFB.SetGameFBDict(FBPlayerDict_MissionType, fbMissionType) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ReqFBMissionID, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_ReqFBMissionType, 0) fbStep = gameFB.GetFBStep() if fbStep < FB_Step_Prepare: FBCommon.SetFBStep(FB_Step_Prepare, tick) if fbStep <= FB_Step_Prepare: notify_tick = GetClearDevilTimeCfg(lineID)[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_Fighting: notify_tick = GetClearDevilTimeCfg(lineID)[Def_FightTime] * 1000 - (tick - GameWorld.GetGameFB().GetFBStepTick()) curPlayer.Sync_TimeTick(IPY_GameWorld.tttTowerTake, 0, max(notify_tick, 0), True) DoFBHelp(curPlayer, tick, not hadDelTicket) 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 = GetClearDevilTimeCfg(lineID)[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) DoFBHelp(curPlayer, tick, True) return ##Íæ¼ÒÍ˳ö¸±±¾ # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ÎÞÒâÒå def DoExitFB(curPlayer, tick): return ##Íæ¼ÒÖ÷¶¯À뿪¸±±¾. # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÎÞÒâÒå def DoPlayerLeaveFB(curPlayer, tick): return ## »ñµÃ¸±±¾°ïÖúÐÅÏ¢ # @param curPlayer µ±Ç°Íæ¼Ò£¨±»Í¨Öª¶ÔÏó£© # @param tick µ±Ç°Ê±¼ä # @return None def DoFBHelp(curPlayer, tick, isEnter=False): gameFB = GameWorld.GetGameFB() # »ñµÃ¸±±¾ÐÅÏ¢ lineID = FBCommon.GetFBPropertyMark() if GetIsPointFBType(lineID): totalPoint = gameFB.GetGameFBDictByKey(FBPlayerDict_TotalPoint) helpDict = {FBCommon.Help_score:totalPoint} else: npcCfg = GetClearDevilNPCCfg(lineID) if not npcCfg: GameWorld.Log("ûÓиÃÏß·ˢ¹ÖÅäÖà lineID=%s" % lineID) return npcDict = {} for info in npcCfg: npcID = info[DL_NPCID] remainCnt = gameFB.GetGameFBDictByKey(FBPlayerDict_NPCRemainCnt % npcID) if isEnter: killCnt = 0 else: killCnt= info[DL_NeedKillCnt] - remainCnt npcDict[npcID] = killCnt helpDict = {FBCommon.Help_npc:FBCommon.GetJsonNPCKillList(npcDict)} #¸±±¾°ïÖú helpDict[FBCommon.Help_lineID] = FBCommon.GetFBPropertyMark() fbMissionID = gameFB.GetGameFBDictByKey(FBPlayerDict_MissionID) helpDict["missionID"] = fbMissionID 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_Prepare: __DoLogic_FB_Prepare(tick) # ¸±±¾½øÐÐÖÐ elif fbStep == FB_Step_Fighting: __DoLogic_FB_Fighting(tick) # ¸±±¾½áÊø elif fbStep == FB_Step_Over: __DoLogic_FB_Over(tick) return ## ¸±±¾×¼±¸Âß¼­ # @param tick:ʱ¼ä´Á # @return ÎÞÒâÒå def __DoLogic_FB_Prepare(tick): #gameFB = GameWorld.GetGameFB() fbCfg = GetClearDevilTimeCfg() # ¼ä¸ôδµ½ if tick - GameWorld.GetGameFB().GetFBStepTick() < fbCfg[Def_PrepareTime] * 1000: return # ÉèÖÿªÊ¼Ë¢¹Ö lineID = FBCommon.GetFBPropertyMark() npcCfg = GetClearDevilNPCCfg(lineID) if not npcCfg: GameWorld.Log("ûÓиÃÏß·ˢ¹ÖÅäÖà lineID=%s" % lineID) return gameFB = GameWorld.GetGameFB() for npcInfo in npcCfg: npcID = npcInfo[DL_NPCID] gameFB.SetGameFBDict(FBPlayerDict_NPCRemainCnt % npcID, npcInfo[DL_NeedKillCnt]) refreshCD = npcInfo[DL_RefreshCD] NPCCustomRefresh.SetNPCRefresh(npcInfo[DL_RefreshMark], [(npcID, npcInfo[DL_SingleNPCCnt])], npcInfo[DL_maxCnt], npcInfo[DL_TotalNPCCnt], refreshTick=refreshCD) NPCCustomRefresh.ProcessAllNPCRefresh(tick) # Á¢¼´³ö·¢Ò»´Î±êʶµãˢРplayerManager = GameWorld.GetMapCopyPlayerManager() if playerManager.GetPlayerCount() > 0: curPlayer = playerManager.GetPlayerByIndex(0) DoFBHelp(curPlayer, tick) FBCommon.SetFBStep(FB_Step_Fighting, tick) FBCommon.Sync_Player_TimeTick(IPY_GameWorld.tttTowerTake, fbCfg[Def_FightTime] * 1000) return ## ¸±±¾½øÐÐÖÐ # @param tick:ʱ¼ä´Á # @return ÎÞÒâÒå def __DoLogic_FB_Fighting(tick): fbCfg = GetClearDevilTimeCfg() # ¼ä¸ôδµ½ if tick - GameWorld.GetGameFB().GetFBStepTick() < fbCfg[Def_FightTime] * 1000: return __DoClearDevilOver(False) return ##¸±±¾¹Ø±ÕÖÐ # @param tick:ʱ¼ä´Á # @return ÎÞÒâÒå # @remarks ¸±±¾¹Ø±ÕÖÐ def __DoLogic_FB_Over(tick): #gameFB = GameWorld.GetGameFB() fbCfg = GetClearDevilTimeCfg() # ¼ä¸ôδµ½ if tick - GameWorld.GetGameFB().GetFBStepTick() < fbCfg[Def_LeaveTime] * 1000: return #¸±±¾¹Ø±Õ GameWorldProcess.CloseFB(tick) FBCommon.SetFBStep(FB_Step_Close, tick) return ## »ñµÃ¾­Ñé # @param curPlayer µ±Ç°Íæ¼Ò # @param addExp »ñµÃµÄ¾­Ñé # @param expViewType ¾­ÑéÀàÐÍ # @return True or False def OnGetExp(curPlayer, addExp, expViewType): if expViewType != ShareDefine.Def_ViewExpType_KillNPC: return playerID = curPlayer.GetID() gameFB = GameWorld.GetGameFB() exp = gameFB.GetPlayerGameFBDictByKey(playerID, FBPlayerDict_TotalExp) expPoint = gameFB.GetPlayerGameFBDictByKey(playerID, FBPlayerDict_TotalExpPoint) totalExp = expPoint * ChConfig.Def_PerPointValue + exp updTotalExp = totalExp + addExp updExp = updTotalExp % ChConfig.Def_PerPointValue updExpPoint = updTotalExp / ChConfig.Def_PerPointValue gameFB.SetPlayerGameFBDict(playerID, FBPlayerDict_TotalExp, updExp) gameFB.SetPlayerGameFBDict(playerID, FBPlayerDict_TotalExpPoint, updExpPoint) GameWorld.DebugLog("OnGetExp() totalExp=%s,addExp=%s,updTotalExp=%s" % (totalExp, addExp, updTotalExp), playerID) return ## Ö´Ðи±±¾É±¹ÖÂß¼­ # @param curPlayer ɱ¹ÖµÄÈË # @param curNPC ±»É±µÄ¹Ö # @param tick µ±Ç°Ê±¼ä # @return None def DoFB_Player_KillNPC(curPlayer, curNPC, tick): gameFB = GameWorld.GetGameFB() fbStep = gameFB.GetFBStep() if fbStep != FB_Step_Fighting: return npcid = curNPC.GetNPCID() lineID = FBCommon.GetFBPropertyMark() isFinish = False #ÊÇ·ñÍê³É if GetIsPointFBType(lineID):#»ý·ÖÀà addPoint = GetPointByNPCID(npcid) if not addPoint: return totalPoint = gameFB.GetGameFBDictByKey(FBPlayerDict_TotalPoint) maxPoint = IpyGameDataPY.GetFuncCfg('ClearDevilPoint') updPoint = min(totalPoint + addPoint, maxPoint) gameFB.SetGameFBDict(FBPlayerDict_TotalPoint, updPoint) if updPoint >= maxPoint: isFinish = True else: remainCnt = gameFB.GetGameFBDictByKey(FBPlayerDict_NPCRemainCnt % npcid) gameFB.SetGameFBDict(FBPlayerDict_NPCRemainCnt % npcid, max(0, remainCnt - 1)) npcCfg = GetClearDevilNPCCfg(lineID) if not npcCfg: GameWorld.Log("ûÓиÃÏß·ˢ¹ÖÅäÖà lineID=%s" % lineID) return isFinish = True for npcInfo in npcCfg: npcID = npcInfo[DL_NPCID] remainCnt = gameFB.GetGameFBDictByKey(FBPlayerDict_NPCRemainCnt % npcID) if remainCnt: isFinish = False break DoFBHelp(curPlayer, tick) if isFinish: __DoClearDevilOver(True) # ÈÎÎñ fbMissionID = gameFB.GetGameFBDictByKey(FBPlayerDict_MissionID) if fbMissionID: EventShell.EventRespons_FBEvent(curPlayer, "cleardevil_pass_%s" % fbMissionID) return ##Íæ¼ÒÍ˳ö¼Ò×å´¦Àí # @param curPlayer Íæ¼ÒʵÀý # @param tick ʱ¼ä´Á # @return ·µ»ØÖµÎÞÒâÒå def OnLeaveFamily(curPlayer, tick): gameFB = GameWorld.GetGameFB() fbMissionType = gameFB.GetGameFBDictByKey(FBPlayerDict_MissionType) if fbMissionType == QuestCommon.Def_Mission_Type_RunFamily: gameFB.SetGameFBDict(FBPlayerDict_MissionType, 0) return ## ÈÎÎñרÓÃ,´¥·¢Ê¼þ£¨¸±±¾ÄÚÍê³ÉijÈÎÎñ£© # @param curPlayer:Íæ¼ÒʵÀý # @param isAchieve:ÊÇ·ñÍê³ÉÈÎÎñ # @return None def DoFB_OnFinishRunAroundTask(curPlayer, curMissionID, addExp=0, moneyDict={}, itemList=[]): gameFB = GameWorld.GetGameFB() #playerID = curPlayer.GetPlayerID() #exp = gameFB.GetPlayerGameFBDictByKey(playerID, FBPlayerDict_TotalExp) #expPoint = gameFB.GetPlayerGameFBDictByKey(playerID, FBPlayerDict_TotalExpPoint) #totalExp = expPoint * ChConfig.Def_PerPointValue + exp exp = addExp % ChConfig.Def_PerPointValue expPoint = addExp / ChConfig.Def_PerPointValue fbMissionID = gameFB.GetGameFBDictByKey(FBPlayerDict_MissionID) GameWorld.DebugLog("ÈÎÎñרÓÃ,´¥·¢Ê¼þ£¨¸±±¾ÄÚÍê³ÉijÈÎÎñ£© curMissionID=%s, fbMissionID=%s, exp=%s,moneyDict=%s,itemList=%s" % (curMissionID, fbMissionID, exp, moneyDict,itemList)) if fbMissionID != curMissionID: return costTime = gameFB.GetGameFBDictByKey(FBPlayerDict_CostTime) awardDict = {} awardDict[FBCommon.Over_isPass] = 1 awardDict[FBCommon.Over_costTime] = costTime awardDict[FBCommon.Over_exp] = exp awardDict[FBCommon.Over_expPoint] = expPoint awardDict[FBCommon.Over_itemInfo] = FBCommon.GetJsonItemList(itemList) awardDict[FBCommon.Over_money] = FBCommon.GetJsonMoneyList(moneyDict) __SendOverInfo(curPlayer, awardDict) 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() != Def_FightTime: return False return True ## ¸±±¾½áÊø´¦Àí def __DoClearDevilOver(isPass): gameFB = GameWorld.GetGameFB() if gameFB.GetFBStep() == FB_Step_Over: return tick = GameWorld.GetGameWorld().GetTick() curPlayer = None playerManager = GameWorld.GetMapCopyPlayerManager() if playerManager.GetPlayerCount() > 0: curPlayer = playerManager.GetPlayerByIndex(0) if not curPlayer: GameWorldProcess.CloseFB(tick) return lineID = FBCommon.GetFBPropertyMark() fbCfg = GetClearDevilTimeCfg() gameFB = GameWorld.GetGameFB() playerID = curPlayer.GetPlayerID() exp = gameFB.GetPlayerGameFBDictByKey(playerID, FBPlayerDict_TotalExp) expPoint = gameFB.GetPlayerGameFBDictByKey(playerID, FBPlayerDict_TotalExpPoint) #totalExp = expPoint * ChConfig.Def_PerPointValue + exp costTime = tick - GameWorld.GetGameFB().GetFBStepTick() gameFB.SetGameFBDict(FBPlayerDict_CostTime, costTime) fbMissionID = gameFB.GetGameFBDictByKey(FBPlayerDict_MissionID) fbMissionType = gameFB.GetGameFBDictByKey(FBPlayerDict_MissionType) # ֪ͨ½á¹û ´Ë´¦Ö»Í¨ÖªÊ§°Ü£¬³É¹¦ÔÚÍê³ÉÈÎÎñʱ֪ͨ, ²»ÊÇͨ¹ýÈÎÎñ½øµÄ¸±±¾Ò²Í¨Öª if not isPass or not fbMissionID or not fbMissionType: __SendOverInfo(curPlayer, {FBCommon.Over_isPass:int(isPass), FBCommon.Over_exp:exp,FBCommon.Over_expPoint:expPoint, FBCommon.Over_costTime:costTime}) # ½øÈëÀ뿪½×¶Î FBCommon.SetFBStep(FB_Step_Over, tick) FBCommon.Sync_Player_TimeTick(IPY_GameWorld.tttLeaveMap, fbCfg[Def_LeaveTime] * 1000) # ¹Ø±ÕË¢¹Ö npcCfg = GetClearDevilNPCCfg(lineID) for npcInfo in npcCfg: NPCCustomRefresh.CloseNPCRefresh(npcInfo[DL_RefreshMark], tick) return ## ·¢ËÍÌôÕ½½á¹ûÐÅÏ¢ def __SendOverInfo(curPlayer, overDict): overDict[FBCommon.Over_dataMapID] = FBCommon.GetRecordMapID(GameWorld.GetMap().GetMapID()) overDict[FBCommon.Over_lineID] = FBCommon.GetFBPropertyMark() GameWorld.DebugLog("__SendOverInfo overDict=%s" % (str(overDict)), curPlayer.GetPlayerID()) FBCommon.Notify_FB_Over(curPlayer, overDict) return