DailyDiamondGift.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. DailyDiamondGift = {}
  2. DailyDiamondGift.__index = DailyDiamondGift
  3. local this = {}
  4. --- 每日钻石礼包类型
  5. local function _rechargeType()
  6. return "15"
  7. end
  8. local function _playerDbKey()
  9. return "J$daily_diamond_gift_pack"
  10. end
  11. function DailyDiamondGift.get(actor)
  12. local obj = getplaydef(actor, _playerDbKey())
  13. return setmetatable(obj or {}, DailyDiamondGift)
  14. end
  15. function DailyDiamondGift:save(actor)
  16. setplaydef(actor, _playerDbKey(), self);
  17. end
  18. function DailyDiamondGift:setRecordIndex(rechargeId, index)
  19. if not self.dailyGiftInfo then
  20. self.dailyGiftInfo = {}
  21. end
  22. self.dailyGiftInfo[rechargeId] = index
  23. end
  24. function DailyDiamondGift:getRecordIndex(rechargeId)
  25. if not self.dailyGiftInfo then
  26. self.dailyGiftInfo = {}
  27. end
  28. return self.dailyGiftInfo[rechargeId] or 0
  29. end
  30. ---充值事件触发
  31. function DailyDiamondGift.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  32. DailyDiamondGift.print(actor, "购买每日钻石礼包", cfg_recharge, "购买数量", count, ext, outRewards)
  33. if ext == "" then
  34. ext = {}
  35. end
  36. local dailyGiftId = cfg_recharge.parameter
  37. local rechargeType = cfg_recharge.type
  38. local giftCfg = ConfigDataManager.getById("cfg_diamondgiftbag", dailyGiftId)
  39. gameDebug.assertTrue(table.notNullOrEmpty(giftCfg), "没有配置每日钻石礼包", dailyGiftId)
  40. if not ConditionManager.Check(actor, giftCfg.conditionid) then
  41. tipinfo(actor, "购买条件不满足")
  42. return
  43. end
  44. local purchase = giftCfg.purchase
  45. local dailyDiamondGift = DailyDiamondGift.get(actor)
  46. if string.isNullOrEmpty(purchase) then
  47. local cfgs = ConfigDataManager.getTable("cfg_diamondgiftbag", "purchase", dailyGiftId)
  48. if not cfgs then
  49. tipinfo(actor, "一键购买配置错误")
  50. end
  51. -- 判断是否购买过单个礼包
  52. for _, cfg in pairs(cfgs) do
  53. if tonumber(cfg.price) == 0 then
  54. goto continue
  55. end
  56. local c = CountManager.getCount(actor, cfg["limited"])
  57. local buyCount = c.count
  58. if buyCount > 0 then
  59. tipinfo(actor, "购买过单个礼包")
  60. return
  61. end
  62. :: continue ::
  63. end
  64. gameDebug.assertTrue(table.notNullOrEmpty(cfgs), "没有一键购买每日钻石礼包配置", dailyGiftId)
  65. DailyDiamondGift.print("读取的配置", cfgs)
  66. -- 购买一键礼包
  67. for i = 1, #cfgs do
  68. local cfg = cfgs[i]
  69. if tonumber(cfg.price) == 0 then
  70. goto continue
  71. end
  72. local limited = cfg["limited"]
  73. local total = tonumber(ConfigDataManager.getTableValue("Count_count", "total", "id", limited))
  74. local index = ext[tonumber(cfg.id)] or 0
  75. for j = 1, total do
  76. DailyDiamondGift.print(actor, "购买一键礼包", cfg.id, "购买次数", j, "i", i, "ext", ext, "ext[e]", index)
  77. this.mergeItem(outRewards, cfg, index)
  78. end
  79. local recId = ConfigDataManager.getTableValue("cfg_recharge", "id", "parameter", cfg.id, "type", rechargeType)
  80. if index ~= 0 then
  81. dailyDiamondGift:setRecordIndex(recId, index)
  82. end
  83. CountManager.count(actor, limited, total)
  84. :: continue ::
  85. end
  86. else
  87. -- 购买单个礼包
  88. local index = ext[tonumber(giftCfg.id)] or 0
  89. this.mergeItem(outRewards, giftCfg, index)
  90. if index ~= 0 then
  91. dailyDiamondGift:setRecordIndex(cfg_recharge.id, index)
  92. end
  93. end
  94. dailyDiamondGift:save(actor)
  95. -- 发送界面信息数据
  96. dailyDiamondGift.queryData(actor, { type = rechargeType, action = "panel" })
  97. dailyDiamondGift.print(actor, "购买每日钻石礼包成功", cfg_recharge, "购买数量", count, ext, outRewards)
  98. end
  99. --- 请求充值档位信息
  100. ---@param msgData table 请求参数
  101. function DailyDiamondGift.reqRechargeAction(actor, rechargeType, action, reqParameter)
  102. if action == "panel" then
  103. DailyDiamondGift.queryData(actor, reqParameter)
  104. end
  105. end
  106. --- 每日钻石礼包信息
  107. function DailyDiamondGift.queryData(actor, reqParameter)
  108. DailyDiamondGift.print(actor, "请求每日钻石礼包信息", reqParameter)
  109. local rechargeType = reqParameter["type"]
  110. local dailyDiamondGifts = ConfigDataManager.getList("cfg_diamondgiftbag")
  111. gameDebug.assertTrue(table.notNullOrEmpty(dailyDiamondGifts), "没有配置充值档位")
  112. local resData = {}
  113. local group = 0
  114. local countInfo = {}
  115. local dailyDiamondGift = DailyDiamondGift.get(actor)
  116. DailyDiamondGift.print("配置表数据", dailyDiamondGifts)
  117. for _, cfg in pairs(dailyDiamondGifts) do
  118. if ConditionManager.Check(actor, cfg.conditionid) then
  119. local id = cfg.id
  120. local rechargeId = ConfigDataManager.getTableValue("cfg_recharge", "id", "parameter", id, "type", rechargeType)
  121. local index = dailyDiamondGift:getRecordIndex(rechargeId)
  122. countInfo[rechargeId] = index
  123. group = cfg.packagetype
  124. end
  125. end
  126. resData['group'] = group
  127. resData['countInfo'] = countInfo
  128. Recharge.resAction(actor, rechargeType, reqParameter.action, resData)
  129. end
  130. function this.mergeItem(outRewards, cfg, index)
  131. string.putIntIntMap(outRewards, cfg['rewards'], "#", "|")
  132. local optionalReward = cfg['optionalreward']
  133. if not string.isNullOrEmpty(optionalReward) then
  134. local strShuXian = string.split(optionalReward, "|")
  135. local strJinHao = strShuXian[index]
  136. DailyDiamondGift.print("合并奖励", cfg, "分隔好的", strShuXian, "根据索引选的", strJinHao, "索引", index)
  137. local str = string.split(strJinHao, "#")
  138. local itemCfgId = tonumber(str[1])
  139. local oldCount = outRewards[itemCfgId] or 0
  140. outRewards[itemCfgId] = oldCount + tonumber(str[2])
  141. end
  142. end
  143. --- 登录处理
  144. function DailyDiamondGift.login(play)
  145. DailyDiamondGift.queryData(play, { type = _rechargeType(), action = "panel" })
  146. end
  147. --- 零点处理
  148. function DailyDiamondGift.zero(play)
  149. DailyDiamondGift.queryData(play, { type = _rechargeType(), action = "panel" })
  150. end
  151. --- 打印日志
  152. local isPrintLog = false
  153. function DailyDiamondGift.print(...)
  154. if isPrintLog then
  155. return
  156. end
  157. gameDebug.print(...)
  158. end
  159. function dailydiamondgifttest(actor, id, type)
  160. gameDebug.print(actor, "请求每日钻石礼包", id)
  161. local tab
  162. if tonumber(type == 1) then
  163. tab = { [1] = 1 }
  164. else
  165. tab = { [1] = 1, [2] = 1, [3] = 1, [4] = 1 }
  166. end
  167. Recharge.request(actor, { rechargeId = id, count = 1, extraParams = tab })
  168. end
  169. EventListerTable.registerType("每日钻石礼包", _rechargeType(), _playerDbKey())
  170. -- 凌晨刷新事件
  171. ZeroEventListerTable:eventLister("0", "每日钻石礼包", DailyDiamondGift.zero)
  172. -- 注册登录事件
  173. LoginEventListerTable:eventLister("0", "每日钻石礼包", DailyDiamondGift.login)
  174. -- 注册充值回调事件
  175. RechargeEventListerTable:eventLister(_rechargeType(), "每日钻石礼包", DailyDiamondGift.rechargeEvent)
  176. -- 注册请求消息监听
  177. RechargeMessageEventListerTable:eventLister(_rechargeType(), "每日钻石礼包", DailyDiamondGift.reqRechargeAction)