AbsExcellentGiftLogic.lua 16 KB

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