WeekGiftPack.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. WeeklyGiftPack = {}
  2. WeeklyGiftPack.__index = WeeklyGiftPack
  3. local this = {}
  4. local function _rechargeType()
  5. return "6"
  6. end
  7. local function _playerDbKey()
  8. return nil
  9. end
  10. function WeeklyGiftPack.login(actor)
  11. this.queryData(actor, { type = _rechargeType(), action = "panel" })
  12. end
  13. --- 请求充值档位信息
  14. function WeeklyGiftPack.reqRechargeAction(actor, _, action, reqParameter)
  15. if action == "panel" then
  16. this.queryData(actor, reqParameter)
  17. end
  18. end
  19. --- 触发充值
  20. function WeeklyGiftPack.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  21. this.debug("购买每周礼包", cfg_recharge, "购买数量", count, ext, outRewards)
  22. local weekGiftId = cfg_recharge.parameter
  23. local rechargeType = cfg_recharge.type
  24. local config = ConfigDataManager.getById("cfg_weeklygiftpack", weekGiftId)
  25. gameDebug.assertTrue(table.notEmpty(config), "没有配置每周礼包", weekGiftId)
  26. local is_pass = ConditionManager.Check(actor, config.conditionid)
  27. if not is_pass then
  28. tipinfo(actor, "每周礼包购买条件不满足")
  29. return
  30. end
  31. local reward_str = config.rewards
  32. if not string.isNullOrEmpty(reward_str, reward_str) then
  33. string.putIntIntMap(outRewards, reward_str, "#", "|")
  34. this.debug("----- 获得的奖励 -----", outRewards)
  35. end
  36. -- 发送界面信息数据
  37. this.queryData(actor, { type = rechargeType, action = "panel" })
  38. this.debug("购买每周礼包成功", cfg_recharge, "购买数量", count, ext, outRewards)
  39. end
  40. function WeeklyGiftPack.weekZero(actor)
  41. this.debug("---------- 触发周凌晨事件 -----------")
  42. intervalcalldelay(actor, 5000, 1000, 1, "delayflushweekgiftpackpanel", { type = _rechargeType(), action = "panel" })
  43. end
  44. function delayflushweekgiftpackpanel(actor, data)
  45. this.queryData(actor, data)
  46. end
  47. function this.queryData(actor, reqParameter)
  48. this.debug("请求每周礼包信息", reqParameter)
  49. local rechargeType = reqParameter["type"]
  50. local config_list = ConfigDataManager.getList("cfg_weeklyGiftPack")
  51. gameDebug.assertTrue(table.notNullOrEmpty(config_list), "没有配置充值档位")
  52. local resData = {}
  53. local recharge_ids = {}
  54. local group = 0
  55. for _, config in pairs(config_list) do
  56. if ConditionManager.Check(actor, config.conditionid) then
  57. group = config.packagetype
  58. local rechargeId = ConfigDataManager.getTableValue("cfg_recharge", "id", "parameter", config.id, "type", rechargeType)
  59. table.insert(recharge_ids, rechargeId)
  60. -- 刷新购买数据
  61. local count_key = ConfigDataManager.getTableValue("cfg_recharge", "countkey", "id", rechargeId)
  62. CountManager.getCount(actor, count_key)
  63. end
  64. end
  65. resData['group'] = group
  66. resData['recharge_ids'] = recharge_ids
  67. Recharge.resAction(actor, rechargeType, reqParameter.action, resData)
  68. end
  69. -- ------------------------------------------------------------- --
  70. this.log_open = false
  71. function this.debug(...)
  72. if not this.log_open then
  73. return
  74. end
  75. gameDebug.print(...)
  76. end
  77. function this.jprint(...)
  78. if not this.log_open then
  79. return
  80. end
  81. if param == nil then
  82. param = "error! 输出内容为空. nil"
  83. end
  84. jprint(...)
  85. end
  86. -- ------------------------------------------------------------- --
  87. EventListerTable.registerType("每周礼包", _rechargeType(), _playerDbKey())
  88. -- 注册事件
  89. LoginEventListerTable:eventLister("0", "recharge_week_gift", WeeklyGiftPack.login)
  90. -- 凌晨事件
  91. ZeroEventListerTable:eventLister("0", "每周礼包", WeeklyGiftPack.weekZero)
  92. RechargeEventListerTable:eventLister(_rechargeType(), "recharge_week_gift", WeeklyGiftPack.rechargeEvent)
  93. -- 注册请求消息监听
  94. RechargeMessageEventListerTable:eventLister(_rechargeType(), "req_week_gift_info", WeeklyGiftPack.reqRechargeAction)