OpenServerSingleCharge.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. local Msg = require("core.Msg")
  2. local Util = require("common.Util")
  3. local Lang = require("common.Lang")
  4. local Broadcast = require("broadcast.Broadcast")
  5. local BagLogic = require("bag.BagLogic")
  6. local Grid = require("bag.Grid")
  7. local OpenAct = require("present.OpenAct")
  8. local YunYingLogic = require("yunying.YunYingLogic")
  9. local OpenActExcel = require("excel.openAct")
  10. local BuyExcel = require("excel.buy")
  11. --[[
  12. 开服活动-单笔充值
  13. DB:
  14. human.db.openServerSingleCharge = {
  15. [id] = { -- 档位id
  16. cnt = xxx, -- 已领取次数
  17. activeCnt = xxx,-- 已激活次数
  18. },
  19. ...
  20. }
  21. local:
  22. getDB() -- 获得单笔充值DB数据
  23. getDayLeftTime() -- 获得当天剩余时间秒
  24. wrapSChargeList() -- 包装单笔充值档位数据
  25. public:
  26. isRed() -- 红点提醒
  27. isActive() -- 激活状态
  28. isBaseOpen() -- 开启活动基本条件
  29. isOpen() -- 活动开启
  30. getLeftTime() -- 得到活动剩余时间
  31. query() -- 发送活动信息
  32. get() -- 领取活动奖励
  33. onCharge() -- 充值回调
  34. updateDaily() -- 每日重置
  35. --]]
  36. STATE_0 = 0 --不可领
  37. STATE_1 = 1 --可领
  38. STATE_2 = 2 -- 已领完
  39. local function getDB(human)
  40. human.db.openServerSingleCharge = human.db.openServerSingleCharge or {}
  41. return human.db.openServerSingleCharge
  42. end
  43. local function getDayLeftTime()
  44. local now = os.time()
  45. local endTime = Util.getDayStartTime(now) + 86400
  46. return endTime - now
  47. end
  48. local function wrapSChargeList(net, id, sChargeInfo, sChargeDB)
  49. net.id = id
  50. net.needPrice = BuyExcel.buy[sChargeInfo.needBuyId].CN
  51. net.maxCnt = sChargeInfo.maxCnt
  52. net.cnt = sChargeDB[id] and sChargeDB[id].cnt or 0
  53. if sChargeDB[id] then
  54. if sChargeDB[id].activeCnt > sChargeDB[id].cnt then
  55. net.state = STATE_1
  56. elseif sChargeDB[id].cnt >= sChargeInfo.maxCnt then
  57. net.state = STATE_2
  58. else
  59. net.state = STATE_0
  60. end
  61. else
  62. net.state = STATE_0
  63. end
  64. local len = 0
  65. for index,itemInfo in ipairs(sChargeInfo.rewards) do
  66. len = len + 1
  67. Grid.makeItem(net.items[index], itemInfo[1], itemInfo[2])
  68. end
  69. net.items[0] = len
  70. end
  71. function isRed(human)
  72. local sChargesDB = human.db.openServerSingleCharge
  73. if not sChargesDB then return end
  74. for id in ipairs(OpenActExcel.singleCharge) do
  75. if sChargesDB[id] and sChargesDB[id].activeCnt > sChargesDB[id].cnt then return true end
  76. end
  77. end
  78. function isActive(human, YYInfo, funcConfig)
  79. return not isOpen(human, YYInfo, funcConfig)
  80. end
  81. function isBaseOpen(human, YYInfo, funcConfig, noSend)
  82. do
  83. return
  84. end
  85. -- if human.db.lv < funcConfig.openLv then
  86. -- if not noSend then
  87. -- local str = Util.format(Lang.ROLE_LEV_ERROR, funcConfig.openLv)
  88. -- return Broadcast.sendErr(human, str)
  89. -- end
  90. -- end
  91. -- local flag = OpenAct.getOpenActTime(funcConfig.param)
  92. -- if not flag then return end
  93. -- return true
  94. end
  95. function isOpen(human, YYInfo, funcConfig)
  96. if isBaseOpen(human, YYInfo, funcConfig, true) then return true end
  97. end
  98. function getLeftTime(human, YYInfo, funcConfig)
  99. local _,leftTime = OpenAct.getOpenActTime(funcConfig.param)
  100. return leftTime
  101. end
  102. function query(human)
  103. local sChargeDB = getDB(human)
  104. local dayLeftTime = getDayLeftTime()
  105. local msgRet = Msg.gc.GC_OPEN_SERVER_SINGLE_CHARGE_QUERY
  106. msgRet.leftTime = dayLeftTime
  107. local len = 0
  108. for id,sChargeInfo in ipairs(OpenActExcel.singleCharge) do
  109. len = len + 1
  110. wrapSChargeList(msgRet.list[len], id, sChargeInfo, sChargeDB)
  111. end
  112. msgRet.list[0] = len
  113. Msg.send(msgRet, human.fd)
  114. end
  115. function get(human, funcID, id)
  116. local funcConfig = YunYingLogic.getFuncConfig(funcID)
  117. if not funcConfig then return end
  118. local sChargeInfo = OpenActExcel.singleCharge[id]
  119. if not sChargeInfo then return end
  120. local sChargeDB = getDB(human)
  121. if not sChargeDB[id] or sChargeDB[id].cnt >= sChargeDB[id].activeCnt then return end
  122. sChargeDB[id].cnt = sChargeDB[id].cnt + 1
  123. BagLogic.addItemList(human, sChargeInfo.rewards, "openServerSCharge_get")
  124. query(human)
  125. -- 现在没有红点了通知
  126. if not isRed(human) then
  127. YunYingLogic.sendBanner(human)
  128. YunYingLogic.updateIcon(YYInfo[funcID], human)
  129. YunYingLogic.sendGroupUpdate(YYInfo[funcID], human, funcConfig.panelID)
  130. end
  131. end
  132. function onCharge(human, price, funcID, buyID)
  133. do
  134. return
  135. end
  136. -- local funcConfig = YunYingLogic.getFuncConfig(funcID)
  137. -- if not funcConfig then return end
  138. -- if not isOpen(human, nil, funcConfig) then return end
  139. -- -- 取之前是不是有红点
  140. -- local beforeRed = isRed(human, nil, funcConfig)
  141. -- local sChargeDB = getDB(human)
  142. -- local isActive
  143. -- for id,sChargeInfo in ipairs(OpenActExcel.singleCharge) do
  144. -- if buyID == sChargeInfo.needBuyId and
  145. -- (not sChargeDB[id] or sChargeDB[id].activeCnt < sChargeInfo.maxCnt) then
  146. -- sChargeDB[id] = sChargeDB[id] or {cnt=0,activeCnt=0}
  147. -- sChargeDB[id].activeCnt = sChargeDB[id].activeCnt + 1
  148. -- isActive = true
  149. -- end
  150. -- end
  151. -- -- 之前没有红点,现在激活了红点通知(只需要通知banner上的红点)
  152. -- if not beforeRed and isActive then
  153. -- YunYingLogic.sendBanner(human)
  154. -- end
  155. end
  156. function updateDaily(human, activityID)
  157. if not human.db.openServerSingleCharge then return end
  158. human.db.openServerSingleCharge = nil
  159. end