AccumulatedRecharge.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. --- 运营累充
  2. AccumulatedRecharge = { }
  3. AccumulatedRecharge.__index = AccumulatedRecharge
  4. local this = {}
  5. local function _rechargeType()
  6. return "17"
  7. end
  8. local function _playerDbKey()
  9. return "T$OPERATION_ACCUMULATED_RECHARGE"
  10. end
  11. function AccumulatedRecharge.get(actor)
  12. local obj = getplaydef(actor, _playerDbKey())
  13. return setmetatable(obj or {}, AccumulatedRecharge)
  14. end
  15. function AccumulatedRecharge:save(actor)
  16. setplaydef(actor, _playerDbKey(), self);
  17. end
  18. local STATISTICS_TYPE = {
  19. ALL = 0,
  20. ACTIVE = 1,
  21. }
  22. --- 请求充值档位信息
  23. function AccumulatedRecharge.reqRechargeAction(actor,mainGroup)
  24. -- 判断当前主活动是否开启了子直购活动
  25. local activity = {}
  26. local allActivityInfo = {}
  27. local operateActivityTable = ConfigDataManager.getList("cfg_rechargeRccrued")
  28. if table.isNullOrEmpty(operateActivityTable) then
  29. return allActivityInfo
  30. end
  31. local type = 0
  32. for _, config in pairs(operateActivityTable) do
  33. if tonumber(mainGroup) == tonumber(config.maingroup) then
  34. type = tonumber(config.type)
  35. local accumulatedId = config.id
  36. local itemCount = config.itemcount
  37. local rewardsMap = string.toIntIntMap(itemCount, "#", "|")
  38. local activityInfo = {
  39. accumulatedId = accumulatedId,
  40. itemInfo = rewardsMap
  41. }
  42. CountManager.getCount(actor, config.countkey)
  43. table.insert(allActivityInfo,activityInfo)
  44. end
  45. end
  46. activity["panel"] = allActivityInfo
  47. local money = this.totalMoney(actor,type)
  48. activity["money"] = money
  49. return activity
  50. end
  51. --- 触发充值
  52. function AccumulatedRecharge.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  53. this.debug("购买直购礼包", cfg_recharge, "购买数量", count, ext, outRewards)
  54. this.saveMoney(actor,amount)
  55. OperationalActivities.openSubActive(actor,{
  56. subType = ACTIVE_TYPE.TOTAL_RECHARGE
  57. })
  58. end
  59. function AccumulatedRecharge.reqAction(actor, rechargeType, action, reqParameter)
  60. if action == "reward" then
  61. local directGiftId = reqParameter["id"]
  62. local config = ConfigDataManager.getById("cfg_rechargeRccrued", directGiftId)
  63. local mainGroup = OperationalActivities.getCurrentMainGroup(actor)
  64. local cfgMainGroup = config.maingroup
  65. if mainGroup ~= tonumber(cfgMainGroup) then
  66. return
  67. end
  68. local count = CountManager.getCount(actor, config.countkey)
  69. local total = ConfigDataManager.getTableValue("Count_count","total","id",config.countkey)
  70. if count.count >= tonumber(total) then
  71. return
  72. end
  73. this.sendReward(actor,config)
  74. CountManager.count(actor, config.countkey,1)
  75. end
  76. OperationalActivities.openSubActive(actor,{
  77. subType = ACTIVE_TYPE.TOTAL_RECHARGE
  78. })
  79. end
  80. -- 保存当前充值的钱
  81. function this.saveMoney(actor,amount)
  82. local currentActive = getsysvar(actor,CURRENT_ACTIVE)
  83. if table.isNullOrEmpty(currentActive) then
  84. return
  85. end
  86. if OperationalActivities.judgeActiveClose(actor,ACTIVE_TYPE.TOTAL_RECHARGE) then
  87. local id = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","id","mainGroup",currentActive.mainActive.mainGroup,"subType",ACTIVE_TYPE.TOTAL_RECHARGE)
  88. if string.isNullOrEmpty(id) then
  89. return
  90. end
  91. local numberId = tonumber(id)
  92. if amount ~= nil then
  93. local operationalActive = AccumulatedRecharge.get(actor)
  94. operationalActive[numberId] = tonumber(operationalActive[numberId] or 0) + amount
  95. operationalActive:save(actor)
  96. end
  97. end
  98. end
  99. --- 累充关闭
  100. function OperationalActivities.closeActive(mainGroup)
  101. local allRoleInfos = getallrolesummaryinfos()
  102. local rechargeTable = ConfigDataManager.getTable("cfg_rechargeRccrued","mainGroup",mainGroup)
  103. if not table.isNullOrEmpty(allRoleInfos) and not table.isNullOrEmpty(rechargeTable) then
  104. local specialCondition = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","specialCondition","mainGroup",mainGroup,"subType",ACTIVE_TYPE.TOTAL_RECHARGE)
  105. for k, roleInfo in pairs(allRoleInfos) do
  106. local actor = roleInfo["actor"]
  107. if ConditionManager.Check(actor, specialCondition) then
  108. local item = {}
  109. local money = this.totalMoney(actor,rechargeTable[1].type)
  110. for k, rechargeInfo in pairs(rechargeTable) do
  111. local countInfo = CountManager.getCount(actor,rechargeInfo.countkey)
  112. if not table.isNullOrEmpty(countInfo) and countInfo.total > countInfo.count and money >= tonumber(rechargeInfo.amount) then
  113. local count = countInfo.total - countInfo.count
  114. for i = 1, count do
  115. string.putIntIntMap(item, rechargeInfo.reward, "#", "|")
  116. end
  117. end
  118. end
  119. if not table.isNullOrEmpty(item) then
  120. sendconfigmailbyrid(actor, actor:toString(), 900003, item)
  121. end
  122. end
  123. end
  124. end
  125. end
  126. -- 发送奖励
  127. function this.sendReward(actor,config)
  128. local money = this.totalMoney(actor,tonumber(config.type))
  129. if tonumber(config.amount) <= money and not string.isNullOrEmpty(config.reward) then
  130. Bag.sendRewards4String(actor, config.reward, "运营累充活动"..config.id)
  131. end
  132. end
  133. -- 获取当前充值多钱前
  134. function this.totalMoney(actor,type)
  135. local money = 0
  136. if type == STATISTICS_TYPE.ALL then
  137. money = RechargeRecord.getTotalMoney(actor)
  138. else
  139. local activityRecharge = AccumulatedRecharge.get(actor)
  140. if not table.isNullOrEmpty(activityRecharge) then
  141. local currentActive = getsysvar(actor, CURRENT_ACTIVE)
  142. if not table.isNullOrEmpty(currentActive) then
  143. local id = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","id","mainGroup",currentActive.mainActive.mainGroup,"subType",ACTIVE_TYPE.TOTAL_RECHARGE)
  144. if not string.isNullOrEmpty(id) then
  145. money = activityRecharge[tonumber(id)] or 0
  146. end
  147. end
  148. end
  149. end
  150. return money
  151. end
  152. -- ------------------------------------------------------------- --
  153. this.log_open = false
  154. function this.debug(...)
  155. if not this.log_open then
  156. return
  157. end
  158. gameDebug.print(...)
  159. end
  160. function this.jprint(...)
  161. if not this.log_open then
  162. return
  163. end
  164. if param == nil then
  165. param = "error! 输出内容为空. nil"
  166. end
  167. jprint(...)
  168. end
  169. -- ------------------------------------------------------------- --
  170. EventListerTable.registerType("运营累充", _rechargeType(), _playerDbKey())
  171. RechargeEventListerTable:eventLister("0", "运营累充", AccumulatedRecharge.rechargeEvent)
  172. RechargeMessageEventListerTable:eventLister(_rechargeType(), "运营累充", AccumulatedRecharge.reqAction)