From 007af97ec4c962bca4887c5f3eec00b54853b595 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Fri, 13 Mar 2020 11:14:22 +0800 Subject: [PATCH] item_random 结构更改 --- src/actions/AdvAction.lua | 54 +++++++++++++++++++++++++++--------------------------- src/actions/HeroAction.lua | 2 +- src/actions/RoleAction.lua | 82 ++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- 3 files changed, 72 insertions(+), 66 deletions(-) diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index fd86914..e513537 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -562,33 +562,33 @@ function _M.endBattleRpc(agent, data) return true end -function _M.workshopRpc(agent, data) - local role = agent.role - local msg = MsgPack.unpack(data) - - local id = msg.id - local count = msg.count or 1 - local mergeData = csvdb["adv_mergeCsv"][id] - if not mergeData then return 1 end - - if not role:isFuncOpen(FuncOpenType.AdvWS) or role:getFuncLv(FuncOpenType.AdvWS) < mergeData.unlock then return 2 end - - local advWs = role.dailyData:getProperty("advWs") - if math.illegalNum(count, 1, mergeData.limit - (advWs[id] or 0)) then return 3 end - - local cost = mergeData.formula:toNumMap() - for k, v in pairs(cost) do - cost[k] = v * count - end - if not role:checkItemEnough(cost) then return 4 end - - role:costItems(cost) - advWs[id] = (advWs[id] or 0) + count - role.dailyData:updateProperty({field = "advWs", value = advWs}) - local reward = role:award({[id] = count}) - SendPacket(actionCodes.Adv_workshopRpc, MsgPack.pack({reward = reward})) - return true -end +-- function _M.workshopRpc(agent, data) +-- local role = agent.role +-- local msg = MsgPack.unpack(data) + +-- local id = msg.id +-- local count = msg.count or 1 +-- local mergeData = csvdb["adv_mergeCsv"][id] +-- if not mergeData then return 1 end + +-- if not role:isFuncOpen(FuncOpenType.AdvWS) or role:getFuncLv(FuncOpenType.AdvWS) < mergeData.unlock then return 2 end + +-- local advWs = role.dailyData:getProperty("advWs") +-- if math.illegalNum(count, 1, mergeData.limit - (advWs[id] or 0)) then return 3 end + +-- local cost = mergeData.formula:toNumMap() +-- for k, v in pairs(cost) do +-- cost[k] = v * count +-- end +-- if not role:checkItemEnough(cost) then return 4 end + +-- role:costItems(cost) +-- advWs[id] = (advWs[id] or 0) + count +-- role.dailyData:updateProperty({field = "advWs", value = advWs}) +-- local reward = role:award({[id] = count}) +-- SendPacket(actionCodes.Adv_workshopRpc, MsgPack.pack({reward = reward})) +-- return true +-- end function _M.wheelSurfRpc(agent, data) local role = agent.role diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index ba6155d..a1a1d16 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -594,7 +594,7 @@ function _M.createHeroRandomRpc(agent, data) local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] if not randomData then return end - local temp = randomData.random_gift:randWeight(true) + local temp = randomData.gift1:randWeight(true) if not temp or not next(temp) then return end local reward = {} if role:isHaveHero(temp[1]) then diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 0af47fb..b954d54 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -410,24 +410,27 @@ function _M.openItemRpc(agent, data) local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] if not randomData or randomData.openTime > 0 then return end - local reward = randomData.gift:toNumMap() - for _id, _count in pairs(reward) do - reward[_id] = _count * count - end - if randomData.random_num > 0 and randomData.random_gift ~= "" then - for i = 1, count do - local pool = {} - for _, temp in ipairs(randomData.random_gift:toArray()) do - table.insert(pool, temp:toArray(true, "=")) - end - local needCount = math.min(#pool, randomData.random_num) - for j = 1, needCount do - local idx = math.randWeight(pool, 3) - reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] - table.remove(pool, idx) + local reward = {} + for _i = 1, count do + for i = 1, 10 do + local num = randomData["num" .. i] + local gift = randomData["gift" .. i] + if num and gift and num > 0 and gift ~= "" then + local pool = {} + for _, temp in ipairs(gift:toArray()) do + table.insert(pool, temp:toArray(true, "=")) + end + local needCount = math.min(#pool, num) + for j = 1, needCount do + local idx = math.randWeight(pool, 3) + reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] + table.remove(pool, idx) + end end end end + reward[0] = nil + role:costItems({[itemId] = count}) reward = role:award(reward) @@ -479,35 +482,38 @@ function _M.openTimeBoxRpc(agent, data) local randomData = csvdb["item_randomCsv"][itemData.id] reward = randomData.gift:toNumMap() -- 固定奖励 -- 随机奖励 - local randomGift = randomData.random_gift - local randomNum = randomData.random_num local gemId = boxL[slot].gem - - if randomNum > 0 and randomGift and randomGift ~= "" then - local selectGift = {} - local pool = {} - for _, temp in ipairs(randomGift:toArray()) do - local set = temp:toArray(true, "=") - if gemId == set[1] then - table.insert(selectGift, set) - else - table.insert(pool, set) + local reward = {} + for i = 1, 10 do + local num = randomData["num" .. i] + local gift = randomData["gift" .. i] + if num and gift and num > 0 and gift ~= "" then + local pool = {} + local selectGift = {} + for _, temp in ipairs(gift:toArray()) do + local set = temp:toArray(true, "=") + if gemId == set[1] then + table.insert(selectGift, set) + else + table.insert(pool, set) + end end - end - if gemId ~= 0 and next(selectGift) then - randomNum = randomNum - 1 - local idx = math.randWeight(selectGift, 3) - reward[selectGift[idx][1]] = (reward[selectGift[idx][1]] or 0) + selectGift[idx][2] - end + if gemId ~= 0 and next(selectGift) then + num = num - 1 + local idx = math.randWeight(selectGift, 3) + reward[selectGift[idx][1]] = (reward[selectGift[idx][1]] or 0) + selectGift[idx][2] + end - local needCount = math.min(#pool, randomNum) - for j = 1, needCount do - local idx = math.randWeight(pool, 3) - reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] - table.remove(pool, idx) + local needCount = math.min(#pool, num) + for j = 1, needCount do + local idx = math.randWeight(pool, 3) + reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] + table.remove(pool, idx) + end end end + reward[0] = nil boxL[slot] = nil reward = role:award(reward) -- libgit2 0.21.2