Commit 448dee6ba7a2d09e552472dd56873703bdf66aa3
1 parent
1068aae9
fix 餐车快速制作
#addSellRpc 可以一次上多个
Showing
2 changed files
with
63 additions
and
64 deletions
Show diff stats
src/actions/DinerAction.lua
| @@ -9,79 +9,78 @@ local _M = {} | @@ -9,79 +9,78 @@ local _M = {} | ||
| 9 | function _M.addSellRpc( agent, data ) | 9 | function _M.addSellRpc( agent, data ) |
| 10 | local role = agent.role | 10 | local role = agent.role |
| 11 | local msg = MsgPack.unpack(data) | 11 | local msg = MsgPack.unpack(data) |
| 12 | + for _,sellData in pairs(msg) do | ||
| 13 | + local slot = sellData.slot | ||
| 14 | + if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then | ||
| 15 | + return 1 | ||
| 16 | + end | ||
| 17 | + slot = tostring(slot) | ||
| 12 | 18 | ||
| 13 | - local slot = msg.slot | ||
| 14 | - if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then | ||
| 15 | - return 1 | ||
| 16 | - end | ||
| 17 | - slot = tostring(slot) | ||
| 18 | - | ||
| 19 | - local dish = msg.dish | ||
| 20 | - local dishSet = csvdb["diner_dishCsv"][dish] | ||
| 21 | - if not dishSet then | ||
| 22 | - return 2 | ||
| 23 | - end | ||
| 24 | - local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) | ||
| 25 | - if dishLevel == 0 then | ||
| 26 | - return 3 | ||
| 27 | - end | ||
| 28 | - local dishData = dishSet[dishLevel] | ||
| 29 | - if not dishData then | ||
| 30 | - return 4 | ||
| 31 | - end | 19 | + local dish = sellData.dish |
| 20 | + local dishSet = csvdb["diner_dishCsv"][dish] | ||
| 21 | + if not dishSet then | ||
| 22 | + return 2 | ||
| 23 | + end | ||
| 24 | + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) | ||
| 25 | + if dishLevel == 0 then | ||
| 26 | + return 3 | ||
| 27 | + end | ||
| 28 | + local dishData = dishSet[dishLevel] | ||
| 29 | + if not dishData then | ||
| 30 | + return 4 | ||
| 31 | + end | ||
| 32 | 32 | ||
| 33 | - local calSell = role.dinerData:updateSell(slot, true) or { | ||
| 34 | - deltaCount = 0, | ||
| 35 | - deltaTime = 0, | ||
| 36 | - lastCount = 0, | ||
| 37 | - } | ||
| 38 | - local count = msg.count | ||
| 39 | - local maxDishCount = role.dinerData:getMaxDishs() | ||
| 40 | - if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then | ||
| 41 | - return 5 | ||
| 42 | - end | 33 | + local calSell = role.dinerData:updateSell(slot, true) or { |
| 34 | + deltaCount = 0, | ||
| 35 | + deltaTime = 0, | ||
| 36 | + lastCount = 0, | ||
| 37 | + } | ||
| 38 | + local count = sellData.count | ||
| 39 | + local maxDishCount = role.dinerData:getMaxDishs() | ||
| 40 | + if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then | ||
| 41 | + return 5 | ||
| 42 | + end | ||
| 43 | 43 | ||
| 44 | - local cost = dishData.material:toNumMap() | ||
| 45 | - for _, n in pairs(cost) do | ||
| 46 | - n = n * count | ||
| 47 | - end | ||
| 48 | - if not role:checkItemEnough(cost) then | ||
| 49 | - return 6 | ||
| 50 | - end | 44 | + local cost = dishData.material:toNumMap() |
| 45 | + for _, n in pairs(cost) do | ||
| 46 | + n = n * count | ||
| 47 | + end | ||
| 48 | + if not role:checkItemEnough(cost) then | ||
| 49 | + return 6 | ||
| 50 | + end | ||
| 51 | 51 | ||
| 52 | - role:costItems(cost) | ||
| 53 | - role.dinerData:updateSell(slot) | 52 | + role:costItems(cost) |
| 53 | + role.dinerData:updateSell(slot) | ||
| 54 | 54 | ||
| 55 | - local dirty = false | ||
| 56 | - for id, value in pairs(cost) do | ||
| 57 | - if role.dinerData:checkDinerTask(DinerTask.UseMaterial, value, id, nil, true) then | 55 | + local dirty = false |
| 56 | + for id, value in pairs(cost) do | ||
| 57 | + if role.dinerData:checkDinerTask(DinerTask.UseMaterial, value, id, nil, true) then | ||
| 58 | + dirty = true | ||
| 59 | + end | ||
| 60 | + end | ||
| 61 | + if role.dinerData:checkDinerTask(DinerTask.AddDish, count, dish, nil, true) then | ||
| 58 | dirty = true | 62 | dirty = true |
| 59 | end | 63 | end |
| 60 | - end | ||
| 61 | - if role.dinerData:checkDinerTask(DinerTask.AddDish, count, dish, nil, true) then | ||
| 62 | - dirty = true | ||
| 63 | - end | ||
| 64 | - if dirty then | ||
| 65 | - role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) | ||
| 66 | - end | 64 | + if dirty then |
| 65 | + role.dinerData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) | ||
| 66 | + end | ||
| 67 | 67 | ||
| 68 | - local sells = json.decode(role.dinerData:getProperty("sells")) | ||
| 69 | - if not sells[slot] then | ||
| 70 | - sells[slot] = { | ||
| 71 | - dish = dish, | ||
| 72 | - level = dishLevel, | ||
| 73 | - reward = "", | ||
| 74 | - count = 0, | ||
| 75 | - } | 68 | + local sells = json.decode(role.dinerData:getProperty("sells")) |
| 69 | + if not sells[slot] then | ||
| 70 | + sells[slot] = { | ||
| 71 | + dish = dish, | ||
| 72 | + level = dishLevel, | ||
| 73 | + reward = "", | ||
| 74 | + count = 0, | ||
| 75 | + } | ||
| 76 | + end | ||
| 77 | + local sell = sells[slot] | ||
| 78 | + sell.count = sell.count + count | ||
| 79 | + sell.time = skynet.timex() - calSell.deltaTime | ||
| 80 | + sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) | ||
| 81 | + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) | ||
| 76 | end | 82 | end |
| 77 | - local sell = sells[slot] | ||
| 78 | - sell.count = sell.count + count | ||
| 79 | - sell.time = skynet.timex() - calSell.deltaTime | ||
| 80 | - sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) | ||
| 81 | - | ||
| 82 | - role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) | ||
| 83 | SendPacket(actionCodes.Diner_addSellRpc, "") | 83 | SendPacket(actionCodes.Diner_addSellRpc, "") |
| 84 | - | ||
| 85 | return true | 84 | return true |
| 86 | end | 85 | end |
| 87 | 86 |