local EventSystem = require('Event/EventSystem') local Task_Model = {} local private = {} local task_pb = require 'Proto/task_pb' local enums_pb = require("Proto/enums_pb") local dig_treasure_pb = require("Proto/dig_treasure_pb") local wanted_task_pb = require("Proto/wanted_task_pb") --region -- **************** 数据部分 ******************* -- --当前任务列表 local _taskDict = {} --任务章节列表 local _taskLevelDict = {} --完成任务字典 local _completedTaskDict = {} local digTreasureRewardInfo = nil --需要上报分包进度的任务常量: local TASK_FATHER_REPORT_PROGRESS = 200100 local TASK_CHILD_REPORT_PROGRESS = 2 --接取环任务常驻NPC local RingDailyNpcItemID = nil local RingDailyMapID = nil --环任务状态枚举 Task_Model.Enum_RingTaskState = { UnAccepet = 1,--未接取 Doing = 2,--已接取未完成 Done = 3,--达到最大轮数 } --任务状态枚举 Task_Model.Enum_TaskState = { Doing = 1, --进行中 Done = 2, --完成未提交 Finish = 3 , --已结束 Failure = 4, --失败 } --环任务类型枚举 Task_Model.Enum_RingTaskType = { RingDaily = 1, --日常环任务 RingWeekly = 2, --周常环任务 RingGuild = 3, --帮会环任务 } --任务类型枚举 Task_Model.Enum_TaskType = { Major = "Major", --主线 Convoy = "Convoy", --押镖 Branch = "Branch", --支线 RingDaily = "RingDaily", --日常环任务 RingWeekly = "RingWeekly", --周常环任务 RingGuild = "RingGuild", --帮会环任务 Lucky = "Lucky", -- 机缘任务 NormalTreasure = "TreasureNormal", --普通藏宝图任务 AdvancedTreasure = "TreasureAdvance", --高级藏宝图任务 TreasureCave = "TreasureCave", --盗洞限时任务 GoldHeroActivity = "GoldHeroActivity", -- 金将活动——秘闻任务 SuperGoldHero = "SuperGoldHero", -- 彩金将活动——体验关任务 Wanted = "Wanted",--国战悬赏任务 PackageSpecifiedRingTask = "PackageSpecifiedRingTask",--分包下载任务 } --行为类型枚举 Task_Model.Enum_ActionType = { Story = "Story", -- 对话 Show = "Show", -- 播放剧情动画 Collection = "Collection", -- 采集 OnGoing = "OnGoing", -- TaskChoose = "TaskChoose", -- 选择后进入不同任务分支 PlayAnimation = "PlayAnimation", -- 播放动画、动作、固定地点 WaitTime = "WaitTime", -- EnterFuben = "EnterFuben", -- 进入副本 Open = "Open", -- 打开界面 PlayMovie = "PlayMovie", -- 播放视频 AutoComplete = "AutoComplete", -- 接任务就自动播放视频 Consistent = "Consistent", -- 播TL且打开选择界面 } Task_Model.Enum_Condition = { ChangeMap = 1, ChangeMirrorMap = 2, ChangeAvatar = 3, RecoverAvatar = 4, } --任务类型排序表 Task_Model.List_TaskType = { "Major", "Convoy", "RingDaily", "Branch", "Lucky", "TreasureNormal", "TreasureAdvance", "TreasureCave", "GoldHeroActivity", "SuperGoldHero", "Wanted", "PackageSpecifiedRingTask" } --endregion 数据部分 function Task_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageTaskCommit, private.TaskCommitResponse) NetManager.RegisterMsgCB(MessageEnums.MessageTaskStateUpdate, private.TaskStateUpdateResponse) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushTaskUpdate,private.G2CPushTaskUpdateResponse) NetManager.RegisterMsgCB(MessageEnums.MessageAcceptRingTask,private.AcceptRingTaskResponse) --NetManager.RegisterMsgCB(MessageEnums.MessageGetRingTaskNum,private.GetRingTaskNumResponse) NetManager.RegisterMsgCB(MessageEnums.MessageTaskClientTimeFinish,private.TaskClientTimeFinishResponse) NetManager.RegisterMsgCB(MessageEnums.MessageClientAcceptTask, private.ClientAcceptTaskResponse) -- 客户端主动接任务 NetManager.RegisterMsgCB(MessageEnums.MessageClientQuitTask, private.ClientQuitTaskResponse) -- 客户端主动放弃任务 NetManager.RegisterMsgCB(MessageEnums.MessageQuickFinishChapterTask, private.QuickFinishChapterTaskResponse) NetManager.RegisterMsgCB(MessageEnums.MessageG2CPushTaskDelete, private.PushTaskDelete) NetManager.RegisterMsgCB(MessageEnums.MessageDigTreasureEnter, private.OnDigTreasureEnter) NetManager.RegisterMsgCB(MessageEnums.MessageChangeDigTreasureSwitch, private.ChangeDigTreasureSwitchRsp) NetManager.RegisterMsgCB(MessageEnums.MessageWantedTaskCollection, private.OnWantedTaskCollectionResp) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.RefreshTreasurePicRedPoint) EventSystem.Regist(EventID.UI_Activity_Refresh_Active, private.RefreshTreasurePicRedPoint) end --region -- **************** 数据获取 ******************* - --获取NPC挂载的任务 function Task_Model.GetTaskByNpc(npcID) for taskType,taskList in pairs(_taskDict) do for taskID,task in pairs(taskList) do for k,v in pairs(task.taskChildData) do local itemIDs = v.MapItemID for _,itemId in ipairs(itemIDs) do local id --悬赏任务需要特殊处理 if CTL.CountryWantedTask.CheckNpcIsWantedTaskPanel(task.TaskData.Type,npcID) then id = 0 elseif CTL.CountryWantedTask.CheckNpcIsWantedTask(v,task.TaskData.Type,npcID) then return task, k else id = private.GetNpcId(v.MapID, itemId) end if id == npcID and task.taskInfo.childInfo[k].taskState == Task_Model.Enum_TaskState.Doing then return task, k end end end end end return nil end --NPC显隐:是否跟当前的任务有关 function Task_Model.IsNPCRelatedTask(npcID) for taskType,taskList in pairs(_taskDict) do for taskID,task in pairs(taskList) do for k,v in pairs(task.taskChildData) do local itemIDs = v.MapItemID for _,itemId in ipairs(itemIDs) do if task.taskInfo.childInfo[k].taskState == Task_Model.Enum_TaskState.Doing then local id = 0 if v.MapID > 0 then id = private.GetNpcId(v.MapID, itemId) end if id == npcID then return true end end end for _,id in ipairs(v.NPCID) do if id == npcID then return true end end end end end return false end --获取当前需要变换天气的task function Task_Model.GetWeatherChangedInfo() for taskType,taskList in pairs(_taskDict) do for taskID,task in pairs(taskList) do for k,v in pairs(task.taskChildData) do local taskState = task.taskInfo.childInfo[k].taskState if taskState == Task_Model.Enum_TaskState.Doing and #v.WeatherID > 0 then return v.WeatherID end end end end return nil end function private.GetNpcId(levelID, levelItemID) return BattleDataGetter.GetNpcIdByLevelItemInfo(levelID,levelItemID) end --公有获取任务列表 function Task_Model.GetTaskList(taskType) return _taskDict[taskType] end function Task_Model.GetAllTasks() return _taskDict end function Task_Model.GetTaskCountByType(taskType) local taskList = _taskDict[taskType] if taskList then return table.getDictCount(taskList) else return 0 end end --公有获取任务数据 function Task_Model.GetTask(taskID) local taskData = DataSheetManager.TaskFatherData:GetDataByID(taskID) if taskData then local taskList = Task_Model.GetTaskList(taskData.Type) -- logging.log(LTAG.XuQian,taskID,taskList,taskData.Type) -- for k,v in pairs(_taskDict) do -- for i,j in pairs(v) do -- logging.log(LTAG.XuQian,k,taskData.Type) -- end -- end if taskList then return taskList[taskID] end end return nil end --公有获取任务章节列表 function Task_Model.Level_GetTaskSheetList(taskType) return _taskLevelDict[taskType] end function Task_Model.GetCompletedTask() return _completedTaskDict end --公有获取完成过的任务数据 function Task_Model.GetCompletedTaskByID(taskID) return _completedTaskDict[taskID] end function Task_Model.GetTaskByCollectionItemID(id) for taskType,taskList in pairs(_taskDict) do for taskID,task in pairs(taskList) do for k,v in pairs(task.taskChildData) do if v.MapID == BattleDataGetter.GetLevelInfoData().LevelID then local itemIDs =v.MapItemID for _,itemId in ipairs(itemIDs) do if itemId == id and task.taskInfo.childInfo[k].taskState == Task_Model.Enum_TaskState.Doing then return task.taskInfo.childInfo[k] end end end end end end end -- 获取隔日完成的任务倒计时 function Task_Model.GetCountdown() local haveCountdown, countdown, taskInfo = false, 0, nil for taskType,taskList in pairs(_taskDict) do for taskID,task in pairs(taskList) do for k,v in pairs(task.taskChildData) do local endTime = task.taskInfo.childInfo[k].autoFinishTime if v.CompleteCondition == 101 and task.taskInfo.childInfo[k].taskState == Task_Model.Enum_TaskState.Doing and endTime > 0 and endTime > countdown then haveCountdown = true countdown = endTime taskInfo = task.taskInfo end end end end if haveCountdown then countdown = countdown - UTL.Time.GetServerTimestamp() end return haveCountdown, countdown, taskInfo end --endregion 数据获取 --region -- **************** 私有数据获取 ******************* - function private.SetCompletedTask(finishedTasks, doingChildTasks) if finishedTasks then for i, v in ipairs(finishedTasks) do for key, value in DataSheetManager.TaskChildData:GetDataByTaskLineID_TaskChildID(v) do _completedTaskDict[v] = value.TaskChildID end end end for i = 1, #doingChildTasks do if #doingChildTasks[i].childInfo == 1 then local preTaskId = doingChildTasks[i].childInfo[1].taskChildId - 1 _completedTaskDict[doingChildTasks[i].taskMainId] = preTaskId local isSuccess, taskChildData = preTaskId > 0 and DataSheetManager.TaskChildData:TryGetDataByTaskLineID_TaskChildID(doingChildTasks[i].taskMainId, preTaskId) if isSuccess then private.RemoveTaskData(doingChildTasks[i].taskMainId) end end end end --私有获取任务,没有就new一个 function private.GetTask(taskData) local taskType = taskData.Type local taskID = taskData.ID local taskList = _taskDict[taskType] if not taskList then taskList = {} _taskDict[taskType] = taskList end local task = taskList[taskID] if not task then task = {} task.TaskData = taskData if taskData.RewardItemID > 0 then task.ItemData = DataSheetManager.ItemData:GetDataByID(taskData.RewardItemID) end taskList[taskID] = task end return task end --私有获取任务篇列表,没有就new一个 function private.Level_GetSheetList(taskType) local sheetList = _taskLevelDict[taskType] if not sheetList then sheetList = {} _taskLevelDict[taskType] = sheetList end return sheetList end --私有获取任务篇,没有就new一个 function private.Level_GetTaskSheet(sheetList, sheetID) local sheet = sheetList[sheetID] if not sheet then sheet = {} local isSuccess, taskSheetData = DataSheetManager.TaskSheetData:TryGetDataByID(sheetID) sheet.SheetData = isSuccess and taskSheetData sheet.List = {} sheetList[sheetID] = sheet end return sheet end --私有获取任务章,没有就new一个 function private.Level_GetTaskChapter(sheet, chapterData,init) local chapter for i, v in ipairs(sheet.List) do if v.ChapterData.ID == chapterData.ID then chapter = v break end end if not chapter then chapter = {} chapter.ChapterData = chapterData table.insert(sheet.List,chapter) end return chapter end --endregion 私有数据获取 --region -- **************** 数据操作 ******************* -- function private.GetTaskState(taskInfo) local haveDoneState = false local haveDoingState = false local havaFinishState = false local havaFailureState = false for i,v in ipairs(taskInfo.childInfo) do if v.taskState == Task_Model.Enum_TaskState.Done then haveDoneState = true elseif v.taskState == Task_Model.Enum_TaskState.Doing then haveDoingState = true elseif v.taskState == Task_Model.Enum_TaskState.Finish then havaFinishState =true elseif v.taskState == Task_Model.Enum_TaskState.Failure then havaFailureState = true end end if havaFailureState then return Task_Model.Enum_TaskState.Failure elseif haveDoneState then return Task_Model.Enum_TaskState.Done elseif haveDoingState then return Task_Model.Enum_TaskState.Doing elseif havaFinishState then return Task_Model.Enum_TaskState.Finish end end ---将task信息组合到变了task里 其中taskinfo是服务器的信息 State是任务阶段 taskChildData是这个任务的子任务信息(数组 支持多个子任务一起显示还是分开显示) --TaskData是任务表父任务数据 ItemData 是奖励数据 function private.SetTaskData(taskInfo,init) local taskID = taskInfo.taskMainId local taskData = DataSheetManager.TaskFatherData:GetDataByID(taskID) if not taskData then logging.error(LTAG.ERROR, "No Task Father Data with ID : ", taskID) return end local task = private.GetTask(taskData) task.State = private.GetTaskState(taskInfo) if task.taskChildData == nil then task.taskChildData = {} task.IsRefresh = false else table.clearArray(task.taskChildData) if task.State == Task_Model.Enum_TaskState.Doing then task.IsRefresh = true else task.IsRefresh = false end end local serverChildInfo = taskInfo.childInfo[1] for _,info in DataSheetManager.TaskChildData:GetDataByTaskLineID_TaskChildID(taskID) do if (taskData.IsOrder and serverChildInfo.taskChildId == info.TaskChildID) or not taskData.IsOrder then table.insert( task.taskChildData,info) end end local isAuto = false --是否自动做下个任务 if init or serverChildInfo.process.param == 1 then else local taskChildData = task.taskChildData[1] if taskChildData and taskChildData.AutoFinish == 1 then isAuto = true end end --日常环任务进度 if taskData.Type == Task_Model.Enum_TaskType.RingDaily then if not Task_Model.CurRingDailyNum or Task_Model.CurRingDailyNum == 0 then isAuto = false end Task_Model.CurRingDailyNum = taskInfo.RingTaskProgress local dailyRingConfig = DataSheetManager.RingTaskRefresh:GetDataByID(Task_Model.Enum_RingTaskType.RingDaily) if Task_Model.CurRingDailyNum == dailyRingConfig.TimesNum then --环任务数量满 private.FinalRingTaskID = taskID else private.FinalRingTaskID = nil end elseif taskData.Type == Task_Model.Enum_TaskType.PackageSpecifiedRingTask then isAuto = true end task.taskInfo = taskInfo private.Level_SetTask(task,init) EventSystem.Dispatch(EventID.Task_ChangeWeather) CTL.Task.OnChildTaskStart(task, init) if not init then if isAuto then if LevelManager.IsTown then if taskData.Type ~= Task_Model.Enum_TaskType.RingDaily or MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.RingTaskAuto) then CTL.Task.DoTask(task) end else Task_Model.DoingTask = task end end -- 如果不是初始化,并且Task 为押镖任务,并且状态为doing 则派发截取押镖任务事件 由押镖模块处理 if taskData.Type == Task_Model.Enum_TaskType.Convoy and task.State == Task_Model.Enum_TaskState.Doing then UIManager.CloseView(Const_UI_Lua.UIEnum.UIGuildEscortMatchPanel) end end local childIndex = CTL.Task.GetTaskCurDoingData(task) local actionType = task.taskChildData[childIndex].ActionType if actionType == MDL.Task.Enum_ActionType.AutoComplete or actionType == MDL.Task.Enum_ActionType.Consistent then -- 自动播动画 CTL.Task.DoTask(task) end end function private.RemoveTaskData(taskID) local taskData = DataSheetManager.TaskFatherData:GetDataByID(taskID) local taskList =Task_Model.GetTaskList(taskData.Type) if taskList and taskList[taskID] then local preChildData = taskList[taskID].taskChildData local task = taskList[taskID] taskList[taskID] = nil CTL.Task.OnChildTaskFinish(preChildData[#preChildData], task) -- 如果放弃的是押镖任务,则需要同时停止跟随 if taskData.Type == Task_Model.Enum_TaskType.Convoy then BattleDataGetter.StopFollowNPC(true) end end end function private.Level_SetFinishedTask(taskID, init) local taskData = DataSheetManager.TaskFatherData:GetDataByID(taskID) if taskData == nil then logging.error(LTAG.ERROR,"问策划,为啥TaskFatherData 表里找不到ID",taskID) end local taskType = taskData.Type if taskType == Task_Model.Enum_TaskType.Major then -- 主线 local sheetList = private.Level_GetSheetList(taskType) local chapterData = DataSheetManager.TaskChapterData:GetDataByID(taskData.BelongToChapter) if not chapterData then --logging.error(LTAG.ERROR, "No Task Chapter Data with TaskLineID : ", taskID) return end local sheet = private.Level_GetTaskSheet(sheetList,chapterData.SheetID) local chapter = private.Level_GetTaskChapter(sheet,chapterData,init) chapter.Task = nil elseif taskType == Task_Model.Enum_TaskType.Branch then -- 支线 if not init then local sheetList = private.Level_GetSheetList(taskType) local sheet = private.Level_GetTaskSheet(sheetList,taskData.BelongToSheet) private.Level_RemoveTask(sheet,taskData) end elseif taskType == Task_Model.Enum_TaskType.PackageSpecifiedRingTask then -- 分包跑腿任务 CTL.HotFix.TryOpenPack2Tips() elseif taskType == Task_Model.Enum_TaskType.RingDaily then -- 日常环任务 if not init and private.FinalRingTaskID then if private.FinalRingTaskID == taskID then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Task_RingDaily_OneRound"]) Task_Model.CurRingDailyNum = nil end end elseif taskType == Task_Model.Enum_TaskType.NormalTreasure or taskType == Task_Model.Enum_TaskType.AdvancedTreasure then if not init then local isAuto = string.isNilOrEmpty(taskData.NextTaskControkID) if not isAuto then isAuto = tonumber(taskData.NextTaskControkID) if isAuto then isAuto = isAuto <= 0 end end if isAuto then CTL.Task.OnTreasureTaskFinish(taskType,taskID) end end end end function private.Level_SetTask(task,init) local taskData = task.TaskData local taskType = taskData.Type local sheetList = private.Level_GetSheetList(taskType) if taskType == Task_Model.Enum_TaskType.Major then -- 主线 if taskData.BelongToChapter == 0 then return end local chapterData = DataSheetManager.TaskChapterData:GetDataByID(taskData.BelongToChapter) local sheet = private.Level_GetTaskSheet(sheetList,chapterData.SheetID) local chapter = private.Level_GetTaskChapter(sheet,chapterData,init) chapter.Task = task elseif taskType == Task_Model.Enum_TaskType.Branch then -- 支线 local sheet = private.Level_GetTaskSheet(sheetList,taskData.BelongToSheet) local found for i, v in ipairs(sheet.List) do if v == task then found = true break end end if not found then table.insert(sheet.List,task) end end end function private.Level_RemoveTask(sheet, taskData) local list = sheet.List local i, max = 1, #list while i <= max do local task = list[i] if task.TaskData.ID == taskData.ID then table.remove(list,i) break end i = i + 1 end end function private.Level_SortTask() local type = Task_Model.Enum_TaskType.Major -- 主线任务 local sheetList = _taskLevelDict[type] if sheetList then for i, sheet in ipairs(sheetList) do table.sort(sheet.List,private.SortByChapterID) end end end function private.SortByChapterID(a,b) return a.ChapterData.ID < b.ChapterData.ID end function Task_Model.SetRingRound(ringTaskNum) if ringTaskNum then for i = 1, #ringTaskNum do if ringTaskNum[i].type == Task_Model.Enum_RingTaskType.RingDaily then Task_Model.CurRingDailyRound = ringTaskNum[i].AcceptRingTaskRoundNum if Task_Model.CurRingDailyRound>0 then BIManager.DispatchBIClientEvent(BIManager.EventName.FinishRingTask) end break end end end end function Task_Model.GetDailyRingTaskState() local dailyRingConfig = DataSheetManager.RingTaskRefresh:GetDataByID(Task_Model.Enum_RingTaskType.RingDaily) if Task_Model.CurRingDailyNum == nil then if (Task_Model.CurRingDailyRound == nil or (Task_Model.CurRingDailyRound and Task_Model.CurRingDailyRound < dailyRingConfig.RoundNum)) then return Task_Model.Enum_RingTaskState.UnAccepet else return Task_Model.Enum_RingTaskState.Done end else return Task_Model.Enum_RingTaskState.Doing end end function Task_Model.GetDailyRingTaskDialogueID(npcItemId) if npcItemId == Task_Model.AcceptDailyRingTaskNPCId() then local state = Task_Model.GetDailyRingTaskState() if(state == Task_Model.Enum_RingTaskState.UnAccepet)then return "Normal_RingDaily_Get" elseif(state == Task_Model.Enum_RingTaskState.Doing)then return "Normal_RingDaily_Doing" else return "Normal_RingDaily_Finish" end end return nil end function Task_Model.AcceptDailyRingTaskNPCId() if RingDailyNpcItemID == nil then local dailyRingActivityConfig = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.RingDaily) local __, levelCfgReplaceData = DataSheetManager.LevelCfgReplace:TryGetDataByReplaceID_ReplaceType(dailyRingActivityConfig.NPCItemID, LuaConst.LevelCfgReplaceType.LevelItem) if levelCfgReplaceData and MDL.Unlock.IsComplete(levelCfgReplaceData.Condition, levelCfgReplaceData.ConditionParam) then RingDailyNpcItemID = levelCfgReplaceData.ReplaceTarget else RingDailyNpcItemID = dailyRingActivityConfig.NPCItemID end end return RingDailyNpcItemID end function Task_Model.AcceptDailyRingTaskMapId() if RingDailyMapID == nil then local dailyRingActivityConfig = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.RingDaily) local __, levelCfgReplaceData = DataSheetManager.LevelCfgReplace:TryGetDataByReplaceID_ReplaceType(dailyRingActivityConfig.MapID, LuaConst.LevelCfgReplaceType.Level) if levelCfgReplaceData and MDL.Unlock.IsComplete(levelCfgReplaceData.Condition, levelCfgReplaceData.ConditionParam) then RingDailyMapID = levelCfgReplaceData.ReplaceTarget else RingDailyMapID = dailyRingActivityConfig.MapID end end return RingDailyMapID end --获取环任务进度 --返回当前环数,总环数 function Task_Model.GetRingTaskProgress(taskType) if taskType == MDL.Task.Enum_RingTaskType.RingDaily then local dailyRingConfig = DataSheetManager.RingTaskRefresh:GetDataByID(Task_Model.Enum_RingTaskType.RingDaily) local perRoundTimes = dailyRingConfig.TimesNum --每一轮的环数 local totalRound = dailyRingConfig.RoundNum --总轮数 local totalTimes = perRoundTimes * totalRound --总环数 --当前轮数,只要接取了就更改为对应轮数,比如接取了第一个任务,当前轮数就从0变为1 local curRound = Task_Model.CurRingDailyRound or 0 --当前环数,做的时候只可能为1~10,未接取或者做完为nil或者0 local curTimes = Task_Model.CurRingDailyNum or 0 --跨天,轮数为0但是环数不清0,继续累积,直到做完后,接取当天新环数,轮数才更改为1 if curRound == 0 and curTimes > 0 then --当前环数为总环数加上前一天剩余的环数 return totalTimes + (perRoundTimes - curTimes) + 1 , totalTimes end --尚未接取 if curRound == 0 then return totalTimes,totalTimes end local hasDoneRingNums = (curRound - 1) * perRoundTimes + curTimes - 1 --已经做过的环数 if hasDoneRingNums >= 0 then return totalTimes - hasDoneRingNums , totalTimes else return 0, totalTimes end end end function Task_Model.SetTreasureRewardInfo(data) digTreasureRewardInfo = data private.RefreshTreasurePicRedPoint() end function private.RefreshTreasurePicRedPoint() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.TreasurePic) and not CTL.Activities.IsDone(LuaConst.ActivityType.TreasurePic) then EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.TreasurePic, true) else EventSystem.Dispatch(EventID.UI_Activity_Refresh_Single_RedPoint, LuaConst.ActivityType.TreasurePic, false) end end function Task_Model.GetTreasureRewardInfo() return digTreasureRewardInfo end --endregion 数据操作 --region -- **************** 协议部分 ******************* -- 登录后初始化任务信息 function Task_Model.InitTaskInfo(finishedTasks,doingChildTasks,unCommitChildTasks) if finishedTasks then private.SetCompletedTask(finishedTasks, doingChildTasks) for i = 1, #finishedTasks do private.Level_SetFinishedTask(finishedTasks[i],true) end end private.Level_SortTask() for i = 1, #doingChildTasks do local taskInfo = doingChildTasks[i] private.SetTaskData(taskInfo,true) end CTL.Task.OnInitTaskList(doingChildTasks) end -- 客户端任务对话或任务收集req function Task_Model.TaskStateUpdateRequest(childTask,levelID,levelItemID,type,chooseValue) logging.log(LTAG.LOG, "MessageTaskStateUpdateReq", levelID,levelItemID) local msg = task_pb.TaskStateUpdateReq() msg.taskUniqueId.taskMainID = childTask.TaskLineID msg.taskUniqueId.taskChildID = childTask.TaskChildID msg.MapId = levelID msg.ItemId = levelItemID msg.typ = type msg.TaskChoose = chooseValue logging.log(LTAG.LOG, MessageEnums.MessageTaskStateUpdate,msg) NetManager.SendMessage(MessageEnums.MessageTaskStateUpdate, msg) end function private.TaskStateUpdateResponse(msgResp) logging.log(LTAG.LOG, "MessageTaskStateUpdateResp", msgResp) end -- 手动提交任务 function Task_Model.TaskCommitRequest(id,childId) logging.log(LTAG.LOG, "MessageTaskCommitReq", id,childId) local msg = task_pb.TaskCommitReq() msg.taskChildId.taskMainID = id msg.taskChildId.taskChildID = childId logging.log(LTAG.LOG, MessageEnums.MessageTaskCommit) NetManager.SendMessage(MessageEnums.MessageTaskCommit, msg) end function private.TaskCommitResponse(msgResp) logging.log(LTAG.LOG, "MessageTaskCommitResp", msgResp) end -- 任务npc采集 function Task_Model.TaskNpcCollectRequest(collectId) local msg = task_pb.C2GTaskNpcCollect() msg.collectId = collectId NetManager.SendMessage(MessageEnums.MessageC2GTaskNpcCollect,msg) end -- 悬赏任务npc交互完毕 function Task_Model.WantedTaskInteractRequest(uniqId, collectServerDataId) local msg = wanted_task_pb.WantedTaskCollectionReq() msg.uniqId = uniqId msg.collectServerDataId = collectServerDataId NetManager.SendMessage(MessageEnums.MessageWantedTaskCollection,msg) end function private.OnWantedTaskCollectionResp(msgResp) if msgResp.Resp.Code ~= 0 then --采集不正常 logging.error(LTAG.ERROR, "WantedTaskCollectionResp error", msgResp.Resp.Code) end end -- 任务变化时,服务器主动推给客户端,只有变化的信息 function private.G2CPushTaskUpdateResponse(msgResp) logging.log(LTAG.LOG, "MessagePushTaskUpdateResp", msgResp) local updateTasks = msgResp.updateTaskInfo private.SetCompletedTask(updateTasks.finishedTaskLine, updateTasks.doingTasks) for _,taskID in ipairs(updateTasks.finishedTaskLine) do private.RemoveTaskData(taskID) private.Level_SetFinishedTask(taskID) end for _, taskInfo in ipairs(updateTasks.doingTasks) do CTL.Task.StartTask(taskInfo) private.SetTaskData(taskInfo) end EventSystem.Dispatch(EventID.UI_Task_Update) EventSystem.Dispatch(EventID.ChildTaskFinish) local moveToTask = CTL.Task.GetMoveToTask() if moveToTask then EventSystem.Dispatch(EventID.UI_Task_MoveTo,moveToTask) CTL.Task.ClearMoveToTask() end private.TryReportPackProgress() end function private.TryReportPackProgress() local task = Task_Model.GetTask(TASK_FATHER_REPORT_PROGRESS) if task then for i, v in ipairs(task.taskInfo.childInfo) do if v.taskChildId == TASK_CHILD_REPORT_PROGRESS and v.taskState == Task_Model.Enum_TaskState.Doing then --接受该任务时,上报分包下载情况 BIManager.ReportPackProgress(CTL.HotFix.GetPackProgress()) break end end end end -- 任务重置 function Task_Model.ResetTaskRequest(taskId) UTL.MessageBox.ShowOKCancelBox(nil,Const_IDS.IDS_TaskRepickup,function() local msg = task_pb.C2GTaskReset() msg.taskMainID = taskId NetManager.SendMessage(MessageEnums.MessageC2GTaskReset,msg) end, nil) end function Task_Model.TimeoutTaskRequest(taskId,childId) if Task_Model.GetTask(taskId) then local msg = task_pb.C2GTaskTimeout() msg.taskId.taskMainID = taskId msg.taskId.taskChildID = childId NetManager.SendMessage(MessageEnums.MessageC2GTaskTimeout,msg) end end --接取环任务 function Task_Model.AcceptRingTaskRequest(taskType) logging.log(LTAG.LOG, "AcceptRingTaskRequest", taskType) local msg = task_pb.AcceptRingTaskReq() msg.RingTaskType = taskType NetManager.SendMessage(MessageEnums.MessageAcceptRingTask,msg) end function private.AcceptRingTaskResponse(msgResp) logging.log(LTAG.LOG, "AcceptRingTaskResponse", msgResp) end -- 刷新已领取任务的状态(间隔XX时间后可提交这种就需要刷新) function Task_Model.TaskClientTimeFinishRequest(taskId, childId) logging.log(LTAG.LOG, "TaskClientTimeFinishRequest", taskId, childId) local msg = task_pb.TaskClientTimeFinishReq() msg.taskChildId.taskMainID = taskId msg.taskChildId.taskChildID = childId NetManager.SendMessage(MessageEnums.MessageTaskClientTimeFinish,msg) end -- 服务器会发来两条response -- G2CPushTaskUpdateResponse这个会刷新任务状态 -- TaskClientTimeFinishResponse现在是空函数,为以后预留 function private.TaskClientTimeFinishResponse(msgResp) logging.log(LTAG.LOG, "TaskClientTimeFinishResponse", msgResp) end -- 客户端主动接任务 function Task_Model.ClientAcceptTaskRequest(taskLineId) local msg = task_pb.ClientAcceptTaskReq() msg.taskLineId = taskLineId NetManager.SendMessage(MessageEnums.MessageClientAcceptTask, msg) end function private.ClientAcceptTaskResponse(msgResp) logging.log(LTAG.LOG, "ClientAcceptTaskResponse", msgResp) EventSystem.Dispatch(EventID.UI_Task_AcceptTask) end -- 客户端主动放弃任务 function Task_Model.ClientQuitTaskRequest(taskLineId) local msg = task_pb.ClientQuitTaskReq() msg.taskLineId = taskLineId NetManager.SendMessage(MessageEnums.MessageClientQuitTask, msg) end function private.ClientQuitTaskResponse(msgResp) logging.log(LTAG.LOG, "ClientQuitTaskResponse", msgResp) end -- 快速完成当前任务线对应的章节的所有主线任务 function Task_Model.QuickFinishChapterTaskReq(taskLineId) local msg = task_pb.QuickFinishChapterTaskReq() msg.taskLineId = taskLineId NetManager.SendMessage(MessageEnums.MessageQuickFinishChapterTask, msg) end function private.QuickFinishChapterTaskResponse(msgResp) if Task_Model.DoingTask then if Task_Model.DoingTask.TaskData.Type == Task_Model.Enum_TaskType.Major then NotSyncBattleSetter.StopAutoFightPathInTown() --停止现在的寻路 end end end function Task_Model.DigTreasureEnterReq(uniqId) local msg = dig_treasure_pb.DigTreasureEnterReq() msg.uniqId = uniqId logging.log(LTAG.LOG," DigTreasureEnterReq ") NetManager.SendMessage(MessageEnums.MessageDigTreasureEnter, msg) end function Task_Model.ChangeDigTreasureSwitchReq(state) local msg = dig_treasure_pb.ChangeDigTreasureSwitchReq() msg.open = state NetManager.SendMessage(MessageEnums.MessageChangeDigTreasureSwitch, msg) end function private.ChangeDigTreasureSwitchRsp(msgResp) Task_Model.SetTreasureRewardInfo(msgResp.Resp.PlayerChange.digTreasureRewardInfo) EventSystem.Dispatch(EventID.DigTreasure_RefreshSwitchState) end function private.PushTaskDelete(msgResp) private.RemoveTaskData(msgResp.taskLineId) private.Level_SetFinishedTask(msgResp.taskLineId) EventSystem.Dispatch(EventID.UI_Task_Update) EventSystem.Dispatch(EventID.ChildTaskFinish) end function private.OnDigTreasureEnter(msgResp) end --endregion 协议部分 return Task_Model