VipGiftPack.lua 8.6 KB

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