AnniversaryActiveWheel.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. -- 周年活动 - 活跃转转乐
  2. -- db
  3. --[=[
  4. human.db.absAct[ACT_ID] = {
  5. lotteryTimes = 0, -- 可用抽奖次数(日常/每周达100活跃各+1,可叠加)
  6. }
  7. ]=]--
  8. local Msg = require("core.Msg")
  9. local Grid = require("bag.Grid")
  10. local BagLogic = require("bag.BagLogic")
  11. local AbsActLogic = require("absAct.AbsActLogic")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local Lang = require("common.Lang")
  14. local YunYingLogic = require("yunying.YunYingLogic")
  15. local AbsActExcel = require("excel.absAct")
  16. local RewardCfg = require("excel.anniversaryAct").activeWheel -- 活跃转转乐奖励配置表
  17. local LOGTYPE = "AnniversaryActiveWheel"
  18. local ACT_ID = 7701 -- 活跃转转乐活动ID(按实际分配)
  19. local function getData(human)
  20. return human.db.absAct[ACT_ID]
  21. end
  22. local function addTimes(human, val)
  23. local d = getData(human)
  24. d.lotteryTimes = (d.lotteryTimes or 0) + val
  25. end
  26. local function isOpenAct(human, funcID)
  27. return AbsActLogic.isStarted(human, funcID or ACT_ID)
  28. end
  29. local function updateRedDot(human)
  30. YunYingLogic.sendBanner(human)
  31. local config = AbsActExcel.absActivity[ACT_ID]
  32. YunYingLogic.sendGroupUpdate(YYInfo[ACT_ID], human, config.panelID)
  33. end
  34. local function doLottery()
  35. local totalWeight = 0
  36. for _, row in ipairs(RewardCfg) do
  37. totalWeight = totalWeight + row.nWeight
  38. end
  39. if totalWeight <= 0 then return 0 end
  40. local r, acc = math.random(1, totalWeight), 0
  41. for i, row in ipairs(RewardCfg) do
  42. acc = acc + row.nWeight
  43. if r <= acc then return i end
  44. end
  45. return 0
  46. end
  47. local function doMultiLottery(count)
  48. local results = {}
  49. for _ = 1, count do
  50. local idx = doLottery()
  51. if idx == 0 then return nil end
  52. local row = RewardCfg[idx]
  53. results[#results + 1] = { itemId = row.reward[1], itemNum = row.reward[2] }
  54. end
  55. return results
  56. end
  57. function genAbsActData(config, human)
  58. local times = 0
  59. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  60. local isReach = DailyTaskLogic.isReachMaxDailyHuoYue(human)
  61. if isReach then
  62. times = times + 1
  63. end
  64. isReach = false
  65. local WeekTaskLogic = require("dailyTask.WeekTaskLogic")
  66. isReach = WeekTaskLogic.isReachMaxWeekHuoYue(human)
  67. if isReach then
  68. times = times + 1
  69. end
  70. return { lotteryTimes = times }
  71. end
  72. function isRed(human, YYInfo, funcConfig)
  73. if not isOpenAct(human, funcConfig and funcConfig.funcID) then return false end
  74. local d = getData(human)
  75. if not d then return false end
  76. return (d.lotteryTimes or 0) > 0
  77. end
  78. function isOpen(human, YYInfo, funcConfig)
  79. return isOpenAct(human, funcConfig and funcConfig.funcID)
  80. end
  81. function isActive(human, YYInfo, funcConfig)
  82. return not isOpen(human, YYInfo, funcConfig)
  83. end
  84. -- 触发入口:日常/每周任务达100活跃
  85. function OnHuoYueReach100(human)
  86. if not isOpenAct(human) then return end
  87. addTimes(human, 1)
  88. updateRedDot(human)
  89. end
  90. function ActiveWheel_Query(human)
  91. if not isOpenAct(human) then
  92. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  93. end
  94. local d = getData(human)
  95. local _, endTime, startTime = isOpenAct(human) -- 取活动起止时间
  96. local msgRet = Msg.gc.GC_ANNIV_ACTIVE_WHEEL_QUERY
  97. msgRet.lotteryTimes = d.lotteryTimes or 0
  98. msgRet.startTime = startTime or 0
  99. msgRet.endTime = endTime or 0
  100. -- 下发完整奖励配置表,客户端据此渲染转盘格子
  101. msgRet.rewardList[0] = 0
  102. for i, row in ipairs(RewardCfg) do
  103. msgRet.rewardList[0] = i
  104. Grid.makeItem(msgRet.rewardList[i].item, row.reward[1], row.reward[2])
  105. msgRet.rewardList[i].weight = row.nWeight
  106. end
  107. Msg.send(msgRet, human.fd)
  108. end
  109. local function doSpin(human, count)
  110. if not isOpenAct(human) then
  111. return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  112. end
  113. local d = getData(human)
  114. local curTimes = d.lotteryTimes or 0
  115. if curTimes < count then
  116. return Broadcast.sendErr(human, Lang.JINBI_EXCHANGE_ERR_CNT)
  117. end
  118. local results = doMultiLottery(count)
  119. if not results then
  120. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  121. end
  122. -- 扣除次数
  123. d.lotteryTimes = curTimes - count
  124. for _, res in ipairs(results) do
  125. BagLogic.addItem(human, res.itemId, res.itemNum, LOGTYPE)
  126. end
  127. -- 通知客户端抽奖结果(客户端根据此结果播放动画)
  128. local msgRet = Msg.gc.GC_ANNIV_ACTIVE_WHEEL_RESULT
  129. msgRet.count = count
  130. msgRet.results[0] = 0
  131. for i, res in ipairs(results) do
  132. msgRet.results[0] = i
  133. Grid.makeItem(msgRet.results[i], res.itemId, res.itemNum)
  134. end
  135. msgRet.lotteryTimes = d.lotteryTimes
  136. Msg.send(msgRet, human.fd)
  137. updateRedDot(human)
  138. end
  139. function ActiveWheel_Single(human)
  140. doSpin(human, 1)
  141. end
  142. function ActiveWheel_Ten(human)
  143. doSpin(human, 10)
  144. end