ExclusiveTaskLogic.lua 12 KB

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