DailyTaskLogic.lua 13 KB

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