DailyTaskLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. local Lang = require("common.Lang")
  2. local Util = require("common.Util")
  3. local Msg = require("core.Msg")
  4. local ObjHuman = require("core.ObjHuman")
  5. local DailyTaskExcel = require("excel.dailyTask")
  6. local BagLogic = require("bag.BagLogic")
  7. local Grid = require("bag.Grid")
  8. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  9. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  10. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  11. local ItemDefine = require("bag.ItemDefine")
  12. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  13. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  14. local YunYingLogic = require("yunying.YunYingLogic")
  15. local WeekTaskLogic = require("dailyTask.WeekTaskLogic")
  16. local HonorTaskLogic = require("dailyTask.HonorJourney")
  17. local CommonActMoneyTree
  18. DAILY_TASK_ID_1 = 1 --日常登陆1次 o
  19. DAILY_TASK_ID_2 = 2 --赠送友情点5次 o
  20. DAILY_TASK_ID_3 = 3 --进行3次招将 o
  21. DAILY_TASK_ID_4 = 4 --擂台挑战3次 x
  22. DAILY_TASK_ID_5 = 5 --通天塔扫荡/挑战3次 o
  23. DAILY_TASK_ID_6 = 6 --公会boss挑战3次 o
  24. DAILY_TASK_ID_7 = 7 --进行1次公会建设 o
  25. DAILY_TASK_ID_8 = 8 --参与1次无尽试炼 x
  26. DAILY_TASK_ID_9 = 9 --接取3次民生任务 o
  27. DAILY_TASK_ID_10 = 10 --参与2次日常副本 o
  28. DAILY_TASK_ID_11 = 11 --圣树试炼胜利3次 o
  29. DAILY_TASK_ID_12 = 12 --征战扫荡5次 o
  30. -- 查询每日任务
  31. function dailyTaskQuery(human, isOnLogin)
  32. local sendErr = isOnLogin == false and true or false
  33. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801, sendErr) ~= true then
  34. return
  35. end
  36. local dailyTaskConfig = DailyTaskExcel.dailyTask
  37. if not dailyTaskConfig then return end
  38. -- 每日更新
  39. ObjHuman.updateDaily(human)
  40. local msgRet = Msg.gc.GC_DAILYTASK_QUERY
  41. local now = os.time()
  42. local ts1 = Util.getDayStartTime(now)
  43. msgRet.nextRefreshTime = 24 * 60 * 60 - (now - ts1)
  44. local cnt = 0
  45. for key, value in ipairs(DailyTaskExcel.dailyTask) do
  46. cnt = cnt + 1
  47. msgRet.list[cnt].taskID = key
  48. msgRet.list[cnt].desc = value.taskDesc
  49. msgRet.list[cnt].maxCnt = value.taskCnt
  50. local len = 0
  51. for i = 1, #value.reward do
  52. len = len + 1
  53. local itemId = value.reward[i][1]
  54. local itemCnt = value.reward[i][2]
  55. Grid.makeItem(msgRet.list[cnt].itemData[len], itemId, itemCnt)
  56. end
  57. msgRet.list[cnt].itemData[0] = len
  58. msgRet.list[cnt].finishCnt = 0
  59. msgRet.list[cnt].isGet = 0
  60. msgRet.list[cnt].jump = value.panelID
  61. if human.db.dailyTask and human.db.dailyTask.task and human.db.dailyTask.task[key] then
  62. msgRet.list[cnt].finishCnt = human.db.dailyTask.task[key].finishCnt or 0
  63. if human.db.dailyTask.task[key].isGet then
  64. msgRet.list[cnt].isGet = 1
  65. end
  66. end
  67. end
  68. local huoYueBoxConfig = DailyTaskExcel.huoYueBox
  69. msgRet.huoYueBox[0] = #huoYueBoxConfig
  70. for i=1,#DailyTaskExcel.huoYueBox do
  71. msgRet.huoYueBox[i].boxID = i
  72. msgRet.huoYueBox[i].needHuoYue = huoYueBoxConfig[i].needHuoYue
  73. msgRet.huoYueBox[i].items[0] = #huoYueBoxConfig[i].reward
  74. for j=1,#huoYueBoxConfig[i].reward do
  75. local itemID = huoYueBoxConfig[i].reward[j][1]
  76. local itemCnt = huoYueBoxConfig[i].reward[j][2]
  77. Grid.makeItem(msgRet.huoYueBox[i].items[j],itemID,itemCnt)
  78. end
  79. local isGet = human.db.dailyTask and human.db.dailyTask.huoYueBox and human.db.dailyTask.huoYueBox[i] or 0
  80. msgRet.huoYueBox[i].isGet = isGet
  81. end
  82. msgRet.nowHuoYue = human.db.dailyTask and human.db.dailyTask.nowHuoYue or 0
  83. msgRet.list[0] = cnt
  84. --Msg.trace(msgRet)
  85. Msg.send(msgRet, human.fd)
  86. end
  87. --统计奖励
  88. local function calcReward(human, awardCfg)
  89. for i = 1, #awardCfg do
  90. local itemId = awardCfg[i][1]
  91. local itemCnt = awardCfg[i][2]
  92. if itemId == ItemDefine.ITME_HUOYUE_ID then
  93. onDailyTaskHuoYue(human,itemCnt)
  94. else
  95. local newCnt = math.ceil(itemCnt)
  96. --BagLogic.updateMomentItem(2, itemId, itemCnt)
  97. BagLogic.updateMomentItem(2, itemId, newCnt)
  98. end
  99. end
  100. end
  101. -- 领取每日任务奖励
  102. function dailyTaskGetReward(human, taskID)
  103. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801) ~= true then
  104. return
  105. end
  106. -- local dailyTaskConfig = DailyTaskExcel.dailyTask[taskID]
  107. -- if not dailyTaskConfig then return end
  108. -- 每日更新
  109. ObjHuman.updateDaily(human)
  110. -- if human.db.dailyTask == nil or human.db.dailyTask.task == nil or human.db.dailyTask.task[taskID] == nil then
  111. -- return
  112. -- end
  113. -- --判断上限
  114. -- if human.db.dailyTask.task[taskID].isGet then
  115. -- return
  116. -- end
  117. -- if human.db.dailyTask.task[taskID].finishCnt == nil or human.db.dailyTask.task[taskID].finishCnt < dailyTaskConfig.taskCnt then
  118. -- return
  119. -- end
  120. -- --改db
  121. -- human.db.dailyTask.task[taskID].isGet = true
  122. -- --奖励倍数
  123. -- BagLogic.cleanMomentItemList()
  124. -- for i = 1, #dailyTaskConfig.reward do
  125. -- local itemId = dailyTaskConfig.reward[i][1]
  126. -- local itemCnt = dailyTaskConfig.reward[i][2]
  127. -- if itemId == ItemDefine.ITME_HUOYUE_ID then
  128. -- onDailyTaskHuoYue(human,itemCnt)
  129. -- else
  130. -- local newCnt = math.ceil(itemCnt)
  131. -- BagLogic.updateMomentItem(2, itemId, itemCnt)
  132. -- end
  133. -- end
  134. -- BagLogic.addMomentItemList(human, "daily_task")
  135. -- ChatPaoMaLogic.trigger(human, ChatPaoMaLogic.TRIGGER_TYPE_2, rewardID, rewardCnt)
  136. -- 通知客户端
  137. -- dailyTaskQuery(human)
  138. -- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  139. ------------------------------------新改为: 一键领取所有能领取的奖励---------------------------------------------
  140. if human.db.dailyTask == nil or human.db.dailyTask.task == nil then
  141. return
  142. end
  143. local isClean = false
  144. local taskData = human.db.dailyTask.task
  145. for taskId, data in pairs(taskData) do
  146. if not data.isGet then
  147. local dailyTaskConfig = DailyTaskExcel.dailyTask[taskId]
  148. if data.finishCnt and data.finishCnt >= dailyTaskConfig.taskCnt then
  149. if not isClean then
  150. BagLogic.cleanMomentItemList()
  151. isClean = true
  152. end
  153. calcReward(human, dailyTaskConfig.reward)
  154. data.isGet = true
  155. end
  156. end
  157. end
  158. if isClean then
  159. BagLogic.addMomentItemList(human, "daily_task")
  160. dailyTaskQuery(human)
  161. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  162. end
  163. end
  164. -- 记录每个任务的完成次数
  165. function recordDailyTaskFinishCnt(human, taskID, addCnt, noSend)
  166. -- 每日更新
  167. ObjHuman.updateDaily(human)
  168. human.db.dailyTask = human.db.dailyTask or {}
  169. human.db.dailyTask.task = human.db.dailyTask.task or {}
  170. human.db.dailyTask.task[taskID] = human.db.dailyTask.task[taskID] or {}
  171. if human.db.dailyTask.task[taskID].state ~= nil then
  172. return
  173. end
  174. human.db.dailyTask.task[taskID].finishCnt = (human.db.dailyTask.task[taskID].finishCnt or 0) + addCnt
  175. local dailyTaskConfig = DailyTaskExcel.dailyTask[taskID]
  176. if not dailyTaskConfig then return end
  177. if human.db.dailyTask.task[taskID].finishCnt >= dailyTaskConfig.taskCnt then
  178. human.db.dailyTask.task[taskID].finishCnt = dailyTaskConfig.taskCnt
  179. human.db.dailyTask.task[taskID].state = 1
  180. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  181. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_12,1)
  182. local msgRet = Msg.gc.GC_DAILYSHARE_SET
  183. msgRet.type = 1
  184. msgRet.desc = dailyTaskConfig.taskDesc
  185. Msg.send(msgRet,human.fd)
  186. end
  187. if noSend ~= true then
  188. dailyTaskQuery(human)
  189. end
  190. end
  191. -- 领取活跃宝箱
  192. local function huoYueBoxCanGet(human,boxID)
  193. local dailyTaskDB = human.db.dailyTask
  194. if not dailyTaskDB then return end
  195. local isGet = dailyTaskDB.huoYueBox and dailyTaskDB.huoYueBox[boxID] or 0
  196. if isGet ~= 0 then return end
  197. local nowHuoYue = dailyTaskDB.nowHuoYue or 0
  198. local huoYueBoxConfig = DailyTaskExcel.huoYueBox[boxID]
  199. if nowHuoYue <= 0 or nowHuoYue < huoYueBoxConfig.needHuoYue then return end
  200. return true
  201. end
  202. function CG_DAILYTASK_GET_HUOYUEBOX(human,boxID)
  203. -- local huoYueBoxConfig = DailyTaskExcel.huoYueBox[boxID]
  204. -- if not huoYueBoxConfig then return end
  205. -- if not huoYueBoxCanGet(human,boxID) then return end
  206. -- human.db.dailyTask.huoYueBox = human.db.dailyTask.huoYueBox or {}
  207. -- human.db.dailyTask.huoYueBox[boxID] = 1
  208. -- local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_801)
  209. -- local rewardCnt = double and 2 or 1
  210. -- local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_2)
  211. -- local item = Util.copyTable(huoYueBoxConfig.reward)
  212. -- if cjPrivilege then
  213. -- local random = math.random(1,100)
  214. -- if random <= 1 then
  215. -- local len = #item
  216. -- for i = 1,len do
  217. -- item[i][2] = item[i][2] * 2
  218. -- end
  219. -- end
  220. -- end
  221. -- if double then
  222. -- local len = #item
  223. -- for i = 1,len do
  224. -- item[i][2] = item[i][2] * rewardCnt
  225. -- end
  226. -- end
  227. -- local msgRet = Msg.gc.GC_DAILYTASK_GET_HUOYUEBOX
  228. -- msgRet.boxID = boxID
  229. -- msgRet.double = double and 1 or 0
  230. -- Msg.send(msgRet,human.fd)
  231. -- BagLogic.addItemList(human, item, "daily_task")
  232. -- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  233. -------------------------------新修改为:一键领取所有能领取的宝箱奖励------------------------------------
  234. local dailyTaskDB = human.db.dailyTask
  235. if not dailyTaskDB then
  236. return
  237. end
  238. local nowHuoYue = dailyTaskDB.nowHuoYue
  239. if not nowHuoYue then
  240. return
  241. end
  242. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_801)
  243. local rewardCnt = double and 2 or 1
  244. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_2)
  245. local len = 0
  246. local randRate = 1
  247. local awardList = {}
  248. local boxData = dailyTaskDB.huoYueBox
  249. local boxConfig = DailyTaskExcel.huoYueBox
  250. for boxId, v in ipairs(boxConfig) do
  251. if nowHuoYue >= v.needHuoYue and (not boxData or not boxData[boxId]) then
  252. dailyTaskDB.huoYueBox = dailyTaskDB.huoYueBox or {}
  253. boxData = dailyTaskDB.huoYueBox
  254. boxData[boxId] = 1
  255. randRate = 1
  256. if cjPrivilege then
  257. local random = math.random(1,100)
  258. if random <= 1 then
  259. randRate = 2
  260. end
  261. end
  262. for _, itemInfo in ipairs(v.reward) do
  263. len = len + 1
  264. awardList[len] = {itemInfo[1], itemInfo[2] * randRate * rewardCnt}
  265. end
  266. --更新
  267. local msgRet = Msg.gc.GC_DAILYTASK_GET_HUOYUEBOX
  268. msgRet.boxID = boxId
  269. msgRet.double = double and 1 or 0
  270. Msg.send(msgRet,human.fd)
  271. if boxId == #boxConfig then
  272. CommonActMoneyTree = CommonActMoneyTree or require("absAct.CommonActMoneyTree")
  273. CommonActMoneyTree.CompleteHuoYueTask(human)
  274. end
  275. end
  276. end
  277. if len > 0 then
  278. BagLogic.addItemList(human, awardList, "daily_task")
  279. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  280. end
  281. end
  282. function isDot(human)
  283. -- 主界面的任务包含2个标签 每日任务/成就
  284. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801) ~= true then
  285. return false
  286. end
  287. if human.db.dailyTask and human.db.dailyTask.task then
  288. for k,v in pairs(human.db.dailyTask.task) do
  289. if k and v and v.isGet ~= true then
  290. local dailyTaskConfig = DailyTaskExcel.dailyTask[k]
  291. if dailyTaskConfig then
  292. local cnt = v.finishCnt or 0
  293. if cnt >= dailyTaskConfig.taskCnt then
  294. return true
  295. end
  296. end
  297. end
  298. end
  299. end
  300. for i=1,#DailyTaskExcel.huoYueBox do
  301. if huoYueBoxCanGet(human,i) then return true end
  302. end
  303. return false
  304. end
  305. function onDailyTaskHuoYue(human,sum)
  306. if not human.db.dailyTask then return end
  307. human.db.dailyTask.nowHuoYue = (human.db.dailyTask.nowHuoYue or 0) + sum
  308. YunYingLogic.onCallBack(human, "onDailyTask",sum)
  309. -- local finallyIdx = #DailyTaskExcel.huoYueBox
  310. -- local finallyCfg = DailyTaskExcel.huoYueBox[finallyIdx]
  311. -- if human.db.dailyTask.nowHuoYue >= finallyCfg.needHuoYue then
  312. -- CommonActMoneyTree = CommonActMoneyTree or require("absAct.CommonActMoneyTree")
  313. -- CommonActMoneyTree.CompleteHuoYueTask(human)
  314. -- end
  315. end
  316. function onLogin(human)
  317. recordDailyTaskFinishCnt(human, DAILY_TASK_ID_1, 1, true)
  318. dailyTaskQuery(human, true)
  319. --周任务和荣耀历程
  320. WeekTaskLogic.onLogin(human)
  321. HonorTaskLogic.onLogin(human)
  322. end
  323. function Gm_AddHuoYue(human, nAddNum)
  324. onDailyTaskHuoYue(human, nAddNum)
  325. end