VipLogic.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. -------------------------------------------------------
  2. -- VIP逻辑
  3. -- db.vipLv
  4. -- db.vipExp
  5. -- db.vipLibao
  6. -- db.vipYueka
  7. -------------------------------------------------------
  8. local VipExcel = require("excel.vip")
  9. local Util = require("common.Util")
  10. local Lang = require("common.Lang")
  11. local Msg = require("core.Msg")
  12. local ObjHuman = require("core.ObjHuman")
  13. local Grid = require("bag.Grid")
  14. local BagLogic = require("bag.BagLogic")
  15. local Broadcast = require("broadcast.Broadcast")
  16. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  17. local HeroLogic = require("hero.HeroLogic")
  18. local RoleHeadLogic = require("role.RoleHeadLogic")
  19. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  20. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  21. local MonthCard = require("present.MonthCard")
  22. -- vip特权
  23. VIP_POWER1 = 1 -- x皇冠联赛(冠军联赛)次数购买x次
  24. VIP_POWER2 = 2 -- o快速作战(征战扫荡)次数x次
  25. VIP_POWER3 = 3 -- o通天塔(恶魔之塔)购买次数x次
  26. VIP_POWER4 = 4 -- o黑市刷新次数x次
  27. VIP_POWER5 = 5 -- x圣树挑战每天复活x次
  28. VIP_POWER6 = 6 -- x女神精力值上限x点
  29. VIP_POWER7 = 7 -- o征战挂机经验+x%
  30. VIP_POWER8 = 8 -- o征战挂机金币+x%
  31. VIP_POWER9 = 9 -- o征战挂机武将经验+x%
  32. VIP_POWER10 = 10 -- o离线挂机收益时长x小时
  33. VIP_POWER11 = 11 -- o摇钱树(点金手)额外金币加成+x%
  34. VIP_POWER12 = 12 -- o英雄背包数量上限+x
  35. VIP_POWER13 = 13 -- o日常副本(黄金圣树)购买各加x次
  36. VIP_POWER14 = 14 -- o道具商城高级召唤券1折购买(某些商品限定vip等级,在shop表中配置)
  37. VIP_POWER15 = 15 -- o开启许愿池(寻宝)多连抽
  38. VIP_POWER16 = 16 -- o激活专属头像
  39. VIP_POWER17 = 17 -- o激活专属头像框
  40. VIP_POWER18 = 18 -- x至尊段位赛战斗跳过
  41. VIP_POWER19 = 19 -- o征战挂机情报+x%
  42. -- VIP_POWER20 = 21 -- o激活专属背景
  43. VIP_POWER21 = 21 -- o抽卡 卷轴折扣特权
  44. VIP_POWER22 = 22 -- o抽卡 钻石特权
  45. -- 礼包状态
  46. local LIBAO_STATE_CANT = 0 -- 不可购买
  47. local LIBAO_STATE_CAN = 1 -- 可购买
  48. local LIBAO_STATE_HAD = 2 -- 已购买
  49. -- 月卡额外奖励状态
  50. local YUEKAITEM_STATE_NONE = 0 -- 未激活
  51. local YUEKAITEM_STATE_CAN = 1 -- 可领取
  52. local YUEKAITEM_STATE_HAD = 2 -- 已领取
  53. -- 获取vip等级
  54. function getVipLv(human)
  55. return human.db.vipLv or 0 --
  56. end
  57. -- 加vip经验
  58. function addExp(human, exp)
  59. do return end
  60. local oldLv = getVipLv(human)
  61. local newLv = 0
  62. local newExp = (human.db.vipExp or 0) + exp
  63. for lv, config in ipairs(VipExcel.vip) do
  64. if newExp < config.exp then
  65. break
  66. end
  67. newLv = lv
  68. end
  69. human.db.vipExp = newExp
  70. human.db.vipLv = newLv
  71. if oldLv ~= newLv then
  72. onVipLvChange(human, oldLv, newLv)
  73. end
  74. sendQuery(human)
  75. end
  76. -- vip等级改变回调
  77. function onVipLvChange(human, oldLv, newLv)
  78. -- 激活专属头像/头像框
  79. for lv = oldLv + 1, newLv do
  80. --[[local headID = getPowerArgsByLv(VIP_POWER16, lv)
  81. if headID and headID > 0 then
  82. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_1, headID)
  83. end
  84. local headFrameID = getPowerArgsByLv(VIP_POWER17, lv)
  85. if headFrameID and headFrameID > 0 then
  86. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_2, headFrameID)
  87. end
  88. local backGroundID = getPowerArgsByLv(VIP_POWER20,lv)
  89. if backGroundID and backGroundID > 0 then
  90. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_6, backGroundID)
  91. end]]
  92. end
  93. HeroLogic.sendHeroBagCap(human)
  94. -- ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE18, newLv)
  95. end
  96. -- 是否购买礼包
  97. function isBuyLibao(human, lv)
  98. if not human.db.vipLibao then
  99. return
  100. end
  101. return Util.getBit(human.db.vipLibao, lv) > 0
  102. end
  103. -- 设置已购买
  104. function setBuyLibao(human, lv)
  105. human.db.vipLibao = human.db.vipLibao or 0
  106. human.db.vipLibao = Util.setBit(human.db.vipLibao, lv)
  107. end
  108. -- 获取礼包状态
  109. function getLibaoState(human, lv)
  110. if getVipLv(human) < lv then
  111. return LIBAO_STATE_CANT
  112. end
  113. if isBuyLibao(human, lv) then
  114. return LIBAO_STATE_HAD
  115. end
  116. return LIBAO_STATE_CAN
  117. end
  118. -- 获取月卡每日奖励状态
  119. function getYuekaItemState(human)
  120. -- todo 是否激活月卡
  121. -- YUEKAITEM_STATE_NONE
  122. if human.db.vipYueka then
  123. return YUEKAITEM_STATE_HAD
  124. end
  125. return YUEKAITEM_STATE_CAN
  126. end
  127. function getPowerArgsByLv(human, powerType, vipLv)
  128. local config = VipExcel.vip[0]
  129. if not config then return end
  130. local vipNum = config[powerType]
  131. local monthNum = MonthCard.getPowerArgs(human, powerType)
  132. return vipNum + monthNum
  133. end
  134. -- 特权参数
  135. function getPowerArgs(human, powerType)
  136. local vipLv = getVipLv(human)
  137. return getPowerArgsByLv(human, powerType, vipLv)
  138. end
  139. -- 激活特权需要VIP等级
  140. local POWERTYPE_2_NEEDLV = nil
  141. function getPowerNeedLv(powerType)
  142. if not POWERTYPE_2_NEEDLV then
  143. POWERTYPE_2_NEEDLV = {}
  144. for vipLv, config in ipairs(VipExcel.vip) do
  145. for ptype, value in pairs(config) do
  146. if type(ptype) == "number" and type(value) == "number" then
  147. POWERTYPE_2_NEEDLV[vipLv] = POWERTYPE_2_NEEDLV[vipLv] or {}
  148. POWERTYPE_2_NEEDLV[vipLv][ptype] = POWERTYPE_2_NEEDLV[vipLv][ptype] or value
  149. end
  150. end
  151. end
  152. end
  153. for vipLv, v in pairs(POWERTYPE_2_NEEDLV) do
  154. if v[powerType] == 1 then
  155. return vipLv
  156. end
  157. end
  158. return 0
  159. end
  160. -- 获取下级提升属性所需vip等级
  161. function getUpPowerNeedLv(human, powerType)
  162. local nowVipLv = getVipLv(human)
  163. local nowValue = getPowerArgsByLv(human, powerType, nowVipLv)
  164. if type(nowValue) ~= "number" then return end
  165. local maxVipLv = #VipExcel.vip
  166. for i = nowVipLv + 1, maxVipLv do
  167. local value = getPowerArgsByLv(human, powerType, i)
  168. if value > nowValue then
  169. return i
  170. end
  171. end
  172. end
  173. ----------------------------------- msg ---------------------------------------------
  174. -- vip基础信息
  175. sendQueryNet = nil
  176. function sendQuery(human)
  177. local vipLv = getVipLv(human)
  178. local nextConfig = VipExcel.vip[vipLv + 1]
  179. local msgRet = Msg.gc.GC_VIP_INFO
  180. msgRet.lv = vipLv
  181. msgRet.maxLv = #VipExcel.vip
  182. msgRet.curExp = human.db.vipExp or 0
  183. msgRet.nextExp = nextConfig and nextConfig.exp or 0
  184. if not sendQueryNet then
  185. local config = VipExcel.vip
  186. local len = 0
  187. for k, v in pairs(config) do
  188. len = len + 1
  189. local net = msgRet.vipList[len]
  190. net.lv = k
  191. net.vipTab = v.vipTab
  192. net.exp = v.exp
  193. end
  194. msgRet.vipList[0] = len
  195. sendQueryNet = 1
  196. end
  197. Msg.send(msgRet, human.fd)
  198. end
  199. -- VIP特权详情
  200. function sendPowerQuery(human,lv)
  201. local config = VipExcel.vip[lv]
  202. if config == nil then
  203. return
  204. end
  205. local msgRet = Msg.gc.GC_VIP_POWER_QUERY
  206. local len = #VipExcel.vip
  207. local net = msgRet.data
  208. net.lv = lv
  209. net.descs[0] = #config.descs
  210. for i = 1, net.descs[0] do
  211. local descNet = net.descs[i]
  212. descNet.desc = config.descs[i]
  213. descNet.isNew = config.news[i]
  214. end
  215. net.libaoItems[0] = #config.libaoItems
  216. for i = 1, net.libaoItems[0] do
  217. local itemID = config.libaoItems[i][1]
  218. local itemCnt = config.libaoItems[i][2]
  219. Grid.makeItem(net.libaoItems[i], itemID, itemCnt)
  220. end
  221. net.libaoPriceNew = config.libaoPriceNew
  222. net.libaoPriceOld = config.libaoPriceOld
  223. net.yuekaItems[0] = #config.yuekaItems
  224. for i = 1, net.yuekaItems[0] do
  225. local itemID = config.yuekaItems[i][1]
  226. local itemCnt = config.yuekaItems[i][2]
  227. Grid.makeItem(net.yuekaItems[i], itemID, itemCnt)
  228. end
  229. net.libaoState = getLibaoState(human, lv)
  230. net.yuekaState = getYuekaItemState(human)
  231. for i = 0,len - 1 do
  232. msgRet.dot[i + 1] = getLibaoState(human, i)
  233. end
  234. msgRet.dot[0] = len
  235. Msg.send(msgRet, human.fd)
  236. end
  237. -- 购买VIP礼包
  238. function buyLibao(human, lv)
  239. local config = VipExcel.vip[lv]
  240. if not config then return end
  241. local state = getLibaoState(human, lv)
  242. if state == LIBAO_STATE_CANT then
  243. return Broadcast.sendErr(human, Lang.YUNYING_BUY_ERR_VIP)
  244. end
  245. if state == LIBAO_STATE_HAD then
  246. return Broadcast.sendErr(human, Lang.YUNYING_BUY_ERR_HAD)
  247. end
  248. if not ObjHuman.checkRMB(human, config.libaoPriceNew) then
  249. return
  250. end
  251. setBuyLibao(human, lv)
  252. ObjHuman.decZuanshi(human, -config.libaoPriceNew, "vip_libao")
  253. for _, item in ipairs(config.libaoItems) do
  254. local itemID = item[1]
  255. local itemCnt = item[2]
  256. BagLogic.addItem(human, itemID, itemCnt, "vip_libao")
  257. end
  258. BagLogic.sendItemGetList(human, config.libaoItems, "vip_libao")
  259. sendPowerQuery(human, lv)
  260. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_105)
  261. end
  262. -- 领取月卡每日奖励
  263. function getYuekaItem(human)
  264. local vipLv = getVipLv(human)
  265. local config = VipExcel.vip[vipLv]
  266. if not config then return end
  267. local state = getYuekaItemState(human)
  268. if state == YUEKAITEM_STATE_NONE then
  269. return Broadcast.sendErr(human, Lang.VIP_YUEKA_ITEM_ERR_GET)
  270. end
  271. if state == YUEKAITEM_STATE_HAD then
  272. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  273. end
  274. human.db.vipYueka = true
  275. for _, item in ipairs(config.yuekaItems) do
  276. local itemID = item[1]
  277. local itemCnt = item[2]
  278. BagLogic.addItem(human, itemID, itemCnt, "vip_yueka")
  279. end
  280. BagLogic.sendItemGetList(human, config.yuekaItems, "vip_yueka")
  281. sendPowerQuery(human, vipLv)
  282. end
  283. -- 登陆回调
  284. function onLogin(human)
  285. sendQuery(human)
  286. end
  287. -- 每日刷新
  288. function updateDaily(human)
  289. human.db.vipYueka = nil
  290. end
  291. function isDot(human)
  292. if isBuyLibao(human, 0) then
  293. return
  294. end
  295. return true
  296. end