DailyTaskLogic.lua 13 KB

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