From f4c65591354382ead8213749c1896f334e7e59a5 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Wed, 18 Sep 2019 19:15:35 +0800 Subject: [PATCH] 抽奖 --- src/GlobalVar.lua | 1 + src/ProtocolCode.lua | 1 + src/actions/AdvAction.lua | 35 +++++++++++++++++++++++++++++++++++ src/adv/Adv.lua | 5 +++++ 4 files changed, 42 insertions(+), 0 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 4390bae..d42de71 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -52,6 +52,7 @@ FuncOpenType = { AdvRelay = 3, -- 中继开放 AdvArtifact = 4, -- 神器开放 AdvWS = 6, -- 工坊解锁 + AdvWheelSurf = 7, -- 抽奖解锁 } TypeIsFunc = {} diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 5c212f7..af9971c 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -41,6 +41,7 @@ actionCodes = { Adv_buyAdvCountRpc = 160, Adv_finishTaskRpc = 161, Adv_workshopRpc = 162, + Adv_wheelSurfRpc = 163, Hero_loadInfos = 201, Hero_updateProperty = 202, diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 8d37310..743ba0f 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -362,5 +362,40 @@ function _M.workshopRpc(agent, data) return true end +function _M.wheelSurfRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + if not role:isFuncOpen(FuncOpenType.AdvWheelSurf) then return end + if not role._advWheelSurfCount then return end + + local drawData = csvdb["adv_wheelsurfCsv"][role:getFuncLv(FuncOpenType.AdvWheelSurf)] + if not drawData then return end + + local costs = drawData.cost:toArray(true, "=") + local maxt = math.max(#costs, drawData.time) + + if role._advWheelSurfCount >= maxt then + role._advWheelSurfCount = nil + return + end + + local cost = costs[role._advWheelSurfCount + 1] + if cost > 0 then + if not role:checkItemEnough({[ItemId.Diamond] = cost}) then return end + role:costItems({[ItemId.Diamond] = cost}) + end + + role._advWheelSurfCount = role._advWheelSurfCount + 1 + if role._advWheelSurfCount >= maxt then + role._advWheelSurfCount = nil + end + + local gift = drawData.pool:randWeight(true) + + local reward = role:award({[gift[1]] = gift[2]}) + SendPacket(actionCodes.Adv_wheelSurfRpc, MsgPack.pack({reward = reward})) + return true +end + return _M \ No newline at end of file diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index f05b214..ba40607 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -49,6 +49,8 @@ function Adv:initByChapter(chapterId, level, isToNext, notNotify) self.lastEnemyId = 1 self.mapStack = {1} -- 最后一个为当前的地图 + self.owner._advWheelSurfCount = nil -- 抽奖进行次数 + -- 随机出地图 local mapId = self:randomMapId(chapterId, level) self.maps = {} @@ -157,6 +159,9 @@ function Adv:over(success) if success then reward = self.owner:award(self.owner:getProperty("advItems"):toNumMap()) self.owner:checkTaskEnter(self.owner.TaskType.AdvPass, {id = self.chapterId}) + if self.owner:isFuncOpen(FuncOpenType.AdvWheelSurf) then + self.owner._advWheelSurfCount = 0 -- 抽奖进行次数 + end end self:clear() -- libgit2 0.21.2