From 6d272f655a32ce87ba312f61d77004ed34ccd78a Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Thu, 26 Sep 2019 13:50:46 +0800 Subject: [PATCH] 餐厅 食材 --- src/ProtocolCode.lua | 1 + src/actions/DinerAction.lua | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- src/models/Diner.lua | 4 ++-- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 2d815e2..29e394d 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -87,6 +87,7 @@ actionCodes = { Diner_refreshTaskRpc = 309, Diner_expediteSellRpc = 310, Diner_getGreenhouseRpc = 311, + Diner_addWantFoodRpc = 312, Tower_roleFormatRpc = 350, Tower_startBattleRpc = 351, diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 6488987..50811a2 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -515,33 +515,77 @@ function _M.refreshTaskRpc( agent, data ) return true end -function _M.getGreenhouseRpc( agent, data ) +function _M.addWantFoodRpc(agent , data) local role = agent.role local msg = MsgPack.unpack(data) + local ids = msg.ids -- list + local buildType = 6 local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) local buildingData = csvdb["diner_buildingCsv"][buildType][level] + if not buildingData then return 1 end - if buildingData.speed <= 0 then - return 2 + + if #ids > buildingData.business then return 2 end + + local had = {} + for _, itemId in ipairs(ids) do + if had[itemId] then return end + had[itemId] = 1 + local foodData = csvdb["diner_materialCsv"][itemId] + if not foodData then return 3 end + if foodData.unlock ~= 0 then + local hangPass = role:getProperty("hangPass") + if not hangPass[foodData.unlock] then + return 4 + end + end + end + local gfood = {} + for slot, itemId in ipairs(ids) do + gfood[slot] = {id = itemId, st = skynet.timex()} end - local reward = "" - local now = skynet.timex() - local timePass = now - role.dinerData:getProperty("gTime") - role.dinerData:setProperty("gTime",now) - role.dinerData:notifyUpdateProperty("gTime",now) - local count = math.floor(timePass/buildingData.speed) - count = math.min(count,buildingData.storage) - for _=1,count do - reward = reward:incrv(string.randWeight(buildingData.gift_normal), 1) + role.dinerData:updateProperty({field = "gfood", value = gfood}) + + SendPacket(actionCodes.Diner_addWantFoodRpc, '') + return true +end + +function _M.getGreenhouseRpc( agent, data ) + local role = agent.role + -- local msg = MsgPack.unpack(data) + + local buildType = 6 + local level = role.dinerData:getProperty("buildL"):getv(buildType, 1) + local buildingData = csvdb["diner_buildingCsv"][buildType][level] + if not buildingData then + return 1 end - for k, v in pairs(reward:toNumMap()) do - role:addItem({itemId = k,count = v}) + + local reward = {} + local now = skynet.timex() + local gfood = role.dinerData:getProperty("gfood") + if not next(gfood) then return end + for k , v in pairs(gfood) do + local itemId = v.id + local st = v.st + local speed = globalCsv.diner_get_food_speed[csvdb["itemCsv"][itemId].quality] * buildingData.speed / 100 + local endTime = st + globalCsv.diner_get_food_time_max + local endTime2 = math.min(now, endTime) + reward[itemId] = math.floor((endTime2 - st) / speed) + if endTime2 == endTime then + gfood[k].st = now + else + gfood[k].st = st + speed * reward[itemId] + end end + role.dinerData:updateProperty({field = "gfood", value = gfood}) + local reward = role:award(reward) + SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward})) return true end diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 14f82e7..f148beb 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -12,7 +12,7 @@ Diner.schema = { skillTree = {"string", ""}, -- 支援天赋 popular = {"number",0}, -- 累计人气 expedite = {"number",1}, --每日加速次数 - gTime = {"number",skynet.timex()}, --温室最后一次领取时间 + gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} } function Diner:refreshDailyData(notify) @@ -242,7 +242,7 @@ function Diner:getMaxDishs() end function Diner:data() - local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gTime"} + local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood"} local data = self:getProperties(properties) return data end -- libgit2 0.21.2