KingRoad.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by zhangkai.
  4. --- DateTime: 2024/9/4 下午2:17
  5. ---
  6. KingRoad = {}
  7. local this = {}
  8. ----章节任务信息
  9. --chapter_task_info{
  10. -- --k:配置的章节(1...5),v:任务池信息
  11. -- chapter = {
  12. -- ---章节状态
  13. -- state = ChapterState.UNLOCK,
  14. -- task_info = {
  15. -- --k:王者之路配置任务id(1001...),v:任务记录
  16. -- taskid = TaskRecord
  17. -- }
  18. -- },
  19. --}
  20. ---章节状态
  21. local ChapterState = {
  22. ---已解锁
  23. UNLOCK = 1,
  24. ---已完成
  25. FINISH = 2,
  26. ---已领取
  27. RECEIVE = 3
  28. }
  29. local KingRoadTask = "T$king_road_task"
  30. ---王者之路任务数据修复
  31. local KING_ROAD_DATA_REPAIR = "T$king_road_data_repair"
  32. local KING_ROAD_DATA_REPAIR_2 = "T$king_road_data_repair_2024_12_27"
  33. -- 最小章节
  34. local MinGroup = 1
  35. --全部章节完成
  36. local ALL_FINISH = -1
  37. --function kingroadtasktest(actor)
  38. --
  39. -- KingRoad.SubmitChapterTask(actor, 102)
  40. -- KingRoad.SendKingRoadTask(actor)
  41. --end
  42. function this.GetNewKingRoadTask()
  43. local KingRoadTaskInfo = {
  44. ---当前章节
  45. now_chapter = 0,
  46. ---章节任务信息
  47. chapter_task_info = {}
  48. }
  49. return KingRoadTaskInfo
  50. end
  51. function KingRoad.Login(actor)
  52. RepairRoleData.action(actor, KING_ROAD_DATA_REPAIR, 202412122050, this.RepairKingRoadTask_2024_12_12, actor)
  53. RepairRoleData.action(actor, KING_ROAD_DATA_REPAIR_2, 202412271400, this.RepairKingRoadTask_2024_12_27, actor)
  54. KingRoad.TryInitKingRoadTask(actor)
  55. KingRoad.SendKingRoadTask(actor)
  56. end
  57. function tryinitkingroadtasktest(actor)
  58. KingRoad.TryInitKingRoadTask(actor)
  59. end
  60. function KingRoad.TryInitKingRoadTask(actor)
  61. local init = this.InitNewChapter(actor)
  62. if init then
  63. KingRoad.SendKingRoadTask(actor)
  64. end
  65. end
  66. function this.SaveKingRoadTask(actor, kingRoadTaskInfo)
  67. setplaydef(actor, KingRoadTask, kingRoadTaskInfo)
  68. end
  69. function this.GetKingRoadTask(actor)
  70. local kingRoadTaskInfo = getplaydef(actor, KingRoadTask)
  71. if kingRoadTaskInfo == nil then
  72. kingRoadTaskInfo = this.GetNewKingRoadTask()
  73. end
  74. return kingRoadTaskInfo
  75. end
  76. function this.CheckAllFinish(kingRoadTask)
  77. local nextChapter = kingRoadTask.now_chapter + 1
  78. local chapterCfgList = ConfigDataManager.getTable("cfg_king_road", "groupid", nextChapter)
  79. if table.isNullOrEmpty(chapterCfgList) then
  80. local chapterTaskInfo = kingRoadTask.chapter_task_info
  81. local chapterTask = chapterTaskInfo[kingRoadTask.now_chapter]
  82. if chapterTask.state == ChapterState.RECEIVE then
  83. return true
  84. end
  85. end
  86. return false
  87. end
  88. function KingRoad.SendKingRoadTask(actor)
  89. local kingRoadTask = this.GetKingRoadTask(actor)
  90. local allFinish = this.CheckAllFinish(kingRoadTask)
  91. if allFinish then
  92. kingRoadTask.now_chapter = ALL_FINISH
  93. end
  94. --jprint("王者之路:", kingRoadTask)
  95. sendluamsg(actor, LuaMessageIdToClient.RES_KING_ROAD_TASK_INFO, kingRoadTask)
  96. end
  97. function this.KingRoadChange(actor, changeTask, chapter, chapterStatus)
  98. local chapterTask = {
  99. now_chapter = chapter,
  100. chapter_state = chapterStatus,
  101. change_task = changeTask
  102. }
  103. sendluamsg(actor, LuaMessageIdToClient.RES_KING_ROAD_TASK_CHANGE, chapterTask)
  104. end
  105. function this.InitNewChapter(actor)
  106. local playerLevel = tonumber(getbaseinfo(actor, "level"))
  107. local kingRoadTask = this.GetKingRoadTask(actor)
  108. local chapterTaskInfo = kingRoadTask.chapter_task_info
  109. local nowChapterTask = chapterTaskInfo[kingRoadTask.now_chapter]
  110. --jprint("初始化章节任务:", kingRoadTask)
  111. if not table.isNullOrEmpty(nowChapterTask) and nowChapterTask.state ~= ChapterState.RECEIVE then
  112. return false
  113. end
  114. local nextChapter = kingRoadTask.now_chapter + 1
  115. local chapterCfgList = ConfigDataManager.getTable("cfg_king_road", "groupid", nextChapter)
  116. --jprint("章节任务配置:", chapterCfgList,nextChapter)
  117. if table.isNullOrEmpty(chapterCfgList) then
  118. return false
  119. end
  120. local chapterCfg = chapterCfgList[1]
  121. local level = tonumber(chapterCfg["level"])
  122. --jprint("章节任务等级限制:", chapterCfgList,level)
  123. if level > playerLevel then
  124. return false
  125. end
  126. local nextChapterTask = this.InitChapterTask(actor, nextChapter)
  127. if table.isNullOrEmpty(nextChapterTask) then
  128. return false
  129. end
  130. chapterTaskInfo[nextChapter] = nextChapterTask
  131. kingRoadTask.now_chapter = nextChapter
  132. kingRoadTask.chapter_task_info = chapterTaskInfo
  133. this.SaveKingRoadTask(actor, kingRoadTask)
  134. return true
  135. end
  136. ---初始化章节任务池
  137. function this.InitChapterTask(actor, group)
  138. local taskCfgList = ConfigDataManager.getTable("cfg_king_road_task", "group", group)
  139. if table.isNullOrEmpty(taskCfgList) then
  140. return nil
  141. end
  142. chapterTask = {
  143. state = ChapterState.UNLOCK,
  144. task_info = {}
  145. }
  146. local taskList = chapterTask.task_info
  147. --jprint("章节任务池初始:", taskList)
  148. for _, taskCfg in pairs(taskCfgList) do
  149. --jprint("章节任务配置:", taskCfg)
  150. local taskId = tonumber(taskCfg["id"])
  151. local taskTargetId = tonumber(taskCfg["tasktargetid"])
  152. local levelLimit = taskCfg["careerlimit"]
  153. local pass = this.CheckCareer(actor, levelLimit)
  154. if pass then
  155. local taskRecord = TaskHandler.BuildTaskRecord(actor, taskId, taskTargetId)
  156. if taskRecord ~= nil then
  157. taskList[taskId] = taskRecord
  158. end
  159. end
  160. end
  161. if table.isNullOrEmpty(taskList) then
  162. return nil
  163. end
  164. --jprint("章节任务池:", taskList)
  165. chapterTask.task_info = taskList
  166. return chapterTask
  167. end
  168. function this.CheckCareer(actor, levelLimit)
  169. if string.isNullOrEmpty(levelLimit)then
  170. return true
  171. end
  172. if #levelLimit == 1 and tonumber(levelLimit) == 0 then
  173. return true
  174. end
  175. local baseCareer = tonumber(getbaseinfo(actor, "getbasecareer"))
  176. local careerNum = tonumber(getbaseinfo(actor, "getcareernum"))
  177. local careerRank = tonumber(getbaseinfo(actor, "getcareerrank"))
  178. local limitArray = string.split(levelLimit, "#")
  179. local careerLimit = tonumber(limitArray[1])
  180. local numLimit = tonumber(limitArray[2])
  181. local rankLimit = tonumber(limitArray[3])
  182. if baseCareer ~= careerLimit or careerNum ~= numLimit then
  183. return false
  184. end
  185. if careerRank < rankLimit then
  186. return false
  187. end
  188. return true
  189. end
  190. function KingRoad.FlushKingRoadTask(actor, taskTargetType, param)
  191. local success, errorInfo = xpcall(this.FlushKingRoadTask, debug.traceback, actor, taskTargetType, param)
  192. gameDebug.assertPrint(success, "王者之路任务目标刷新异常:", actor, taskTargetType, param, errorInfo)
  193. end
  194. ---刷新任务
  195. function this.FlushKingRoadTask(actor, taskTargetType, param)
  196. local kingRoadTask = this.GetKingRoadTask(actor)
  197. local nowChapter = kingRoadTask.now_chapter
  198. if nowChapter == 0 then
  199. return
  200. end
  201. local chapterTaskInfo = kingRoadTask.chapter_task_info
  202. if table.isNullOrEmpty(chapterTaskInfo) then
  203. return
  204. end
  205. -- 当前章节
  206. local chapterTask = chapterTaskInfo[nowChapter]
  207. if chapterTask.state >= ChapterState.FINISH or table.isNullOrEmpty(chapterTask) then
  208. return
  209. end
  210. local taskList = chapterTask.task_info
  211. local changeTask = this.CheckTaskRecord(actor, taskList, taskTargetType, param)
  212. if table.isNullOrEmpty(changeTask) then
  213. return
  214. end
  215. chapterTask.task_info = taskList
  216. chapterTaskInfo[nowChapter] = chapterTask
  217. kingRoadTask.chapter_task_info = chapterTaskInfo
  218. this.SaveKingRoadTask(actor, kingRoadTask)
  219. this.KingRoadChange(actor, changeTask, nowChapter, chapterTask.state)
  220. end
  221. ---检查任务记录
  222. function this.CheckTaskRecord(actor, taskList, taskTargetType, param)
  223. local changeTask = {}
  224. for taskId, taskRecord in pairs(taskList) do
  225. local taskGoal = taskRecord.task_goal
  226. local target_id = taskRecord.target_id
  227. local goal_count = taskRecord.goal_count
  228. local needCount = taskRecord.max_count
  229. if taskTargetType == taskGoal and taskRecord.state == TaskHandler.Status.ACCEPT then
  230. local count = TaskGoal.FlushTaskCount(actor, taskGoal, target_id, goal_count, param)
  231. if count >= needCount then
  232. taskRecord.state = TaskHandler.Status.FINISH
  233. end
  234. if count > goal_count then
  235. taskRecord.goal_count = math.min(count, needCount)
  236. changeTask[taskId] = taskRecord
  237. end
  238. end
  239. end
  240. return changeTask
  241. end
  242. ---提交任务
  243. function KingRoad.SubmitChapterTask(actor, taskId)
  244. jprint("提交任务:", taskId)
  245. local kingRoadTask = this.GetKingRoadTask(actor)
  246. local nowChapter = kingRoadTask.now_chapter
  247. local chapterTaskInfo = kingRoadTask.chapter_task_info
  248. if table.isNullOrEmpty(chapterTaskInfo) then
  249. noticeTip.noticeinfo(actor, StringIdConst.TEXT405)
  250. return
  251. end
  252. local chapterTask = chapterTaskInfo[nowChapter]
  253. if chapterTask.state >= ChapterState.FINISH then
  254. tipinfo(actor, "任务已提交")
  255. return
  256. end
  257. local taskList = chapterTask.task_info
  258. local taskRecord = taskList[taskId]
  259. if taskRecord == nil then
  260. noticeTip.noticeinfo(actor, StringIdConst.TEXT355)
  261. return
  262. end
  263. if taskRecord.state == TaskHandler.Status.SUBMIT then
  264. tipinfo(actor, "任务已提交")
  265. return
  266. end
  267. if taskRecord.state == TaskHandler.Status.ACCEPT then
  268. tipinfo(actor, "任务未完成")
  269. return
  270. end
  271. --发奖励
  272. local rewardCfg = ConfigDataManager.getTableValue("cfg_king_road_task", "rewarditem", "id", taskRecord.task_id)
  273. this.SendTaskReward(actor, rewardCfg)
  274. taskList[taskId].state = TaskHandler.Status.SUBMIT
  275. chapterTask.task_info = taskList
  276. --检查章节完成
  277. local chapterFinish = this.CheckChapterFinish(taskList)
  278. if chapterFinish then
  279. chapterTask.state = ChapterState.FINISH
  280. end
  281. chapterTaskInfo[nowChapter] = chapterTask
  282. kingRoadTask.chapter_task_info = chapterTaskInfo
  283. this.SaveKingRoadTask(actor, kingRoadTask)
  284. local changeTask = {}
  285. changeTask[taskId] = taskRecord
  286. this.KingRoadChange(actor, changeTask, nowChapter, chapterTask.state)
  287. end
  288. function this.SendTaskReward(actor, rewardCfg)
  289. if string.isNullOrEmpty(rewardCfg) then
  290. --error("奖励未配置")
  291. return
  292. end
  293. local awardMap = {}
  294. local itemArray = string.split(rewardCfg, "|")
  295. for _, param in pairs(itemArray) do
  296. local cfgArray = string.split(param, "#")
  297. local itemId = tonumber(cfgArray[1])
  298. local itemNum = tonumber(cfgArray[2])
  299. awardMap[itemId] = itemNum
  300. --奖励入包
  301. local itemBing = ConfigDataManager.getTableValue("cfg_bind","bind","id", 4)
  302. jprint("首饰任务配置的绑定信息")
  303. jprint(itemBing)
  304. additemtobag(actor, itemId, itemNum, itemBing,9999,'王者之路')
  305. end
  306. --奖励弹框
  307. sendluamsg(actor, LuaMessageIdToClient.COMMON_REWARD_PANEL, awardMap)
  308. end
  309. function this.CheckChapterFinish(taskList)
  310. for _, taskRecord in pairs(taskList) do
  311. if taskRecord.state ~= TaskHandler.Status.SUBMIT then
  312. return false
  313. end
  314. end
  315. return true
  316. end
  317. function KingRoad.ReceiveChapterAward(actor)
  318. --jprint("领取章节奖励")
  319. local kingRoadTask = this.GetKingRoadTask(actor)
  320. local nowChapter = kingRoadTask.now_chapter
  321. if nowChapter == 0 then
  322. tipinfo(actor, "未解锁")
  323. return
  324. end
  325. local chapterTaskInfo = kingRoadTask.chapter_task_info
  326. local chapterTask = chapterTaskInfo[nowChapter]
  327. if table.isNullOrEmpty(chapterTask) or chapterTask.state ~= ChapterState.FINISH then
  328. tipinfo(actor, "无奖励可领取")
  329. return
  330. end
  331. --发奖励
  332. local rewardCfg = ConfigDataManager.getTableValue("cfg_king_road", "rewarditem", "groupid", nowChapter)
  333. this.SendTaskReward(actor, rewardCfg)
  334. chapterTask.state = ChapterState.RECEIVE
  335. chapterTaskInfo[nowChapter] = chapterTask
  336. kingRoadTask.chapter_task_info = chapterTaskInfo
  337. this.SaveKingRoadTask(actor, kingRoadTask)
  338. --尝试初始化下一章
  339. this.InitNewChapter(actor)
  340. KingRoad.SendKingRoadTask(actor)
  341. TaskHandler.TriggerTaskGoal(actor, TaskTargetType.JEWELRY_TASK_CHAPTER)
  342. end
  343. ---获取已完成章节
  344. function KingRoad.GetFinishChapter(actor)
  345. local kingRoadTask = this.GetKingRoadTask(actor)
  346. if table.isNullOrEmpty(kingRoadTask) then
  347. return 0
  348. end
  349. local nowChapter = kingRoadTask.now_chapter
  350. local chapterTaskInfo = kingRoadTask.chapter_task_info
  351. if table.isNullOrEmpty(chapterTaskInfo) then
  352. return nowChapter
  353. end
  354. local chapterTask = chapterTaskInfo[nowChapter]
  355. if chapterTask.state == ChapterState.RECEIVE then
  356. return nowChapter
  357. end
  358. return nowChapter - 1
  359. end
  360. --GM一键完成章节任务
  361. function gmfinishchaptertask(actor)
  362. local kingRoadTask = this.GetKingRoadTask(actor)
  363. local nowChapter = kingRoadTask.now_chapter
  364. if nowChapter == 0 then
  365. return
  366. end
  367. local chapterTaskInfo = kingRoadTask.chapter_task_info
  368. local chapterTask = chapterTaskInfo[nowChapter]
  369. if chapterTask.state >= ChapterState.FINISH then
  370. return
  371. end
  372. local taskInfo = chapterTask.task_info
  373. for _, taskRecord in pairs(taskInfo) do
  374. if taskRecord.state == TaskHandler.Status.ACCEPT then
  375. taskRecord.goal_count = taskRecord.max_count
  376. taskRecord.state = TaskHandler.Status.FINISH
  377. end
  378. end
  379. chapterTask.task_info = taskInfo
  380. chapterTaskInfo[nowChapter] = chapterTask
  381. kingRoadTask.chapter_task_info = chapterTaskInfo
  382. this.SaveKingRoadTask(actor, kingRoadTask)
  383. KingRoad.SendKingRoadTask(actor)
  384. end
  385. ---修复王者之路任务数据
  386. function this.RepairKingRoadTask_2024_12_12(actor)
  387. local kingRoadTaskInfo = this.GetKingRoadTask(actor)
  388. if table.isNullOrEmpty(kingRoadTaskInfo) then
  389. return
  390. end
  391. local nowChapter = kingRoadTaskInfo.now_chapter
  392. if nowChapter ~= 2 then
  393. return
  394. end
  395. local chapterTaskInfo = kingRoadTaskInfo.chapter_task_info
  396. if table.isNullOrEmpty(chapterTaskInfo) then
  397. return
  398. end
  399. local chapterTask = chapterTaskInfo[nowChapter]
  400. if table.isNullOrEmpty(chapterTask) then
  401. return
  402. end
  403. if chapterTask.state >= ChapterState.FINISH then
  404. return
  405. end
  406. local newTaskRecord = {}
  407. local repairTaskId = 0
  408. local taskList = chapterTask.task_info
  409. for taskId, taskRecord in pairs(taskList) do
  410. local taskGoal = taskRecord.task_goal
  411. if taskGoal == TaskTargetType.TRADE_LINE_UP_GOODS and taskRecord.state == TaskHandler.Status.ACCEPT then
  412. newTaskRecord = TaskHandler.BuildTaskRecord(actor,taskId,4000039)
  413. if not table.isNullOrEmpty(newTaskRecord) then
  414. repairTaskId = taskId
  415. end
  416. end
  417. end
  418. if repairTaskId > 0 then
  419. taskList[repairTaskId] = newTaskRecord
  420. chapterTask.task_info = taskList
  421. chapterTaskInfo[nowChapter] = chapterTask
  422. kingRoadTaskInfo.chapter_task_info = chapterTaskInfo
  423. this.SaveKingRoadTask(actor, kingRoadTaskInfo)
  424. jprint("修复玩家王者之路任务数据,4000039 --->",actor, newTaskRecord)
  425. end
  426. end
  427. ---修复王者之路任务数据
  428. function this.RepairKingRoadTask_2024_12_27(actor)
  429. local kingRoadTaskInfo = this.GetKingRoadTask(actor)
  430. if table.isNullOrEmpty(kingRoadTaskInfo) then
  431. return
  432. end
  433. local nowChapter = kingRoadTaskInfo.now_chapter
  434. if nowChapter ~= 3 then
  435. return
  436. end
  437. local chapterTaskInfo = kingRoadTaskInfo.chapter_task_info
  438. if table.isNullOrEmpty(chapterTaskInfo) then
  439. return
  440. end
  441. local chapterTask = chapterTaskInfo[nowChapter]
  442. if table.isNullOrEmpty(chapterTask) then
  443. return
  444. end
  445. if chapterTask.state >= ChapterState.FINISH then
  446. return
  447. end
  448. local newTaskRecord = {}
  449. local repairTaskId = 0
  450. local taskList = chapterTask.task_info
  451. for taskId, taskRecord in pairs(taskList) do
  452. local taskGoal = taskRecord.task_goal
  453. if (taskGoal == TaskTargetType.FINISH_DUPLICATE or taskGoal == TaskTargetType.FLUSH_BRAVE_TEST_LV)
  454. and taskRecord.state == TaskHandler.Status.ACCEPT then
  455. newTaskRecord = TaskHandler.BuildTaskRecord(actor,taskId,4000040)
  456. if not table.isNullOrEmpty(newTaskRecord) then
  457. repairTaskId = taskId
  458. end
  459. end
  460. end
  461. if repairTaskId > 0 then
  462. taskList[repairTaskId] = newTaskRecord
  463. chapterTask.task_info = taskList
  464. chapterTaskInfo[nowChapter] = chapterTask
  465. kingRoadTaskInfo.chapter_task_info = chapterTaskInfo
  466. this.SaveKingRoadTask(actor, kingRoadTaskInfo)
  467. jprint("修复玩家王者之路勇气试炼任务数据,4000040 --->",actor, newTaskRecord)
  468. end
  469. end