VipGiftPack.lua 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. VipGiftPack = {}
  2. VipGiftPack.__index = VipGiftPack
  3. local this = {}
  4. local function _rechargeType()
  5. return "8"
  6. end
  7. local function _playerDbKey()
  8. return "T$_VIP_WEEK_GIFT_DATA_KEY"
  9. end
  10. function VipGiftPack.get(actor)
  11. local data = getplaydef(actor, _playerDbKey())
  12. return setmetatable(data or {}, VipGiftPack)
  13. end
  14. function VipGiftPack.getLv(actor)
  15. local data = VipGiftPack.get(actor)
  16. return data.lv or 0
  17. end
  18. function VipGiftPack:save(actor)
  19. setplaydef(actor, _playerDbKey(), self)
  20. end
  21. function VipGiftPack.getVipLv(actor)
  22. local data = VipGiftPack.get(actor)
  23. if table.isEmpty(data) then
  24. return 0
  25. end
  26. return data.lv or 0
  27. end
  28. function VipGiftPack.login(actor)
  29. this.queryData(actor, { type = _rechargeType(), action = "panel" })
  30. this.showVipExpRate(actor)
  31. end
  32. --- 请求充值档位信息
  33. function VipGiftPack.reqRechargeAction(actor, _, action, reqParameter)
  34. if action == "panel" then
  35. this.queryData(actor, reqParameter)
  36. end
  37. end
  38. --- 触发充值
  39. function VipGiftPack.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
  40. this.debug("购买VIP礼包", cfg_recharge, "购买数量", count, ext, outRewards)
  41. local vipGiftId = cfg_recharge.parameter
  42. local rechargeType = cfg_recharge.type
  43. local config = ConfigDataManager.getById("cfg_VIP_Pack", vipGiftId)
  44. gameDebug.assertTrue(table.notEmpty(config), "没有配置VIP礼包", vipGiftId)
  45. local is_pass = ConditionManager.Check(actor, config.conditionid)
  46. if not is_pass then
  47. tipinfo(actor, "VIP购买条件不满足")
  48. return
  49. end
  50. local career = getbaseinfo(actor, "getbasecareer")
  51. -- 发放道具
  52. local reward_str = config.rewards
  53. if not string.isNullOrEmpty(reward_str) then
  54. string.putIntIntMap4Career(outRewards, career, reward_str, "#", "|")
  55. end
  56. local vip_config_list = ConfigDataManager.getTable("cfg_vip", "vippack", vipGiftId)
  57. if table.notEmpty(vip_config_list) then
  58. local vip_config = vip_config_list[1]
  59. this.debug("----- vip_config -----", vip_config, vip_config.grade)
  60. local lv = string.tonumber(vip_config.grade)
  61. local gift_data = VipGiftPack.get(actor)
  62. local old_lv = gift_data.lv or 0
  63. -- 激活
  64. gift_data.lv = lv
  65. gift_data:save(actor)
  66. local success, result = xpcall(VipPrivilege.activateVIP, debug.traceback, actor, vip_config, old_lv)
  67. gameDebug.assertPrint(success, "激活特权异常!", result, "vip等级", lv)
  68. SceneMap.sendEnterViewInfoByType(actor, SceneMap.viewKey.VIP_LV, lv)
  69. end
  70. -- 发送界面信息数据
  71. this.queryData(actor, { type = rechargeType, action = "panel" })
  72. this.debug("购买VIP礼包成功", cfg_recharge, "购买数量", count, ext, outRewards)
  73. end
  74. function this.queryData(actor, reqParameter)
  75. this.debug("请求VIP礼包信息", reqParameter)
  76. local rechargeType = reqParameter["type"]
  77. local config_list = ConfigDataManager.getList("cfg_VIP_Pack")
  78. gameDebug.assertTrue(table.notNullOrEmpty(config_list), "没有配置充值档位")
  79. local gift_data = VipGiftPack.get(actor)
  80. local resData = {}
  81. this.debug("配置表数据", config_list)
  82. resData['lv'] = gift_data.lv or 0
  83. Recharge.resAction(actor, rechargeType, reqParameter.action, resData)
  84. end
  85. -- ------------------------------------------------------------- --
  86. VipPrivilege = {}
  87. VipPrivilege.Type = {
  88. goldway = "goldway", -- 黄金线路
  89. tqboss = "tqboss", -- 特权boss
  90. rate = "rate", -- 攻速加成
  91. castle = "castle", -- 血色城堡每日次数
  92. plaza = "plaza", -- 恶魔广场每日次数
  93. exp = "exp", -- 经验加成
  94. attributepoint = "attributepoint", -- 赠送额外属性点
  95. recycle = "recycle", -- 收回金币提升
  96. explosiverate = "explosiverate", -- 套装爆率提升
  97. tax = "tax" -- 交易行税率下降
  98. }
  99. function VipGiftPack.hasPrivilege(actor, type)
  100. local gift_data = VipGiftPack.get(actor)
  101. if table.isEmpty(gift_data) then
  102. return false
  103. end
  104. local lv = gift_data.lv
  105. local config = ConfigDataManager.getById("cfg_vip", lv)
  106. if table.isNullOrEmpty(config) then
  107. return false, 0
  108. end
  109. this.debug("VIP获取特权信息", "VIP等级", lv, "VIP特权配置", config[type], config)
  110. return true, config[type]
  111. end
  112. function VipPrivilege.activateVIP(actor, vip_config, old_lv)
  113. -- 添加自由属性
  114. local point_data = vip_config[VipPrivilege.Type.attributepoint]
  115. if not string.isNullOrEmpty(point_data) then
  116. local point_item = string.toIntIntMap(point_data, "#", "|")
  117. additemmaptobag(actor, point_item, 0, 9999, 'vip特权')
  118. end
  119. -- 活动剩余次数
  120. local dup_add_map = {}
  121. -- 血色城堡和恶魔广场
  122. this.addDupCount(dup_add_map, vip_config, VipPrivilege.Type.castle)
  123. this.addDupCount(dup_add_map, vip_config, VipPrivilege.Type.plaza)
  124. this.addDupLeftCount(actor, dup_add_map)
  125. -- 属性加成
  126. local attr_map = {}
  127. -- 攻速加成属性
  128. this.addAttr(attr_map, vip_config, VipPrivilege.Type.rate)
  129. -- 套装爆率提升属性
  130. this.addAttr(attr_map, vip_config, VipPrivilege.Type.explosiverate)
  131. -- 经验加成属性
  132. this.addAttr(attr_map, vip_config, VipPrivilege.Type.exp)
  133. addrolekmlattributes(actor, RoleAttrKey.VIP_GIFT_PACK, attr_map)
  134. -- 经验加成前端显示协议
  135. this.showVipExpRate(actor)
  136. -- 特权BOSS增加次数
  137. local old_boss_count = ConfigDataManager.getTableValue("cfg_vip", "tqboss", "id", old_lv)
  138. if string.tonumber(old_boss_count) < string.tonumber(vip_config.tqboss) then
  139. PrivilegeBoss.addCount(actor, PrivilegeBossCountType.VIP)
  140. end
  141. this.debug("---- VIP特权结算 ----", "lv " .. vip_config.grade,
  142. "dup_count", dup_add_map, "attr_map", attr_map, "point", point_data)
  143. end
  144. function VipPrivilege.entryCountHandler(actor, activityId)
  145. local dup_map = {}
  146. local act_id = tonumber(activityId)
  147. if act_id == DuplicateType.BLOODY_CASTLE then
  148. this.getLevelActivityCount(actor, dup_map, VipPrivilege.Type.castle)
  149. elseif act_id == DuplicateType.DEVIL_SQUARE then
  150. this.getLevelActivityCount(actor, dup_map, VipPrivilege.Type.plaza)
  151. end
  152. this.addDupLeftCount(actor, dup_map)
  153. end
  154. function this.getLevelActivityCount(actor, dup_map, type)
  155. local level = VipGiftPack.getLv(actor)
  156. if level < 1 then
  157. return
  158. end
  159. for lv = 1, level do
  160. local config = ConfigDataManager.getById("cfg_vip", lv)
  161. if table.notEmpty(config) then
  162. this.addDupCount(dup_map, config, type)
  163. end
  164. end
  165. end
  166. function this.addDupCount(dup_add_map, vip_config, type)
  167. local str = vip_config[type]
  168. if not string.isNullOrEmpty(str) then
  169. string.putIntIntMap(dup_add_map, str, "#", "|")
  170. end
  171. end
  172. function this.addAttr(attr_map, vip_config, type)
  173. string.putIntIntMap(attr_map, vip_config[type], "#", "|")
  174. end
  175. function this.addDupLeftCount(actor, dup_map)
  176. if table.isEmpty(dup_map) then
  177. return
  178. end
  179. for k, v in pairs(dup_map) do
  180. if v > 0 then
  181. addleftcountofactivity(actor, k, v)
  182. end
  183. end
  184. end
  185. function this.showVipExpRate(actor)
  186. local is_has, rate = VipGiftPack.hasPrivilege(actor, VipPrivilege.Type.exp)
  187. if is_has then
  188. local rate_arr = string.split(rate, "#")
  189. ExpBonus.changeBonus(actor, BonusType.VIP_EXP_BONUS, tonumber(rate_arr[2]), 0, 0)
  190. end
  191. end
  192. -- ------------------------------------------------------------- --
  193. this.log_open = false
  194. function this.debug(...)
  195. if not this.log_open then
  196. return
  197. end
  198. gameDebug.print(...)
  199. end
  200. function this.jprint(...)
  201. if not this.log_open then
  202. return
  203. end
  204. if param == nil then
  205. param = "error! 输出内容为空. nil"
  206. end
  207. jprint(...)
  208. end
  209. -- ------------------------------------------------------------- --
  210. EventListerTable.registerType("VIP礼包", _rechargeType(), _playerDbKey())
  211. -- 注册登录事件
  212. LoginEventListerTable:eventLister("0", "VIP礼包", VipGiftPack.login)
  213. -- 注册充值回调事件
  214. RechargeEventListerTable:eventLister(_rechargeType(), "recharge_vip_gift", VipGiftPack.rechargeEvent)
  215. -- 注册请求消息监听
  216. RechargeMessageEventListerTable:eventLister(_rechargeType(), "req_vip_gift_info", VipGiftPack.reqRechargeAction)