AbsExcellentGiftLogic.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. --新商业化活动——超值豪礼
  2. --db
  3. --[=[
  4. human.db.absAct[id] = {
  5. recordData = {
  6. [1] = { --key为任务ID
  7. [1] = 10, --key为触发事件Id, value为进度
  8. [0] = 1, --key为需要充值的ID, value为充值次数。key为0时, 表示免费
  9. isGet = nil, --有值时表示已领取
  10. },
  11. }
  12. }
  13. ]=]--
  14. local Msg = require("core.Msg")
  15. local Grid = require("bag.Grid")
  16. local BagLogic = require("bag.BagLogic")
  17. local AbsActLogic = require("absAct.AbsActLogic")
  18. local Broadcast = require("broadcast.Broadcast")
  19. local Lang = require("common.Lang")
  20. local YunYingLogic = require("yunying.YunYingLogic")
  21. local AbsActExcel = require("excel.absAct")
  22. local BuyLogic = require("topup.BuyLogic")
  23. local CommonDefine = require("common.CommonDefine")
  24. local ItemDefine = require("bag.ItemDefine")
  25. --本活动ID
  26. local ACTID = 753
  27. --日志标识
  28. local LOGTAG = "AbsExcellentGiftLogic"
  29. --完成任务消耗道具ID
  30. local FINISH_TASK_COST_ID = ItemDefine.ITEM_ZUANSHI_ID
  31. --完成任务消耗道具数量
  32. local FINISH_TASK_COST_CNT = 500
  33. local BATTLE_MOP_UP = 1 --冒险闯关扫荡
  34. local LOSTTEMPLE_PASS = 2 --失落神庙通关
  35. local YJTREASURE_PASS_LEVEL = 3 --遗迹探险层数
  36. local FRIEND_COMBAT = 4 --好友切磋次数
  37. local CHAT_TIMES = 5 --所有聊天频道发言次数
  38. local MOZHU_CHALLENGE = 6 --魔王梼杌参数次数
  39. local DRAWCALL_SERNIOR_CNT = 7 --高级召唤次数
  40. local FUWEN_RECASTING = 8 --符文重铸次数
  41. local UNION_DONATE = 9 --公会捐献次数
  42. local ZHANBU_SYNTHESIS = 10 --占卜合成次数
  43. ---------------------------------各类事件处理接口----------------------------------
  44. function onMopup(human, funcID, value)
  45. TriggerCbFunc(human, BATTLE_MOP_UP, value, true)
  46. end
  47. function friendCombat(human, funcID, value)
  48. TriggerCbFunc(human, FRIEND_COMBAT, value, true)
  49. end
  50. function lostTempleCombat(human, funcID, value)
  51. TriggerCbFunc(human, LOSTTEMPLE_PASS, value, true)
  52. end
  53. function YJTreasurePass(human, funcID, value)
  54. TriggerCbFunc(human, YJTREASURE_PASS_LEVEL, value, true)
  55. end
  56. function ChatTimes(human, funcID, value)
  57. TriggerCbFunc(human, CHAT_TIMES, value, true)
  58. end
  59. function MoZhuCombat(human, funcID, value)
  60. TriggerCbFunc(human, MOZHU_CHALLENGE, value, true)
  61. end
  62. function onDrawCard(human, funcID, value)
  63. TriggerCbFunc(human, DRAWCALL_SERNIOR_CNT, value, true)
  64. end
  65. function onFuwenChongZhu(human, funcID, value)
  66. TriggerCbFunc(human, FUWEN_RECASTING, value, true)
  67. end
  68. function onUnionDonate(human, funcID, value)
  69. TriggerCbFunc(human, UNION_DONATE, value, true)
  70. end
  71. function ZhanBuHecheng(human, funcID, value)
  72. TriggerCbFunc(human, ZHANBU_SYNTHESIS, value, true)
  73. end
  74. -----------------------------------------------------------------------------------
  75. -- --订阅触发事件
  76. -- local function registerTrigger(human)
  77. -- local len = 0
  78. -- local triggerTagVec = {}
  79. -- local config = AbsActExcel.AbsExcellentGiftLogic
  80. -- for _, v in ipairs(config) do
  81. -- len = len + 1
  82. -- triggerTagVec[len] = v.taskId
  83. -- end
  84. -- TriggerLogic.RegisterMoniter(triggerTagVec, TriggerCbFunc, human.db.newUniqueTag)
  85. -- end
  86. --获取任务ID
  87. local function getTaskIdVec(triggerId, buyId)
  88. local ids = {}
  89. local len = 0
  90. local config = AbsActExcel.AbsExcellentGiftLogic
  91. for id, cfg in ipairs(config) do
  92. if triggerId and cfg.taskId == triggerId then
  93. len = len + 1
  94. ids[len] = id
  95. end
  96. if buyId and cfg.buyId == buyId then
  97. len = len + 1
  98. ids[len] = id
  99. end
  100. end
  101. return ids
  102. end
  103. --是否完成任务, 0-未完成, 1-可领取,2-已领取
  104. local function getTaskState(taskId, taskData)
  105. if not taskData then
  106. return CommonDefine.COMMON_PRIZE_STATE_NOGET
  107. end
  108. if taskData.isGet then
  109. return CommonDefine.COMMON_PRIZE_STATE_GET
  110. end
  111. local config = AbsActExcel.AbsExcellentGiftLogic
  112. local singleCfg = config[taskId]
  113. local triggerId = singleCfg.taskId
  114. local triggerVal = singleCfg.taskVal
  115. local isFinish = true
  116. if not taskData[triggerId] or taskData[triggerId] < triggerVal then
  117. isFinish = false
  118. end
  119. if not isFinish then
  120. return CommonDefine.COMMON_PRIZE_STATE_NOGET
  121. end
  122. local condBuyId = singleCfg.buyId
  123. if condBuyId ~= 0 and not taskData[condBuyId] then
  124. return CommonDefine.COMMON_PRIZE_STATE_NOGET
  125. end
  126. if isFinish and not taskData.isGet then
  127. return CommonDefine.COMMON_PRIZE_STATE_CANGET
  128. end
  129. end
  130. --红点检查
  131. local function redDotCheck(recordData)
  132. local redDotPageTb = {}
  133. local taskState = 0
  134. local config = AbsActExcel.AbsExcellentGiftLogic
  135. for taskId, data in pairs(recordData) do
  136. taskState = getTaskState(taskId, data)
  137. if taskState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  138. local taskCfg = config[taskId]
  139. redDotPageTb[taskCfg.page] = '1'
  140. end
  141. end
  142. if not next(redDotPageTb) then
  143. return false
  144. end
  145. return redDotPageTb
  146. end
  147. -- function onLogin(human, id)
  148. -- local state = AbsActLogic.isStarted(human, id)
  149. -- if not state then
  150. -- return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  151. -- end
  152. -- local actData = human.db.absAct[id]
  153. -- if not actData then
  154. -- return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  155. -- end
  156. -- --registerTrigger(human)
  157. -- end
  158. --充值处理接口
  159. function onCharge(human, price, funcID, buyID)
  160. local state = AbsActLogic.isStarted(human, funcID)
  161. if not state then
  162. return
  163. end
  164. local isChange = false
  165. local taskState = COMMON_PRIZE_STATE_NOGET
  166. local actData = human.db.absAct[ACTID]
  167. actData.recordData = actData.recordData or {}
  168. local recordData = actData.recordData
  169. local ids = getTaskIdVec(nil, buyID)
  170. local config = AbsActExcel.AbsExcellentGiftLogic
  171. for _, id in ipairs(ids) do
  172. if not recordData[id] or not recordData[id].isGet then
  173. local singleCfg = config[id]
  174. local needBuyId = singleCfg.buyId
  175. recordData[id] = recordData[id] or {}
  176. recordData[id][needBuyId] = (recordData[id][needBuyId] or 0) + 1
  177. isChange = true
  178. if taskState ~= CommonDefine.COMMON_PRIZE_STATE_CANGET then
  179. taskState = getTaskState(id, recordData[id])
  180. end
  181. end
  182. end
  183. if isChange then
  184. Query(human, ACTID, human.nowPage or 0)
  185. end
  186. if taskState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  187. --红点刷新
  188. YunYingLogic.sendBanner(human)
  189. local config = AbsActExcel.absActivity[ACTID]
  190. YunYingLogic.sendGroupUpdate(YYInfo[ACTID], human, config.panelID)
  191. end
  192. end
  193. --事件触发接口
  194. function TriggerCbFunc(human, triggerTag, val, isAdd)
  195. local state = AbsActLogic.isStarted(human, ACTID)
  196. if not state then
  197. return
  198. end
  199. --local isChange = false
  200. local taskState = COMMON_PRIZE_STATE_NOGET
  201. local actData = human.db.absAct[ACTID]
  202. actData.recordData = actData.recordData or {}
  203. local recordData = actData.recordData
  204. local ids = getTaskIdVec(triggerTag)
  205. for _, id in ipairs(ids) do
  206. if not recordData[id] or not recordData[id].isGet then
  207. recordData[id] = recordData[id] or {}
  208. if isAdd then
  209. recordData[id][triggerTag] = (recordData[id][triggerTag] or 0) + val
  210. else
  211. recordData[id][triggerTag] = val
  212. end
  213. --isChange = true
  214. if taskState ~= CommonDefine.COMMON_PRIZE_STATE_CANGET then
  215. taskState = getTaskState(id, recordData[id])
  216. end
  217. end
  218. end
  219. -- if isChange then
  220. -- Query(human, ACTID, nowPage)
  221. -- end
  222. if taskState == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  223. --红点刷新
  224. YunYingLogic.sendBanner(human)
  225. local config = AbsActExcel.absActivity[ACTID]
  226. YunYingLogic.sendGroupUpdate(YYInfo[ACTID], human, config.panelID)
  227. end
  228. end
  229. --红点判断
  230. function isRed(human, YYInfo, funcConfig)
  231. local actData = human.db.absAct[funcConfig.funcID]
  232. if not actData then
  233. return false
  234. end
  235. local recordData = actData.recordData
  236. if not recordData then
  237. return false
  238. end
  239. if not redDotCheck(recordData) then
  240. return false
  241. end
  242. return true
  243. end
  244. function isOpen(human, YYInfo, funcConfig)
  245. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  246. return state, endTime, startTime
  247. end
  248. function isActive(human, YYInfo, funcConfig)
  249. local state = isOpen(human, YYInfo, funcConfig)
  250. return not state
  251. end
  252. --查询
  253. function Query(human, id, page)
  254. local state = AbsActLogic.isStarted(human, id)
  255. if not state then
  256. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  257. end
  258. local actData = human.db.absAct[id]
  259. if not actData then
  260. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  261. end
  262. actData.recordData = actData.recordData or {}
  263. local recordData = actData.recordData
  264. local config = AbsActExcel.AbsExcellentGiftLogic
  265. local msgRet = Msg.gc.GC_EXCELLENTGIFT_QUERY
  266. local len = 0
  267. local taskList = msgRet.taskList
  268. for taskId, v in ipairs(config) do
  269. if v.page == page then
  270. len = len + 1
  271. local taskData = recordData[taskId]
  272. taskList[len].state = getTaskState(taskId, taskData)
  273. taskList[len].idx = len
  274. taskList[len].taskDesc = v.taskDes
  275. taskList[len].taskMaxProgress = v.taskVal
  276. taskList[len].taskNowProgress = taskData and taskData[v.taskId] or 0
  277. BuyLogic.fontBuyItem(human, taskList[len].buyMsg, v.buyId)
  278. taskList[len].buyState = taskData and taskData[v.buyId] or 0
  279. if v.buyId == 0 then
  280. taskList[len].buyState = 1
  281. end
  282. local awardVec = taskList[len].award
  283. awardVec[0] = #v.award
  284. for j, itemInfo in ipairs(v.award) do
  285. Grid.makeItem(awardVec[j], itemInfo[1], itemInfo[2])
  286. end
  287. end
  288. end
  289. taskList[0] = len
  290. --完成任务消耗
  291. Grid.makeItem(msgRet.finishTaskCost, FINISH_TASK_COST_ID, FINISH_TASK_COST_CNT)
  292. --红点
  293. local redDotList = msgRet.redDotList
  294. redDotList[0] = 0
  295. local redDotPageTb = redDotCheck(recordData)
  296. if redDotPageTb then
  297. len = 0
  298. for redPage in pairs(redDotPageTb) do
  299. len = len + 1
  300. redDotList[len] = redPage
  301. end
  302. redDotList[0] = len
  303. end
  304. Msg.send(msgRet, human.fd)
  305. human.nowPage = page
  306. end
  307. --领奖
  308. function GetReward(human, id, taskIdx, page)
  309. local state = AbsActLogic.isStarted(human, id)
  310. if not state then
  311. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  312. end
  313. local actData = human.db.absAct[id]
  314. if not actData then
  315. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  316. end
  317. local len = 0
  318. local taskIdList = {}
  319. local recordData = actData.recordData
  320. local config = AbsActExcel.AbsExcellentGiftLogic
  321. -- for k, v in ipairs(config) do
  322. -- if v.page == page then
  323. -- len = len + 1
  324. -- if len == taskIdx then
  325. -- taskId = k
  326. -- break
  327. -- end
  328. -- end
  329. -- end
  330. for k, v in ipairs(config) do
  331. if v.page == page then
  332. if getTaskState(k, recordData and recordData[k]) == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  333. len = len + 1
  334. taskIdList[len] = k
  335. end
  336. end
  337. end
  338. if len == 0 then
  339. return Broadcast.sendErr(human, Lang.ABS_ANSWER_ITEM_IS_GET)
  340. end
  341. local awardtbl = {}
  342. for _, taskId in ipairs(taskIdList) do
  343. recordData[taskId].isGet = '1'
  344. local taskCfg = config[taskId]
  345. for _, itemInfo in ipairs(taskCfg.award) do
  346. awardtbl[#awardtbl+1] = itemInfo
  347. end
  348. end
  349. BagLogic.addItemList(human, awardtbl, LOGTAG)
  350. --BagLogic.addItemList(human, taskCfg.award, LOGTAG)
  351. Query(human, id, page)
  352. --红点
  353. if not redDotCheck(recordData) then
  354. YunYingLogic.sendBanner(human)
  355. local otherConfig = AbsActExcel.absActivity[ACTID]
  356. YunYingLogic.sendGroupUpdate(YYInfo[ACTID], human, otherConfig.panelID)
  357. end
  358. end
  359. --消耗古玉完成任务
  360. function FinishTaskByDiamond(human, id, taskIdx, page)
  361. local state = AbsActLogic.isStarted(human, id)
  362. if not state then
  363. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  364. end
  365. local actData = human.db.absAct[id]
  366. if not actData then
  367. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  368. end
  369. local recordData = actData.recordData
  370. local len = 0
  371. local taskId = 0
  372. local taskCfg = nil
  373. local config = AbsActExcel.AbsExcellentGiftLogic
  374. for k, v in ipairs(config) do
  375. if v.page == page then
  376. len = len + 1
  377. if len == taskIdx then
  378. taskId = k
  379. taskCfg = v
  380. break
  381. end
  382. end
  383. end
  384. if taskId == 0 then
  385. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  386. end
  387. if recordData and recordData[taskId] and recordData[taskId].isGet then
  388. return Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  389. end
  390. if getTaskState(taskId, recordData and recordData[taskId]) == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  391. return Broadcast.sendErr(human, Lang.COMMON_FINISH)
  392. end
  393. if BagLogic.getItemCnt(human, FINISH_TASK_COST_ID) < FINISH_TASK_COST_CNT then
  394. return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
  395. end
  396. --扣消耗
  397. BagLogic.delItem(human, FINISH_TASK_COST_ID, FINISH_TASK_COST_CNT, LOGTAG)
  398. recordData[taskId] = recordData[taskId] or {}
  399. recordData[taskId][taskCfg.taskId] = taskCfg.taskVal
  400. --红点
  401. YunYingLogic.sendBanner(human)
  402. local otherConfig = AbsActExcel.absActivity[ACTID]
  403. YunYingLogic.sendGroupUpdate(YYInfo[ACTID], human, otherConfig.panelID)
  404. --更新
  405. Query(human, id, page)
  406. end