From 448dee6ba7a2d09e552472dd56873703bdf66aa3 Mon Sep 17 00:00:00 2001 From: gaofengduan <782277855@qq.com> Date: Wed, 29 May 2019 17:58:59 +0800 Subject: [PATCH] fix 餐车快速制作 #addSellRpc 可以一次上多个 --- src/actions/DinerAction.lua | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------- src/csvdata | 2 +- 2 files changed, 63 insertions(+), 64 deletions(-) diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index b164e8a..e7aae65 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -9,79 +9,78 @@ local _M = {} function _M.addSellRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) + for _,sellData in pairs(msg) do + local slot = sellData.slot + if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then + return 1 + end + slot = tostring(slot) - local slot = msg.slot - if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then - return 1 - end - slot = tostring(slot) - - local dish = msg.dish - local dishSet = csvdb["diner_dishCsv"][dish] - if not dishSet then - return 2 - end - local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) - if dishLevel == 0 then - return 3 - end - local dishData = dishSet[dishLevel] - if not dishData then - return 4 - end + local dish = sellData.dish + local dishSet = csvdb["diner_dishCsv"][dish] + if not dishSet then + return 2 + end + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) + if dishLevel == 0 then + return 3 + end + local dishData = dishSet[dishLevel] + if not dishData then + return 4 + end - local calSell = role.dinerData:updateSell(slot, true) or { - deltaCount = 0, - deltaTime = 0, - lastCount = 0, - } - local count = msg.count - local maxDishCount = role.dinerData:getMaxDishs() - if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then - return 5 - end + local calSell = role.dinerData:updateSell(slot, true) or { + deltaCount = 0, + deltaTime = 0, + lastCount = 0, + } + local count = sellData.count + local maxDishCount = role.dinerData:getMaxDishs() + if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then + return 5 + end - local cost = dishData.material:toNumMap() - for _, n in pairs(cost) do - n = n * count - end - if not role:checkItemEnough(cost) then - return 6 - end + local cost = dishData.material:toNumMap() + for _, n in pairs(cost) do + n = n * count + end + if not role:checkItemEnough(cost) then + return 6 + end - role:costItems(cost) - role.dinerData:updateSell(slot) + role:costItems(cost) + role.dinerData:updateSell(slot) - local dirty = false - for id, value in pairs(cost) do - if role.dinerData:checkDinerTask(DinerTask.UseMaterial, value, id, nil, true) then + local dirty = false + for id, value in pairs(cost) do + if role.dinerData:checkDinerTask(DinerTask.UseMaterial, value, id, nil, true) then + dirty = true + end + end + if role.dinerData:checkDinerTask(DinerTask.AddDish, count, dish, nil, true) then dirty = true end - end - if role.dinerData:checkDinerTask(DinerTask.AddDish, count, dish, nil, true) then - dirty = true - end - if dirty then - role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) - end + if dirty then + role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) + end - local sells = json.decode(role.dinerData:getProperty("sells")) - if not sells[slot] then - sells[slot] = { - dish = dish, - level = dishLevel, - reward = "", - count = 0, - } + local sells = json.decode(role.dinerData:getProperty("sells")) + if not sells[slot] then + sells[slot] = { + dish = dish, + level = dishLevel, + reward = "", + count = 0, + } + end + local sell = sells[slot] + sell.count = sell.count + count + sell.time = skynet.timex() - calSell.deltaTime + sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) end - local sell = sells[slot] - sell.count = sell.count + count - sell.time = skynet.timex() - calSell.deltaTime - sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) - - role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) SendPacket(actionCodes.Diner_addSellRpc, "") - return true end diff --git a/src/csvdata b/src/csvdata index ea68ace..322f4a5 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit ea68ace5f3aa7feca54e640851838f030b471f9f +Subproject commit 322f4a5db56d1e952f0edee648d346a79449de37 -- libgit2 0.21.2