local Level_Controller = {} local enter_world_pb = require("Proto/enter_world_pb") local EventSystem = require('Event/EventSystem') local LocalizationCfg = require "Localization/LocalizationCfg" local LevelWeatherManager = require "Modules/Level/LevelWeatherManager" local private = {} local LevelConditionType = LuaConst.LevelConditionType local GetLocalizedTxt = UIUtils.GetLocalizedTxt local Const_IDS = Const_IDS local formatByIdsId = string.FormatByIdsId local string_isNilOrEmpty = string.isNilOrEmpty local MISSION_DESCRIBE_FUNC = {} function Level_Controller.OnStartup() Level_Controller.conveyProgressDur = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("MapChangeWaitTime").FloatValue) EventSystem.Regist(EventID.Level_ConveyLevelByItem,private.ConveyLevelByItem) EventSystem.Regist(EventID.Level_StartWait,private.OpenProgressBarUI) EventSystem.Regist(EventID.Level_EndWait,private.CloseProgressBarUI) EventSystem.Regist(EventID.Level_ConveyLevelByItem,private.ConveyLevelByItem) EventSystem.Regist(EventID.UI_VirtualController_Move, private.OnVirtualControllerMove) EventSystem.Regist(EventID.Level_Pause_Sync, private.OnLevelPauseSync) EventSystem.Regist(EventID.Level_Resume_Sync, private.OnLevelResumeSync) EventSystem.Regist(EventID.ApplicationQuit, private.OnApplicationQuit) -- 初始化天气模块 LevelWeatherManager.OnStartup() end function Level_Controller.OnShutdown() EventSystem.UnRegist(EventID.Level_StartWait,private.OpenProgressBarUI) EventSystem.UnRegist(EventID.Level_EndWait,private.CloseProgressBarUI) EventSystem.UnRegist(EventID.Level_ConveyLevelByItem,private.ConveyLevelByItem) EventSystem.UnRegist(EventID.UI_VirtualController_Move, private.OnVirtualControllerMove) EventSystem.UnRegist(EventID.Level_Pause_Sync, private.OnLevelPauseSync) EventSystem.UnRegist(EventID.Level_Resume_Sync, private.OnLevelResumeSync) end function private.OnApplicationQuit() if BattleDataGetter.IsSyncLevel() then EventSystem.Dispatch(EventID.BI_LevelMiddle, BIManager.BIType.SyncBattle, "[sync]GameQuit") end end function Level_Controller.ConveyLevelByLevelID(targetLevelID, forceConvey) MDL.Level.LevelConveyRequest(enter_world_pb.MapConvey, targetLevelID, 0, forceConvey) end --场景传送且切线 function Level_Controller.ConveyLevelByLevelIDAncLineID(targetLevelID, lineID) NotSyncBattleSetter.SendChangeSceneLineRequest(lineID, targetLevelID) end function Level_Controller.GetMissionShowFun(type) local func = MISSION_DESCRIBE_FUNC[type] assert(func,"not mission describe func find, please check mission type: "..type) return func end local _conveyProgressEffectId function Level_Controller.StartConveyProgress(levelID, lineID, conveyProgressDur) --资源是否下好 if CTL.HotFix.HasLevelPackageDownload(nil, levelID) == false then return false end --跨服与本服互相传送前先检测是否符合条件 if not CTL.CrossServer.CheckConveyCondition(levelID) then return false end --去国战地图前取消匹配的处理 if not CTL.TeamMatch.IgnoreCheckMatchForLoading() then local matchId = CTL.TeamMatch.IsInMatching() if matchId then local func = CTL.TeamMatch.GetFuncById(matchId) if func then for _, v in DataSheetManager.CountryBase:GetEnumerator() do if levelID == v.SceneId then UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CountryPVP_MatchingTips, function() CTL.TeamMatch.OnPressMatchButton(matchId, func)--告知服务器取消匹配 CTL.TeamMatch.SetIgnoreCheckMatchForLoading(true) Level_Controller.StartConveyProgress(levelID, lineID, conveyProgressDur) end) return end end end end end CTL.TeamMatch.SetIgnoreCheckMatchForLoading(false) Level_Controller.curConveyProgressingLevelID = levelID Level_Controller.curConveyProgressingLineID = lineID NotSyncBattleSetter.OffHorse() if not _conveyProgressEffectId then _conveyProgressEffectId = NotSyncBattleSetter.MainPlayerPlayPsEffect(ConstAssetPathConfig.Path10) end NotSyncBattleSetter.PauseAutoFindPathInTown() Level_Controller.StartCommonProgressBar(Level_Controller.OnConveyProgressFinish, UIUtils.GetLocalizedTxt(Const_IDS.IDS_Map_Transmitting), conveyProgressDur or Level_Controller.conveyProgressDur, Level_Controller.TryBreakConveyProgress, EventID.UI_VirtualController_Move) Level_Controller.isConveyProgressing = true end function Level_Controller.TryBreakConveyProgress(townFindPathType) if Level_Controller.isConveyProgressing then if _conveyProgressEffectId then AuxUtil.StopPsEffect(_conveyProgressEffectId) _conveyProgressEffectId = nil end if not LevelManager.IsSyncLevel() then NotSyncBattleSetter.StopAutoFightPathInTown(townFindPathType) end Level_Controller.isConveyProgressing = false UIManager.CloseView(Const_UI_Lua.UIEnum.UICommonProgressBar) end end function Level_Controller.OnConveyProgressFinish() if Level_Controller.isConveyProgressing then if _conveyProgressEffectId then AuxUtil.StopPsEffect(_conveyProgressEffectId) _conveyProgressEffectId = nil end Level_Controller.isConveyProgressing = false NotSyncBattleSetter.ResumeAutoFindPathInTown() if Level_Controller.curConveyProgressingLineID then Level_Controller.ConveyLevelByLevelIDAncLineID(Level_Controller.curConveyProgressingLevelID, Level_Controller.curConveyProgressingLineID) else Level_Controller.ConveyLevelByLevelID(Level_Controller.curConveyProgressingLevelID) end end end ---callback完成回调 titleStr显示文字 duration 时长 打断回调breakCallback breakEvent 打断event function Level_Controller.StartCommonProgressBar(callback, titleStr, duration, breakCallback, breakEvent) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UICommonProgressBar) then UIManager.CloseView(Const_UI_Lua.UIEnum.UICommonProgressBar) end UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonProgressBar, {callback = callback, titleStr = titleStr, duration = duration, breakCallback = breakCallback, breakEvent = breakEvent}) end function private.ConveyLevelByItem(conveyItemID) local levelID local levelItem = LevelItemManager.GetLevelItem(BattleDataGetter.GetLevelID(), conveyItemID) if levelItem then levelID = levelItem.TargetMapID end --判断资源是否已下载好 if CTL.HotFix.HasLevelPackageDownload(nil, levelID) == false then return end NotSyncBattleSetter.ForceC2SRoleCheck() MDL.Level.LevelConveyRequest(enter_world_pb.ItemConvey, 0, conveyItemID) end function private.OnVirtualControllerMove() if Level_Controller.isConveyProgressing then Level_Controller.TryBreakConveyProgress() end end function private.OnLevelPauseSync(battleRoomID) MDL.Level.LevelPauseSync(battleRoomID) end function private.OnLevelResumeSync(battleRoomID) MDL.Level.LevelResumeSync(battleRoomID) end function private.OpenProgressBarUI(entity, time, text) if entity._logicInitData.IsPlayerSelf then UIManager.OpenView("Common/UICommonProgressBar", { titleStr = GetLocalizedTxt(Const_IDS[text]), duration = time }) end end function private.CloseProgressBarUI(entity) if entity._logicInitData.IsPlayerSelf then UIManager.CloseView("Common/UICommonProgressBar") end end --region 28633 海外需求格式改为 %3:%1/%2(动词名词或者名词动词:进度/总数) 目前一共处理了6、7、9、12四条IDS逻辑 --1.根据 monsterID 去 MonsterData 表中检索怪物对应的动名词位置 + 组合 -- 关卡编辑器坑点:当 missionData 的类型为多类型击杀、保护、采集编组时候,monsterID 有可能为空或者不对甚至是写死为某一个 IDS -- 根据规则有三种处理:1.monsterID nil 就写死敌兵。 2.monsterID 有值就用传来的值。 3.monsterID 被写死成敌兵就用敌兵 -- 为了上面的规则实现,引入 IDS 的后缀为 idsType 辅助我们判断应该用哪种逻辑才是正确的 function private.GetLevelHintsTipsByRegion(idsId, currentCount, totalCount, paramStr, monsterID, idsType) --国服 if GameAppInfo.IsChinesePackage() then if paramStr == nil and monsterID == nil then --IDS_LevelMissionText_7 return formatByIdsId(idsId, currentCount, totalCount) else --IDS_LevelMissionText_6 return formatByIdsId(idsId, currentCount, totalCount, paramStr) end end local diBingStr = GetLocalizedTxt(Const_IDS["IDS_MonsterName_DiBing"]) local jiBaiRightStr = "IDS_MonsterName_Verb_Right_JiBai" local jiBaiLeftStr = "IDS_MonsterName_Verb_Left_JiBai" local caiJiRightStr = "IDS_MonsterName_Verb_Right_CaiJi" local caiJiLeftStr = "IDS_MonsterName_Verb_Left_CaiJi" --动名词组合的字符串 local verbAndNounStr = nil local verbsStr = nil local rightStr = nil local leftStr = nil if idsType == 6 or idsType == 7 or idsType == 9 then if monsterID == nil then --当 monsterID 为空的时候。只有可能是 IDS_LevelMissionText_6 和 IDS_LevelMissionText_7 两种逻辑 verbsStr = (paramStr == diBingStr or paramStr == nil) and diBingStr or paramStr rightStr = jiBaiRightStr leftStr = jiBaiLeftStr else --当 monsterID 不为空的时候,需要判断是用写死的 IDS 还是读表的,只可能是 IDS_LevelMissionText_6 + IDS_LevelMissionText_9 两种逻辑 verbsStr = paramStr == diBingStr and diBingStr or paramStr rightStr = paramStr == diBingStr and jiBaiRightStr or DataSheetManager.MonsterData:GetDataByID(monsterID).MonsterVerbRight leftStr = paramStr == diBingStr and jiBaiLeftStr or DataSheetManager.MonsterData:GetDataByID(monsterID).MonsterVerbLeft end elseif idsType == 12 then verbsStr = paramStr rightStr = caiJiRightStr leftStr = caiJiLeftStr end if private.GetGrammarOrderByLanguages() then verbAndNounStr = string.FormatByIdsKey(rightStr, verbsStr) else verbAndNounStr = string.FormatByIdsKey(leftStr, verbsStr) end --%3:%1/%2 return verbAndNounStr .. private.GetColonStrByLanguages() .. currentCount .. "/" .. totalCount end --语言规则,目前除简中繁中是动词在左,其他语言动词在右边,后面添加新语言可以在这里改写 --海外需求:1.动词+名词返回true 2.名词+动词返回false 只有这两种情况 function private.GetGrammarOrderByLanguages() local curLanguage = Localization.GetLanguage() if curLanguage == LocalizationCfg.LANGUAGE_SC_WORLD or curLanguage == LocalizationCfg.LANGUAGE_TRADITIONAL then --1.动词+名词 return true else --2.名词+动词,目前有印尼 英文 日文 return false end end --目前中文+日文采用全角,其他语言用半角+空格,后面添加新语言可以在这里改写 function private.GetColonStrByLanguages() local curLanguage = Localization.GetLanguage() if curLanguage == LocalizationCfg.LANGUAGE_JAPANESE or curLanguage == LocalizationCfg.LANGUAGE_SC_WORLD then return ":" else return ": " end end --endregion 28633 --region ************** MISSION_DESCRIBE_FUNC by type ************** MISSION_DESCRIBE_FUNC[LevelConditionType.Mission_TimeRun] = function(missionAim, complete) local progress = (complete and missionAim.Data.Param1 or missionAim.value) or FP.Const.Zero return formatByIdsId(Const_IDS.IDS_LevelMissionText_1, FP.tonumberV1(progress), FP.tonumberV1(missionAim.Data.Param1)) end MISSION_DESCRIBE_FUNC[LevelConditionType.Global_TimeRemain] = function(missionAim, complete) return formatByIdsId(Const_IDS.IDS_LevelMissionText_2, FP.tonumberV1(missionAim.Data.Param1)) end MISSION_DESCRIBE_FUNC[LevelConditionType.Mission_WaveReach]= function(missionAim, complete) if missionAim.Data.Param2 then local progress = (complete and missionAim.Data.Param1 or missionAim.value) or 0 return formatByIdsId(Const_IDS.IDS_LevelMissionText_3, progress, missionAim.Data.Param1) else return formatByIdsId(Const_IDS.IDS_LevelMissionText_4, missionAim.Data.Param1) end end MISSION_DESCRIBE_FUNC[LevelConditionType.Global_LevelWaveReach] = MISSION_DESCRIBE_FUNC[LevelConditionType.Mission_WaveReach] MISSION_DESCRIBE_FUNC[LevelConditionType.DeadNumber] = function(missionAim, complete) local missionData = missionAim.Data if missionData.PlayerBornID and missionData.PlayerBornID > LuaConst.ItemMaxCount then -- 需要区分玩家 local playerID = missionData.PlayerBornID - LuaConst.ItemMaxCount local playerName = LevelPlayerManager.GetPlayerName(playerID) if playerName == "" or not LevelManager.CurLevelFunc:GetPlayerHasReward(playerID) then return nil end return formatByIdsId(Const_IDS.IDS_LevelMissionText_13, playerName, GetLocalizedTxt(Const_IDS[missionData.ParamStr])) elseif missionData.ItemIDList then if missionData.Param1 == 1 then local str if missionData.ParamStr then str = GetLocalizedTxt(Const_IDS[missionData.ParamStr]) else local monsterID = BattleDataGetter.GetLevelItemByID(missionData.ItemIDList[1]):GetMonsterID(1) str = GetLocalizedTxt(Const_IDS[DataSheetManager.MonsterData:GetDataByID(monsterID).MonsterNameIDS]) end return formatByIdsId(Const_IDS.IDS_LevelMissionText_5, str) else local progress = (complete and missionData.Param1 or missionAim.value) or 0 local str local monsterID = BattleDataGetter.GetLevelItemByID(missionData.ItemIDList[1]):GetMonsterID(1) if missionData.ParamStr then str = GetLocalizedTxt(Const_IDS[missionData.ParamStr]) else str = GetLocalizedTxt(Const_IDS[DataSheetManager.MonsterData:GetDataByID(monsterID).MonsterNameIDS]) end return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_6, progress, missionData.Param1, str, monsterID ~= nil and monsterID or nil, 6) end elseif missionData.ParamID then if missionData.ParamID > 0 then local monsterData = DataSheetManager.MonsterData:GetDataByID(missionData.ParamID) if missionData.Param1 == 1 then return formatByIdsId(Const_IDS.IDS_LevelMissionText_5, GetLocalizedTxt(Const_IDS[monsterData.MonsterNameIDS])) else local progress = (complete and missionData.Param1 or missionAim.value) or 0 if string_isNilOrEmpty(missionData.ParamStr) then return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_6, progress, missionData.Param1, GetLocalizedTxt(Const_IDS[monsterData.MonsterNameIDS]), monsterData.ID ,6) else return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_6, progress, missionData.Param1, GetLocalizedTxt(Const_IDS[missionData.ParamStr]), monsterData.ID, 6) end end else logging.error(LTAG.ERROR,"【任务元素】非法参数") end else local progress = (complete and missionData.Param1 or missionAim.value) or 0 if string_isNilOrEmpty(missionData.ParamStr) then return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_7, progress, missionData.Param1, nil, nil, 7) else return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_6, progress, missionData.Param1, GetLocalizedTxt(Const_IDS[missionData.ParamStr]), nil, 6) end end end MISSION_DESCRIBE_FUNC[LevelConditionType.Global_GivenMonsterAliveNum] = function(missionAim, complete) local monsterData = DataSheetManager.MonsterData:GetDataByID(missionAim.Data.ParamID) if missionAim.Data.Param1 == 1 then return formatByIdsId(Const_IDS.IDS_LevelMissionText_8, GetLocalizedTxt(Const_IDS[monsterData.MonsterNameIDS])) else local progress = (complete and missionAim.Data.Param1 or missionAim.value) or 0 return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_9, progress, missionAim.Data.Param1, GetLocalizedTxt(Const_IDS[monsterData.MonsterNameIDS]), monsterData.ID, 9) end end MISSION_DESCRIBE_FUNC[LevelConditionType.Global_PlayerReachArea] = function(missionAim, complete) return GetLocalizedTxt(Const_IDS[missionAim.Data.ParamStr]) end MISSION_DESCRIBE_FUNC[LevelConditionType.Global_GivenMonsterReachArea] = function(missionAim, complete) local monsterData = DataSheetManager.MonsterData:GetDataByID(missionAim.Data.ParamID) return formatByIdsId(Const_IDS.IDS_LevelMissionText_10, GetLocalizedTxt(Const_IDS[monsterData.MonsterNameIDS]), GetLocalizedTxt(Const_IDS[missionAim.Data.ParamStr])) end MISSION_DESCRIBE_FUNC[LevelConditionType.Global_GivenMonsterAllReachArea] = function(missionAim, complete) local name = "" local itemIDList = missionAim.Data.Param3 for i, itemID in ipairs(itemIDList) do local levelItem = BattleDataGetter.GetLevelItemByID(itemID) local mid = levelItem:GetMonsterID(1) if mid then local monsterData = DataSheetManager.MonsterData:GetDataByID(mid) if monsterData then name = monsterData.MonsterNameIDS end end end return formatByIdsId(Const_IDS.IDS_LevelMissionText_10, GetLocalizedTxt(Const_IDS[name]), GetLocalizedTxt(Const_IDS[missionAim.Data.ParamStr or 1])) end MISSION_DESCRIBE_FUNC[LevelConditionType.Global_GivenMonsterAnyReachArea] = MISSION_DESCRIBE_FUNC[LevelConditionType.Global_GivenMonsterAllReachArea] MISSION_DESCRIBE_FUNC[LevelConditionType.CollectNumber] = function(missionAim, complete) if missionAim.Data.ItemIDList then if missionAim.Data.Param1 == 1 then return formatByIdsId(Const_IDS.IDS_LevelMissionText_11, GetLocalizedTxt(Const_IDS[missionAim.Data.ParamStr])) else local progress = (complete and missionAim.Data.Param1 or missionAim.value) or 0 return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_12, progress, missionAim.Data.Param1, GetLocalizedTxt(Const_IDS[missionAim.Data.ParamStr]), nil, 12) end elseif missionAim.Data.ParamID and missionAim.Data.ParamID > 0 then local collectionData = DataSheetManager.CollectionData:GetDataByID(missionAim.Data.ParamID) if missionAim.Data.Param1 == 1 then return formatByIdsId(Const_IDS.IDS_LevelMissionText_11, GetLocalizedTxt(Const_IDS[collectionData.CollectionNameIDS])) else local progress = (complete and missionAim.Data.Param1 or missionAim.value) or 0 return private.GetLevelHintsTipsByRegion(Const_IDS.IDS_LevelMissionText_12, progress, missionAim.Data.Param1, GetLocalizedTxt(Const_IDS[collectionData.CollectionNameIDS]), collectionData.ID ,12) end else logging.error(LTAG.ERROR,"【任务元素】非法参数") end end MISSION_DESCRIBE_FUNC[LevelConditionType.Trigger_PlayerStayNumber] = function(missionAim, complete) local totalPlayerCount = LevelPlayerManager.GetValidPlayerCount() local progress = (complete and totalPlayerCount or missionAim.value) or 0 return formatByIdsId(Const_IDS.IDS_LevelMissionText_14, GetLocalizedTxt(Const_IDS[missionAim.Data.ParamStr]), progress, totalPlayerCount) end --endregion MISSION_DESCRIBE_FUNC by type local MAINCITY_MAP_ID = DataSheetManager.ConstData:GetDataByID("DefaultMainCityId").IntValue function Level_Controller.GetMainCityId() return MAINCITY_MAP_ID end local AUTO_FIGHT_STATE_KEY = "AUTO_FIGHT_STATE" function Level_Controller.SetAutoFight(levelType, autoFight) local saveTb = PersistentData.DeviceData:Get(AUTO_FIGHT_STATE_KEY) or {} saveTb[levelType] = autoFight PersistentData.DeviceData:Set(AUTO_FIGHT_STATE_KEY, saveTb, true) end function Level_Controller.GetIsAutoFight(levelType) local saveTb = PersistentData.DeviceData:Get(AUTO_FIGHT_STATE_KEY) or {} return saveTb[levelType] and saveTb[levelType]==1 or false, saveTb[levelType] ~= nil end return Level_Controller