AbsWeeklyCardLogic.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. -- ABS 周卡
  2. local Config = require("Config")
  3. local AbsActExcel = require("excel.absAct")
  4. local Lang = require("common.Lang")
  5. local Util = require("common.Util")
  6. local Msg = require("core.Msg")
  7. local AbsActDefine = require("absAct.AbsActDefine")
  8. local ObjHuman = require("core.ObjHuman")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local MangHeLogic = require("absAct.MangHeLogic")
  11. local MailExcel = require("excel.mail")
  12. local MailManager = require("mail.MailManager")
  13. local CommonDB = require("common.CommonDB")
  14. local AbsActLogic = require("absAct.AbsActLogic")
  15. local HeroGrid = require("hero.HeroGrid")
  16. local DrawCardLogic = require("drawCard.DrawCardLogic")
  17. local Log = require("common.Log")
  18. local HeroBook = require("hero.HeroBook")
  19. local HeroExcel = require("excel.hero")
  20. local HeroLogic = require("hero.HeroLogic")
  21. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  22. local Grid = require("bag.Grid")
  23. local BuyLogic = require("topup.BuyLogic")
  24. local BuyExcel = require("excel.buy")
  25. local TopupLogic = require("topup.TopupLogic")
  26. local MailExcel = require("excel.mail")
  27. local MailManager = require("mail.MailManager")
  28. local BagLogic = require("bag.BagLogic")
  29. DAY_CNT = 7
  30. local function initDB(human, id, actId)
  31. if not human.db.absAct[id] then return end
  32. human.db.absAct[id][actId] = { dayCnt = DAY_CNT }
  33. end
  34. function isOpen(human, YYInfo, funcConfig)
  35. return AbsActLogic.isStarted(human, funcConfig.funcID)
  36. end
  37. function isActive(human, YYInfo, funcConfig)
  38. return not isOpen(human, YYInfo, funcConfig)
  39. end
  40. function isRed(human, YYInfo, funcConfig)
  41. return false
  42. end
  43. function getAndSendMsg(human, id, config)
  44. local msgRet = Msg.gc.GC_ABS_WEEK_LYCARD_QUERY
  45. msgRet.leftTime = 0
  46. msgRet.actId = id
  47. local actId = config.actId
  48. local weeklyCardConfig = AbsActExcel.absWeeklyCard
  49. if not weeklyCardConfig then return end
  50. local buyItemConfig = BuyExcel.libao[TopupLogic.TOPUP_LIBAO_ID2]
  51. if not buyItemConfig then return end
  52. local absAct = human.db.absAct[id]
  53. msgRet.isActive = absAct and absAct[config.actId] and 1 or 0
  54. local len = 0
  55. for k, item in ipairs(weeklyCardConfig) do
  56. len = len + 1
  57. if len > #msgRet.weekLyCard then
  58. break
  59. end
  60. local net = msgRet.weekLyCard[len]
  61. net.id = k
  62. net.items[0] = #item[actId]
  63. for i = 1, #item[actId] do
  64. Grid.makeItem(net.items[i], item[actId][i][1], item[actId][i][2])
  65. end
  66. end
  67. msgRet.weekLyCard[0] = len
  68. msgRet.buyItem.item[0] = #buyItemConfig.reward
  69. for i = 1, #buyItemConfig.reward do
  70. Grid.makeItem(msgRet.buyItem.item[i], buyItemConfig.reward[i][1], buyItemConfig.reward[i][2])
  71. end
  72. msgRet.buyItem.cnt = isActive and 1 or 0
  73. msgRet.buyItem.id = TopupLogic.TOPUP_LIBAO_ID2
  74. msgRet.buyItem.maxCnt = buyItemConfig.cnt
  75. msgRet.buyItem.icon = buyItemConfig.icon or 0
  76. msgRet.buyItem.name = buyItemConfig.name or ""
  77. BuyLogic.fontBuyItem(human, msgRet.buyItem.buyMsg[1], buyItemConfig.buyID)
  78. msgRet.buyItem.buyMsg[0] = 1
  79. msgRet.buyItem.needItem[0] = 0
  80. Msg.send(msgRet, human.fd)
  81. end
  82. function updateDaily(human, id, findActId)
  83. local config = AbsActExcel.absActivity[id]
  84. if not config then return end
  85. -- 有无激活记录
  86. local absAct = human.db.absAct[id]
  87. if not absAct then return end
  88. -- 发放奖励
  89. local clean = false
  90. for actId, v in pairs(absAct) do
  91. -- 是否只发放当期奖励
  92. local bSend = false
  93. if findActId == nil or
  94. findActId == actId then
  95. bSend = true
  96. end
  97. if type(v) == "table" and v.dayCnt and v.dayCnt > 0 and bSend then
  98. v.dayCnt = v.dayCnt - 1
  99. local dayIndex = DAY_CNT - v.dayCnt
  100. local weeklyCardConfig = AbsActExcel.absWeeklyCard[dayIndex]
  101. if weeklyCardConfig then
  102. -- 减去一天
  103. local mailId = config.param[1]
  104. local mailConfig = MailExcel.mail[mailId]
  105. local title = mailConfig.title
  106. local senderName = mailConfig.senderName
  107. local content = Util.format(mailConfig.content, DAY_CNT, DAY_CNT - v.dayCnt)
  108. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, weeklyCardConfig[actId], senderName)
  109. end
  110. clean = true
  111. -- 有数据就 跳出重置流程
  112. if v.dayCnt > 0 then
  113. clean = false
  114. else
  115. -- 小于0的 清除掉
  116. human.db.absAct[id][actId] = nil
  117. end
  118. end
  119. end
  120. if clean and findActId == nil then
  121. human.db.absAct[id] = { endTime = config.realEndTime }
  122. end
  123. end
  124. -- 礼包激活
  125. function absWeeklyCard(human, id, buyConf, isFirst, cnt)
  126. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  127. if not state then return end
  128. local config = AbsActExcel.absActivity[id]
  129. if not config then return end
  130. local buyItemConfig = BuyExcel.libao[TopupLogic.TOPUP_LIBAO_ID2]
  131. if not buyItemConfig then return end
  132. AbsActLogic.checkAbsActClean(human, id)
  133. -- 是否已经激活
  134. local absAct = human.db.absAct[id][config.actId]
  135. if absAct ~= nil then return end
  136. -- 激活
  137. initDB(human, id, config.actId)
  138. -- 给礼包道具
  139. BagLogic.addItemList(human, buyItemConfig.reward, "abs_weeklyCard")
  140. -- 发送一天道具
  141. updateDaily(human, id, config.actId)
  142. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  143. getAndSendMsg(human, id, config)
  144. end