Commit 6d272f655a32ce87ba312f61d77004ed34ccd78a
1 parent
916096ed
餐厅 食材
Showing
3 changed files
with
61 additions
and
16 deletions
Show diff stats
src/ProtocolCode.lua
| @@ -87,6 +87,7 @@ actionCodes = { | @@ -87,6 +87,7 @@ actionCodes = { | ||
| 87 | Diner_refreshTaskRpc = 309, | 87 | Diner_refreshTaskRpc = 309, |
| 88 | Diner_expediteSellRpc = 310, | 88 | Diner_expediteSellRpc = 310, |
| 89 | Diner_getGreenhouseRpc = 311, | 89 | Diner_getGreenhouseRpc = 311, |
| 90 | + Diner_addWantFoodRpc = 312, | ||
| 90 | 91 | ||
| 91 | Tower_roleFormatRpc = 350, | 92 | Tower_roleFormatRpc = 350, |
| 92 | Tower_startBattleRpc = 351, | 93 | Tower_startBattleRpc = 351, |
src/actions/DinerAction.lua
| @@ -515,33 +515,77 @@ function _M.refreshTaskRpc( agent, data ) | @@ -515,33 +515,77 @@ function _M.refreshTaskRpc( agent, data ) | ||
| 515 | return true | 515 | return true |
| 516 | end | 516 | end |
| 517 | 517 | ||
| 518 | -function _M.getGreenhouseRpc( agent, data ) | 518 | +function _M.addWantFoodRpc(agent , data) |
| 519 | local role = agent.role | 519 | local role = agent.role |
| 520 | local msg = MsgPack.unpack(data) | 520 | local msg = MsgPack.unpack(data) |
| 521 | 521 | ||
| 522 | + local ids = msg.ids -- list | ||
| 523 | + | ||
| 522 | local buildType = 6 | 524 | local buildType = 6 |
| 523 | local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) | 525 | local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) |
| 524 | local buildingData = csvdb["diner_buildingCsv"][buildType][level] | 526 | local buildingData = csvdb["diner_buildingCsv"][buildType][level] |
| 527 | + | ||
| 525 | if not buildingData then | 528 | if not buildingData then |
| 526 | return 1 | 529 | return 1 |
| 527 | end | 530 | end |
| 528 | - if buildingData.speed <= 0 then | ||
| 529 | - return 2 | 531 | + |
| 532 | + if #ids > buildingData.business then return 2 end | ||
| 533 | + | ||
| 534 | + local had = {} | ||
| 535 | + for _, itemId in ipairs(ids) do | ||
| 536 | + if had[itemId] then return end | ||
| 537 | + had[itemId] = 1 | ||
| 538 | + local foodData = csvdb["diner_materialCsv"][itemId] | ||
| 539 | + if not foodData then return 3 end | ||
| 540 | + if foodData.unlock ~= 0 then | ||
| 541 | + local hangPass = role:getProperty("hangPass") | ||
| 542 | + if not hangPass[foodData.unlock] then | ||
| 543 | + return 4 | ||
| 544 | + end | ||
| 545 | + end | ||
| 546 | + end | ||
| 547 | + local gfood = {} | ||
| 548 | + for slot, itemId in ipairs(ids) do | ||
| 549 | + gfood[slot] = {id = itemId, st = skynet.timex()} | ||
| 530 | end | 550 | end |
| 531 | 551 | ||
| 532 | - local reward = "" | ||
| 533 | - local now = skynet.timex() | ||
| 534 | - local timePass = now - role.dinerData:getProperty("gTime") | ||
| 535 | - role.dinerData:setProperty("gTime",now) | ||
| 536 | - role.dinerData:notifyUpdateProperty("gTime",now) | ||
| 537 | - local count = math.floor(timePass/buildingData.speed) | ||
| 538 | - count = math.min(count,buildingData.storage) | ||
| 539 | - for _=1,count do | ||
| 540 | - reward = reward:incrv(string.randWeight(buildingData.gift_normal), 1) | 552 | + role.dinerData:updateProperty({field = "gfood", value = gfood}) |
| 553 | + | ||
| 554 | + SendPacket(actionCodes.Diner_addWantFoodRpc, '') | ||
| 555 | + return true | ||
| 556 | +end | ||
| 557 | + | ||
| 558 | +function _M.getGreenhouseRpc( agent, data ) | ||
| 559 | + local role = agent.role | ||
| 560 | + -- local msg = MsgPack.unpack(data) | ||
| 561 | + | ||
| 562 | + local buildType = 6 | ||
| 563 | + local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) | ||
| 564 | + local buildingData = csvdb["diner_buildingCsv"][buildType][level] | ||
| 565 | + if not buildingData then | ||
| 566 | + return 1 | ||
| 541 | end | 567 | end |
| 542 | - for k, v in pairs(reward:toNumMap()) do | ||
| 543 | - role:addItem({itemId = k,count = v}) | 568 | + |
| 569 | + local reward = {} | ||
| 570 | + local now = skynet.timex() | ||
| 571 | + local gfood = role.dinerData:getProperty("gfood") | ||
| 572 | + if not next(gfood) then return end | ||
| 573 | + for k , v in pairs(gfood) do | ||
| 574 | + local itemId = v.id | ||
| 575 | + local st = v.st | ||
| 576 | + local speed = globalCsv.diner_get_food_speed[csvdb["itemCsv"][itemId].quality] * buildingData.speed / 100 | ||
| 577 | + local endTime = st + globalCsv.diner_get_food_time_max | ||
| 578 | + local endTime2 = math.min(now, endTime) | ||
| 579 | + reward[itemId] = math.floor((endTime2 - st) / speed) | ||
| 580 | + if endTime2 == endTime then | ||
| 581 | + gfood[k].st = now | ||
| 582 | + else | ||
| 583 | + gfood[k].st = st + speed * reward[itemId] | ||
| 584 | + end | ||
| 544 | end | 585 | end |
| 586 | + role.dinerData:updateProperty({field = "gfood", value = gfood}) | ||
| 587 | + local reward = role:award(reward) | ||
| 588 | + | ||
| 545 | SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward})) | 589 | SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward})) |
| 546 | return true | 590 | return true |
| 547 | end | 591 | end |
src/models/Diner.lua
| @@ -12,7 +12,7 @@ Diner.schema = { | @@ -12,7 +12,7 @@ Diner.schema = { | ||
| 12 | skillTree = {"string", ""}, -- 支援天赋 | 12 | skillTree = {"string", ""}, -- 支援天赋 |
| 13 | popular = {"number",0}, -- 累计人气 | 13 | popular = {"number",0}, -- 累计人气 |
| 14 | expedite = {"number",1}, --每日加速次数 | 14 | expedite = {"number",1}, --每日加速次数 |
| 15 | - gTime = {"number",skynet.timex()}, --温室最后一次领取时间 | 15 | + gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | function Diner:refreshDailyData(notify) | 18 | function Diner:refreshDailyData(notify) |
| @@ -242,7 +242,7 @@ function Diner:getMaxDishs() | @@ -242,7 +242,7 @@ function Diner:getMaxDishs() | ||
| 242 | end | 242 | end |
| 243 | 243 | ||
| 244 | function Diner:data() | 244 | function Diner:data() |
| 245 | - local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gTime"} | 245 | + local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood"} |
| 246 | local data = self:getProperties(properties) | 246 | local data = self:getProperties(properties) |
| 247 | return data | 247 | return data |
| 248 | end | 248 | end |