Commit fdb86cad4102054d3210f942f81694a582b3e2fa
1 parent
32161569
fix diner task
Showing
4 changed files
with
49 additions
and
30 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -65,8 +65,8 @@ actionCodes = { | @@ -65,8 +65,8 @@ actionCodes = { | ||
| 65 | Diner_skillUpRpc = 305, | 65 | Diner_skillUpRpc = 305, |
| 66 | Diner_removeSellRpc = 306, | 66 | Diner_removeSellRpc = 306, |
| 67 | Diner_lockTaskRpc = 307, | 67 | Diner_lockTaskRpc = 307, |
| 68 | - Diner_finishTaskRpc = 308, | ||
| 69 | - Diner_getSpecialTaskRpc = 309, | 68 | + Diner_updateTaskRpc = 308, |
| 69 | + Diner_refreshTaskRpc = 309, | ||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | rpcResponseBegin = 10000 | 72 | rpcResponseBegin = 10000 |
src/actions/DinerAction.lua
| @@ -297,20 +297,25 @@ function _M.lockTaskRpc( agent, data ) | @@ -297,20 +297,25 @@ function _M.lockTaskRpc( agent, data ) | ||
| 297 | if not order then | 297 | if not order then |
| 298 | return 2 | 298 | return 2 |
| 299 | end | 299 | end |
| 300 | - if order.lock ~= 0 then | ||
| 301 | - return 3 | 300 | + if order.lock == 0 then |
| 301 | + order.lock = 1 | ||
| 302 | + else | ||
| 303 | + order.lock = 0 | ||
| 302 | end | 304 | end |
| 303 | - | ||
| 304 | - order.lock = 1 | ||
| 305 | role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) | 305 | role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) |
| 306 | - SendPacket(actionCodes.Diner_lockTaskRpc, '') | 306 | + SendPacket(actionCodes.Diner_lockTaskRpc, MsgPack.pack({lock = order.lock})) |
| 307 | return true | 307 | return true |
| 308 | end | 308 | end |
| 309 | 309 | ||
| 310 | -function _M.finishTaskRpc( agent, data ) | 310 | +function _M.updateTaskRpc( agent, data ) |
| 311 | local role = agent.role | 311 | local role = agent.role |
| 312 | local msg = MsgPack.unpack(data) | 312 | local msg = MsgPack.unpack(data) |
| 313 | + for k,v in pairs(msg) do | ||
| 314 | + echoInfo(k,v) | ||
| 315 | + end | ||
| 313 | local index = msg.index | 316 | local index = msg.index |
| 317 | + -- 0 放弃已接受任务,1 接受任务,2 完成已接受任务 | ||
| 318 | + local cmd = msg.cmd | ||
| 314 | 319 | ||
| 315 | if math.illegalNum(index, 1, 7) then | 320 | if math.illegalNum(index, 1, 7) then |
| 316 | return 1 | 321 | return 1 |
| @@ -320,9 +325,6 @@ function _M.finishTaskRpc( agent, data ) | @@ -320,9 +325,6 @@ function _M.finishTaskRpc( agent, data ) | ||
| 320 | if not order then | 325 | if not order then |
| 321 | return 2 | 326 | return 2 |
| 322 | end | 327 | end |
| 323 | - if order.lock == 2 then | ||
| 324 | - return 3 | ||
| 325 | - end | ||
| 326 | local taskSet = csvdb["diner_questCsv"][order.lv] | 328 | local taskSet = csvdb["diner_questCsv"][order.lv] |
| 327 | if not taskSet then | 329 | if not taskSet then |
| 328 | return 4 | 330 | return 4 |
| @@ -331,25 +333,45 @@ function _M.finishTaskRpc( agent, data ) | @@ -331,25 +333,45 @@ function _M.finishTaskRpc( agent, data ) | ||
| 331 | if not taskData then | 333 | if not taskData then |
| 332 | return 5 | 334 | return 5 |
| 333 | end | 335 | end |
| 334 | - if order.n <= taskData.value then | ||
| 335 | - return 6 | ||
| 336 | - end | 336 | + |
| 337 | 337 | ||
| 338 | - order.lock = 2 | ||
| 339 | - role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) | ||
| 340 | - for type, count in pairs(taskData.reward:toNumMap()) do | ||
| 341 | - role:addItem({itemId = type, count = count}) | 338 | + if cmd == 0 then |
| 339 | + if order.status ~= 0 then | ||
| 340 | + return 30 | ||
| 341 | + end | ||
| 342 | + orders[index].status = 1 | ||
| 343 | + orders[index].lock = 1 | ||
| 344 | + elseif cmd == 1 then | ||
| 345 | + if order.status ~= 1 then | ||
| 346 | + return 31 | ||
| 347 | + end | ||
| 348 | + orders[index].status = 0 | ||
| 349 | + orders[index].lock = 0 | ||
| 350 | + elseif cmd == 2 then | ||
| 351 | + if order.status ~= 2 then | ||
| 352 | + return 32 | ||
| 353 | + end | ||
| 354 | + if order.n <= taskData.value then | ||
| 355 | + return 6 | ||
| 356 | + end | ||
| 357 | + for typ, count in pairs(taskData.reward:toNumMap()) do | ||
| 358 | + role:addItem({itemId = typ, count = count}) | ||
| 359 | + end | ||
| 360 | + orders[index] = nil | ||
| 361 | + else | ||
| 362 | + return 33 | ||
| 342 | end | 363 | end |
| 343 | 364 | ||
| 344 | - SendPacket(actionCodes.Diner_finishTaskRpc, '') | 365 | + role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) |
| 366 | + SendPacket(actionCodes.Diner_updateTaskRpc, '') | ||
| 345 | return true | 367 | return true |
| 346 | end | 368 | end |
| 347 | 369 | ||
| 348 | -function _M.getSpecialTaskRpc( agent, data ) | 370 | +function _M.refreshTaskRpc( agent, data ) |
| 349 | local role = agent.role | 371 | local role = agent.role |
| 350 | local msg = MsgPack.unpack(data) | 372 | local msg = MsgPack.unpack(data) |
| 351 | 373 | ||
| 352 | - local cost = {[DinerSpTask] = 1} | 374 | + local cost = {[ItemId.Diamond] = 40} |
| 353 | if not role:checkItemEnough(cost) then | 375 | if not role:checkItemEnough(cost) then |
| 354 | return 1 | 376 | return 1 |
| 355 | end | 377 | end |
| @@ -379,7 +401,7 @@ function _M.getSpecialTaskRpc( agent, data ) | @@ -379,7 +401,7 @@ function _M.getSpecialTaskRpc( agent, data ) | ||
| 379 | local index = math.randWeight(taskPool, "chance") | 401 | local index = math.randWeight(taskPool, "chance") |
| 380 | local data = taskPool[index] | 402 | local data = taskPool[index] |
| 381 | 403 | ||
| 382 | - table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0}) | 404 | + table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0}) |
| 383 | role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) | 405 | role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) |
| 384 | 406 | ||
| 385 | SendPacket(actionCodes.Diner_getSpecialTaskRpc, '') | 407 | SendPacket(actionCodes.Diner_getSpecialTaskRpc, '') |
src/models/Diner.lua
| @@ -55,7 +55,7 @@ function Diner:refreshDailyData(notify) | @@ -55,7 +55,7 @@ function Diner:refreshDailyData(notify) | ||
| 55 | for n = 1, 6 do | 55 | for n = 1, 6 do |
| 56 | local index = math.randWeight(taskPool, "chance") | 56 | local index = math.randWeight(taskPool, "chance") |
| 57 | local data = taskPool[index] | 57 | local data = taskPool[index] |
| 58 | - table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0}) | 58 | + table.insert(orders, {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0}) |
| 59 | table.remove(taskPool, index) | 59 | table.remove(taskPool, index) |
| 60 | end | 60 | end |
| 61 | end | 61 | end |
| @@ -98,7 +98,7 @@ function Diner:checkDinerTask(type, count, param1, param2, notNotify) | @@ -98,7 +98,7 @@ function Diner:checkDinerTask(type, count, param1, param2, notNotify) | ||
| 98 | local taskSet = csvdb["diner_questCsv"][order.lv] | 98 | local taskSet = csvdb["diner_questCsv"][order.lv] |
| 99 | if taskSet and taskSet[order.id] then | 99 | if taskSet and taskSet[order.id] then |
| 100 | local data = taskSet[order.id] | 100 | local data = taskSet[order.id] |
| 101 | - if data.type == type and data.condition1 == param1 and order.lock > 0 then | 101 | + if data.type == type and data.condition1 == param1 and order.status == 1 then |
| 102 | data.n = data.n + count | 102 | data.n = data.n + count |
| 103 | dirty = true | 103 | dirty = true |
| 104 | end | 104 | end |
| @@ -171,7 +171,7 @@ function Diner:updateSell(slot, calOnly) | @@ -171,7 +171,7 @@ function Diner:updateSell(slot, calOnly) | ||
| 171 | deltaCount = math.min(deltaCount, sell.count) | 171 | deltaCount = math.min(deltaCount, sell.count) |
| 172 | local lastCount = sell.count - deltaCount | 172 | local lastCount = sell.count - deltaCount |
| 173 | 173 | ||
| 174 | - if not calOnly then | 174 | + if not calOnly and deltaCount > 0 then |
| 175 | local reward, popular = self:calSellReward(sell, deltaCount, dishData) | 175 | local reward, popular = self:calSellReward(sell, deltaCount, dishData) |
| 176 | sells[slot].time = skynet.timex() - deltaTime | 176 | sells[slot].time = skynet.timex() - deltaTime |
| 177 | sells[slot].count = lastCount | 177 | sells[slot].count = lastCount |
| @@ -180,10 +180,7 @@ function Diner:updateSell(slot, calOnly) | @@ -180,10 +180,7 @@ function Diner:updateSell(slot, calOnly) | ||
| 180 | sells[slot].reward = reward | 180 | sells[slot].reward = reward |
| 181 | self:setProperty("sells", json.encode(sells)) | 181 | self:setProperty("sells", json.encode(sells)) |
| 182 | self:incrProperty("popular",popular) | 182 | self:incrProperty("popular",popular) |
| 183 | - | ||
| 184 | - if deltaCount > 0 then | ||
| 185 | - self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish) | ||
| 186 | - end | 183 | + self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish) |
| 187 | end | 184 | end |
| 188 | return { | 185 | return { |
| 189 | deltaCount = deltaCount, | 186 | deltaCount = deltaCount, |