CycleBreakThrough.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. -- 新商业化活动2——6元闯关
  2. -- 玩法: 充值指定购买项后, 获得一次参与机会,通过权重随机出前进步数,获得1~最终位置的所有奖励
  3. -- db
  4. --[=[
  5. human.db.absAct[id] = {
  6. times = nil, --参与次数
  7. dailyBuyCnt = nil, --每日购买次数
  8. }
  9. ]=]--
  10. local Msg = require("core.Msg")
  11. local Grid = require("bag.Grid")
  12. local Lang = require("common.Lang")
  13. local BagLogic = require("bag.BagLogic")
  14. local BuyLogic = require("topup.BuyLogic")
  15. local AbsActExcel = require("excel.absAct")
  16. local Broadcast = require("broadcast.Broadcast")
  17. local YunYingLogic = require("yunying.YunYingLogic")
  18. local CycleActivityLogic = require("yunying.CycleActivity")
  19. local actVariableCfg = require("excel.commercializationActivity").variable[2]
  20. local breakThroughCfg = require("excel.commercializationActivity").breakThrough
  21. -- 本活动日志标识
  22. local LOGTAG = "cycleAct_breakThrough"
  23. local DAILY_MAX_BUY_CNT = 50
  24. local function getActData(human, actId)
  25. return human.db.absAct[actId]
  26. end
  27. local function updateActTimes(human, actId, value)
  28. local actData = getActData(human, actId)
  29. actData.times = (actData.times or 0) + value
  30. end
  31. local function updateActDailyBuyCnt(human, actId, value)
  32. local actData = getActData(human, actId)
  33. actData.dailyBuyCnt = (actData.dailyBuyCnt or 0) + value
  34. actData.dailyBuyCnt = math.max(actData.dailyBuyCnt, 0)
  35. end
  36. local function calcWeightSum()
  37. local weight = 0
  38. for _, v in ipairs(breakThroughCfg) do
  39. weight = weight + v.weight
  40. end
  41. return weight
  42. end
  43. -- 更新红点
  44. local function updateRedDot(human, actId)
  45. YunYingLogic.sendBanner(human)
  46. local otherConfig = AbsActExcel.absActivity[actId]
  47. YunYingLogic.sendGroupUpdate(YYInfo[actId], human, otherConfig.panelID)
  48. end
  49. function isOpen(human, YYInfo, funcConfig)
  50. local state, endTime, startTime = CycleActivityLogic.isStarted(human, funcConfig.funcID)
  51. if not state then return end
  52. return true, endTime, startTime
  53. end
  54. function isActive(human, YYInfo, funcConfig)
  55. return not isOpen(human, YYInfo, funcConfig)
  56. end
  57. function isRed(human, YYInfo, funcConfig)
  58. local actData = getActData(human, funcConfig.funcID)
  59. if not actData then
  60. return false
  61. end
  62. if not actData.times or actData.times <= 0 then
  63. return false
  64. end
  65. return true
  66. end
  67. function onCharge(human, price, funcID, buyID)
  68. local actData = getActData(human, funcID)
  69. if not actData then
  70. return
  71. end
  72. if buyID == actVariableCfg.va1[1] and (not actData.dailyBuyCnt or actData.dailyBuyCnt < DAILY_MAX_BUY_CNT) then
  73. local oldTimes = actData.times or 0
  74. updateActTimes(human, funcID, 1)
  75. updateActDailyBuyCnt(human, funcID, 1)
  76. Query(human, funcID)
  77. if oldTimes <= 0 then
  78. updateRedDot(human, funcID)
  79. end
  80. end
  81. end
  82. function updateDaily(human, funcID)
  83. local actData = getActData(human, funcID)
  84. if not actData then
  85. return
  86. end
  87. updateActDailyBuyCnt(human, funcID, -DAILY_MAX_BUY_CNT)
  88. end
  89. function Query(human, actId)
  90. local actData = getActData(human, actId)
  91. if not actData then
  92. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  93. end
  94. local msgRet = Msg.gc.GC_CYCLEBREAKTHROUGH_QUERY
  95. msgRet.state = 0
  96. if actData.times and actData.times > 0 then
  97. msgRet.state = 1
  98. end
  99. msgRet.maxDailyBuyCnt = DAILY_MAX_BUY_CNT
  100. msgRet.nowDailyBuyCnt = actData.dailyBuyCnt or 0
  101. BuyLogic.fontBuyItem(human, msgRet.buyMsg, actVariableCfg.va1[1])
  102. local gridList = msgRet.gridList
  103. for idx, gridCfg in ipairs(breakThroughCfg) do
  104. gridList[0] = idx
  105. local rewardList = gridList[idx].rewardList
  106. for k, itemCfg in ipairs(gridCfg.reward) do
  107. rewardList[0] = k
  108. Grid.makeItem(rewardList[k], itemCfg[1], itemCfg[2])
  109. end
  110. end
  111. Msg.send(msgRet, human.fd)
  112. end
  113. function RandPos(human, actId)
  114. local actData = getActData(human, actId)
  115. if not actData then
  116. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  117. end
  118. if not actData.times or actData.times <= 0 then
  119. return Broadcast.sendErr(human, Lang.JINBI_EXCHANGE_ERR_CNT)
  120. end
  121. local weightSum = calcWeightSum()
  122. local randWeight = math.random(1, weightSum)
  123. local itemVec = {}
  124. local len, randIdx, weight = 0, 0, 0
  125. for idx, gridCfg in ipairs(breakThroughCfg) do
  126. for _, itemCfg in ipairs(gridCfg.reward) do
  127. len = len + 1
  128. itemVec[len] = {itemCfg[1], itemCfg[2]}
  129. end
  130. weight = weight + gridCfg.weight
  131. if weight >= randWeight then
  132. randIdx = idx
  133. break
  134. end
  135. end
  136. -- 扣除次数
  137. updateActTimes(human, actId, -1)
  138. local msgRet = Msg.gc.GC_CYCLEBREAKTHROUGH_RAND
  139. msgRet.randVal = randIdx
  140. msgRet.state = 1
  141. local itemArray = msgRet.itemArray
  142. for idx, itemInfo in ipairs(itemVec) do
  143. itemArray[0] = idx
  144. Grid.makeItem(itemArray[idx], itemInfo[1], itemInfo[2])
  145. BagLogic.addItem(human, itemInfo[1], itemInfo[2], LOGTAG)
  146. end
  147. if actData.times <= 0 then
  148. msgRet.state = 0
  149. updateRedDot(human, actId)
  150. end
  151. Msg.send(msgRet, human.fd)
  152. -- BagLogic.addItemList(human, itemVec, LOGTAG)
  153. end