LimitMangHeLogic.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. --- 限时盲盒
  2. local CommonDB = require("common.CommonDB")
  3. local Util = require("common.Util")
  4. local Lang = require("common.Lang")
  5. local ObjHuman = require("core.ObjHuman")
  6. local Msg = require("core.Msg")
  7. local Broadcast = require("broadcast.Broadcast")
  8. local Grid = require("bag.Grid")
  9. local BagLogic = require("bag.BagLogic")
  10. local ItemDefine = require("bag.ItemDefine")
  11. local BuyLogic = require("topup.BuyLogic")
  12. local AbsActDefine = require("absAct.AbsActDefine")
  13. local AbsActLogic = require("absAct.AbsActLogic")
  14. local OpenActExcel = require("excel.openAct")
  15. local YunYingLogic = require("yunying.YunYingLogic")
  16. local PanelDefine = require("broadcast.PanelDefine")
  17. PRESENT_LIMIT_MANGHE_LIST = nil
  18. function initAfterHot()
  19. -- if PRESENT_LIMIT_MANGHE_LIST then return end -- 策划测试 OS 修改可能会导致 不会重复 载入 去掉
  20. local oepenTime = CommonDB.getServerOpenTime()
  21. if oepenTime == 0 then return end
  22. PRESENT_LIMIT_MANGHE_LIST = {}
  23. local oneDay = 24 * 60 * 60
  24. for k, config in pairs(OpenActExcel.limitMangHe) do
  25. if not PRESENT_LIMIT_MANGHE_LIST[config.actId] then
  26. PRESENT_LIMIT_MANGHE_LIST[config.actId] = {}
  27. local time = (config.openStart - 1) * oneDay + oepenTime
  28. local time2 = config.openEnd * oneDay + oepenTime
  29. local startTime = Util.getDayStartTime(time)
  30. local endTime = Util.getDayStartTime(time2) - 1
  31. -- 如果是当天就结束的活动
  32. if config.openStart == config.openEnd then
  33. endTime = startTime + oneDay - 1
  34. end
  35. PRESENT_LIMIT_MANGHE_LIST[config.actId].startTime = startTime
  36. PRESENT_LIMIT_MANGHE_LIST[config.actId].endTime = endTime
  37. config.startTime = startTime
  38. config.endTime = endTime
  39. end
  40. PRESENT_LIMIT_MANGHE_LIST[config.actId].list = PRESENT_LIMIT_MANGHE_LIST[config.actId].list or {}
  41. local len = #PRESENT_LIMIT_MANGHE_LIST[config.actId].list
  42. PRESENT_LIMIT_MANGHE_LIST[config.actId].list[len + 1] = {}
  43. PRESENT_LIMIT_MANGHE_LIST[config.actId].list[len + 1] = k
  44. end
  45. end
  46. function isOpen(human, YYInfo, funcConfig)
  47. if not PRESENT_LIMIT_MANGHE_LIST then return end
  48. local now = os.time()
  49. local config = PRESENT_LIMIT_MANGHE_LIST[funcConfig.param]
  50. if not config then return end
  51. if now >= config.startTime and now < config.endTime then
  52. return true
  53. end
  54. end
  55. --
  56. function getLeftTime(human, YYInfo, funcConfig)
  57. if isOpen(human, YYInfo, funcConfig) then
  58. local config = PRESENT_LIMIT_MANGHE_LIST[funcConfig.param]
  59. return config.endTime - os.time()
  60. end
  61. return 0
  62. end
  63. function getBuyCnt(human, id)
  64. if human.db.limitMangHe and human.db.limitMangHe[id] then
  65. return human.db.limitMangHe[id]
  66. end
  67. return 0
  68. end
  69. function getBoxState(human, param)
  70. local now = os.time()
  71. local limitConfig = PRESENT_LIMIT_MANGHE_LIST[param]
  72. if now >= limitConfig.startTime and now < limitConfig.endTime then
  73. if not human.db.limitMangHe or not human.db.limitMangHe.boxGet or not human.db.limitMangHe.boxGet[param] or not Util.isSameDay(human.db.limitMangHe.boxGet[param]) then
  74. return true
  75. end
  76. end
  77. return false
  78. end
  79. function fontGift(human, net , id)
  80. local config = OpenActExcel.limitMangHe[id]
  81. net.id = id
  82. for i = 1, #config.reward do
  83. Grid.makeItem(net.item[i], config.reward[i][1], config.reward[i][2])
  84. end
  85. net.item[0] = #config.reward
  86. net.cnt = getBuyCnt(human, id)
  87. net.maxCnt = config.cnt
  88. net.name = config.name or ""
  89. BuyLogic.fontBuyItem(human, net.buyMsg, config.buyID)
  90. end
  91. function query(human, param)
  92. local now = os.time()
  93. local limitConfig = PRESENT_LIMIT_MANGHE_LIST[param]
  94. if now < limitConfig.startTime or now >= limitConfig.endTime then
  95. return
  96. end
  97. local msgRet = Msg.gc.GC_OA_LIMIT_MANGHE_QUERY
  98. for k, id in ipairs(limitConfig.list) do
  99. local net = msgRet.list[k]
  100. fontGift(human, msgRet.list[k], id)
  101. end
  102. msgRet.list[0] = #limitConfig.list
  103. msgRet.startTime = limitConfig.startTime
  104. msgRet.endTime = limitConfig.endTime
  105. msgRet.param = param
  106. msgRet.state = getBoxState(human, param) and 1 or 0
  107. -- Msg.trace(msgRet)
  108. Msg.send(msgRet, human.fd)
  109. end
  110. function buy(human, buyID)
  111. -- 存在多个特惠礼包 同时 开放
  112. local actId
  113. local id
  114. for k, config in pairs(OpenActExcel.limitMangHe) do
  115. if config.buyID == buyID then
  116. actId = config.actId
  117. id = k
  118. break
  119. end
  120. end
  121. if not id then return end
  122. local now = os.time()
  123. local limitConfig = PRESENT_LIMIT_MANGHE_LIST[actId]
  124. if now < limitConfig.startTime or now >= limitConfig.endTime then
  125. return
  126. end
  127. local config = OpenActExcel.limitMangHe[id]
  128. if getBuyCnt(human, id) >= config.cnt then
  129. return
  130. end
  131. -- 当金币购买之后超过最大金币时,不允许购买
  132. for j = 1, #config.reward do
  133. local itemID = config.reward[j][1]
  134. local itemCnt = config.reward[j][2]
  135. if itemID == ItemDefine.ITEM_JINBI_ID then
  136. if not ObjHuman.canAddJinbi(human, itemCnt) then
  137. return
  138. end
  139. end
  140. end
  141. human.db.limitMangHe = human.db.limitMangHe or {}
  142. human.db.limitMangHe[id] = human.db.limitMangHe[id] or 0
  143. human.db.limitMangHe[id] = human.db.limitMangHe[id] + 1
  144. BagLogic.addItemList(human, config.reward , "limit_mangHe")
  145. Broadcast.sendErr(human, Lang.ITEM_BUY_SUCCESS)
  146. query(human, config.actId)
  147. end
  148. function getBox(human, param)
  149. if getBoxState(human, param) then
  150. local now = os.time()
  151. local get = false
  152. local limitConfig = PRESENT_LIMIT_MANGHE_LIST[param]
  153. if now >= limitConfig.startTime and now < limitConfig.endTime then
  154. if not human.db.limitMangHe or not human.db.limitMangHe.boxGet or not human.db.limitMangHe.boxGet[param]
  155. or not Util.isSameDay(human.db.limitMangHe.boxGet[param]) then
  156. human.db.limitMangHe = human.db.limitMangHe or {}
  157. human.db.limitMangHe.boxGet = human.db.limitMangHe.boxGet or {}
  158. human.db.limitMangHe.boxGet[param] = now
  159. get = true
  160. end
  161. end
  162. if get then
  163. for k, config in pairs(OpenActExcel.limitMangHe) do
  164. if config.actId == param and #config.dayReward > 0 then
  165. BagLogic.addItemList(human, config.dayReward, "limit_mangHe")
  166. break
  167. end
  168. end
  169. query(human, param)
  170. for k, v in pairs(funcID) do
  171. YunYingLogic.updateIcon(YYInfo[k], human)
  172. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3606,param)
  173. break
  174. end
  175. end
  176. end
  177. end
  178. function isRed(human,YYInfo, funcConfig)
  179. local now = os.time()
  180. local limitConfig = PRESENT_LIMIT_MANGHE_LIST[funcConfig.param]
  181. if now >= limitConfig.startTime and now < limitConfig.endTime then
  182. if getBoxState(human, funcConfig.param) then
  183. return true
  184. end
  185. end
  186. end