DiamondPack.lua 7.1 KB

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