--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by zhangkai. --- DateTime: 2024/9/4 下午2:17 --- KingRoad = {} local this = {} ----章节任务信息 --chapter_task_info{ -- --k:配置的章节(1...5),v:任务池信息 -- chapter = { -- ---章节状态 -- state = ChapterState.UNLOCK, -- task_info = { -- --k:王者之路配置任务id(1001...),v:任务记录 -- taskid = TaskRecord -- } -- }, --} ---章节状态 local ChapterState = { ---已解锁 UNLOCK = 1, ---已完成 FINISH = 2, ---已领取 RECEIVE = 3 } local KingRoadTask = "T$king_road_task" ---王者之路任务数据修复 local KING_ROAD_DATA_REPAIR = "T$king_road_data_repair" local KING_ROAD_DATA_REPAIR_2 = "T$king_road_data_repair_2024_12_27" -- 最小章节 local MinGroup = 1 --全部章节完成 local ALL_FINISH = -1 --function kingroadtasktest(actor) -- -- KingRoad.SubmitChapterTask(actor, 102) -- KingRoad.SendKingRoadTask(actor) --end function this.GetNewKingRoadTask() local KingRoadTaskInfo = { ---当前章节 now_chapter = 0, ---章节任务信息 chapter_task_info = {} } return KingRoadTaskInfo end function KingRoad.Login(actor) RepairRoleData.action(actor, KING_ROAD_DATA_REPAIR, 202412122050, this.RepairKingRoadTask_2024_12_12, actor) RepairRoleData.action(actor, KING_ROAD_DATA_REPAIR_2, 202412271400, this.RepairKingRoadTask_2024_12_27, actor) KingRoad.TryInitKingRoadTask(actor) KingRoad.SendKingRoadTask(actor) end function tryinitkingroadtasktest(actor) KingRoad.TryInitKingRoadTask(actor) end function KingRoad.TryInitKingRoadTask(actor) local init = this.InitNewChapter(actor) if init then KingRoad.SendKingRoadTask(actor) end end function this.SaveKingRoadTask(actor, kingRoadTaskInfo) setplaydef(actor, KingRoadTask, kingRoadTaskInfo) end function this.GetKingRoadTask(actor) local kingRoadTaskInfo = getplaydef(actor, KingRoadTask) if kingRoadTaskInfo == nil then kingRoadTaskInfo = this.GetNewKingRoadTask() end return kingRoadTaskInfo end function this.CheckAllFinish(kingRoadTask) local nextChapter = kingRoadTask.now_chapter + 1 local chapterCfgList = ConfigDataManager.getTable("cfg_king_road", "groupid", nextChapter) if table.isNullOrEmpty(chapterCfgList) then local chapterTaskInfo = kingRoadTask.chapter_task_info local chapterTask = chapterTaskInfo[kingRoadTask.now_chapter] if chapterTask.state == ChapterState.RECEIVE then return true end end return false end function KingRoad.SendKingRoadTask(actor) local kingRoadTask = this.GetKingRoadTask(actor) local allFinish = this.CheckAllFinish(kingRoadTask) if allFinish then kingRoadTask.now_chapter = ALL_FINISH end --jprint("王者之路:", kingRoadTask) sendluamsg(actor, LuaMessageIdToClient.RES_KING_ROAD_TASK_INFO, kingRoadTask) end function this.KingRoadChange(actor, changeTask, chapter, chapterStatus) local chapterTask = { now_chapter = chapter, chapter_state = chapterStatus, change_task = changeTask } sendluamsg(actor, LuaMessageIdToClient.RES_KING_ROAD_TASK_CHANGE, chapterTask) end function this.InitNewChapter(actor) local playerLevel = tonumber(getbaseinfo(actor, "level")) local kingRoadTask = this.GetKingRoadTask(actor) local chapterTaskInfo = kingRoadTask.chapter_task_info local nowChapterTask = chapterTaskInfo[kingRoadTask.now_chapter] --jprint("初始化章节任务:", kingRoadTask) if not table.isNullOrEmpty(nowChapterTask) and nowChapterTask.state ~= ChapterState.RECEIVE then return false end local nextChapter = kingRoadTask.now_chapter + 1 local chapterCfgList = ConfigDataManager.getTable("cfg_king_road", "groupid", nextChapter) --jprint("章节任务配置:", chapterCfgList,nextChapter) if table.isNullOrEmpty(chapterCfgList) then return false end local chapterCfg = chapterCfgList[1] local level = tonumber(chapterCfg["level"]) --jprint("章节任务等级限制:", chapterCfgList,level) if level > playerLevel then return false end local nextChapterTask = this.InitChapterTask(actor, nextChapter) if table.isNullOrEmpty(nextChapterTask) then return false end chapterTaskInfo[nextChapter] = nextChapterTask kingRoadTask.now_chapter = nextChapter kingRoadTask.chapter_task_info = chapterTaskInfo this.SaveKingRoadTask(actor, kingRoadTask) return true end ---初始化章节任务池 function this.InitChapterTask(actor, group) local taskCfgList = ConfigDataManager.getTable("cfg_king_road_task", "group", group) if table.isNullOrEmpty(taskCfgList) then return nil end chapterTask = { state = ChapterState.UNLOCK, task_info = {} } local taskList = chapterTask.task_info --jprint("章节任务池初始:", taskList) for _, taskCfg in pairs(taskCfgList) do --jprint("章节任务配置:", taskCfg) local taskId = tonumber(taskCfg["id"]) local taskTargetId = tonumber(taskCfg["tasktargetid"]) local levelLimit = taskCfg["careerlimit"] local pass = this.CheckCareer(actor, levelLimit) if pass then local taskRecord = TaskHandler.BuildTaskRecord(actor, taskId, taskTargetId) if taskRecord ~= nil then taskList[taskId] = taskRecord end end end if table.isNullOrEmpty(taskList) then return nil end --jprint("章节任务池:", taskList) chapterTask.task_info = taskList return chapterTask end function this.CheckCareer(actor, levelLimit) if string.isNullOrEmpty(levelLimit)then return true end if #levelLimit == 1 and tonumber(levelLimit) == 0 then return true end local baseCareer = tonumber(getbaseinfo(actor, "getbasecareer")) local careerNum = tonumber(getbaseinfo(actor, "getcareernum")) local careerRank = tonumber(getbaseinfo(actor, "getcareerrank")) local limitArray = string.split(levelLimit, "#") local careerLimit = tonumber(limitArray[1]) local numLimit = tonumber(limitArray[2]) local rankLimit = tonumber(limitArray[3]) if baseCareer ~= careerLimit or careerNum ~= numLimit then return false end if careerRank < rankLimit then return false end return true end function KingRoad.FlushKingRoadTask(actor, taskTargetType, param) local success, errorInfo = xpcall(this.FlushKingRoadTask, debug.traceback, actor, taskTargetType, param) gameDebug.assertPrint(success, "王者之路任务目标刷新异常:", actor, taskTargetType, param, errorInfo) end ---刷新任务 function this.FlushKingRoadTask(actor, taskTargetType, param) local kingRoadTask = this.GetKingRoadTask(actor) local nowChapter = kingRoadTask.now_chapter if nowChapter == 0 then return end local chapterTaskInfo = kingRoadTask.chapter_task_info if table.isNullOrEmpty(chapterTaskInfo) then return end -- 当前章节 local chapterTask = chapterTaskInfo[nowChapter] if chapterTask.state >= ChapterState.FINISH or table.isNullOrEmpty(chapterTask) then return end local taskList = chapterTask.task_info local changeTask = this.CheckTaskRecord(actor, taskList, taskTargetType, param) if table.isNullOrEmpty(changeTask) then return end chapterTask.task_info = taskList chapterTaskInfo[nowChapter] = chapterTask kingRoadTask.chapter_task_info = chapterTaskInfo this.SaveKingRoadTask(actor, kingRoadTask) this.KingRoadChange(actor, changeTask, nowChapter, chapterTask.state) end ---检查任务记录 function this.CheckTaskRecord(actor, taskList, taskTargetType, param) local changeTask = {} for taskId, taskRecord in pairs(taskList) do local taskGoal = taskRecord.task_goal local target_id = taskRecord.target_id local goal_count = taskRecord.goal_count local needCount = taskRecord.max_count if taskTargetType == taskGoal and taskRecord.state == TaskHandler.Status.ACCEPT then local count = TaskGoal.FlushTaskCount(actor, taskGoal, target_id, goal_count, param) if count >= needCount then taskRecord.state = TaskHandler.Status.FINISH end if count > goal_count then taskRecord.goal_count = math.min(count, needCount) changeTask[taskId] = taskRecord end end end return changeTask end ---提交任务 function KingRoad.SubmitChapterTask(actor, taskId) jprint("提交任务:", taskId) local kingRoadTask = this.GetKingRoadTask(actor) local nowChapter = kingRoadTask.now_chapter local chapterTaskInfo = kingRoadTask.chapter_task_info if table.isNullOrEmpty(chapterTaskInfo) then noticeTip.noticeinfo(actor, StringIdConst.TEXT405) return end local chapterTask = chapterTaskInfo[nowChapter] if chapterTask.state >= ChapterState.FINISH then tipinfo(actor, "任务已提交") return end local taskList = chapterTask.task_info local taskRecord = taskList[taskId] if taskRecord == nil then noticeTip.noticeinfo(actor, StringIdConst.TEXT355) return end if taskRecord.state == TaskHandler.Status.SUBMIT then tipinfo(actor, "任务已提交") return end if taskRecord.state == TaskHandler.Status.ACCEPT then tipinfo(actor, "任务未完成") return end --发奖励 local rewardCfg = ConfigDataManager.getTableValue("cfg_king_road_task", "rewarditem", "id", taskRecord.task_id) this.SendTaskReward(actor, rewardCfg) taskList[taskId].state = TaskHandler.Status.SUBMIT chapterTask.task_info = taskList --检查章节完成 local chapterFinish = this.CheckChapterFinish(taskList) if chapterFinish then chapterTask.state = ChapterState.FINISH end chapterTaskInfo[nowChapter] = chapterTask kingRoadTask.chapter_task_info = chapterTaskInfo this.SaveKingRoadTask(actor, kingRoadTask) local changeTask = {} changeTask[taskId] = taskRecord this.KingRoadChange(actor, changeTask, nowChapter, chapterTask.state) end function this.SendTaskReward(actor, rewardCfg) if string.isNullOrEmpty(rewardCfg) then --error("奖励未配置") return end local awardMap = {} local itemArray = string.split(rewardCfg, "|") for _, param in pairs(itemArray) do local cfgArray = string.split(param, "#") local itemId = tonumber(cfgArray[1]) local itemNum = tonumber(cfgArray[2]) awardMap[itemId] = itemNum --奖励入包 local itemBing = ConfigDataManager.getTableValue("cfg_bind","bind","id", 4) jprint("首饰任务配置的绑定信息") jprint(itemBing) additemtobag(actor, itemId, itemNum, itemBing,9999,'王者之路') end --奖励弹框 sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, awardMap) end function this.CheckChapterFinish(taskList) for _, taskRecord in pairs(taskList) do if taskRecord.state ~= TaskHandler.Status.SUBMIT then return false end end return true end function KingRoad.ReceiveChapterAward(actor) --jprint("领取章节奖励") local kingRoadTask = this.GetKingRoadTask(actor) local nowChapter = kingRoadTask.now_chapter if nowChapter == 0 then tipinfo(actor, "未解锁") return end local chapterTaskInfo = kingRoadTask.chapter_task_info local chapterTask = chapterTaskInfo[nowChapter] if table.isNullOrEmpty(chapterTask) or chapterTask.state ~= ChapterState.FINISH then tipinfo(actor, "无奖励可领取") return end --发奖励 local rewardCfg = ConfigDataManager.getTableValue("cfg_king_road", "rewarditem", "groupid", nowChapter) this.SendTaskReward(actor, rewardCfg) chapterTask.state = ChapterState.RECEIVE chapterTaskInfo[nowChapter] = chapterTask kingRoadTask.chapter_task_info = chapterTaskInfo this.SaveKingRoadTask(actor, kingRoadTask) --尝试初始化下一章 this.InitNewChapter(actor) KingRoad.SendKingRoadTask(actor) TaskHandler.TriggerTaskGoal(actor, TaskTargetType.JEWELRY_TASK_CHAPTER) end ---获取已完成章节 function KingRoad.GetFinishChapter(actor) local kingRoadTask = this.GetKingRoadTask(actor) if table.isNullOrEmpty(kingRoadTask) then return 0 end local nowChapter = kingRoadTask.now_chapter local chapterTaskInfo = kingRoadTask.chapter_task_info if table.isNullOrEmpty(chapterTaskInfo) then return nowChapter end local chapterTask = chapterTaskInfo[nowChapter] if chapterTask.state == ChapterState.RECEIVE then return nowChapter end return nowChapter - 1 end --GM一键完成章节任务 function gmfinishchaptertask(actor) local kingRoadTask = this.GetKingRoadTask(actor) local nowChapter = kingRoadTask.now_chapter if nowChapter == 0 then return end local chapterTaskInfo = kingRoadTask.chapter_task_info local chapterTask = chapterTaskInfo[nowChapter] if chapterTask.state >= ChapterState.FINISH then return end local taskInfo = chapterTask.task_info for _, taskRecord in pairs(taskInfo) do if taskRecord.state == TaskHandler.Status.ACCEPT then taskRecord.goal_count = taskRecord.max_count taskRecord.state = TaskHandler.Status.FINISH end end chapterTask.task_info = taskInfo chapterTaskInfo[nowChapter] = chapterTask kingRoadTask.chapter_task_info = chapterTaskInfo this.SaveKingRoadTask(actor, kingRoadTask) KingRoad.SendKingRoadTask(actor) end ---修复王者之路任务数据 function this.RepairKingRoadTask_2024_12_12(actor) local kingRoadTaskInfo = this.GetKingRoadTask(actor) if table.isNullOrEmpty(kingRoadTaskInfo) then return end local nowChapter = kingRoadTaskInfo.now_chapter if nowChapter ~= 2 then return end local chapterTaskInfo = kingRoadTaskInfo.chapter_task_info if table.isNullOrEmpty(chapterTaskInfo) then return end local chapterTask = chapterTaskInfo[nowChapter] if table.isNullOrEmpty(chapterTask) then return end if chapterTask.state >= ChapterState.FINISH then return end local newTaskRecord = {} local repairTaskId = 0 local taskList = chapterTask.task_info for taskId, taskRecord in pairs(taskList) do local taskGoal = taskRecord.task_goal if taskGoal == TaskTargetType.TRADE_LINE_UP_GOODS and taskRecord.state == TaskHandler.Status.ACCEPT then newTaskRecord = TaskHandler.BuildTaskRecord(actor,taskId,4000039) if not table.isNullOrEmpty(newTaskRecord) then repairTaskId = taskId end end end if repairTaskId > 0 then taskList[repairTaskId] = newTaskRecord chapterTask.task_info = taskList chapterTaskInfo[nowChapter] = chapterTask kingRoadTaskInfo.chapter_task_info = chapterTaskInfo this.SaveKingRoadTask(actor, kingRoadTaskInfo) jprint("修复玩家王者之路任务数据,4000039 --->",actor, newTaskRecord) end end ---修复王者之路任务数据 function this.RepairKingRoadTask_2024_12_27(actor) local kingRoadTaskInfo = this.GetKingRoadTask(actor) if table.isNullOrEmpty(kingRoadTaskInfo) then return end local nowChapter = kingRoadTaskInfo.now_chapter if nowChapter ~= 3 then return end local chapterTaskInfo = kingRoadTaskInfo.chapter_task_info if table.isNullOrEmpty(chapterTaskInfo) then return end local chapterTask = chapterTaskInfo[nowChapter] if table.isNullOrEmpty(chapterTask) then return end if chapterTask.state >= ChapterState.FINISH then return end local newTaskRecord = {} local repairTaskId = 0 local taskList = chapterTask.task_info for taskId, taskRecord in pairs(taskList) do local taskGoal = taskRecord.task_goal if (taskGoal == TaskTargetType.FINISH_DUPLICATE or taskGoal == TaskTargetType.FLUSH_BRAVE_TEST_LV) and taskRecord.state == TaskHandler.Status.ACCEPT then newTaskRecord = TaskHandler.BuildTaskRecord(actor,taskId,4000040) if not table.isNullOrEmpty(newTaskRecord) then repairTaskId = taskId end end end if repairTaskId > 0 then taskList[repairTaskId] = newTaskRecord chapterTask.task_info = taskList chapterTaskInfo[nowChapter] = chapterTask kingRoadTaskInfo.chapter_task_info = chapterTaskInfo this.SaveKingRoadTask(actor, kingRoadTaskInfo) jprint("修复玩家王者之路勇气试炼任务数据,4000040 --->",actor, newTaskRecord) end end