VipLogic.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. VIP_POWER23 = 23 -- 100抽卡 卷轴折扣特权
  46. VIP_POWER24 = 24 -- 100抽卡 钻石特权
  47. -- 礼包状态
  48. local LIBAO_STATE_CANT = 0 -- 不可购买
  49. local LIBAO_STATE_CAN = 1 -- 可购买
  50. local LIBAO_STATE_HAD = 2 -- 已购买
  51. -- 月卡额外奖励状态
  52. local YUEKAITEM_STATE_NONE = 0 -- 未激活
  53. local YUEKAITEM_STATE_CAN = 1 -- 可领取
  54. local YUEKAITEM_STATE_HAD = 2 -- 已领取
  55. -- 获取vip等级
  56. function getVipLv(human)
  57. return human.db.vipLv or 0 --
  58. end
  59. -- 加vip经验
  60. function addExp(human, exp)
  61. do return end
  62. local oldLv = getVipLv(human)
  63. local newLv = 0
  64. local newExp = (human.db.vipExp or 0) + exp
  65. for lv, config in ipairs(VipExcel.vip) do
  66. if newExp < config.exp then
  67. break
  68. end
  69. newLv = lv
  70. end
  71. human.db.vipExp = newExp
  72. human.db.vipLv = newLv
  73. if oldLv ~= newLv then
  74. onVipLvChange(human, oldLv, newLv)
  75. end
  76. sendQuery(human)
  77. end
  78. -- vip等级改变回调
  79. function onVipLvChange(human, oldLv, newLv)
  80. -- 激活专属头像/头像框
  81. for lv = oldLv + 1, newLv do
  82. --[[local headID = getPowerArgsByLv(VIP_POWER16, lv)
  83. if headID and headID > 0 then
  84. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_1, headID)
  85. end
  86. local headFrameID = getPowerArgsByLv(VIP_POWER17, lv)
  87. if headFrameID and headFrameID > 0 then
  88. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_2, headFrameID)
  89. end
  90. local backGroundID = getPowerArgsByLv(VIP_POWER20,lv)
  91. if backGroundID and backGroundID > 0 then
  92. RoleHeadLogic.active(human, RoleHeadLogic.HEAD_TYPE_6, backGroundID)
  93. end]]
  94. end
  95. HeroLogic.sendHeroBagCap(human)
  96. -- ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE18, newLv)
  97. end
  98. -- 是否购买礼包
  99. function isBuyLibao(human, lv)
  100. if not human.db.vipLibao then
  101. return
  102. end
  103. return Util.getBit(human.db.vipLibao, lv) > 0
  104. end
  105. -- 设置已购买
  106. function setBuyLibao(human, lv)
  107. human.db.vipLibao = human.db.vipLibao or 0
  108. human.db.vipLibao = Util.setBit(human.db.vipLibao, lv)
  109. end
  110. -- 获取礼包状态
  111. function getLibaoState(human, lv)
  112. if getVipLv(human) < lv then
  113. return LIBAO_STATE_CANT
  114. end
  115. if isBuyLibao(human, lv) then
  116. return LIBAO_STATE_HAD
  117. end
  118. return LIBAO_STATE_CAN
  119. end
  120. -- 获取月卡每日奖励状态
  121. function getYuekaItemState(human)
  122. -- todo 是否激活月卡
  123. -- YUEKAITEM_STATE_NONE
  124. if human.db.vipYueka then
  125. return YUEKAITEM_STATE_HAD
  126. end
  127. return YUEKAITEM_STATE_CAN
  128. end
  129. function getPowerArgsByLv(human, powerType, vipLv)
  130. local config = VipExcel.vip[0]
  131. if not config then return end
  132. local vipNum = config[powerType]
  133. local monthNum = MonthCard.getPowerArgs(human, powerType)
  134. return vipNum + monthNum
  135. end
  136. -- 特权参数
  137. function getPowerArgs(human, powerType)
  138. local vipLv = getVipLv(human)
  139. return getPowerArgsByLv(human, powerType, vipLv)
  140. end
  141. -- 激活特权需要VIP等级
  142. local POWERTYPE_2_NEEDLV = nil
  143. function getPowerNeedLv(powerType)
  144. if not POWERTYPE_2_NEEDLV then
  145. POWERTYPE_2_NEEDLV = {}
  146. for vipLv, config in ipairs(VipExcel.vip) do
  147. for ptype, value in pairs(config) do
  148. if type(ptype) == "number" and type(value) == "number" then
  149. POWERTYPE_2_NEEDLV[vipLv] = POWERTYPE_2_NEEDLV[vipLv] or {}
  150. POWERTYPE_2_NEEDLV[vipLv][ptype] = POWERTYPE_2_NEEDLV[vipLv][ptype] or value
  151. end
  152. end
  153. end
  154. end
  155. for vipLv, v in pairs(POWERTYPE_2_NEEDLV) do
  156. if v[powerType] == 1 then
  157. return vipLv
  158. end
  159. end
  160. return 0
  161. end
  162. -- 获取下级提升属性所需vip等级
  163. function getUpPowerNeedLv(human, powerType)
  164. local nowVipLv = getVipLv(human)
  165. local nowValue = getPowerArgsByLv(human, powerType, nowVipLv)
  166. if type(nowValue) ~= "number" then return end
  167. local maxVipLv = #VipExcel.vip
  168. for i = nowVipLv + 1, maxVipLv do
  169. local value = getPowerArgsByLv(human, powerType, i)
  170. if value > nowValue then
  171. return i
  172. end
  173. end
  174. end
  175. ----------------------------------- msg ---------------------------------------------
  176. -- vip基础信息
  177. sendQueryNet = nil
  178. function sendQuery(human)
  179. local vipLv = getVipLv(human)
  180. local nextConfig = VipExcel.vip[vipLv + 1]
  181. local msgRet = Msg.gc.GC_VIP_INFO
  182. msgRet.lv = vipLv
  183. msgRet.maxLv = #VipExcel.vip
  184. msgRet.curExp = human.db.vipExp or 0
  185. msgRet.nextExp = nextConfig and nextConfig.exp or 0
  186. if not sendQueryNet then
  187. local config = VipExcel.vip
  188. local len = 0
  189. for k, v in pairs(config) do
  190. len = len + 1
  191. local net = msgRet.vipList[len]
  192. net.lv = k
  193. net.vipTab = v.vipTab
  194. net.exp = v.exp
  195. end
  196. msgRet.vipList[0] = len
  197. sendQueryNet = 1
  198. end
  199. Msg.send(msgRet, human.fd)
  200. end
  201. -- VIP特权详情
  202. function sendPowerQuery(human,lv)
  203. local config = VipExcel.vip[lv]
  204. if config == nil then
  205. return
  206. end
  207. local msgRet = Msg.gc.GC_VIP_POWER_QUERY
  208. local len = #VipExcel.vip
  209. local net = msgRet.data
  210. net.lv = lv
  211. net.descs[0] = #config.descs
  212. for i = 1, net.descs[0] do
  213. local descNet = net.descs[i]
  214. descNet.desc = config.descs[i]
  215. descNet.isNew = config.news[i]
  216. end
  217. net.libaoItems[0] = #config.libaoItems
  218. for i = 1, net.libaoItems[0] do
  219. local itemID = config.libaoItems[i][1]
  220. local itemCnt = config.libaoItems[i][2]
  221. Grid.makeItem(net.libaoItems[i], itemID, itemCnt)
  222. end
  223. net.libaoPriceNew = config.libaoPriceNew
  224. net.libaoPriceOld = config.libaoPriceOld
  225. net.yuekaItems[0] = #config.yuekaItems
  226. for i = 1, net.yuekaItems[0] do
  227. local itemID = config.yuekaItems[i][1]
  228. local itemCnt = config.yuekaItems[i][2]
  229. Grid.makeItem(net.yuekaItems[i], itemID, itemCnt)
  230. end
  231. net.libaoState = getLibaoState(human, lv)
  232. net.yuekaState = getYuekaItemState(human)
  233. for i = 0,len - 1 do
  234. msgRet.dot[i + 1] = getLibaoState(human, i)
  235. end
  236. msgRet.dot[0] = len
  237. Msg.send(msgRet, human.fd)
  238. end
  239. -- 购买VIP礼包
  240. function buyLibao(human, lv)
  241. local config = VipExcel.vip[lv]
  242. if not config then return end
  243. local state = getLibaoState(human, lv)
  244. if state == LIBAO_STATE_CANT then
  245. return Broadcast.sendErr(human, Lang.YUNYING_BUY_ERR_VIP)
  246. end
  247. if state == LIBAO_STATE_HAD then
  248. return Broadcast.sendErr(human, Lang.YUNYING_BUY_ERR_HAD)
  249. end
  250. if not ObjHuman.checkRMB(human, config.libaoPriceNew) then
  251. return
  252. end
  253. setBuyLibao(human, lv)
  254. ObjHuman.decZuanshi(human, -config.libaoPriceNew, "vip_libao")
  255. for _, item in ipairs(config.libaoItems) do
  256. local itemID = item[1]
  257. local itemCnt = item[2]
  258. BagLogic.addItem(human, itemID, itemCnt, "vip_libao")
  259. end
  260. BagLogic.sendItemGetList(human, config.libaoItems, "vip_libao")
  261. sendPowerQuery(human, lv)
  262. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_105)
  263. end
  264. -- 领取月卡每日奖励
  265. function getYuekaItem(human)
  266. local vipLv = getVipLv(human)
  267. local config = VipExcel.vip[vipLv]
  268. if not config then return end
  269. local state = getYuekaItemState(human)
  270. if state == YUEKAITEM_STATE_NONE then
  271. return Broadcast.sendErr(human, Lang.VIP_YUEKA_ITEM_ERR_GET)
  272. end
  273. if state == YUEKAITEM_STATE_HAD then
  274. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  275. end
  276. human.db.vipYueka = true
  277. for _, item in ipairs(config.yuekaItems) do
  278. local itemID = item[1]
  279. local itemCnt = item[2]
  280. BagLogic.addItem(human, itemID, itemCnt, "vip_yueka")
  281. end
  282. BagLogic.sendItemGetList(human, config.yuekaItems, "vip_yueka")
  283. sendPowerQuery(human, vipLv)
  284. end
  285. -- 登陆回调
  286. function onLogin(human)
  287. sendQuery(human)
  288. end
  289. -- 每日刷新
  290. function updateDaily(human)
  291. human.db.vipYueka = nil
  292. end
  293. function isDot(human)
  294. if isBuyLibao(human, 0) then
  295. return
  296. end
  297. return true
  298. end