From 5d620aefb2f4b7932dfa5aae6b7dfac1bfeaf5a2 Mon Sep 17 00:00:00 2001 From: chenyueqi <1056825054@qq.com> Date: Mon, 10 Feb 2020 21:14:59 +0800 Subject: [PATCH] 拆解室指定某一项为必得奖励 --- src/actions/RoleAction.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index d107d5c..113e93b 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -481,16 +481,26 @@ function _M.openTimeBoxRpc(agent, data) -- 随机奖励 local randomGift = randomData.random_gift local randomNum = randomData.random_num - if boxL[slot].gem ~= 0 then - randomNum = randomData[boxL[slot].gem .. "_gem_num"] - randomGift = randomData[boxL[slot].gem .. "_gem_gift"] - end + local gemId = boxL[slot].gem if randomNum > 0 and randomGift and randomGift ~= "" then + local selectGift = {} local pool = {} for _, temp in ipairs(randomGift:toArray()) do - table.insert(pool, temp:toArray(true, "=")) + local set = temp:toArray(true, "=") + if gemId == set[1] then + table.insert(selectGift, set) + else + table.insert(pool, set) + end + end + + if gemId ~= 0 and next(selectGift) then + randomNum = randomNum - 1 + local idx = math.randWeight(pool, 3) + reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] end + local needCount = math.min(#pool, randomNum) for j = 1, needCount do local idx = math.randWeight(pool, 3) -- libgit2 0.21.2