From 550ba7e78c30537a3035a582b965d0a88208120f Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Tue, 20 Aug 2019 17:08:20 +0800 Subject: [PATCH] 订单 --- src/actions/DinerAction.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++------------- src/models/Diner.lua | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 75 insertions(+), 27 deletions(-) diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index ea41398..d8f7994 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -366,10 +366,12 @@ function _M.lockTaskRpc( agent, data ) local msg = MsgPack.unpack(data) local index = msg.index - if math.illegalNum(index, 1, 7) then + local orders = json.decode(role.dinerData:getProperty("order")) + + if math.illegalNum(index, 1, #orders) then return 1 end - local orders = json.decode(role.dinerData:getProperty("order")) + local order = orders[index] if not order then return 2 @@ -388,13 +390,13 @@ function _M.updateTaskRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) local index = msg.index - -- 0 放弃已接受任务,1 接受任务,2 完成已接受任务 + -- 0 接受任务,1 放弃已接受任务,2 完成已接受任务 local cmd = msg.cmd - - if math.illegalNum(index, 1, 7) then + local orders = json.decode(role.dinerData:getProperty("order")) + if math.illegalNum(index, 1, #orders) then return 1 end - local orders = json.decode(role.dinerData:getProperty("order")) + local order = orders[index] if not order then return 2 @@ -451,25 +453,55 @@ function _M.refreshTaskRpc( agent, data ) end local orders = json.decode(role.dinerData:getProperty("order")) - if #orders > 6 then - return 2 + + local hadTask = {} + local needCount = globalCsv.diner_task_count + for idx, temp in pairs(orders) do + if temp.lock ~= 0 and temp.status ~= 0 then + hadTask[temp.id] = 1 + needCount = needCount - 1 + end end + if needCount <= 0 then return 2 end + local taskLevel = role.dinerData:getProperty("buildL"):getv(5, 1) local taskData = csvdb["diner_questCsv"][taskLevel] if not taskData then return 3 end + local pool = {} + for id, temp in pairs(taskData) do + if not hadTask[id] then + table.insert(pool, temp) + end + end + local needCount = math.min(#pool, needCount) -- 需要的任务个数 + + if needCount <= 0 then return end + + local cost = globalCsv.diner_task_refresh_cost:toNumMap() + for itemId, count in pairs(cost) do + cost[itemId] = count * needCount + end + if not role:checkItemEnough(cost) then return end + role:costItems(cost) - for k,v in pairs(orders) do - if v.lock == 0 then - local index = math.randWeight(taskData, "chance") - local t = taskData[index] - orders[k] = {lv = taskLevel, id = t.id, n = 0, lock = 0,status = 0} + for idx = 1, globalCsv.diner_task_count do + local order = orders[idx] + if not order or (order.lock == 0 and order.status == 0) then + if needCount > 0 then + local index = math.randWeight(pool, "chance") + local data = pool[index] + orders[idx] = {lv = taskLevel, id = data.id, n = 0, lock = 0, status = 0} + needCount = needCount - 1 + table.remove(pool, index) + end end end + role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) SendPacket(actionCodes.Diner_refreshTaskRpc, '') diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 0e2b6d9..672f359 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -22,26 +22,42 @@ function Diner:refreshDailyData(notify) -- 特殊订单 local orders = json.decode(self:getProperty("order")) + local hadTask = {} + local needCount = globalCsv.diner_task_count + for idx, temp in pairs(orders) do + if temp.lock ~= 0 then + hadTask[temp.id] = 1 + needCount = needCount - 1 + end + end + + if needCount <= 0 then return end + -- 等级由订单板等级决定 local taskLevel = self:getProperty("buildL"):getv(5, 1) local taskData = csvdb["diner_questCsv"][taskLevel] - if taskData then - local taskPool = table.values(taskData) - if #taskPool > 6 then - for n = 1, 6 do - local index = math.randWeight(taskPool, "chance") - local data = taskPool[index] - local order = orders[n] - if order then - if order.lock == 0 then - orders[n] = {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0} - end - else - orders[n] = {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0} - end + if not taskData then return end + local pool = {} + for id, temp in pairs(taskData) do + if not hadTask[id] then + table.insert(pool, temp) + end + end + local needCount = math.min(#pool, needCount) -- 需要的任务个数 + + for idx = 1, globalCsv.diner_task_count do + local order = orders[idx] + if not order or order.lock == 0 then + if needCount > 0 then + local index = math.randWeight(pool, "chance") + local data = pool[index] + orders[idx] = {lv = taskLevel, id = data.id, n = 0, lock = 0, status = 0} + needCount = needCount - 1 + table.remove(pool, index) end end end + self:updateProperty({field = "order", value = json.encode(orders), notNotify = not notify}) end -- libgit2 0.21.2