From 4d8bd32c55e9c8dca2cce26b1c6f24e4507ef604 Mon Sep 17 00:00:00 2001 From: chenyueqi <1056825054@qq.com> Date: Tue, 26 Nov 2019 15:21:20 +0800 Subject: [PATCH] 倒计时开箱子 --- src/actions/RoleAction.lua | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 8dff9c1..0af9643 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -363,7 +363,7 @@ end function _M.openTimeBoxRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) - local oper = msg.oper -- 操作 1 - 3 + local oper = msg.oper -- 操作 1 - 2 local slot = msg.slot -- 位置 1 - 6 if math.illegalNum(slot, 1, globalCsv.box_timeOpen_maxNum) then return end @@ -374,25 +374,22 @@ function _M.openTimeBoxRpc(agent, data) if role:getItemCount(itemId) < 1 then return end local itemData = csvdb["itemCsv"][itemId] local randomData = csvdb["item_randomCsv"][itemId] - if not randomData or randomData.openTime <= 0 then return end + if not itemData or not randomData or randomData.openTime <= 0 then return end if boxL[slot] then return end role:costItems({[itemId] = 1}) boxL[slot] = {id = itemId, time = skynet.timex() + randomData.openTime} - elseif oper == 2 then -- 上宝石 + -- 上宝石 local gemId = msg.gem or 0 - if not boxL[slot] then return end - if boxL[slot].gem or boxL[slot].time <= skynet.timex() then return end - local itemData = csvdb["itemCsv"][boxL[slot].id] - local randomData = csvdb["item_randomCsv"][itemId] local num = randomData[gemId .. "_gem_num"] - if not num then return end + if num then + if not role:checkItemEnough({[gemId] = 1}) then return end + role:costItems({[gemId] = 1}) + end - if not role:checkItemEnough({[gemId] = 1}) then return end - role:costItems({[gemId] = 1}) boxL[slot].gem = gemId - elseif oper == 3 then -- 领取 + elseif oper == 2 then -- 领取 local quick = msg.quick if not boxL[slot] then return end if boxL[slot].time > skynet.timex() then -- 没开完 @@ -404,12 +401,12 @@ function _M.openTimeBoxRpc(agent, data) end local itemData = csvdb["itemCsv"][boxL[slot].id] - local randomData = csvdb["item_randomCsv"][itemId] + local randomData = csvdb["item_randomCsv"][itemData.id] reward = randomData.gift:toNumMap() -- 固定奖励 -- 随机奖励 local randomGift = randomData.random_gift local randomNum = randomData.random_num - if boxL[slot].gem then + if boxL[slot].gem ~= 0 then randomNum = randomData[boxL[slot].gem .. "_gem_num"] randomGift = randomData[boxL[slot].gem .. "_gem_gift"] end -- libgit2 0.21.2