diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 18a81d6..f7f4a8f 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -14,19 +14,62 @@ function _M.addSellRpc( agent, data ) if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then return end - if slot > role.dinerData:getMaxSlots() then - return - end + slot = tostring(slot) + local dish = msg.dish local dishSet = csvdb["diner_dishCsv"][dish] if not dishSet then return end + local dishLevel = role.dinerData:getProperty("dishTree"):getv(dish, 0) + if dishLevel == 0 then + return + end + local dishData = dishSet[dishLevel] + if not dishData then + return + end + + local calSell = role.dinerData:updateSell(slot, true) or { + deltaCount = 0, + deltaTime = 0, + lastCount = 0, + } local count = msg.count - if math.illegalNum(count, 1, role.dinerData:getMaxDishs()) then + local maxDishCount = role.dinerData:getMaxDishs() + if math.illegalNum(count + calSell.lastCount, 1, maxDishCount) then return end + local cost = dishData.material:toNumMap() + for _, n in pairs(cost) do + n = n * count + end + if not role:checkItemEnough(cost) then + return + end + + role:costItems(cost) + role.dinerData:updateSell(slot) + + local sells = json.decode(role.dinerData:getProperty("sells")) + if not sells[slot] then + sells[slot] = { + dish = dish, + level = dishLevel, + reward = "", + count = 0, + } + end + local sell = sells[slot] + sell.count = sell.count + count + sell.time = skynet.timex() - calSell.deltaTime + sell.hot = role.dinerData:getProperty("hot"):getv(sell.dish, 0) + + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) + SendPacket(actionCodes.Diner_addSellRpc, "") + + return true end function _M.getSellRewardRpc( agent, data ) @@ -54,7 +97,7 @@ function _M.levelUpRpc( agent, data ) return end - role:costItems(cost, {}) + role:costItems(cost) role.dinerData:updateProperty({field = "level", value = buildL:setv(index, curLevel + 1)}) SendPacket(actionCodes.Diner_levelUpRpc, '') diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 7bf8c31..5046454 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -289,7 +289,7 @@ function _M.quickRpc(agent , data) if not costs[curCount] then return end if costs[curCount] > 0 then if not role:checkItemEnough({[ItemId.Diamond] = costs[curCount]}) then return end - role:costItems({[ItemId.Diamond] = costs[curCount]}, {}) + role:costItems({[ItemId.Diamond] = costs[curCount]}) end role.dailyData:updateProperty({field = "hangQC", value = curCount}) diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index 1811fd4..f0b907e 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -25,7 +25,7 @@ function _M.levelUpRpc( agent, data ) local curData = csvdb["unit_expCsv"][hero:getProperty("level")] local cost = {[ItemId.Exp] = curData.exp, [ItemId.Gold] = curData.gold} if not role:checkItemEnough(cost) then return end - role:costItems(cost, {}) + role:costItems(cost) hero:updateProperty({field = "level", delta = 1}) SendPacket(actionCodes.Hero_levelUpRpc, '') @@ -43,7 +43,7 @@ function _M.breakRpc( agent, data ) local curData = csvdb["unit_breakCsv"][hero:getProperty("breakL")] local cost = {[ItemId.BreakCost] = curData.cost, [ItemId.Gold] = curData.gold} if not role:checkItemEnough(cost) then return end - role:costItems(cost, {}) + role:costItems(cost) hero:updateProperty({field = "breakL", delta = 1}) SendPacket(actionCodes.Hero_breakRpc, '') @@ -62,7 +62,7 @@ function _M.wakeRpc(agent, data) cost[ItemId.HeroFC[csvdb["unitCsv"][hero:getProperty("type")].rare]] = less[hero:getProperty("type")] if not role:checkItemEnough(cost) then return end end - role:costItems(cost, {}) + role:costItems(cost) hero:updateProperty({field = "wakeL", delta = 1}) SendPacket(actionCodes.Hero_wakeRpc, '') @@ -113,7 +113,7 @@ function _M.talentRpc(agent, data) end if not role:checkItemEnough(cost) then return end - role:costItems(cost, {}) + role:costItems(cost) talent = talent:incrv(index, 1) --是否进阶 @@ -424,7 +424,7 @@ function _M.createHeroRpc(agent, data) if hero:getProperty("type") == heroType then return end end - role:costItems({[heroType] = cost}, {}) + role:costItems({[heroType] = cost}) role:award({[heroType + ItemStartId.Hero] = 1}, {}) SendPacket(actionCodes.Hero_createHeroRpc, "") diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index a8d0e4e..4e095b7 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -256,7 +256,7 @@ function _M.saleItemRpc(agent, data) if itemData.sell_effect == "" then return end local sellEffect = itemData.sell_effect:toArray(true, "=") - role:costItems({[itemId] = count}, {}) + role:costItems({[itemId] = count}) local reward = role:award({[sellEffect[1]] = sellEffect[2] * count}, {}) SendPacket(actionCodes.Role_saleItemRpc, MsgPack.pack({reward = reward})) @@ -292,7 +292,7 @@ function _M.openItemRpc(agent, data) end end end - role:costItems({[itemId] = count}, {}) + role:costItems({[itemId] = count}) reward = role:award(reward, {}) SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward})) diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 89658a0..c6a54c1 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -6,10 +6,10 @@ end Diner.schema = { buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 - order = {"string", ""}, -- 特殊订单 - slots = {"string", ""}, -- 贩卖位置 + order = {"string", "[]"}, -- 特殊订单 + sells = {"string", "[]"}, -- 贩卖位置 hot = {"string", ""}, -- 今日热门 - dishTree = {"string", ""}, -- 料理天赋 + dishTree = {"string", "1=1 2=1 3=1"}, -- 料理天赋 skillTree = {"string", ""}, -- 支援天赋 } @@ -76,13 +76,51 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) end -function Diner:doSell(notify) - +function Diner:updateSell(slot, calOnly) + local sells = json.decode(self:getProperty("sells")) + local sell = sells[slot] + if not sell or sell.count <= 0 then + return + end + local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level] + + local deltaTime = 0 + local deltaCount = 0 + local timePass = skynet.timex() - sell.time + local sellTime = dishData.sell_time + if self:getProperty("hot"):getv(sell.dish, 0) > 0 then + sellTime = sellTime * 1.5 + end + deltaCount = math.floor(timePass / sellTime) + if deltaCount < sell.count then + deltaTime = math.floor(timePass - sellTime * deltaCount) + end + deltaCount = math.min(deltaCount, sell.count) + local lastCount = sell.count - deltaCount + + if not calOnly then + sell.time = skynet.timex() - deltaTime + sell.count = lastCount + sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) + + self:setProperty("sells", json.encode(sells)) + end + return { + deltaCount = deltaCount, + deltaTime = deltaTime, + lastCount = lastCount, + } end function Diner:getMaxSlots() local slotCount = globalCsv.diner_sell_slots_init + local hangPass = self.owner:getProperty("hangPass") + for _, carbonId in ipairs(globalCsv.diner_sell_slots_unlock) do + if hangPass[carbonId] then + slotCount = slotCount + 1 + end + end return slotCount end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 79a6911..8e4bbb8 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -191,8 +191,8 @@ function RolePlugin.bind(Role) end function Role:costItems(itemCountT, params) + local pms = clone(params or {}) if itemCountT[ItemId.Diamond] then --优先扣除钻石 - local pms = clone(params or {}) pms.count = itemCountT[ItemId.Diamond] if not self:costDiamond(pms) then return @@ -200,7 +200,6 @@ function RolePlugin.bind(Role) itemCountT[ItemId.Diamond] = nil end for itemId, count in pairs(itemCountT) do - local pms = clone(params or {}) pms.itemId = itemId pms.count = - count self:addItem(pms) -- libgit2 0.21.2