AbsWeeklyCardLogic.lua 5.7 KB

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