local EventSystem = require('Event/EventSystem') local enums_pb = require("Proto/enums_pb") local Task_Controller = {} local private = {} --region -- **************** 数据部分 ******************* -- --协议定义 local task_pb = require("Proto/task_pb") --当前正在执行的子任务 local _curChildTask = {} local TIMELINE_PATH = ConstAssetPathConfig.TIMELINE_PATH local curCollectionIndex = nil ---当前采集堆的第几个 --endregion 数据部分 --- 挖宝相关数据 local NormalTreasureMonsterId = DataSheetManager.ConstData:GetDataByID("DigTreasureNormal").IntValue local AdvancedTreasureMonsterId = DataSheetManager.ConstData:GetDataByID("DigTreasureAdvance").IntValue local TreasureDoorMonsterId = DataSheetManager.ConstData:GetDataByID("DigTreasureDoor").IntValue local TreasureBoxMonsterId = DataSheetManager.ConstData:GetDataByID("DigTreasureBox").IntValue local normalTreasureItemId = 51 local advancedTreasuretemId = 52 function Task_Controller.OnStartup() EventSystem.Regist(EventID.Task_SetCurCollectionIndex, private.SetCurCollectionIndex) EventSystem.Regist(EventID.Task_DoTaskAction, private.DoTaskAction) EventSystem.Regist(EventID.Task_ContinueAutoTask, private.ContinueAutoTask) EventSystem.Regist(EventID.Task_ShowTaskTrigger, private.ShowLevelItemTrigger) -- 切场景后激活任务触发器 EventSystem.Regist(EventID.Level_EnterTriggerItem, private.TaskTriggerReceive) -- 任务触发器触发接任务 EventSystem.Regist(EventID.RandomScenePoint_OnActive,private.OnRandomScenePointActive) --藏宝图点出生 刷新哪个藏宝图需要刷新 EventSystem.Regist(EventID.Task_FinishInteract, private.OnTreasureInteractFinish) --当挖宝完成 EventSystem.Regist(EventID.DigTreasure_OpenMulDoor, private.OnOpenMulDoor) --打开多人藏宝图界面 EventSystem.Regist(EventID.WantedTask_InteractFinish, private.WantedTaskInteractFinish) end function Task_Controller.OnShutdown() private.showChapter = nil end function Task_Controller.OpenTaskMainPanel() UIManager.OpenView(Const_UI_Lua.UIEnum.UITaskMainPanel) end function Task_Controller.TryShowNewChapter() if private.showChapter and BattleDataGetter.IsOnlineTownLevel() then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITaskChapterPanel,private.showChapter) private.showChapter = nil end end function Task_Controller.DoTask(task, isClick) if task.State == MDL.Task.Enum_TaskState.Doing then private.StartAutoTask(task, isClick) elseif task.State == MDL.Task.Enum_TaskState.Done then private.CommitTask(task) elseif task.State == MDL.Task.Enum_TaskState.Failure then MDL.Task.ResetTaskRequest(task.taskInfo.taskMainId) end end function Task_Controller.OnStopAutoTask(townFindPathType) if townFindPathType ~= LuaConst.ETownFindPathType.TASK then if MDL.Task.DoingTask then MDL.Task.DoingTask = nil --是否到达采集地 if CTL.Interact.IsEnterCollection() then EventSystem.Dispatch(EventID.UI_Scene_AutoCollectItem) else EventSystem.Dispatch(EventID.UI_Task_BreakAuto, BattleDataGetter.GetCurEntity()) end end end end function private.StartNewChapter(chapterData) if string.isNilOrEmpty(chapterData.UIShow) then return end if BattleDataGetter.IsOnlineTownLevel() then --打断表现 CTL.FunctionNotice.TryBreakUnlockExp() UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UITaskChapterPanel,chapterData) else private.showChapter = chapterData end end function private.ContinueAutoTask() if MDL.Task.DoingTask then Task_Controller.DoTask(MDL.Task.DoingTask) end end function Task_Controller.OnChildTaskStart(task, init) if task.taskChildData[1].MapID == BattleDataGetter.GetLevelID() then for i,v in ipairs(task.taskChildData[1].NPCID) do EventSystem.Dispatch(EventID.ChildTaskStart,private.GetItemIdByNpcId(v)) end --这里是通知地图采集物元素的事件 采集物需要任务id EventSystem.Dispatch(EventID.ChildTaskStart,nil,task.taskInfo.taskMainId) else Task_Controller.InitTreasureItem(task, init) end --判断该任务是否需要打开章节展示的界面 if not init then local chapterData for i, v in ipairs(task.taskChildData) do if v.Opening > 0 then chapterData = DataSheetManager.TaskChapterData:GetDataByID(v.Opening) break end end if chapterData then private.StartNewChapter(chapterData) end end end function Task_Controller.InitTreasureItem(task, init) local boxId local isSuccess, treasureItem = DataSheetManager.DigTreasurePoint:TryGetDataByID(task.taskInfo.treasureId) if task.TaskData.Type == MDL.Task.Enum_TaskType.NormalTreasure or task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure then if task.taskChildData[1].ActionType == MDL.Task.Enum_ActionType.Collection then if treasureItem.MapID == BattleDataGetter.GetLevelID() then local params = string.split(task.taskChildData[1].CompleteConditionParam, ";") boxId = params[1] and tonumber(params[1]) end end end if treasureItem then if treasureItem.MapID == BattleDataGetter.GetLevelID() then EventSystem.Dispatch(EventID.RandomScenePoint_RemoveOneCharacter, treasureItem.MapAreaID, task.taskInfo.treasureGroupId, task.taskInfo.treasureIndexId) end if boxId then EventSystem.Dispatch(EventID.RandomScenePoint_BornOneCharacter, treasureItem.MapAreaID, LuaConst.CharacterType.Monster, boxId, task.taskInfo.treasureGroupId, task.taskInfo.treasureIndexId) --这里没啥好的判断方法 宝箱出生时需要弹出tips 这里拿任务进度去判断是否是一次接这个任务 if not init and boxId == TreasureBoxMonsterId and task.taskInfo.childInfo[1].process.param == 0 then CTL.HomeMain.AddTownHomeDelayFunc(private.ShowDigTreasureTips) end end end if task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure and treasureItem.MapID == BattleDataGetter.GetLevelID() then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UICompass) then local item = LevelItemManager.GetItemByID(treasureItem.MapAreaID) local entity = item:GetEntity(task.taskInfo.treasureGroupId, task.taskInfo.treasureIndexId) if entity == nil then logging.error(LTAG.ERROR, " 错误 藏宝图生成点 找不到entity ") end UIManager.OpenView(Const_UI_Lua.UIEnum.UICompass, { entity = entity }) end end if task.TaskData.Type == MDL.Task.Enum_TaskType.TreasureCave and not init then CTL.HomeMain.AddTownHomeDelayFunc(private.ShowDigTreasureCaveTips) end end function Task_Controller.OnChildTaskFinish(preChildData,task)--修改 任务完成时显隐npc规则 这个方法是最后一个子任务 logging.log(LTAG.LOG," OnChildTaskFinish ",task) if preChildData.MapID == BattleDataGetter.GetLevelID() then local ids = preChildData.NPCID for j,v in ipairs(ids) do EventSystem.Dispatch(EventID.ChildTaskFinish,private.GetItemIdByNpcId(v)) end end if task.TaskData.Type == MDL.Task.Enum_TaskType.NormalTreasure or task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure then local treasureItem = DataSheetManager.DigTreasurePoint:GetDataByID(task.taskInfo.treasureId) if treasureItem then EventSystem.Dispatch(EventID.RandomScenePoint_RemoveOneCharacter, treasureItem.MapAreaID, task.taskInfo.treasureGroupId,task.taskInfo.treasureIndexId) end end if task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure then UIManager.CloseView(Const_UI_Lua.UIEnum.UICompass) end end function Task_Controller.OnTreasureTaskFinish(taskType,taskID) local lastData = Task_Controller.GetLastChildData(taskID) --需求是每完成一个任务继续自动使用物品 但是单人副本是任务完成之后传送进去的 但此时已经跟任务没有联系了 需要副本完成时才能继续使用 不能在任务完成点使用 if lastData.FinishActionType and lastData.FinishActionType > 0 then return end local Enum_TaskType = MDL.Task.Enum_TaskType if taskType == Enum_TaskType.NormalTreasure then Task_Controller.QuickUseNormalTreasure() private.TreasureShowTips(taskType,taskID) elseif taskType == Enum_TaskType.AdvancedTreasure then CTL.Bag.ShowQuickUseItem(advancedTreasuretemId) private.TreasureShowTips(taskType,taskID) end end function Task_Controller.GetLastChildData(taskId) local lastData = nil for key, value in DataSheetManager.TaskChildData:GetDataByTaskLineID_TaskChildID(taskId) do lastData = value end return lastData end function Task_Controller.OnInitTaskList(doingList) --进游戏时当前所有任务 处理超时任务逻辑 for i,taskInfo in ipairs(doingList) do for _,childInfo in ipairs(taskInfo.childInfo) do if childInfo.expireTime > 0 then local taskId = taskInfo.taskMainId local childId= childInfo.taskChildId local timeValue = childInfo.expireTime - UTL.Time.GetServerTimestamp() if timeValue <= 0 then MDL.Task.TimeoutTaskRequest(taskId,childId) else TimerUtil.Interval(function () MDL.Task.TimeoutTaskRequest(taskId,childId) end,timeValue,1) end end end end end function Task_Controller.StartTask(taskInfo) --任务到身上时触发的接口 -- local isNew = false -- local taskFatherData = DataSheetManager.TaskFatherData:GetDataByID(taskInfo.taskMainId) -- if taskFatherData.IsOrder then -- local taskChildData = DataSheetManager.TaskChildData:GetDataByTaskLineID_TaskChildID(taskInfo.taskMainId,taskInfo.childInfo[1].taskChildId) -- local task = MDL.Task.GetTask(taskInfo.taskMainId) -- if task == nil then -- isNew = true -- elseif task.taskInfo.childInfo[1].taskChildId ~= taskInfo.childInfo[1].taskChildId then -- isNew = true -- end -- if isNew then -- if taskChildData.StartActionType == MDL.Task.Enum_Condition.ChangeAvatar then -- MDL.Player.ShowChangeHeroRequest(tonumber(taskChildData.StartParam),true) -- elseif taskChildData.StartActionType == MDL.Task.Enum_Condition.RecoverAvatar then -- -- -- elseif taskChildData.StartActionType == MDL.Task.Enum_Condition.ChangeMirrorMap then -- MDL.LevelSelect.EnterFuben(LuaConst.LevelType.Planes,tonumber(taskChildData.StartParam)) -- end -- end -- end for i,v in ipairs(taskInfo.childInfo) do if v.expireTime > 0 then local timeValue = v.expireTime - UTL.Time.GetServerTimestamp() if timeValue <= 0 then MDL.Task.TimeoutTaskRequest(taskInfo.taskMainId,v.taskChildId) else local taskId = taskInfo.taskMainId local childId= v.taskChildId TimerUtil.Interval(function () MDL.Task.TimeoutTaskRequest(taskId,childId) end,timeValue,1) end else local taskChildData = DataSheetManager.TaskChildData:GetDataByTaskLineID_TaskChildID(taskInfo.taskMainId,v.taskChildId) if taskChildData.ActionType == MDL.Task.Enum_ActionType.WaitTime then local timeValue = v.acceptTime +tonumber(taskChildData.Factor) - UTL.Time.GetServerTimestamp() if timeValue <= 0 then MDL.Task.TaskStateUpdateRequest(taskChildData,0,0,task_pb.Finish,0) else TimerUtil.Interval(function () MDL.Task.TaskStateUpdateRequest(taskChildData,0,0,task_pb.Finish,0) end,timeValue,1) end end end end end function private.CommitTask(task) MDL.Task.TaskCommitRequest(task.taskInfo.taskMainId,task.taskInfo.childInfo[#task.taskInfo.childInfo].taskChildId) end --前往领取环任务 function Task_Controller.GoAcceptRingTask(taskType) if taskType == MDL.Task.Enum_RingTaskType.RingDaily then local state = MDL.Task.GetDailyRingTaskState() if(state == MDL.Task.Enum_RingTaskState.UnAccepet)then --自动寻路到环任务NPC local function callback() local entity = BattleDataGetter.GetEntityByLevelItemID(MDL.Task.AcceptDailyRingTaskNPCId()) EventSystem.Dispatch(entity.Event_EntityVisited,entity,nil) end NotSyncBattleSetter.FindPathByLevelItemIDAndRide(MDL.Task.AcceptDailyRingTaskMapId(),MDL.Task.AcceptDailyRingTaskNPCId(),callback) elseif(state == MDL.Task.Enum_RingTaskState.Doing)then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Task_RingDaily_Doing"]) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Task_RingDaily_Max"]) end end end --前往环任务,未接取前往任务npc function Task_Controller.GoToRingTask(taskType) if taskType == MDL.Task.Enum_RingTaskType.RingDaily then local state = MDL.Task.GetDailyRingTaskState() if(state == MDL.Task.Enum_RingTaskState.UnAccepet)then --自动寻路到环任务NPC local function callback() local entity = BattleDataGetter.GetEntityByLevelItemID(MDL.Task.AcceptDailyRingTaskNPCId()) EventSystem.Dispatch(entity.Event_EntityVisited,entity,nil) end NotSyncBattleSetter.FindPathByLevelItemIDAndRide(MDL.Task.AcceptDailyRingTaskMapId(),MDL.Task.AcceptDailyRingTaskNPCId(),callback) elseif(state == MDL.Task.Enum_RingTaskState.Doing)then local task local taskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.RingDaily) if taskList then for _,vo in pairs(taskList) do task = vo break end end if task then Task_Controller.DoTask(task) end else CTL.Tips.AddTipsMsg(Const_IDS["IDS_Task_RingDaily_Max"]) end end end --region -- *************** 行为部分 ***************** -- function Task_Controller.GetTaskCurDoingData(task) local curPorcess = nil for i,v in ipairs(task.taskInfo.childInfo) do if v.taskState == MDL.Task.Enum_TaskState.Doing then return i end end return 1 end function private.DoTaskAction(task,entity ,callback,index)--到达目的地的行为 if index == nil then index = Task_Controller.GetTaskCurDoingData(task) end local childData = task.taskChildData[index] _curChildTask.LevelItemID = childData.MapItemID[1] _curChildTask.LevelID = childData.MapID _curChildTask.Task = childData _curChildTask.Entity = entity local type = task.taskChildData[index].ActionType local enumType = MDL.Task.Enum_ActionType private.DoTaskActionOver = callback if type == enumType.Story then -- 对话 EventSystem.Dispatch(EventID.UI_MainShowDialogue ,childData.Factor, private.OnTaskActionCallback, childData, entity) elseif type == enumType.Show or type == enumType.AutoComplete then -- Show:播放剧情动画, AutoComplete:接任务自动播动画 --播放剧情timeline前停止寻路 NotSyncBattleSetter.StopAutoFightPathInTown() NotSyncBattleSetter.SetMainPlayerMoveInTown(BattleDataGetter.GetMainPlayerLastLogicPos(), nil) SystemManager.PlayTimeline(string.format(TIMELINE_PATH, childData.Factor),true,-1,private.OnTimeLineCallback) elseif type == enumType.Collection then -- 采集 --private.DoCollectionAction(task,_curChildTask.LevelID,_curChildTask.LevelItemID) elseif type == enumType.OnGoing then -- --执行过场 elseif type == enumType.TaskChoose then -- 选择后进入不同任务分支 --执行任务选择 CTL.HomeMain.ShowTaskChoose(childData, private.OnTaskActionCallback, entity) elseif type == enumType.PlayAnimation then -- 播放动画、动作、固定地点 if childData.Factor and string.len(childData.Factor) > 0 then local animationList = string.split(childData.Factor,',') NotSyncBattleSetter.SetMainPlayerNextState(LuaConst.StateType.Common,-1, animationList[1], nil ,-1) if animationList[2] then local fun = function ( ) NotSyncBattleSetter.SetMainPlayerNextState(LuaConst.StateType.Idle,-1, "idle_loop", nil ,-1) end TimerUtil.Interval(fun,tonumber(animationList[2]),1) end end private.OnTaskActionCallback() elseif type == enumType.EnterFuben then -- 进副本 --国战悬赏任务特殊处理 if task.TaskData.Type == MDL.Task.Enum_TaskType.Wanted then local taskFatherID = childData.TaskLineID local taskChildId = childData.TaskChildID local taskWanted = MDL.CountryWantedTask.GetTaskWantedByTaskFatherIDAndChildId(taskFatherID,taskChildId) if taskWanted and taskWanted.TaskType == MDL.CountryWantedTask.TaskType.NeutralityPVE then --中立PVE MDL.CountryWantedTask.EnterWantedTaskReq(tonumber(childData.Factor),taskFatherID,taskChildId,LuaConst.ActivityType.WantedTask) return elseif taskWanted and taskWanted.TaskType == MDL.CountryWantedTask.TaskType.EnemyCountryPVE then --敌国PVE local mapId = CTL.CountryWantedTask.GetEnemyCountryPVEMap(childData) MDL.CountryWantedTask.EnterWantedTaskReq(mapId,taskFatherID,taskChildId,LuaConst.ActivityType.WantedTask) return end end --其他走默认enter副本 MDL.LevelSelect.EnterFuben(LuaConst.LevelType.Planes,tonumber(childData.Factor)) elseif type == enumType.Open then -- 打开界面 CTL.ItemSources.ExecuteSourceFunctionById(childData.Factor) elseif type == enumType.PlayMovie then local params = string.split(childData.Factor,';') local context = { movieID = params[1] , banSkipTime = params[2] and tonumber(params[2]) , autoPassTime = -1, callback = private.OnTaskActionCallback} if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIMoviePanel) then EventSystem.Dispatch(EventID.UI_MoviePanel_OpenInit, context) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIMoviePanel, context) end elseif type == enumType.Consistent then -- 播放剧情timeline且打开选择后进入不同任务分支 --播放剧情timeline前停止寻路 NotSyncBattleSetter.StopAutoFightPathInTown() NotSyncBattleSetter.SetMainPlayerMoveInTown(BattleDataGetter.GetMainPlayerLastLogicPos(), nil) SystemManager.PlayTimeline(string.format(TIMELINE_PATH, childData.Factor),true,-1) -- 这里的TL是循环播放的,完成任务的回调挪到接后续任务的界面里 --执行任务选择 CTL.HomeMain.ShowTaskChoose(childData, private.OnTaskActionCallback, entity) -- 传入的回调是完成当前任务 end end function private.OnTimeLineCallback(id, level, requestReward) private.OnTaskActionCallback(id) ExpLevelManager.OnTimelineEnd(id, requestReward) end function private.OnTaskActionCallback(id,value) local task = _curChildTask.Task local levelID = _curChildTask.LevelID local entity = _curChildTask.Entity local levelItemID = _curChildTask.LevelItemID _curChildTask.LevelID = nil _curChildTask.Task = nil _curChildTask.Entity = nil _curChildTask.LevelItemID = nil if task.CompleteCondition == 0 then value = value or 0 MDL.Task.TaskStateUpdateRequest(task,levelID,levelItemID,task_pb.Finish,value) end local npcID = task.NPCID[1] --发晋升请求 if npcID and CTL.OfficialPosition.CheckFirstTitlePromotion(npcID) then CTL.OfficialPosition.OfficialPositionPromotion() end if private.DoTaskActionOver then private.DoTaskActionOver() end end function private.SetCurCollectionIndex(index) curCollectionIndex = index end function Task_Controller.GetChildTaskDesc(task,i) local data =task.taskChildData[i] if task.TaskData.Type == MDL.Task.Enum_TaskType.NormalTreasure or task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure then local treasureItem = DataSheetManager.DigTreasurePoint:GetDataByID(task.taskInfo.treasureId) local mapInfo = DataSheetManager.LevelInfoData:GetDataByLevelID(treasureItem.MapID) local mapName = UIUtils.GetLocalizedTxt(Const_IDS[mapInfo.LevelNameIDS]) return string.FormatByIdsId(Const_IDS[data.Des],mapName) elseif task.TaskData.Type == MDL.Task.Enum_TaskType.TreasureCave then local mapInfo = DataSheetManager.LevelInfoData:GetDataByLevelID(task.taskInfo.conveyDoorMapId) local mapName = UIUtils.GetLocalizedTxt(Const_IDS[mapInfo.LevelNameIDS]) return string.FormatByIdsId(Const_IDS[data.Des],mapName) end local info = task.taskInfo.childInfo[i] if data.ActionType == MDL.Task.Enum_ActionType.Collection then return string.FormatByIdsId(Const_IDS[data.Des],info.process.param) end return UIUtils.GetLocalizedTxt(Const_IDS[data.Des]) end --endregion 行为部分 --region -- *************** 自动部分 ***************** -- function private.GetNpcId(levelID, levelItemID) return BattleDataGetter.GetNpcIdByLevelItemInfo(levelID,levelItemID) end --自动做寻路的任务 --跟寻路有关的任务,需要判断地图id是否已下载完成,未下载完成提示 function private.StartAutoTask(task, isClick)--执行任务 local index = Task_Controller.GetTaskCurDoingData(task) local taskChildData = task.taskChildData[index] --timeline相关的任务,在timeline资源未下完前,提示下载 if taskChildData and (taskChildData.ActionType == MDL.Task.Enum_ActionType.Show or taskChildData.ActionType == MDL.Task.Enum_ActionType.AutoComplete or taskChildData.ActionType == MDL.Task.Enum_ActionType.Consistent) then local timelineStageGroup = taskChildData.PackStage if CTL.HotFix.CheckAndWarnDownloadPack(timelineStageGroup) == false then logging.error(LTAG.ERROR, "TimelineStageGroup download is not complete !!! stage : ", timelineStageGroup) return end end NotSyncBattleSetter.StopAutoFightPathInTown(LuaConst.ETownFindPathType.TASK) --停止现在的寻路(主要是为了清空活动寻路的缓存) if task.TaskData.Type == MDL.Task.Enum_TaskType.TreasureCave then if CTL.HotFix.HasLevelPackageDownload(nil, task.taskInfo.conveyDoorMapId) == false then return end --跨服与本服互相传送前先检测是否符合条件 if not CTL.CrossServer.CheckConveyCondition(task.taskInfo.conveyDoorMapId) then return end MDL.Task.DoingTask = task EventSystem.Dispatch(EventID.UI_Task_SetAuto) NotSyncBattleSetter.FindPathByPos(task.taskInfo.conveyDoorMapId, task.taskInfo.conveyDoorPosX, task.taskInfo.conveyDoorPosZ, true, NotSyncBattleSetter.OffHorse, LuaConst.ETownFindPathType.TASK, true) if isClick and task.taskInfo.conveyDoorMapId == LevelManager.GetCurInfoData().LevelID then if #LogicUpdateManager._curEntity.components.path.Path <= 0 then logging.crit(LTAG.CRIT, "Not Find Path", task.taskInfo.conveyDoorMapId, task.taskInfo.conveyDoorPosX, task.taskInfo.conveyDoorPosZ) end end return end if task.TaskData.Type == MDL.Task.Enum_TaskType.Wanted then --国战悬赏任务 local isReturn = private.DoCountryWantedTask(task,task.taskChildData[index]) if isReturn then return end end if task.TaskData.Type == MDL.Task.Enum_TaskType.Convoy then -- 押镖任务走自身的镖车跟随逻辑 CTL.GuildEscort.BeginFollowCart() return end if task.TaskData.Type == MDL.Task.Enum_TaskType.NormalTreasure or task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure then local treasureItem = DataSheetManager.DigTreasurePoint:GetDataByID(task.taskInfo.treasureId) local unlockAutoArrive = DataSheetManager.ConstData:GetDataByID("DigForTreasureAutoLevel").IntValue local teamLevel = MDL.Player.GetRoleInfo() if task.TaskData.Type == MDL.Task.Enum_TaskType.NormalTreasure or (task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure and teamLevel >= unlockAutoArrive) then if CTL.HotFix.HasLevelPackageDownload(nil, treasureItem.MapID) == false then CTL.TeamDungeon.StopTreasure() return end --跨服与本服互相传送前先检测是否符合条件 if not CTL.CrossServer.CheckConveyCondition(treasureItem.MapID) then CTL.TeamDungeon.StopTreasure() return end MDL.Task.DoingTask = task EventSystem.Dispatch(EventID.UI_Task_SetAuto) local callback = function () private.OnArriveTreasureTarget(task) end local itemData = LevelItemManager.GetLevelItem(treasureItem.MapID,treasureItem.MapAreaID) local posX, posY = FP.tonumberV2(itemData.ScenePointGroupList[task.taskInfo.treasureGroupId][task.taskInfo.treasureIndexId].Position) NotSyncBattleSetter.FindPathByPos(treasureItem.MapID, posX*1000, posY*1000, true, callback, LuaConst.ETownFindPathType.TASK, true) if task.TaskData.Type == MDL.Task.Enum_TaskType.NormalTreasure then CTL.TeamDungeon.StartTreasure() end else MDL.Task.DoingTask = nil if treasureItem.MapID ~= BattleDataGetter.GetCurLevelID() then CTL.Level.StartConveyProgress(treasureItem.MapID) else if task.taskChildData[index].ActionType ~= MDL.Task.Enum_ActionType.Collection then private.OnArriveTreasureTarget(task) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_DigTreasure_FindWay) end end end return else CTL.TeamDungeon.StopTreasure() end local mapId = task.taskChildData[index].MapID local mapItemId = task.taskChildData[index].MapItemID[1] local type = task.taskChildData[index].ActionType if mapId > 0 and (mapItemId and mapItemId > 0) then if CTL.HotFix.HasLevelPackageDownload(nil, mapId) == false then return end --跨服与本服互相传送前先检测是否符合条件 if not CTL.CrossServer.CheckConveyCondition(mapId) then return end --设置正在自动执行的任务 MDL.Task.DoingTask = task local callback = function () Task_Controller.OnArriveTargetNode(task,mapItemId) end NotSyncBattleSetter.FindPathByLevelItemIDAndRide(mapId, mapItemId, callback, LuaConst.ETownFindPathType.TASK) EventSystem.Dispatch(EventID.UI_Task_SetAuto) elseif type == MDL.Task.Enum_ActionType.Open then -- 打开界面 CTL.Level.TryBreakConveyProgress(LuaConst.ETownFindPathType.TASK) MDL.Task.DoingTask = nil local childData = task.taskChildData[index] CTL.ItemSources.ExecuteSourceFunctionById(tonumber(childData.Factor)) elseif type == MDL.Task.Enum_ActionType.AutoComplete or type == MDL.Task.Enum_ActionType.Consistent then -- 接任务就播动画 local callback = function () Task_Controller.OnArriveTargetNode(task,nil) end NotSyncBattleSetter.FindPathByLevelItemIDAndRide(mapId, nil, callback, LuaConst.ETownFindPathType.TASK) else if Task_Controller.IsTaskComplete(task) then MDL.Task.TaskStateUpdateRequest(task.taskChildData[index],0,0,task_pb.Finish,1) private.CommitTask(task) end end end --单独处理国战悬赏任务 function private.DoCountryWantedTask(task,taskChildData) --没有国家就提示 if MDL.Country.GetMyCountryId() == nil or MDL.Country.GetMyCountryId() == 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_WantedTask_NeedCountry2) return true end local taskFatherID = taskChildData.TaskLineID local taskChildId = taskChildData.TaskChildID local taskWanted = MDL.CountryWantedTask.GetTaskWantedByTaskFatherIDAndChildId(taskFatherID,taskChildId) --多国家任务对话的情况,找对应本国的NPC if taskWanted == nil then local mapId = CTL.CountryWantedTask.GetMyCountryMap() local mapItemId = CTL.CountryWantedTask.GetNpcByMapIdOfTask(taskFatherID,taskChildId,mapId) local callback = function () Task_Controller.OnArriveTargetNode(task,mapItemId) end --执行任务寻路 private.SetTaskForWantedTask(task,mapId,mapItemId,callback) return true end if taskWanted.TaskType == MDL.CountryWantedTask.TaskType.EnemyCountryCollect then --敌国采集 local isInTaskScene,mapItemId = CTL.CountryWantedTask.IsCurrentInEnemyCollectTaskScene(taskChildData.MapItemID) --判断是否在任务的采集物所在场景 if isInTaskScene then local currentMapId = BattleDataGetter.GetCurLevelID() if CTL.CountryWantedTask.CheckTask(currentMapId) then return true end local callback = function () Task_Controller.OnArriveTargetNode(task,mapItemId) CTL.Tips.AddTipsMsg(Const_IDS.IDS_WantedTask_ManualTips) end private.SetTaskForWantedTask(task,currentMapId,mapItemId,callback) else --如果处于中立国,且有目的地,那么继续前往目的地 if CTL.CountryWantedTask.HasDestSceneData() then CTL.CountryWantedTask.OnEnterHanScene() MDL.Task.DoingTask = task EventSystem.Dispatch(EventID.UI_Task_SetAuto) return true end local cellPos = CTL.CountryWantedTask.GetCacheTaskCellPos() if cellPos == nil then return true end MDL.Task.DoingTask = task EventSystem.Dispatch(EventID.UI_Task_SetAuto) local enemyCountryCollectData = CTL.CountryWantedTask.GetEnemyCountryCollectData(taskChildData.MapItemID) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIHomeMain) then UIManager.OpenView(Const_UI_Lua.UIEnum.UITownGotoCountry,{data = enemyCountryCollectData,pos = cellPos ,task = task, taskType = taskWanted.TaskType}) end end return true elseif taskWanted.TaskType == MDL.CountryWantedTask.TaskType.NeutralityCollect then --中立采集 local neutralityCountryMap = CTL.CountryWantedTask.GetNeutralityCountryMap() local currentMapId = BattleDataGetter.GetCurLevelID() --如果当前在中立场景,根据距离找采集物ID,否则,随机一个采集物ID local mapItemId = CTL.CountryWantedTask.GetNeutralityRandomMapItemId(taskChildData.MapItemID) if currentMapId == neutralityCountryMap then mapItemId = CTL.CountryWantedTask.FindNearMapItemIdInSameScene(taskChildData.MapItemID) end if CTL.CountryWantedTask.CheckTask(neutralityCountryMap) then return true end local callback = function () Task_Controller.OnArriveTargetNode(task,mapItemId) CTL.Tips.AddTipsMsg(Const_IDS.IDS_WantedTask_ManualTips) end private.SetTaskForWantedTask(task,neutralityCountryMap,mapItemId,callback) return true elseif taskWanted.TaskType == MDL.CountryWantedTask.TaskType.EnemyCountryPVE then --敌国PVE local isInTaskScene = CTL.CountryWantedTask.IsInEnemyCountryMap() if isInTaskScene then local currentMapId = BattleDataGetter.GetCurLevelID() if CTL.CountryWantedTask.CheckTask(currentMapId) then return true end local mapItemId = CTL.CountryWantedTask.GetNpcByMapIdOfTask(taskFatherID,taskChildId,currentMapId) local callback = function () Task_Controller.OnArriveTargetNode(task,mapItemId) end private.SetTaskForWantedTask(task,currentMapId,mapItemId,callback) else --如果处于中立国,且有目的地,那么继续前往目的地 if CTL.CountryWantedTask.HasDestSceneData() then CTL.CountryWantedTask.OnEnterHanScene() MDL.Task.DoingTask = task EventSystem.Dispatch(EventID.UI_Task_SetAuto) return true end local cellPos = CTL.CountryWantedTask.GetCacheTaskCellPos() if cellPos == nil then return true end MDL.Task.DoingTask = task EventSystem.Dispatch(EventID.UI_Task_SetAuto) local enemyMapData = CTL.CountryWantedTask.GetEnemyCountryMapDataOfTask(taskFatherID,taskChildId) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIHomeMain) then UIManager.OpenView(Const_UI_Lua.UIEnum.UITownGotoCountry,{data = enemyMapData,pos = cellPos ,task = task,taskType = taskWanted.TaskType}) end end return true --elseif taskWanted.TaskType == MDL.CountryWantedTask.TaskType.KillInvasion and taskChildData.ActionType ~= MDL.Task.Enum_ActionType.Story then --击杀来犯(非对话) -- local mapId = CTL.CountryWantedTask.GetMyCountryMap() -- local currentMapId = BattleDataGetter.GetCurLevelID() -- private.CacheMoveToTask(task) -- --玩家不在本国时,传送到本国 -- if mapId ~= currentMapId then -- CTL.Level.StartConveyProgress(mapId) -- end -- return true --策划要求这里不要做特殊处理的跳转,按照配置打开界面,所以走逻辑即可,不用单独处理 end return false end function private.CacheMoveToTask(task) private.moveToTask = task end function Task_Controller.GetMoveToTask() return private.moveToTask end function Task_Controller.ClearMoveToTask() private.moveToTask = nil end function private.SetTaskForWantedTask(task,currentMapId,mapItemId,callback) MDL.Task.DoingTask = task NotSyncBattleSetter.FindPathByLevelItemIDAndRide(currentMapId, mapItemId, callback, LuaConst.ETownFindPathType.TASK) EventSystem.Dispatch(EventID.UI_Task_SetAuto) end function Task_Controller.IsTaskComplete(task) local index = Task_Controller.GetTaskCurDoingData(task) local childTask = task.taskChildData[index] -- 定时完成的任务类型 if childTask.CompleteCondition == 101 or childTask.CompleteCondition == 102 then return task.taskInfo.childInfo[index].autoFinishTime - UTL.Time.GetServerTimestamp() <= 0 end if childTask and not MDL.Unlock.IsComplete(childTask.CompleteCondition,childTask.CompleteConditionParam) then return false end return true end function Task_Controller.OnArriveTargetNode(task,itemId) if BattleDataGetter.CheckMainPlayerHasBuffState(LuaConst.SpecialBuffs.InRiding) then NotSyncBattleSetter.OffHorse() end local entity = BattleDataGetter.GetEntityByLevelItemID(itemId) if not entity then private.DoTaskAction(task,nil,nil) --logging.error(LTAG.ERROR, "Error!! Find No NPC Entity!! NPC ID:", itemId) return end if entity:CheckType(LuaConst.CharacterType.NPC) then EventSystem.Dispatch(entity.Event_EntityVisited,entity,task) else private.DoTaskAction(task,entity,nil) end end --endregion 自动部分 --region -- *************** 采集部分 ***************** -- function private.GetItemIdByNpcId(npcID) local npcData = BattleDataGetter.GetLevelItemByNpcID(npcID) if npcData then return npcData.LevelItemID end end --endregion 采集部分 -- 刷新当前场景里的任务触发器激活状态 function private.ShowLevelItemTrigger() local CurLevelID = LevelManager.GetCurLevelID() -- 当前场景ID local taskTriggers = DataSheetManager.TaskTrigger:GetDataLengthByMapID_TriggerID(CurLevelID) if taskTriggers <= 0 then return end for i,triggerInfo in DataSheetManager.TaskTrigger:GetDataByMapID_TriggerID(CurLevelID) do local isShow = true for i,v in ipairs(triggerInfo.FunctionItemID) do isShow = isShow and MDL.Unlock.IsClientUnlockWithText(v) end local isFinishTask = MDL.Task.GetCompletedTaskByID(triggerInfo.TaskLineID) -- 需判断这个任务是否是做过的或正在做的 if isShow and (not isFinishTask) then local item = BattleDataGetter.GetLevelItemByID(triggerInfo.TriggerID) item:DoAction(LuaConst.LevelActionType.Trigger_Active) end end end -- 任务触发器触发,客户端主动接任务 function private.TaskTriggerReceive(triggerID, entity) local CurLevelID = LevelManager.GetCurLevelID() -- 当前场景ID local isSuccess, triggerInfo = DataSheetManager.TaskTrigger:TryGetDataByMapID_TriggerID(CurLevelID, triggerID) if isSuccess then local item = BattleDataGetter.GetLevelItemByID(triggerID) item:DoAction(LuaConst.LevelActionType.Trigger_Deactive) local isShow = true for i,v in ipairs(triggerInfo.FunctionItemID) do isShow = isShow and MDL.Unlock.IsClientUnlockWithText(v) if not isShow then logging.error(LTAG.ERROR, "DTF : TaskTriggerReceive : 解锁条件不满足,无法触发任务 TaskTrigger.FunctionItemID: ", v) end end local isFinishTask = MDL.Task.GetCompletedTaskByID(triggerInfo.TaskLineID) -- 需判断这个任务是否是做过的或正在做的 if isShow and (not isFinishTask) then MDL.Task.ClientAcceptTaskRequest(triggerInfo.TaskLineID) return end end end function private.OnRandomScenePointActive(levelItemID) local advancedTaskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.AdvancedTreasure) local normalTaskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.NormalTreasure) if advancedTaskList then for taskID, task in pairs(advancedTaskList) do local treasureItem = DataSheetManager.DigTreasurePoint:GetDataByID(task.taskInfo.treasureId) if treasureItem and treasureItem.MapAreaID == levelItemID then Task_Controller.InitTreasureItem(task) end end end if normalTaskList then for taskID, task in pairs(normalTaskList) do local treasureItem = DataSheetManager.DigTreasurePoint:GetDataByID(task.taskInfo.treasureId) if treasureItem and treasureItem.MapAreaID == levelItemID then Task_Controller.InitTreasureItem(task) end end end end function private.OnArriveTreasureTarget(task) NotSyncBattleSetter.OffHorse() local index = Task_Controller.GetTaskCurDoingData(task) local fubenId = DataSheetManager.DigTreasurePoint:GetDataByID(task.taskInfo.treasureId).MirrorCopymap if task.taskChildData[index].ActionType == MDL.Task.Enum_ActionType.EnterFuben then MDL.LevelSelect.EnterFuben(LuaConst.LevelType.DigPlanes, fubenId) elseif task.taskChildData[index].ActionType == MDL.Task.Enum_ActionType.Collection and task.TaskData.Type == MDL.Task.Enum_TaskType.NormalTreasure then CTL.Interact.TryDoFirstInteract(0) elseif task.taskChildData[index].ActionType == MDL.Task.Enum_ActionType.Collection and task.TaskData.Type == MDL.Task.Enum_TaskType.AdvancedTreasure then CTL.Interact.TryDoFirstInteract(1) end end function private.OnTreasureInteractFinish(monsterId) local advancedTaskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.AdvancedTreasure) local normalTaskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.NormalTreasure) if advancedTaskList then for taskID, task in pairs(advancedTaskList) do local params = string.split(task.taskChildData[1].CompleteConditionParam, ";") local taskMonsterId = params[1] and tonumber(params[1]) if taskMonsterId == monsterId then MDL.Task.TaskNpcCollectRequest(monsterId) return end end end if normalTaskList then for taskID, task in pairs(normalTaskList) do local params = string.split(task.taskChildData[1].CompleteConditionParam, ";") local taskMonsterId = params[1] and tonumber(params[1]) if taskMonsterId == monsterId then MDL.Task.TaskNpcCollectRequest(monsterId) return end end end end function Task_Controller.FindTreasureDoor() local taskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.TreasureCave) if taskList and next(taskList) then for k, v in pairs(taskList) do private.StartAutoTask(v) return end else CTL.Tips.AddTipsMsg(Const_IDS.IDS_DigTreasure_CaveTimeOut) end end function Task_Controller.QuickUseNormalTreasure() CTL.Bag.ShowQuickUseItem(normalTreasureItemId, true) end function Task_Controller.QuickUseAdvancedTreasure() CTL.Bag.ShowQuickUseItem(advancedTreasuretemId) end function Task_Controller.OnSyncDigTreasureQuickUse() local itemCount = MDL.Bag.GetItemCount(advancedTreasuretemId) if itemCount > 0 then Task_Controller.QuickUseAdvancedTreasure() else Task_Controller.QuickUseNormalTreasure() end end function private.OnOpenMulDoor(doorId) UIManager.OpenView(Const_UI_Lua.UIEnum.UIDigTreasureIntroduction, { doorId = doorId }) end function private.TreasureShowTips(taskType,taskID) if taskType == MDL.Task.Enum_TaskType.NormalTreasure then for i, v in DataSheetManager.DigTreasureTaskNormal:GetEnumerator() do if not string.isNilOrEmpty(v.FinishTips) then for _, taskId in ipairs(v.NormalTask) do if taskId == taskID then CTL.Tips.AddTipsMsg(Const_IDS[v.FinishTips]) return end end end end end if taskType == MDL.Task.Enum_TaskType.AdvancedTreasure then for i, v in DataSheetManager.DigTreasureTaskAdvance:GetEnumerator() do if not string.isNilOrEmpty(v.FinishTips) then for _, taskId in ipairs(v.AdvanceTask) do if taskId == taskID then CTL.Tips.AddTipsMsg(Const_IDS[v.FinishTips]) return end end end end end end function private.ShowDigTreasureTips() EventSystem.Dispatch(EventID.UI_TownHome_TipsShow, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DigTreasure_RareBox)) end function private.ShowDigTreasureCaveTips() EventSystem.Dispatch(EventID.UI_TownHome_TipsShow, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DigTreasure_FindTreasureCave)) end function private.WantedTaskInteractFinish(uniqId, collectServerDataId) MDL.Task.WantedTaskInteractRequest(uniqId, collectServerDataId) end return Task_Controller