WeekDiamondPack.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. --- 钻石礼包
  2. WeekDiamondPack = {}
  3. WeekDiamondPack.__index = WeekDiamondPack
  4. local this = {}
  5. local function _rechargeType()
  6. return "188"
  7. end
  8. local BUY_TYPE = {
  9. NOE_BUY = 2, -- 一键购买
  10. FREE_BUY = 3 -- 免费购买
  11. }
  12. --- 请求充值档位信息
  13. function WeekDiamondPack.reqRechargeAction(actor,mainGroup)
  14. -- 判断当前主活动是否开启了子直购活动
  15. local allActivityInfo = {}
  16. local operateActivityTable = ConfigDataManager.getList("cfg_DiamondPack")
  17. if table.isNullOrEmpty(operateActivityTable) then
  18. return allActivityInfo
  19. end
  20. for _, config in pairs(operateActivityTable) do
  21. if tonumber(mainGroup) == tonumber(config.maingroup) then
  22. local diamondPackId = config.id
  23. local itemCount = config.reward
  24. local rewardsMap = string.toIntIntMap(itemCount, "#", "|")
  25. local activityInfo = {
  26. diamondPackId = diamondPackId,
  27. itemInfo = rewardsMap
  28. }
  29. table.insert(allActivityInfo,activityInfo)
  30. end
  31. end
  32. return allActivityInfo
  33. end
  34. --- 触发充值
  35. function WeekDiamondPack.reqAction(actor, rechargeType, action, reqParameter)
  36. local directGiftId = reqParameter["id"]
  37. local config = ConfigDataManager.getById("cfg_DiamondPack", directGiftId)
  38. local count = CountManager.getCount(actor, config.countkey)
  39. local total = ConfigDataManager.getTableValue("Count_count","total","id",config.countkey)
  40. if count.count >= tonumber(total) then
  41. return
  42. end
  43. local mainGroup = WeekActives.getCurrentMainGroup(actor)
  44. local cfgMainGroup = config.maingroup
  45. if mainGroup ~= tonumber(cfgMainGroup) then
  46. return
  47. end
  48. if tonumber(config.type) == BUY_TYPE.NOE_BUY then
  49. -- 一键购买
  50. local operateActivity = ConfigDataManager.getTable("cfg_DiamondPack","mainGroup",mainGroup)
  51. if not table.isNullOrEmpty(operateActivity) then
  52. for _, config in pairs(operateActivity) do
  53. local operateActivityId = config.id
  54. local count = CountManager.getCount(actor, tonumber(config.countkey))
  55. if tonumber(operateActivityId) ~= tonumber(directGiftId) then
  56. if tonumber(config.type) ~= BUY_TYPE.FREE_BUY and count.count > 0 then
  57. return
  58. end
  59. end
  60. end
  61. end
  62. if this.costDiamond(actor,config.diamond,config.money) then
  63. local outRewards = {}
  64. this.oneBug(actor,outRewards,operateActivity)
  65. Bag.sendRewards(actor, outRewards, "幸运周末钻石礼包一键购买")
  66. end
  67. else
  68. if this.costDiamond(actor,config.diamond,config.money) then
  69. local reward_str = config.reward
  70. if not string.isNullOrEmpty(reward_str) then
  71. Bag.sendRewards4String(actor, reward_str, "幸运周末钻石礼包"..config.id)
  72. end
  73. CountManager.count(actor, config.countkey,1)
  74. end
  75. end
  76. -- 发送界面信息数据
  77. WeekActives.openSubActive(actor,{
  78. subType = ACTIVE_TYPE.DIAMOND_PACK
  79. })
  80. end
  81. -- 消耗钻石
  82. function this.costDiamond(actor,type,count)
  83. if string.isNullOrEmpty(count) then
  84. return true
  85. end
  86. local money = tonumber(count)
  87. if money == 0 then
  88. return true
  89. end
  90. if tonumber(type) == 2 then
  91. local haveBindCount = getbagitemcountbyid(actor,10050001)
  92. if money <= haveBindCount then
  93. removeitemfrombag(actor,10050001,money,0,9999,'周钻石礼包')
  94. return true
  95. else
  96. local haveCount = getbagitemcountbyid(actor,10040001)
  97. if haveCount + haveBindCount >= money then
  98. removeitemfrombag(actor,10050001,haveBindCount,0,9999,'周钻石礼包')
  99. local needCount = money - haveBindCount
  100. removeitemfrombag(actor,10040001,needCount,0,9999,'周钻石礼包')
  101. return true
  102. else
  103. return false
  104. end
  105. end
  106. else
  107. local haveCount = getbagitemcountbyid(actor,10040001)
  108. if haveCount >= money then
  109. removeitemfrombag(actor,10040001,money,0,9999,'周钻石礼包')
  110. end
  111. return false
  112. end
  113. end
  114. -- 一键购买
  115. function this.oneBug(actor,outRewards,operateActivity)
  116. if not table.isNullOrEmpty(operateActivity) then
  117. for _, config in pairs(operateActivity) do
  118. if tonumber(config.type) ~= BUY_TYPE.FREE_BUY then
  119. local total = ConfigDataManager.getTableValue("Count_count","total","id",config.countkey)
  120. CountManager.count(actor, tonumber(config.countkey),tonumber(total))
  121. for i = 1, tonumber(total) do
  122. string.putIntIntMap(outRewards, config.reward, "#", "|")
  123. end
  124. end
  125. end
  126. end
  127. end
  128. --- 直购关闭
  129. function WeekDiamondPack.closeActive(mainGroup)
  130. -- local diamondPackTable = ConfigDataManager.getTable("cfg_DiamondPack","mainGroup",mainGroup,"type",BUY_TYPE.FREE_BUY)
  131. -- if table.isNullOrEmpty(diamondPackTable) then
  132. -- return
  133. -- end
  134. -- local allRoleInfos = getallrolesummaryinfos()
  135. -- local diamondPack = diamondPackTable[1]
  136. -- if not table.isNullOrEmpty(allRoleInfos) then
  137. -- local specialCondition = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","specialCondition","mainGroup",mainGroup,"subType",ACTIVE_TYPE.DIRECT)
  138. -- for k, roleInfo in pairs(allRoleInfos) do
  139. -- local actor = roleInfo["actor"]
  140. -- -- 判断当前玩家有没有另外免费直购
  141. -- local item = {}
  142. -- local countInfo = CountManager.getCount(actor,diamondPack.countkey)
  143. -- if not table.isNullOrEmpty(countInfo) and countInfo.total > countInfo.count and ConditionManager.Check(actor, specialCondition) then
  144. -- local itemInfo = diamondPack.reward
  145. -- local count = countInfo.total - countInfo.count
  146. -- for i = 1, count do
  147. -- string.putIntIntMap(item, itemInfo, "#", "|")
  148. -- end
  149. -- --
  150. -- sendconfigmailbyrid(actor,actor:toString(), 900004, item)
  151. -- end
  152. -- end
  153. -- end
  154. end
  155. -- ------------------------------------------------------------- --
  156. this.log_open = false
  157. function this.debug(...)
  158. if not this.log_open then
  159. return
  160. end
  161. gameDebug.print(...)
  162. end
  163. function this.jprint(...)
  164. if not this.log_open then
  165. return
  166. end
  167. if param == nil then
  168. param = "error! 输出内容为空. nil"
  169. end
  170. jprint(...)
  171. end
  172. -- ------------------------------------------------------------- --
  173. EventListerTable.registerType("幸运周末钻石礼包", _rechargeType())
  174. RechargeMessageEventListerTable:eventLister(_rechargeType(), "幸运周末钻石礼包", WeekDiamondPack.reqAction)