DirectPurchase.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. --- 运营直购礼包
  2. DirectPurchase = {}
  3. DirectPurchase.__index = DirectPurchase
  4. local this = {}
  5. local function _rechargeType()
  6. return "16"
  7. end
  8. local function _playerDbKey()
  9. return nil
  10. end
  11. local BUY_TYPE = {
  12. NOE_BUY = 2, -- 一键购买
  13. FREE_BUY = 3 -- 免费购买
  14. }
  15. --- 请求充值档位信息
  16. function DirectPurchase.reqRechargeAction(actor,mainGroup)
  17. -- 判断当前主活动是否开启了子直购活动
  18. local allActivityInfo = {}
  19. local operateActivityTable = ConfigDataManager.getList("cfg_OperateActivity_CDM")
  20. if table.isNullOrEmpty(operateActivityTable) then
  21. return allActivityInfo
  22. end
  23. for _, config in pairs(operateActivityTable) do
  24. if tonumber(mainGroup) == tonumber(config.maingroup) then
  25. local directId = config.id
  26. local itemCount = config.itemcount
  27. local rewardsMap = string.toIntIntMap(itemCount, "#", "|")
  28. local rechargeId = ConfigDataManager.getTableValue("cfg_recharge","id","type",config.rechargetype,"parameter",directId)
  29. local activityInfo = {
  30. directId = directId,
  31. itemInfo = rewardsMap,
  32. rechargeId = rechargeId
  33. }
  34. table.insert(allActivityInfo,activityInfo)
  35. -- 刷新购买数据
  36. --local count_key = ConfigDataManager.getTableValue("cfg_recharge", "countkey", "id", rechargeId)
  37. --CountManager.getCount(actor, count_key)
  38. end
  39. end
  40. -- 更新充值count
  41. -- CountManager.getCount(actor, count_key)
  42. return allActivityInfo
  43. end
  44. --- 触发充值
  45. function DirectPurchase.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  46. local directGiftId = cfg_recharge.parameter
  47. local config = ConfigDataManager.getById("cfg_OperateActivity_CDM", directGiftId)
  48. local mainGroup = OperationalActivities.getCurrentMainGroup(actor)
  49. local cfgMainGroup = config.maingroup
  50. if mainGroup ~= tonumber(cfgMainGroup) then
  51. return
  52. end
  53. if tonumber(config.bugtype) == BUY_TYPE.NOE_BUY then
  54. -- 一键购买
  55. local operateActivity = ConfigDataManager.getTable("cfg_OperateActivity_CDM","mainGroup",mainGroup)
  56. if not table.isNullOrEmpty(operateActivity) then
  57. for _, config in pairs(operateActivity) do
  58. local operateActivityId = config.id
  59. local countKey = ConfigDataManager.getTableValue("cfg_recharge","Countkey","parameter",operateActivityId,"type",_rechargeType())
  60. local count = CountManager.getCount(actor, tonumber(countKey))
  61. -- local total = ConfigDataManager.getTableValue("Count_count","total","id",countKey)
  62. if tonumber(operateActivityId) ~= tonumber(directGiftId) then
  63. if tonumber(config.bugtype) ~= BUY_TYPE.FREE_BUY and count.count > 0 then
  64. return
  65. end
  66. end
  67. end
  68. end
  69. this.oneBug(actor,outRewards,operateActivity)
  70. else
  71. gameDebug.assertTrue(table.notEmpty(config), "没有配置直购礼包", directGiftId)
  72. local reward_str = config.itemcount
  73. if not string.isNullOrEmpty(reward_str) then
  74. -- Bag.sendRewards4String(actor, reward_str, "运营直购活动"..config.id)
  75. string.putIntIntMap(outRewards, reward_str, "#", "|")
  76. end
  77. end
  78. -- 发送界面信息数据
  79. this.debug("购买直购礼包成功", cfg_recharge, "购买数量", count, ext, outRewards)
  80. OperationalActivities.openSubActive(actor,{
  81. subType = ACTIVE_TYPE.DIRECT
  82. })
  83. end
  84. -- 一键购买
  85. function this.oneBug(actor,outRewards,operateActivity)
  86. if not table.isNullOrEmpty(operateActivity) then
  87. for _, config in pairs(operateActivity) do
  88. local operateActivityId = config.id
  89. local countKey = ConfigDataManager.getTableValue("cfg_recharge","Countkey","parameter",operateActivityId,"type",_rechargeType())
  90. local total = ConfigDataManager.getTableValue("Count_count","total","id",countKey)
  91. CountManager.count(actor, tonumber(countKey),tonumber(total))
  92. for i = 1, tonumber(total) do
  93. string.putIntIntMap(outRewards, config.itemcount, "#", "|")
  94. end
  95. end
  96. end
  97. end
  98. --- 直购关闭
  99. function DirectPurchase.closeActive(mainGroup)
  100. local allRoleInfos = getallrolesummaryinfos()
  101. local activeInfo = {}
  102. if not table.isNullOrEmpty(allRoleInfos) then
  103. local directId = ConfigDataManager.getTableValue("cfg_OperateActivity_CDM","id","mainGroup",mainGroup,"bugType",BUY_TYPE.FREE_BUY)
  104. local countKey = ConfigDataManager.getTableValue("cfg_recharge","Countkey","parameter",directId,"type",_rechargeType())
  105. local specialCondition = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","specialCondition","mainGroup",mainGroup,"subType",ACTIVE_TYPE.DIRECT)
  106. for k, roleInfo in pairs(allRoleInfos) do
  107. local actor = roleInfo["actor"]
  108. -- 判断当前玩家有没有另外免费直购
  109. local item = {}
  110. local countInfo = CountManager.getCount(actor,countKey)
  111. if not table.isNullOrEmpty(countInfo) and countInfo.total > countInfo.count and ConditionManager.Check(actor, specialCondition) then
  112. local itemInfo = ConfigDataManager.getTableValue("cfg_OperateActivity_CDM","itemCount","id",directId)
  113. local count = countInfo.total - countInfo.count
  114. for i = 1, count do
  115. string.putIntIntMap(item, itemInfo, "#", "|")
  116. end
  117. sendconfigmailbyrid(actor,actor:toString(), 900002, item)
  118. -- Bag.sendRewards(actor, item, "直购免费礼包补发")
  119. end
  120. end
  121. end
  122. end
  123. -- ------------------------------------------------------------- --
  124. this.log_open = false
  125. function this.debug(...)
  126. if not this.log_open then
  127. return
  128. end
  129. gameDebug.print(...)
  130. end
  131. function this.jprint(...)
  132. if not this.log_open then
  133. return
  134. end
  135. if param == nil then
  136. param = "error! 输出内容为空. nil"
  137. end
  138. jprint(...)
  139. end
  140. -- ------------------------------------------------------------- --
  141. EventListerTable.registerType("直购礼包", _rechargeType(), _playerDbKey())
  142. RechargeEventListerTable:eventLister(_rechargeType(), "直购礼包", DirectPurchase.rechargeEvent)