DailyTaskLogic.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. DAILY_TASK_ID_1 = 1 --日常登陆1次 o
  16. DAILY_TASK_ID_2 = 2 --赠送友情点5次 o
  17. DAILY_TASK_ID_3 = 3 --进行3次招将 o
  18. DAILY_TASK_ID_4 = 4 --擂台挑战3次 x
  19. DAILY_TASK_ID_5 = 5 --通天塔扫荡/挑战3次 o
  20. DAILY_TASK_ID_6 = 6 --公会boss挑战3次 o
  21. DAILY_TASK_ID_7 = 7 --进行1次公会建设 o
  22. DAILY_TASK_ID_8 = 8 --参与1次无尽试炼 x
  23. DAILY_TASK_ID_9 = 9 --接取3次民生任务 o
  24. DAILY_TASK_ID_10 = 10 --参与2次日常副本 o
  25. DAILY_TASK_ID_11 = 11 --圣树试炼胜利3次 o
  26. DAILY_TASK_ID_12 = 12 --征战扫荡5次 o
  27. -- 查询每日任务
  28. function dailyTaskQuery(human, isOnLogin)
  29. local sendErr = isOnLogin == false and true or false
  30. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801, sendErr) ~= true then
  31. return
  32. end
  33. local dailyTaskConfig = DailyTaskExcel.dailyTask
  34. if not dailyTaskConfig then return end
  35. -- 每日更新
  36. ObjHuman.updateDaily(human)
  37. local msgRet = Msg.gc.GC_DAILYTASK_QUERY
  38. local now = os.time()
  39. local ts1 = Util.getDayStartTime(now)
  40. msgRet.nextRefreshTime = 24 * 60 * 60 - (now - ts1)
  41. local cnt = 0
  42. for key, value in ipairs(DailyTaskExcel.dailyTask) do
  43. cnt = cnt + 1
  44. msgRet.list[cnt].taskID = key
  45. msgRet.list[cnt].desc = value.taskDesc
  46. msgRet.list[cnt].maxCnt = value.taskCnt
  47. local len = 0
  48. for i = 1, #value.reward do
  49. len = len + 1
  50. local itemId = value.reward[i][1]
  51. local itemCnt = value.reward[i][2]
  52. Grid.makeItem(msgRet.list[cnt].itemData[len], itemId, itemCnt)
  53. end
  54. msgRet.list[cnt].itemData[0] = len
  55. msgRet.list[cnt].finishCnt = 0
  56. msgRet.list[cnt].isGet = 0
  57. msgRet.list[cnt].jump = value.panelID
  58. if human.db.dailyTask and human.db.dailyTask.task and human.db.dailyTask.task[key] then
  59. msgRet.list[cnt].finishCnt = human.db.dailyTask.task[key].finishCnt or 0
  60. if human.db.dailyTask.task[key].isGet then
  61. msgRet.list[cnt].isGet = 1
  62. end
  63. end
  64. end
  65. local huoYueBoxConfig = DailyTaskExcel.huoYueBox
  66. msgRet.huoYueBox[0] = #huoYueBoxConfig
  67. for i=1,#DailyTaskExcel.huoYueBox do
  68. msgRet.huoYueBox[i].boxID = i
  69. msgRet.huoYueBox[i].needHuoYue = huoYueBoxConfig[i].needHuoYue
  70. msgRet.huoYueBox[i].items[0] = #huoYueBoxConfig[i].reward
  71. for j=1,#huoYueBoxConfig[i].reward do
  72. local itemID = huoYueBoxConfig[i].reward[j][1]
  73. local itemCnt = huoYueBoxConfig[i].reward[j][2]
  74. Grid.makeItem(msgRet.huoYueBox[i].items[j],itemID,itemCnt)
  75. end
  76. local isGet = human.db.dailyTask and human.db.dailyTask.huoYueBox and human.db.dailyTask.huoYueBox[i] or 0
  77. msgRet.huoYueBox[i].isGet = isGet
  78. end
  79. msgRet.nowHuoYue = human.db.dailyTask and human.db.dailyTask.nowHuoYue or 0
  80. msgRet.list[0] = cnt
  81. --Msg.trace(msgRet)
  82. Msg.send(msgRet, human.fd)
  83. end
  84. -- 领取每日任务奖励
  85. function dailyTaskGetReward(human, taskID)
  86. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801) ~= true then
  87. return
  88. end
  89. local dailyTaskConfig = DailyTaskExcel.dailyTask[taskID]
  90. if not dailyTaskConfig then return end
  91. -- 每日更新
  92. ObjHuman.updateDaily(human)
  93. if human.db.dailyTask == nil or human.db.dailyTask.task == nil or human.db.dailyTask.task[taskID] == nil then
  94. return
  95. end
  96. -- 判断上限
  97. if human.db.dailyTask.task[taskID].isGet then
  98. return
  99. end
  100. if human.db.dailyTask.task[taskID].finishCnt == nil or human.db.dailyTask.task[taskID].finishCnt < dailyTaskConfig.taskCnt then
  101. return
  102. end
  103. -- 改db
  104. human.db.dailyTask.task[taskID].isGet = true
  105. -- 奖励倍数
  106. BagLogic.cleanMomentItemList()
  107. for i = 1, #dailyTaskConfig.reward do
  108. local itemId = dailyTaskConfig.reward[i][1]
  109. local itemCnt = dailyTaskConfig.reward[i][2]
  110. if itemId == ItemDefine.ITME_HUOYUE_ID then
  111. onDailyTaskHuoYue(human,itemCnt)
  112. else
  113. local newCnt = math.ceil(itemCnt)
  114. BagLogic.updateMomentItem(2, itemId, itemCnt)
  115. end
  116. end
  117. BagLogic.addMomentItemList(human, "daily_task")
  118. -- ChatPaoMaLogic.trigger(human, ChatPaoMaLogic.TRIGGER_TYPE_2, rewardID, rewardCnt)
  119. -- 通知客户端
  120. dailyTaskQuery(human)
  121. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  122. end
  123. -- 记录每个任务的完成次数
  124. function recordDailyTaskFinishCnt(human, taskID, addCnt, noSend)
  125. -- 每日更新
  126. ObjHuman.updateDaily(human)
  127. human.db.dailyTask = human.db.dailyTask or {}
  128. human.db.dailyTask.task = human.db.dailyTask.task or {}
  129. human.db.dailyTask.task[taskID] = human.db.dailyTask.task[taskID] or {}
  130. if human.db.dailyTask.task[taskID].state ~= nil then
  131. return
  132. end
  133. human.db.dailyTask.task[taskID].finishCnt = (human.db.dailyTask.task[taskID].finishCnt or 0) + addCnt
  134. local dailyTaskConfig = DailyTaskExcel.dailyTask[taskID]
  135. if not dailyTaskConfig then return end
  136. if human.db.dailyTask.task[taskID].finishCnt >= dailyTaskConfig.taskCnt then
  137. human.db.dailyTask.task[taskID].finishCnt = dailyTaskConfig.taskCnt
  138. human.db.dailyTask.task[taskID].state = 1
  139. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  140. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_12,1)
  141. local msgRet = Msg.gc.GC_DAILYSHARE_SET
  142. msgRet.type = 1
  143. msgRet.desc = dailyTaskConfig.taskDesc
  144. Msg.send(msgRet,human.fd)
  145. end
  146. if noSend ~= true then
  147. dailyTaskQuery(human)
  148. end
  149. end
  150. -- 领取活跃宝箱
  151. local function huoYueBoxCanGet(human,boxID)
  152. local dailyTaskDB = human.db.dailyTask
  153. if not dailyTaskDB then return end
  154. local isGet = dailyTaskDB.huoYueBox and dailyTaskDB.huoYueBox[boxID] or 0
  155. if isGet ~= 0 then return end
  156. local nowHuoYue = dailyTaskDB.nowHuoYue or 0
  157. local huoYueBoxConfig = DailyTaskExcel.huoYueBox[boxID]
  158. if nowHuoYue <= 0 or nowHuoYue < huoYueBoxConfig.needHuoYue then return end
  159. return true
  160. end
  161. function CG_DAILYTASK_GET_HUOYUEBOX(human,boxID)
  162. local huoYueBoxConfig = DailyTaskExcel.huoYueBox[boxID]
  163. if not huoYueBoxConfig then return end
  164. if not huoYueBoxCanGet(human,boxID) then return end
  165. human.db.dailyTask.huoYueBox = human.db.dailyTask.huoYueBox or {}
  166. human.db.dailyTask.huoYueBox[boxID] = 1
  167. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_801)
  168. local rewardCnt = double and 2 or 1
  169. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_2)
  170. local item = Util.copyTable(huoYueBoxConfig.reward)
  171. if cjPrivilege then
  172. local random = math.random(1,100)
  173. if random <= 1 then
  174. local len = #item
  175. for i = 1,len do
  176. item[i][2] = item[i][2] * 2
  177. end
  178. end
  179. end
  180. if double then
  181. local len = #item
  182. for i = 1,len do
  183. item[i][2] = item[i][2] * rewardCnt
  184. end
  185. end
  186. local msgRet = Msg.gc.GC_DAILYTASK_GET_HUOYUEBOX
  187. msgRet.boxID = boxID
  188. msgRet.double = double and 1 or 0
  189. Msg.send(msgRet,human.fd)
  190. BagLogic.addItemList(human, item, "daily_task")
  191. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  192. end
  193. function isDot(human)
  194. -- 主界面的任务包含2个标签 每日任务/成就
  195. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801) ~= true then
  196. return false
  197. end
  198. if human.db.dailyTask and human.db.dailyTask.task then
  199. for k,v in pairs(human.db.dailyTask.task) do
  200. if k and v and v.isGet ~= true then
  201. local dailyTaskConfig = DailyTaskExcel.dailyTask[k]
  202. if dailyTaskConfig then
  203. local cnt = v.finishCnt or 0
  204. if cnt >= dailyTaskConfig.taskCnt then
  205. return true
  206. end
  207. end
  208. end
  209. end
  210. end
  211. for i=1,#DailyTaskExcel.huoYueBox do
  212. if huoYueBoxCanGet(human,i) then return true end
  213. end
  214. return false
  215. end
  216. function onDailyTaskHuoYue(human,sum)
  217. if not human.db.dailyTask then return end
  218. human.db.dailyTask.nowHuoYue = (human.db.dailyTask.nowHuoYue or 0) + sum
  219. YunYingLogic.onCallBack(human, "onDailyTask",sum)
  220. end
  221. function onLogin(human)
  222. recordDailyTaskFinishCnt(human, DAILY_TASK_ID_1, 1, true)
  223. dailyTaskQuery(human, true)
  224. end