Commit 550ba7e78c30537a3035a582b965d0a88208120f
1 parent
0e06d7a6
订单
Showing
2 changed files
with
75 additions
and
27 deletions
Show diff stats
src/actions/DinerAction.lua
| ... | ... | @@ -366,10 +366,12 @@ function _M.lockTaskRpc( agent, data ) |
| 366 | 366 | local msg = MsgPack.unpack(data) |
| 367 | 367 | local index = msg.index |
| 368 | 368 | |
| 369 | - if math.illegalNum(index, 1, 7) then | |
| 369 | + local orders = json.decode(role.dinerData:getProperty("order")) | |
| 370 | + | |
| 371 | + if math.illegalNum(index, 1, #orders) then | |
| 370 | 372 | return 1 |
| 371 | 373 | end |
| 372 | - local orders = json.decode(role.dinerData:getProperty("order")) | |
| 374 | + | |
| 373 | 375 | local order = orders[index] |
| 374 | 376 | if not order then |
| 375 | 377 | return 2 |
| ... | ... | @@ -388,13 +390,13 @@ function _M.updateTaskRpc( agent, data ) |
| 388 | 390 | local role = agent.role |
| 389 | 391 | local msg = MsgPack.unpack(data) |
| 390 | 392 | local index = msg.index |
| 391 | - -- 0 放弃已接受任务,1 接受任务,2 完成已接受任务 | |
| 393 | + -- 0 接受任务,1 放弃已接受任务,2 完成已接受任务 | |
| 392 | 394 | local cmd = msg.cmd |
| 393 | - | |
| 394 | - if math.illegalNum(index, 1, 7) then | |
| 395 | + local orders = json.decode(role.dinerData:getProperty("order")) | |
| 396 | + if math.illegalNum(index, 1, #orders) then | |
| 395 | 397 | return 1 |
| 396 | 398 | end |
| 397 | - local orders = json.decode(role.dinerData:getProperty("order")) | |
| 399 | + | |
| 398 | 400 | local order = orders[index] |
| 399 | 401 | if not order then |
| 400 | 402 | return 2 |
| ... | ... | @@ -451,25 +453,55 @@ function _M.refreshTaskRpc( agent, data ) |
| 451 | 453 | end |
| 452 | 454 | |
| 453 | 455 | local orders = json.decode(role.dinerData:getProperty("order")) |
| 454 | - if #orders > 6 then | |
| 455 | - return 2 | |
| 456 | + | |
| 457 | + local hadTask = {} | |
| 458 | + local needCount = globalCsv.diner_task_count | |
| 459 | + for idx, temp in pairs(orders) do | |
| 460 | + if temp.lock ~= 0 and temp.status ~= 0 then | |
| 461 | + hadTask[temp.id] = 1 | |
| 462 | + needCount = needCount - 1 | |
| 463 | + end | |
| 456 | 464 | end |
| 457 | 465 | |
| 466 | + if needCount <= 0 then return 2 end | |
| 467 | + | |
| 458 | 468 | local taskLevel = role.dinerData:getProperty("buildL"):getv(5, 1) |
| 459 | 469 | local taskData = csvdb["diner_questCsv"][taskLevel] |
| 460 | 470 | if not taskData then |
| 461 | 471 | return 3 |
| 462 | 472 | end |
| 463 | 473 | |
| 474 | + local pool = {} | |
| 475 | + for id, temp in pairs(taskData) do | |
| 476 | + if not hadTask[id] then | |
| 477 | + table.insert(pool, temp) | |
| 478 | + end | |
| 479 | + end | |
| 480 | + local needCount = math.min(#pool, needCount) -- 需要的任务个数 | |
| 481 | + | |
| 482 | + if needCount <= 0 then return end | |
| 483 | + | |
| 484 | + local cost = globalCsv.diner_task_refresh_cost:toNumMap() | |
| 485 | + for itemId, count in pairs(cost) do | |
| 486 | + cost[itemId] = count * needCount | |
| 487 | + end | |
| 488 | + if not role:checkItemEnough(cost) then return end | |
| 489 | + | |
| 464 | 490 | role:costItems(cost) |
| 465 | 491 | |
| 466 | - for k,v in pairs(orders) do | |
| 467 | - if v.lock == 0 then | |
| 468 | - local index = math.randWeight(taskData, "chance") | |
| 469 | - local t = taskData[index] | |
| 470 | - orders[k] = {lv = taskLevel, id = t.id, n = 0, lock = 0,status = 0} | |
| 492 | + for idx = 1, globalCsv.diner_task_count do | |
| 493 | + local order = orders[idx] | |
| 494 | + if not order or (order.lock == 0 and order.status == 0) then | |
| 495 | + if needCount > 0 then | |
| 496 | + local index = math.randWeight(pool, "chance") | |
| 497 | + local data = pool[index] | |
| 498 | + orders[idx] = {lv = taskLevel, id = data.id, n = 0, lock = 0, status = 0} | |
| 499 | + needCount = needCount - 1 | |
| 500 | + table.remove(pool, index) | |
| 501 | + end | |
| 471 | 502 | end |
| 472 | 503 | end |
| 504 | + | |
| 473 | 505 | role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) |
| 474 | 506 | |
| 475 | 507 | SendPacket(actionCodes.Diner_refreshTaskRpc, '') | ... | ... |
src/models/Diner.lua
| ... | ... | @@ -22,26 +22,42 @@ function Diner:refreshDailyData(notify) |
| 22 | 22 | |
| 23 | 23 | -- 特殊订单 |
| 24 | 24 | local orders = json.decode(self:getProperty("order")) |
| 25 | + local hadTask = {} | |
| 26 | + local needCount = globalCsv.diner_task_count | |
| 27 | + for idx, temp in pairs(orders) do | |
| 28 | + if temp.lock ~= 0 then | |
| 29 | + hadTask[temp.id] = 1 | |
| 30 | + needCount = needCount - 1 | |
| 31 | + end | |
| 32 | + end | |
| 33 | + | |
| 34 | + if needCount <= 0 then return end | |
| 35 | + | |
| 25 | 36 | -- 等级由订单板等级决定 |
| 26 | 37 | local taskLevel = self:getProperty("buildL"):getv(5, 1) |
| 27 | 38 | local taskData = csvdb["diner_questCsv"][taskLevel] |
| 28 | - if taskData then | |
| 29 | - local taskPool = table.values(taskData) | |
| 30 | - if #taskPool > 6 then | |
| 31 | - for n = 1, 6 do | |
| 32 | - local index = math.randWeight(taskPool, "chance") | |
| 33 | - local data = taskPool[index] | |
| 34 | - local order = orders[n] | |
| 35 | - if order then | |
| 36 | - if order.lock == 0 then | |
| 37 | - orders[n] = {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0} | |
| 38 | - end | |
| 39 | - else | |
| 40 | - orders[n] = {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0} | |
| 41 | - end | |
| 39 | + if not taskData then return end | |
| 40 | + local pool = {} | |
| 41 | + for id, temp in pairs(taskData) do | |
| 42 | + if not hadTask[id] then | |
| 43 | + table.insert(pool, temp) | |
| 44 | + end | |
| 45 | + end | |
| 46 | + local needCount = math.min(#pool, needCount) -- 需要的任务个数 | |
| 47 | + | |
| 48 | + for idx = 1, globalCsv.diner_task_count do | |
| 49 | + local order = orders[idx] | |
| 50 | + if not order or order.lock == 0 then | |
| 51 | + if needCount > 0 then | |
| 52 | + local index = math.randWeight(pool, "chance") | |
| 53 | + local data = pool[index] | |
| 54 | + orders[idx] = {lv = taskLevel, id = data.id, n = 0, lock = 0, status = 0} | |
| 55 | + needCount = needCount - 1 | |
| 56 | + table.remove(pool, index) | |
| 42 | 57 | end |
| 43 | 58 | end |
| 44 | 59 | end |
| 60 | + | |
| 45 | 61 | self:updateProperty({field = "order", value = json.encode(orders), notNotify = not notify}) |
| 46 | 62 | end |
| 47 | 63 | ... | ... |