ExclusiveTaskLogic.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. local AbsActLogic = require("absAct.AbsActLogic")
  2. local AbsActExcel = require("excel.absAct")
  3. local Msg = require("core.Msg")
  4. local Grid = require("bag.Grid")
  5. local BagLogic = require("bag.BagLogic")
  6. local AbsActDefine = require("absAct.AbsActDefine")
  7. local YunYingLogic = require("yunying.YunYingLogic")
  8. local PanelDefine = require("broadcast.PanelDefine")
  9. local BuyLogic = require("topup.BuyLogic")
  10. local Util = require("common.Util")
  11. local CycleActivityLogic = require("yunying.CycleActivity")
  12. --[[
  13. absAct.xlsx-exclusiveTask、absAct.xlsx-exclusiveTaskBox
  14. 新英雄来袭-专属任务
  15. 1.完成任务可获得任务奖励,还会增加宝箱积分
  16. 2.宝箱积分达到指定数量可获得宝箱奖励
  17. 3.现在只实现了任务7和任务8,后续新加任务需要再实现
  18. DB:
  19. human.db.absAct[id] = {
  20. boxScore = xx, -- 箱子积分数
  21. task = { -- 任务数据
  22. xxx = { -- 任务id
  23. cnt = xxx, -- 完成进度
  24. state = xxx,-- 任务状态 1可领 2已领
  25. },
  26. ...
  27. },
  28. box = {
  29. xxx = state, -- 箱子id = 箱子状态 1可领 2已领
  30. ...
  31. },
  32. buling = 0, -- 补领状态
  33. }
  34. local:
  35. isComplRuleTask() -- 是否完成了任务
  36. public:
  37. getAndSendMsg() -- 发送活动数据
  38. isRed() -- 红点提醒
  39. isActive() -- 激活状态
  40. isOpen() -- 活动开启
  41. getLeftTime() -- 得到活动剩余时间
  42. getBoxReward() -- 领取箱子奖励
  43. getTaskReward() -- 领取任务奖励
  44. finishTaskCB() -- 任务完成回调
  45. --]]
  46. HERO_LOG_TYPE_1 = 1 --每日登录
  47. HERO_LOG_TYPE_2 = 2 --冠军联赛挑战X次
  48. HERO_LOG_TYPE_3 = 3 --扫荡X次
  49. HERO_LOG_TYPE_4 = 4 --领取X次5星以上悬赏任务
  50. HERO_LOG_TYPE_5 = 5 --任意难度勇者试炼通关X次
  51. HERO_LOG_TYPE_6 = 6 --累计消耗X钻石
  52. HERO_LOG_TYPE_7 = 7 --获得任务中指定的英雄
  53. HERO_LOG_TYPE_8 = 8 --获得任务中指定的英雄升到多少星
  54. STATE_0 = 0 -- 不可领
  55. STATE_1 = 1 -- 可领
  56. STATE_2 = 2 -- 已领
  57. local function isComplRuleTask(type, rules, value1, value2)
  58. if not rules then return true end
  59. local isCompl
  60. -- 特殊完成规则
  61. if type == HERO_LOG_TYPE_7 then
  62. for _,heroID in ipairs(rules) do
  63. if value1 == heroID then
  64. isCompl = true
  65. break
  66. end
  67. end
  68. elseif type == HERO_LOG_TYPE_8 then
  69. for _,rule in ipairs(rules) do
  70. if value1 == rule[1] and value2 >= rule[2] then
  71. isCompl = true
  72. break
  73. end
  74. end
  75. else
  76. isCompl = true
  77. end
  78. return isCompl
  79. end
  80. local function finishTaskCB(human, funcID, type, cnt, value1, value2)
  81. local absActConfig = AbsActExcel.absActivity[funcID]
  82. if not absActConfig then return end
  83. -- AbsActLogic.checkAbsActClean(human, funcID)
  84. local absAct = human.db.absAct[funcID]
  85. if not absAct then return end
  86. local isActive
  87. for index,v in pairs(AbsActExcel.exclusiveTask) do
  88. if v.actID == absActConfig.actId and v.type == type and isComplRuleTask(type, v.rules, value1, value2) then
  89. absAct.task = absAct.task or {}
  90. if not absAct.task[index] or absAct.task[index].cnt < v.maxCnt then
  91. absAct.task[index] = absAct.task[index] or {}
  92. absAct.task[index].cnt = absAct.task[index].cnt or 0
  93. absAct.task[index].cnt = absAct.task[index].cnt + cnt
  94. absAct.task[index].state = 0
  95. if absAct.task[index].cnt >= v.maxCnt then
  96. absAct.task[index].state = STATE_1
  97. isActive = true
  98. end
  99. end
  100. end
  101. end
  102. if isActive then
  103. YunYingLogic.sendGroupUpdate(YYInfo[funcID], human, absActConfig.panelID)
  104. YunYingLogic.sendBanner(human)
  105. end
  106. end
  107. function getAndSendMsg(human, id, actId)
  108. -- local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  109. local state,endTime, starTime = CycleActivityLogic.isStarted(human, id)
  110. if not state then return end
  111. local absAct = human.db.absAct[id]
  112. if not absAct then return end
  113. local msgRet = Msg.gc.GC_ABS_ACT_EXCLUSIVE_TASK_QUERY
  114. msgRet.actId = id
  115. msgRet.boxScore = absAct.boxScore or 0
  116. local nowDay = Util.diffDay(starTime) + 1
  117. msgRet.day = nowDay
  118. local len = 0
  119. for index,v in pairs(AbsActExcel.exclusiveTask) do
  120. if v.actID == actId then
  121. len = len + 1
  122. msgRet.taskList[len].id = index
  123. msgRet.taskList[len].state = STATE_0
  124. msgRet.taskList[len].maxCnt = v.maxCnt
  125. msgRet.taskList[len].desc = v.desc
  126. msgRet.taskList[len].panelID = v.panelID
  127. msgRet.taskList[len].addScoreCnt = v.addBoxCnt
  128. if not absAct.task or not absAct.task[index] then
  129. msgRet.taskList[len].nowCnt = 0
  130. else
  131. msgRet.taskList[len].nowCnt = absAct.task[index].cnt
  132. msgRet.taskList[len].state = absAct.task[index].state
  133. end
  134. for i = 1,#v.item do
  135. Grid.makeItem(msgRet.taskList[len].item[i],v.item[i][1],v.item[i][2])
  136. end
  137. msgRet.taskList[len].item[0] = #v.item
  138. end
  139. end
  140. msgRet.taskList[0] = len
  141. len = 0
  142. local buyID
  143. for index,v in pairs(AbsActExcel.exclusiveTaskBox) do
  144. if v.actId == actId then
  145. if not buyID and v.buyID ~= 0 then
  146. buyID = v.buyID
  147. end
  148. len = len + 1
  149. msgRet.box[len].id = index
  150. msgRet.box[len].needCnt = v.needCnt
  151. if not absAct.box or not absAct.box[index] then
  152. msgRet.box[len].state = STATE_0
  153. else
  154. msgRet.box[len].state = absAct.box[index]
  155. end
  156. for i = 1,#v.item do
  157. Grid.makeItem(msgRet.box[len].item[i],v.item[i][1],v.item[i][2])
  158. end
  159. msgRet.box[len].item[0] = #v.item
  160. end
  161. end
  162. msgRet.box[0] = len
  163. BuyLogic.fontBuyItem(human, msgRet.buyItem, buyID)
  164. Msg.send(msgRet,human.fd)
  165. end
  166. function isRed(human, YYInfo, funcConfig)
  167. -- local state, endTime, starTime = AbsActLogic.isStarted(human, )
  168. local state,endTime, starTime = CycleActivityLogic.isStarted(human, funcConfig.funcID)
  169. if not state then return end
  170. local absAct = human.db.absAct[funcConfig.funcID]
  171. if not absAct or (not absAct.box and not absAct.task) then
  172. return
  173. end
  174. if absAct.box then
  175. for _,v in pairs(absAct.box) do
  176. if v == STATE_1 then return true end
  177. end
  178. end
  179. if absAct.task then
  180. for _,v in pairs(absAct.task) do
  181. if v.state == STATE_1 then return true end
  182. end
  183. end
  184. return false
  185. end
  186. function isActive(human, YYInfo, funcConfig)
  187. return not isOpen(human, YYInfo, funcConfig)
  188. end
  189. function isOpen(human, YYInfo, funcConfig)
  190. -- return AbsActLogic.isStarted(human, funcConfig.funcID)
  191. return CycleActivityLogic.isStarted(human, funcConfig.funcID)
  192. end
  193. function getLeftTime(human, YInfo, funcConfig)
  194. -- local ret, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  195. local ret, endTime, startTime = CycleActivityLogic.isStarted(human, funcConfig.funcID)
  196. if ret == true then
  197. return endTime - os.time()
  198. else
  199. return 0
  200. end
  201. end
  202. function getBoxReward(human, index, id)
  203. -- local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  204. local state,endTime, starTime = CycleActivityLogic.isStarted(human, id)
  205. if not state then return end
  206. -- AbsActLogic.checkAbsActClean(human, id)
  207. local absAct = human.db.absAct[id]
  208. if not absAct or not absAct.box then return end
  209. if absAct.box[index] ~= STATE_1 then return end
  210. local absActConfig = AbsActExcel.absActivity[id]
  211. absAct.box[index] = STATE_2
  212. BagLogic.addItemList(human, AbsActExcel.exclusiveTaskBox[index].item, "abs_exclusive_task_box_get")
  213. getAndSendMsg(human, id, absActConfig.actId)
  214. YunYingLogic.sendBanner(human)
  215. YunYingLogic.updateIcon(YYInfo[id], human)
  216. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absActConfig.panelID)
  217. end
  218. function getTaskReward(human, index, id)
  219. -- local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  220. local state,endTime, starTime = CycleActivityLogic.isStarted(human, id)
  221. if not state then return end
  222. -- AbsActLogic.checkAbsActClean(human, id)
  223. local absAct = human.db.absAct[id]
  224. if not absAct or not absAct.task then return end
  225. -- 不可领或已领过
  226. if not absAct.task or not absAct.task[index]
  227. or absAct.task[index].state ~= STATE_1 then return end
  228. local absActConfig = AbsActExcel.absActivity[id]
  229. local absExTaskInfo = AbsActExcel.exclusiveTask[index]
  230. absAct.task[index].state = STATE_2
  231. absAct.boxScore = (absAct.boxScore or 0) + absExTaskInfo.addBoxCnt
  232. for index2,v2 in ipairs(AbsActExcel.exclusiveTaskBox) do
  233. if v2.actId == absActConfig.actId and absAct.boxScore >= v2.needCnt then
  234. absAct.box = absAct.box or {}
  235. absAct.box[index2] = absAct.box[index2] or STATE_1
  236. end
  237. end
  238. BagLogic.addItemList(human, absExTaskInfo.item, "abs_exclusive_task_get")
  239. getAndSendMsg(human, id, absActConfig.actId)
  240. YunYingLogic.sendBanner(human)
  241. YunYingLogic.updateIcon(YYInfo[id], human)
  242. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absActConfig.panelID)
  243. end
  244. function onLogin(human,funcID)
  245. finishTaskCB(human, funcID, 1, 1)
  246. end
  247. function onCharge(human, price, funcID)
  248. finishTaskCB(human, funcID, 3, price)
  249. end
  250. function onDailyTask(human,funcID, parameter)
  251. finishTaskCB(human, funcID, 2, parameter)
  252. end
  253. function onBinglong(human, funcID, parameter)
  254. finishTaskCB(human, funcID, 4, parameter)
  255. end
  256. function onDecZuanshi(human, funcID, parameter)
  257. finishTaskCB(human, funcID, 5, parameter)
  258. end
  259. function onGetNewHeroAct(human, funcID, parameters)
  260. local logType = parameters[1]
  261. if logType == "abs_hero_come_draw_card" or logType == "item_summon" then
  262. local heroID = parameters[2]
  263. local cnt = parameters[3] or 1
  264. finishTaskCB(human, funcID, HERO_LOG_TYPE_7, cnt, heroID)
  265. end
  266. end
  267. function onHeroStarChange(human, funcID, parameters)
  268. local heroID = parameters[1]
  269. local star = parameters[2] or 0
  270. local cnt = parameters[3] or 1
  271. finishTaskCB(human, funcID, HERO_LOG_TYPE_8, cnt, heroID, star)
  272. end
  273. function buling(human,funcID,conf)
  274. if funcID ~= conf.args[1] then
  275. return
  276. end
  277. -- boxScore设置成最大值
  278. local absConfig = AbsActExcel.absActivity[funcID]
  279. local absAct = human.db.absAct[funcID]
  280. if not absAct then
  281. return
  282. end
  283. if absAct.buling == 1 then
  284. return
  285. end
  286. absAct.buling = 1
  287. local maxNeedCnt
  288. for index,v in pairs(AbsActExcel.exclusiveTaskBox) do
  289. if v.actId == absConfig.actId then
  290. if not maxNeedCnt or maxNeedCnt < v.needCnt then
  291. maxNeedCnt = v.needCnt
  292. end
  293. end
  294. end
  295. absAct.boxScore = maxNeedCnt
  296. for index2,v2 in ipairs(AbsActExcel.exclusiveTaskBox) do
  297. if v2.actId == absConfig.actId and absAct.boxScore >= v2.needCnt then
  298. absAct.box = absAct.box or {}
  299. absAct.box[index2] = absAct.box[index2] or STATE_1
  300. end
  301. end
  302. getAndSendMsg(human, funcID, absConfig.actId)
  303. YunYingLogic.sendBanner(human)
  304. YunYingLogic.updateIcon(YYInfo[id], human)
  305. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  306. end
  307. function updateDaily(human, funcID)
  308. -- local state, endTime, starTime = AbsActLogic.isStarted(human, funcID)
  309. local state, endTime, starTime = CycleActivityLogic.isStarted(human, funcID)
  310. if not state then return end
  311. local absAct = human.db.absAct[funcID]
  312. if not absAct then return end
  313. local isUpdate = false
  314. local absActConf = AbsActExcel.absActivity[funcID]
  315. for index,v in pairs(AbsActExcel.exclusiveTask) do
  316. if v.actID == absActConf.actId then
  317. if v.refresh == 0 then
  318. isUpdate = false
  319. break
  320. elseif v.refresh == 1 then
  321. isUpdate = true
  322. break
  323. end
  324. end
  325. end
  326. if isUpdate == true then
  327. absAct.task = {}
  328. end
  329. end