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 | 65 | Diner_skillUpRpc = 305, |
| 66 | 66 | Diner_removeSellRpc = 306, |
| 67 | 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 | 72 | rpcResponseBegin = 10000 | ... | ... |
src/actions/DinerAction.lua
| ... | ... | @@ -297,20 +297,25 @@ function _M.lockTaskRpc( agent, data ) |
| 297 | 297 | if not order then |
| 298 | 298 | return 2 |
| 299 | 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 | 304 | end |
| 303 | - | |
| 304 | - order.lock = 1 | |
| 305 | 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 | 307 | return true |
| 308 | 308 | end |
| 309 | 309 | |
| 310 | -function _M.finishTaskRpc( agent, data ) | |
| 310 | +function _M.updateTaskRpc( agent, data ) | |
| 311 | 311 | local role = agent.role |
| 312 | 312 | local msg = MsgPack.unpack(data) |
| 313 | + for k,v in pairs(msg) do | |
| 314 | + echoInfo(k,v) | |
| 315 | + end | |
| 313 | 316 | local index = msg.index |
| 317 | + -- 0 放弃已接受任务,1 接受任务,2 完成已接受任务 | |
| 318 | + local cmd = msg.cmd | |
| 314 | 319 | |
| 315 | 320 | if math.illegalNum(index, 1, 7) then |
| 316 | 321 | return 1 |
| ... | ... | @@ -320,9 +325,6 @@ function _M.finishTaskRpc( agent, data ) |
| 320 | 325 | if not order then |
| 321 | 326 | return 2 |
| 322 | 327 | end |
| 323 | - if order.lock == 2 then | |
| 324 | - return 3 | |
| 325 | - end | |
| 326 | 328 | local taskSet = csvdb["diner_questCsv"][order.lv] |
| 327 | 329 | if not taskSet then |
| 328 | 330 | return 4 |
| ... | ... | @@ -331,25 +333,45 @@ function _M.finishTaskRpc( agent, data ) |
| 331 | 333 | if not taskData then |
| 332 | 334 | return 5 |
| 333 | 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 | 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 | 367 | return true |
| 346 | 368 | end |
| 347 | 369 | |
| 348 | -function _M.getSpecialTaskRpc( agent, data ) | |
| 370 | +function _M.refreshTaskRpc( agent, data ) | |
| 349 | 371 | local role = agent.role |
| 350 | 372 | local msg = MsgPack.unpack(data) |
| 351 | 373 | |
| 352 | - local cost = {[DinerSpTask] = 1} | |
| 374 | + local cost = {[ItemId.Diamond] = 40} | |
| 353 | 375 | if not role:checkItemEnough(cost) then |
| 354 | 376 | return 1 |
| 355 | 377 | end |
| ... | ... | @@ -379,7 +401,7 @@ function _M.getSpecialTaskRpc( agent, data ) |
| 379 | 401 | local index = math.randWeight(taskPool, "chance") |
| 380 | 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 | 405 | role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) |
| 384 | 406 | |
| 385 | 407 | SendPacket(actionCodes.Diner_getSpecialTaskRpc, '') | ... | ... |
src/models/Diner.lua
| ... | ... | @@ -55,7 +55,7 @@ function Diner:refreshDailyData(notify) |
| 55 | 55 | for n = 1, 6 do |
| 56 | 56 | local index = math.randWeight(taskPool, "chance") |
| 57 | 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 | 59 | table.remove(taskPool, index) |
| 60 | 60 | end |
| 61 | 61 | end |
| ... | ... | @@ -98,7 +98,7 @@ function Diner:checkDinerTask(type, count, param1, param2, notNotify) |
| 98 | 98 | local taskSet = csvdb["diner_questCsv"][order.lv] |
| 99 | 99 | if taskSet and taskSet[order.id] then |
| 100 | 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 | 102 | data.n = data.n + count |
| 103 | 103 | dirty = true |
| 104 | 104 | end |
| ... | ... | @@ -171,7 +171,7 @@ function Diner:updateSell(slot, calOnly) |
| 171 | 171 | deltaCount = math.min(deltaCount, sell.count) |
| 172 | 172 | local lastCount = sell.count - deltaCount |
| 173 | 173 | |
| 174 | - if not calOnly then | |
| 174 | + if not calOnly and deltaCount > 0 then | |
| 175 | 175 | local reward, popular = self:calSellReward(sell, deltaCount, dishData) |
| 176 | 176 | sells[slot].time = skynet.timex() - deltaTime |
| 177 | 177 | sells[slot].count = lastCount |
| ... | ... | @@ -180,10 +180,7 @@ function Diner:updateSell(slot, calOnly) |
| 180 | 180 | sells[slot].reward = reward |
| 181 | 181 | self:setProperty("sells", json.encode(sells)) |
| 182 | 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 | 184 | end |
| 188 | 185 | return { |
| 189 | 186 | deltaCount = deltaCount, | ... | ... |