DailyGiveaway.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. --- 每日馈赠,每日礼包
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by 無心道(15388152619).
  4. --- DateTime: 2024/11/11 10:44
  5. DailyGiveaway = {}
  6. DailyGiveaway.__index = DailyGiveaway
  7. local this = {}
  8. local function __rechargeType()
  9. return "13"
  10. end
  11. local function __playerDbKey()
  12. return "T$daily_giveaway_data"
  13. end
  14. function DailyGiveaway.get(actor)
  15. local obj = getplaydef(actor, __playerDbKey())
  16. return setmetatable(obj or {}, DailyGiveaway)
  17. end
  18. function DailyGiveaway:save(actor)
  19. setplaydef(actor, __playerDbKey(), self);
  20. end
  21. ---设置标记下一组
  22. function DailyGiveaway:nextGroup(actor)
  23. local group = tonumber(self["group"] or 0) + 1
  24. if table.isNullOrEmpty(ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", group)) then
  25. if table.notEmpty(ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", 1)) then
  26. --策划说需要循环,如果没有下一组直接切换到第一组
  27. group = 1;
  28. else
  29. --说明没有找到下一组
  30. return
  31. end
  32. end
  33. self["group"] = group;
  34. self["buyTime"] = 0 --更新最好一次购买时间
  35. self["buyDay"] = 0 --记录购买天数
  36. self["rewards"] = {};
  37. self:save(actor)
  38. info(actor, "玩家", actor, "每日馈赠切换到下一组:", group)
  39. end
  40. ---购买分组
  41. function DailyGiveaway:getGroup()
  42. return self["group"] or 1;
  43. end
  44. ---购买时间
  45. function DailyGiveaway:getBuyTime()
  46. return self["buyTime"] or 0;
  47. end
  48. ---购买天数
  49. function DailyGiveaway:getBuyDay()
  50. return self["buyDay"] or 0;
  51. end
  52. ---已经领取过的奖励
  53. function DailyGiveaway:getRewards()
  54. if self["rewards"] == nil then
  55. self["rewards"] = {}
  56. end
  57. return self["rewards"];
  58. end
  59. ---免费礼包领取时间
  60. function DailyGiveaway:getDayFreeGift()
  61. return self["dayFreeGift"] or 0;
  62. end
  63. ---免费礼包领取时间
  64. function DailyGiveaway:setDayFreeGift(nowSec)
  65. self["dayFreeGift"] = nowSec;
  66. end
  67. ---更新购买时间
  68. function DailyGiveaway:buy(nowSec)
  69. self["buyTime"] = nowSec --更新最后一次购买时间
  70. self["buyDay"] = tonumber(self["buyDay"] or 0) + 1 --记录购买天数
  71. end
  72. ---充值事件触发
  73. function this.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  74. local data = DailyGiveaway.get(actor)
  75. if not this.checkOpen(data, actor) then
  76. return
  77. end
  78. local parameter = cfg_recharge["parameter"]
  79. local nowSec = getbaseinfo("nowsec")
  80. local cfg_recharge_type = cfg_recharge["type"]
  81. if cfg_recharge_type == __rechargeType() and data:getGroup() == tonumber(parameter) then
  82. -- todo 判断充值类型 发送礼包奖励
  83. end
  84. local cfgList = ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", data:getGroup())
  85. if table.isNullOrEmpty(cfgList) then
  86. return
  87. end
  88. local cfgOne = cfgList[2]--取第二条数据,因为第一条是免费礼包
  89. --每天充值的金额
  90. local dailyTotalMoney = RechargeRecord.getDailyTotalMoney(actor)
  91. if dailyTotalMoney < tonumber(cfgOne["needcost"]) then
  92. return --累充金额不满足条件
  93. end
  94. if TimeUtil.isSameDay(data:getBuyTime(), nowSec) then
  95. return --是同一天说明已经处理过了
  96. end
  97. data:buy(nowSec)
  98. data:save(actor)
  99. this.sendPanel(actor)
  100. info(actor, "每日馈赠购买记录", actor, "购买分组:", data:getGroup(), "购买天数:", data:getBuyDay())
  101. end
  102. function this.reqAction(actor, type, action, reqParameter)
  103. if action == "panel" then
  104. this.sendPanel(actor)
  105. elseif action == "reward" then
  106. this.reward(actor, reqParameter)
  107. end
  108. end
  109. function this.reward(actor, reqParameter)
  110. local data = DailyGiveaway.get(actor)
  111. if not this.checkOpen(data, actor) then
  112. return
  113. end
  114. local id = tonumber(reqParameter["id"])
  115. local nowSec = getbaseinfo("nowsec")
  116. local buyDay = data:getBuyDay()
  117. local rewards = data:getRewards()
  118. local cfg = ConfigDataManager.getById("cfg_everydaygift_recharge", id)
  119. gameDebug.assertNil(cfg, "配置不存在", id)
  120. local group = data:getGroup()
  121. if tonumber(cfg["round"]) ~= group then
  122. tipinfo(actor, "当前分组未开放领取")
  123. return
  124. end
  125. if buyDay < tonumber(cfg["sort"]) then
  126. tipinfo(actor, "不满足条件")
  127. return
  128. end
  129. if cfg["sort"] == "0" then
  130. if TimeUtil.isSameDay(data:getDayFreeGift(), nowSec) then
  131. tipinfo(actor, "免费礼包已经领取")
  132. return
  133. end
  134. data:setDayFreeGift(nowSec)
  135. else
  136. local checkRewards = table.contains(rewards, id)
  137. if checkRewards then
  138. tipinfo(actor, "已经领取过该奖励")
  139. return
  140. end
  141. table.insert(rewards, id)
  142. end
  143. info(actor, "玩家", actor, "每日馈赠", group, "领取奖励:", id)
  144. --存储数据
  145. data:save(actor)
  146. -- 发送奖励
  147. Bag.sendRewards4CareerString(actor, cfg["gift"], "每日馈赠")
  148. this.checkNext(data, actor)
  149. this.sendPanel(actor)
  150. end
  151. function this.sendPanel(actor)
  152. local data = DailyGiveaway.get(actor)
  153. if not this.checkOpen(data, actor) then
  154. return
  155. end
  156. local nowSec = getbaseinfo("nowsec")
  157. local resInfo = {
  158. group = data:getGroup(), --分组 第几轮
  159. buyDay = data:getBuyDay(), --本轮购买天数
  160. rewards = data:getRewards(), --已经领取过的奖励ID
  161. todayBuy = TimeUtil.isSameDay(data:getBuyTime(), nowSec), --今日是否购买
  162. dayFreeGift = TimeUtil.isSameDay(data:getDayFreeGift(), nowSec), --今日免费礼包是否已经领取
  163. }
  164. Recharge.resAction(actor, __rechargeType(), "panel", resInfo)
  165. end
  166. function this.checkNext(data, actor)
  167. if not this.checkOpen(data, actor) then
  168. return
  169. end
  170. local cfgList = ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", data:getGroup())
  171. local cfgCount = table.count(cfgList) - 1 -- 扣除一个免费礼包
  172. local nowSec = getbaseinfo("nowsec")
  173. local buyDay = DailyGiveaway.getBuyDay(data)
  174. if buyDay >= cfgCount and TimeUtil.isSameDay(DailyGiveaway.getBuyTime(data), nowSec) == false then
  175. --购买天数满足条件,且不是同一天
  176. DailyGiveaway.nextGroup(data, actor)
  177. end
  178. end
  179. ---登录监听事件
  180. function this.onLogin(actor)
  181. local data = DailyGiveaway.get(actor)
  182. if not this.checkOpen(data, actor) then
  183. return
  184. end
  185. if data["group"] == nil then
  186. data:nextGroup(actor)
  187. end
  188. local nowSec = getbaseinfo("nowsec")
  189. local buyDay = data:getBuyDay()
  190. if buyDay > 0 then
  191. --购买的第二天上线检查前一天的奖励是否领取,没有领取的话,自动发邮件
  192. local rewards = data:getRewards()
  193. --职业
  194. local career = getbaseinfo(actor, "getbasecareer")
  195. for i = 1, buyDay do
  196. if i < buyDay or (not TimeUtil.isSameDay(data:getBuyTime(), nowSec)) then
  197. local cfg = ConfigDataManager.getTableFirst("cfg_everydaygift_recharge", "round", data:getGroup(), "sort", i)
  198. if cfg then
  199. local intId = tonumber(cfg["id"])
  200. if not table.contains(rewards, intId) then
  201. table.insert(rewards, intId)
  202. data:save(actor)
  203. local sendReward = string.toIntIntMap4Career(career, cfg["gift"], "#", "|")
  204. info(actor, "每日馈赠昨日未领取奖励发送邮件", actor, data:getGroup(), intId, sendReward)
  205. sendconfigmailbyrid(actor, actor:toString(), tonumber(cfg["mail"]), sendReward, "")
  206. end
  207. end
  208. end
  209. end
  210. this.checkNext(data, actor)
  211. end
  212. this.sendPanel(actor)
  213. end
  214. function this.checkOpen(data, actor)
  215. local inshowCondition = ConfigDataManager.getTableValue("sub_mainRecharge", "inshowCondition", "id", 6)
  216. if not ConditionManager.Check(actor, inshowCondition) then
  217. return false
  218. end
  219. local cfgList = ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", data:getGroup())
  220. if table.isEmpty(cfgList) then
  221. return false
  222. end
  223. return true
  224. end
  225. EventListerTable.registerType("每日馈赠", __rechargeType(), __playerDbKey())
  226. --注册登录事件
  227. LoginEventListerTable:eventLister("0", "每日馈赠", this.onLogin)
  228. --注册凌晨刷新事件
  229. ZeroEventListerTable:eventLister("0", "每日馈赠", this.onLogin)
  230. --充值回调,不关心类型
  231. RechargeEventListerTable:eventLister("0", "每日馈赠", this.rechargeEvent)
  232. --请求事件
  233. RechargeMessageEventListerTable:eventLister(__rechargeType(), "每日馈赠", this.reqAction)