SingleGift.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. -----
  2. ----- Created by zhouzhipeng.
  3. ----- DateTime: 2024/11/6 14:50
  4. ----- Desc:炎狼兽礼包
  5. -----
  6. SingleGift = {}
  7. SingleGift.__index = SingleGift
  8. local this = {}
  9. --- 类型
  10. local function _rechargeType()
  11. return "5"
  12. end
  13. local function _playerDbKey()
  14. return "T$single_gift_data"
  15. end
  16. function SingleGift.get(actor)
  17. local obj = getplaydef(actor, _playerDbKey())
  18. return setmetatable(obj or {}, SingleGift)
  19. end
  20. function SingleGift:save(actor)
  21. setplaydef(actor, _playerDbKey(), self)
  22. end
  23. function SingleGift:getSingGiftInfo()
  24. if not self.singleGiftInfo then
  25. self.singleGiftInfo = {}
  26. end
  27. return self.singleGiftInfo
  28. end
  29. function SingleGift:getEndTimeById(cfgId)
  30. local singleGiftInfo = self:getSingGiftInfo()
  31. return singleGiftInfo[cfgId] or 0
  32. end
  33. function SingleGift:setSingGiftCfgId(cfgId, endTime)
  34. local singleGiftInfo = self:getSingGiftInfo()
  35. singleGiftInfo[cfgId] = endTime
  36. end
  37. function SingleGift.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  38. SingleGift.print(actor, "充值炎狼兽礼包", cfg_recharge, "购买数量", count, ext, outRewards)
  39. --local rechargeRecord = RechargeRecord.get(actor)
  40. --local buyCount = rechargeRecord:stallTotalCount(tonumber(cfg_recharge.id))
  41. --if buyCount > 1 then
  42. -- tipinfo(actor, "该礼包已购买过")
  43. -- return
  44. --end
  45. local id = cfg_recharge.parameter
  46. local singleGiftCfg = ConfigDataManager.getById("cfg_recharge_singleItem", id)
  47. string.putIntIntMap(outRewards, singleGiftCfg['item'], "#", "|")
  48. end
  49. --- 请求充值档位信息
  50. ---@param msgData table 请求参数
  51. function SingleGift.reqRechargeAction(actor, rechargeType, action, reqParameter)
  52. if action == "panel" then
  53. SingleGift.queryData(actor, reqParameter)
  54. elseif action == "reward" then
  55. SingleGift.gainReward(actor, reqParameter)
  56. end
  57. end
  58. function SingleGift.queryData(actor, reqParameter)
  59. SingleGift.print(actor, "请求单次礼包信息", reqParameter)
  60. local nowMillis = getbaseinfo(actor, "now")
  61. local singleGiftData = SingleGift.get(actor)
  62. local singleGiftInfo = singleGiftData:getSingGiftInfo()
  63. local resData = {}
  64. local cfgIds = {}
  65. for cfgId, endTime in pairs(singleGiftInfo) do
  66. if nowMillis < endTime then
  67. local recId = ConfigDataManager.getTableValue("cfg_recharge", "id", "parameter", cfgId, "type", _rechargeType())
  68. resData['rechargeId'] = recId
  69. resData['endTime'] = endTime
  70. table.insert(cfgIds, cfgId)
  71. end
  72. end
  73. if #cfgIds > 1 then
  74. jprint("单礼包,同时满足配置数据大于1条", cfgIds)
  75. end
  76. Recharge.resAction(actor, reqParameter.type, reqParameter.action, resData)
  77. end
  78. function SingleGift.gainReward(actor, reqParameter)
  79. end
  80. -- 登录处理
  81. function SingleGift.login(actor)
  82. SingleGift.queryData(actor, { type = _rechargeType(), action = "panel" })
  83. end
  84. --- 0点触发和升级都需要
  85. function SingleGift.triggerSingleGift(actor, level)
  86. local singleGiftData = SingleGift.get(actor)
  87. local singleGiftCfgs = ConfigDataManager.getList("cfg_recharge_singleItem")
  88. if table.isNullOrEmpty(singleGiftCfgs) then
  89. jprint("炎狼兽礼包配置为空")
  90. return
  91. end
  92. local nowMillis = getbaseinfo(actor, "now")
  93. local isUpdate = false
  94. for _, cfg in pairs(singleGiftCfgs) do
  95. local cfgId = tonumber(cfg.id)
  96. local endTime = singleGiftData:getEndTimeById(cfgId)
  97. if endTime ~= 0 then
  98. goto continue
  99. end
  100. SingleGift.print("校验条件", cfg, "条件内容", cfg.condition)
  101. if not ConditionManager.Check(actor, cfg.condition) then
  102. SingleGift.print("校验条件 条件不满足", cfg, "条件内容", cfg.condition)
  103. goto continue
  104. end
  105. SingleGift.print("校验条件 条件满足", cfg, "条件内容", cfg.condition)
  106. local time = nowMillis + tonumber(cfg.time)
  107. singleGiftData:setSingGiftCfgId(cfgId, time)
  108. isUpdate = true
  109. SingleGift.print("设置配置与开启时间", cfgId, "时间", time)
  110. :: continue ::
  111. end
  112. if isUpdate then
  113. singleGiftData:save(actor)
  114. SingleGift.queryData(actor, { type = _rechargeType(), action = "panel" })
  115. end
  116. end
  117. function singlegifttest(actor, type, id)
  118. gameDebug.print(actor, "炎狼兽礼包", id)
  119. --SingleGift.triggerSingleGift(actor)
  120. local singleGiftData = SingleGift.get(actor)
  121. local singleGiftInfo = singleGiftData:getSingGiftInfo()
  122. Recharge.request(actor, { rechargeId = id, count = 1, extraParams = {} })
  123. SingleGift.print("炎狼兽gm测试内容", singleGiftInfo)
  124. end
  125. --- 打印日志
  126. local isPrintLog = true
  127. function SingleGift.print(...)
  128. if isPrintLog then
  129. return
  130. end
  131. gameDebug.print(...)
  132. end
  133. EventListerTable.registerType("单个礼包", _rechargeType(), _playerDbKey())
  134. -- 注册登录事件
  135. LoginEventListerTable:eventLister("0", "单个礼包", SingleGift.login)
  136. -- 注册等级提升事件
  137. LevelUpEventListerTable:eventLister("0", "单个礼包", SingleGift.triggerSingleGift)
  138. --注册凌晨刷新事件
  139. ZeroEventListerTable:eventLister("0", "单个礼包", SingleGift.triggerSingleGift)
  140. -- 注册充值回调事件
  141. RechargeEventListerTable:eventLister(_rechargeType(), "单个礼包", SingleGift.rechargeEvent)
  142. -- 注册商业化请求消息监听
  143. RechargeMessageEventListerTable:eventLister(_rechargeType(), "单个礼包", SingleGift.reqRechargeAction)