AbsExcellentGiftLogic.lua 15 KB

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