From fdb86cad4102054d3210f942f81694a582b3e2fa Mon Sep 17 00:00:00 2001 From: gaofengduan <782277855@qq.com> Date: Tue, 28 May 2019 11:24:41 +0800 Subject: [PATCH] fix diner task --- src/ProtocolCode.lua | 4 ++-- src/actions/DinerAction.lua | 62 ++++++++++++++++++++++++++++++++++++++++++-------------------- src/csvdata | 2 +- src/models/Diner.lua | 11 ++++------- 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 8baeca4..c2e2a59 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -65,8 +65,8 @@ actionCodes = { Diner_skillUpRpc = 305, Diner_removeSellRpc = 306, Diner_lockTaskRpc = 307, - Diner_finishTaskRpc = 308, - Diner_getSpecialTaskRpc = 309, + Diner_updateTaskRpc = 308, + Diner_refreshTaskRpc = 309, } rpcResponseBegin = 10000 diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 67a690e..965d699 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -297,20 +297,25 @@ function _M.lockTaskRpc( agent, data ) if not order then return 2 end - if order.lock ~= 0 then - return 3 + if order.lock == 0 then + order.lock = 1 + else + order.lock = 0 end - - order.lock = 1 role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) - SendPacket(actionCodes.Diner_lockTaskRpc, '') + SendPacket(actionCodes.Diner_lockTaskRpc, MsgPack.pack({lock = order.lock})) return true end -function _M.finishTaskRpc( agent, data ) +function _M.updateTaskRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) + for k,v in pairs(msg) do + echoInfo(k,v) + end local index = msg.index + -- 0 放弃已接受任务,1 接受任务,2 完成已接受任务 + local cmd = msg.cmd if math.illegalNum(index, 1, 7) then return 1 @@ -320,9 +325,6 @@ function _M.finishTaskRpc( agent, data ) if not order then return 2 end - if order.lock == 2 then - return 3 - end local taskSet = csvdb["diner_questCsv"][order.lv] if not taskSet then return 4 @@ -331,25 +333,45 @@ function _M.finishTaskRpc( agent, data ) if not taskData then return 5 end - if order.n <= taskData.value then - return 6 - end + - order.lock = 2 - role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) - for type, count in pairs(taskData.reward:toNumMap()) do - role:addItem({itemId = type, count = count}) + if cmd == 0 then + if order.status ~= 0 then + return 30 + end + orders[index].status = 1 + orders[index].lock = 1 + elseif cmd == 1 then + if order.status ~= 1 then + return 31 + end + orders[index].status = 0 + orders[index].lock = 0 + elseif cmd == 2 then + if order.status ~= 2 then + return 32 + end + if order.n <= taskData.value then + return 6 + end + for typ, count in pairs(taskData.reward:toNumMap()) do + role:addItem({itemId = typ, count = count}) + end + orders[index] = nil + else + return 33 end - SendPacket(actionCodes.Diner_finishTaskRpc, '') + role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) + SendPacket(actionCodes.Diner_updateTaskRpc, '') return true end -function _M.getSpecialTaskRpc( agent, data ) +function _M.refreshTaskRpc( agent, data ) local role = agent.role local msg = MsgPack.unpack(data) - local cost = {[DinerSpTask] = 1} + local cost = {[ItemId.Diamond] = 40} if not role:checkItemEnough(cost) then return 1 end @@ -379,7 +401,7 @@ function _M.getSpecialTaskRpc( agent, data ) local index = math.randWeight(taskPool, "chance") local data = taskPool[index] - table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0}) + table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0}) role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) SendPacket(actionCodes.Diner_getSpecialTaskRpc, '') diff --git a/src/csvdata b/src/csvdata index 01cf508..9f5e58a 160000 --- a/src/csvdata +++ b/src/csvdata @@ -1 +1 @@ -Subproject commit 01cf508187c65894bed310be2d903087b86f0255 +Subproject commit 9f5e58a4fe6e6d10741caad1078a25f014a45de8 diff --git a/src/models/Diner.lua b/src/models/Diner.lua index dfcb2be..5b1fb65 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -55,7 +55,7 @@ function Diner:refreshDailyData(notify) for n = 1, 6 do local index = math.randWeight(taskPool, "chance") local data = taskPool[index] - table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0}) + table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0}) table.remove(taskPool, index) end end @@ -98,7 +98,7 @@ function Diner:checkDinerTask(type, count, param1, param2, notNotify) local taskSet = csvdb["diner_questCsv"][order.lv] if taskSet and taskSet[order.id] then local data = taskSet[order.id] - if data.type == type and data.condition1 == param1 and order.lock > 0 then + if data.type == type and data.condition1 == param1 and order.status == 1 then data.n = data.n + count dirty = true end @@ -171,7 +171,7 @@ function Diner:updateSell(slot, calOnly) deltaCount = math.min(deltaCount, sell.count) local lastCount = sell.count - deltaCount - if not calOnly then + if not calOnly and deltaCount > 0 then local reward, popular = self:calSellReward(sell, deltaCount, dishData) sells[slot].time = skynet.timex() - deltaTime sells[slot].count = lastCount @@ -180,10 +180,7 @@ function Diner:updateSell(slot, calOnly) sells[slot].reward = reward self:setProperty("sells", json.encode(sells)) self:incrProperty("popular",popular) - - if deltaCount > 0 then - self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish) - end + self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish) end return { deltaCount = deltaCount, -- libgit2 0.21.2