DailyTaskLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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. local function calcReward(human, awardCfg)
  86. for i = 1, #awardCfg do
  87. local itemId = awardCfg[i][1]
  88. local itemCnt = awardCfg[i][2]
  89. if itemId == ItemDefine.ITME_HUOYUE_ID then
  90. onDailyTaskHuoYue(human,itemCnt)
  91. else
  92. local newCnt = math.ceil(itemCnt)
  93. --BagLogic.updateMomentItem(2, itemId, itemCnt)
  94. BagLogic.updateMomentItem(2, itemId, newCnt)
  95. end
  96. end
  97. end
  98. -- 领取每日任务奖励
  99. function dailyTaskGetReward(human, taskID)
  100. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801) ~= true then
  101. return
  102. end
  103. -- local dailyTaskConfig = DailyTaskExcel.dailyTask[taskID]
  104. -- if not dailyTaskConfig then return end
  105. -- 每日更新
  106. ObjHuman.updateDaily(human)
  107. -- if human.db.dailyTask == nil or human.db.dailyTask.task == nil or human.db.dailyTask.task[taskID] == nil then
  108. -- return
  109. -- end
  110. -- --判断上限
  111. -- if human.db.dailyTask.task[taskID].isGet then
  112. -- return
  113. -- end
  114. -- if human.db.dailyTask.task[taskID].finishCnt == nil or human.db.dailyTask.task[taskID].finishCnt < dailyTaskConfig.taskCnt then
  115. -- return
  116. -- end
  117. -- --改db
  118. -- human.db.dailyTask.task[taskID].isGet = true
  119. -- --奖励倍数
  120. -- BagLogic.cleanMomentItemList()
  121. -- for i = 1, #dailyTaskConfig.reward do
  122. -- local itemId = dailyTaskConfig.reward[i][1]
  123. -- local itemCnt = dailyTaskConfig.reward[i][2]
  124. -- if itemId == ItemDefine.ITME_HUOYUE_ID then
  125. -- onDailyTaskHuoYue(human,itemCnt)
  126. -- else
  127. -- local newCnt = math.ceil(itemCnt)
  128. -- BagLogic.updateMomentItem(2, itemId, itemCnt)
  129. -- end
  130. -- end
  131. -- BagLogic.addMomentItemList(human, "daily_task")
  132. -- ChatPaoMaLogic.trigger(human, ChatPaoMaLogic.TRIGGER_TYPE_2, rewardID, rewardCnt)
  133. -- 通知客户端
  134. -- dailyTaskQuery(human)
  135. -- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  136. ------------------------------------新改为: 一键领取所有能领取的奖励---------------------------------------------
  137. if human.db.dailyTask == nil or human.db.dailyTask.task == nil then
  138. return
  139. end
  140. local isClean = false
  141. local taskData = human.db.dailyTask.task
  142. for taskId, data in pairs(taskData) do
  143. if not data.isGet then
  144. local dailyTaskConfig = DailyTaskExcel.dailyTask[taskId]
  145. if data.finishCnt and data.finishCnt >= dailyTaskConfig.taskCnt then
  146. if not isClean then
  147. BagLogic.cleanMomentItemList()
  148. isClean = true
  149. end
  150. calcReward(human, dailyTaskConfig.reward)
  151. data.isGet = true
  152. end
  153. end
  154. end
  155. if isClean then
  156. BagLogic.addMomentItemList(human, "daily_task")
  157. dailyTaskQuery(human)
  158. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  159. end
  160. end
  161. -- 记录每个任务的完成次数
  162. function recordDailyTaskFinishCnt(human, taskID, addCnt, noSend)
  163. -- 每日更新
  164. ObjHuman.updateDaily(human)
  165. human.db.dailyTask = human.db.dailyTask or {}
  166. human.db.dailyTask.task = human.db.dailyTask.task or {}
  167. human.db.dailyTask.task[taskID] = human.db.dailyTask.task[taskID] or {}
  168. if human.db.dailyTask.task[taskID].state ~= nil then
  169. return
  170. end
  171. human.db.dailyTask.task[taskID].finishCnt = (human.db.dailyTask.task[taskID].finishCnt or 0) + addCnt
  172. local dailyTaskConfig = DailyTaskExcel.dailyTask[taskID]
  173. if not dailyTaskConfig then return end
  174. if human.db.dailyTask.task[taskID].finishCnt >= dailyTaskConfig.taskCnt then
  175. human.db.dailyTask.task[taskID].finishCnt = dailyTaskConfig.taskCnt
  176. human.db.dailyTask.task[taskID].state = 1
  177. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  178. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_12,1)
  179. local msgRet = Msg.gc.GC_DAILYSHARE_SET
  180. msgRet.type = 1
  181. msgRet.desc = dailyTaskConfig.taskDesc
  182. Msg.send(msgRet,human.fd)
  183. end
  184. if noSend ~= true then
  185. dailyTaskQuery(human)
  186. end
  187. end
  188. -- 领取活跃宝箱
  189. local function huoYueBoxCanGet(human,boxID)
  190. local dailyTaskDB = human.db.dailyTask
  191. if not dailyTaskDB then return end
  192. local isGet = dailyTaskDB.huoYueBox and dailyTaskDB.huoYueBox[boxID] or 0
  193. if isGet ~= 0 then return end
  194. local nowHuoYue = dailyTaskDB.nowHuoYue or 0
  195. local huoYueBoxConfig = DailyTaskExcel.huoYueBox[boxID]
  196. if nowHuoYue <= 0 or nowHuoYue < huoYueBoxConfig.needHuoYue then return end
  197. return true
  198. end
  199. function CG_DAILYTASK_GET_HUOYUEBOX(human,boxID)
  200. -- local huoYueBoxConfig = DailyTaskExcel.huoYueBox[boxID]
  201. -- if not huoYueBoxConfig then return end
  202. -- if not huoYueBoxCanGet(human,boxID) then return end
  203. -- human.db.dailyTask.huoYueBox = human.db.dailyTask.huoYueBox or {}
  204. -- human.db.dailyTask.huoYueBox[boxID] = 1
  205. -- local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_801)
  206. -- local rewardCnt = double and 2 or 1
  207. -- local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_2)
  208. -- local item = Util.copyTable(huoYueBoxConfig.reward)
  209. -- if cjPrivilege then
  210. -- local random = math.random(1,100)
  211. -- if random <= 1 then
  212. -- local len = #item
  213. -- for i = 1,len do
  214. -- item[i][2] = item[i][2] * 2
  215. -- end
  216. -- end
  217. -- end
  218. -- if double then
  219. -- local len = #item
  220. -- for i = 1,len do
  221. -- item[i][2] = item[i][2] * rewardCnt
  222. -- end
  223. -- end
  224. -- local msgRet = Msg.gc.GC_DAILYTASK_GET_HUOYUEBOX
  225. -- msgRet.boxID = boxID
  226. -- msgRet.double = double and 1 or 0
  227. -- Msg.send(msgRet,human.fd)
  228. -- BagLogic.addItemList(human, item, "daily_task")
  229. -- RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  230. -------------------------------新修改为:一键领取所有能领取的宝箱奖励------------------------------------
  231. local dailyTaskDB = human.db.dailyTask
  232. if not dailyTaskDB then
  233. return
  234. end
  235. local nowHuoYue = dailyTaskDB.nowHuoYue
  236. if not nowHuoYue then
  237. return
  238. end
  239. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_801)
  240. local rewardCnt = double and 2 or 1
  241. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_2)
  242. local len = 0
  243. local randRate = 1
  244. local awardList = {}
  245. local boxData = dailyTaskDB.huoYueBox
  246. local boxConfig = DailyTaskExcel.huoYueBox
  247. for boxId, v in ipairs(boxConfig) do
  248. if nowHuoYue >= v.needHuoYue and (not boxData or not boxData[boxId]) then
  249. dailyTaskDB.huoYueBox = dailyTaskDB.huoYueBox or {}
  250. boxData = dailyTaskDB.huoYueBox
  251. boxData[boxId] = 1
  252. randRate = 1
  253. if cjPrivilege then
  254. local random = math.random(1,100)
  255. if random <= 1 then
  256. randRate = 2
  257. end
  258. end
  259. for _, itemInfo in ipairs(v.reward) do
  260. len = len + 1
  261. awardList[len] = {itemInfo[1], itemInfo[2] * randRate * rewardCnt}
  262. end
  263. --更新
  264. local msgRet = Msg.gc.GC_DAILYTASK_GET_HUOYUEBOX
  265. msgRet.boxID = boxId
  266. msgRet.double = double and 1 or 0
  267. Msg.send(msgRet,human.fd)
  268. end
  269. end
  270. if len > 0 then
  271. BagLogic.addItemList(human, awardList, "daily_task")
  272. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_801)
  273. end
  274. end
  275. function isDot(human)
  276. -- 主界面的任务包含2个标签 每日任务/成就
  277. if RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_801) ~= true then
  278. return false
  279. end
  280. if human.db.dailyTask and human.db.dailyTask.task then
  281. for k,v in pairs(human.db.dailyTask.task) do
  282. if k and v and v.isGet ~= true then
  283. local dailyTaskConfig = DailyTaskExcel.dailyTask[k]
  284. if dailyTaskConfig then
  285. local cnt = v.finishCnt or 0
  286. if cnt >= dailyTaskConfig.taskCnt then
  287. return true
  288. end
  289. end
  290. end
  291. end
  292. end
  293. for i=1,#DailyTaskExcel.huoYueBox do
  294. if huoYueBoxCanGet(human,i) then return true end
  295. end
  296. return false
  297. end
  298. function onDailyTaskHuoYue(human,sum)
  299. if not human.db.dailyTask then return end
  300. human.db.dailyTask.nowHuoYue = (human.db.dailyTask.nowHuoYue or 0) + sum
  301. YunYingLogic.onCallBack(human, "onDailyTask",sum)
  302. end
  303. function onLogin(human)
  304. recordDailyTaskFinishCnt(human, DAILY_TASK_ID_1, 1, true)
  305. dailyTaskQuery(human, true)
  306. end