AbsWeeklyCardLogic.lua 6.0 KB

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