DailyTaskLogic.lua 12 KB

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