diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 6fcd765..c3f21b3 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -57,9 +57,8 @@ function _M.addSellRpc( agent, data ) sells[slot] = { dish = dish, level = dishLevel, - reward = {}, - count = 0, reward = "", + count = 0, famous = 0, } end @@ -122,7 +121,7 @@ function _M.getSellRewardRpc( agent, data ) local sells = json.decode(role.dinerData:getProperty("sells")) for slot,sell in pairs(sells) do role.dinerData:updateSell(slot) - for k,v in pairs(sell.reward) do + for k,v in pairs(sell.reward:toMap()) do if reward[k] then reward[k] = reward[k] + v else diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 3407bfb..2f9ca05 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -11,6 +11,7 @@ Diner.schema = { hot = {"string", ""}, -- 今日热门 dishTree = {"string", "1=1 2=1 3=1"}, -- 料理天赋 skillTree = {"string", ""}, -- 支援天赋 + popular = {"number",0}, -- 累计人气 } function Diner:refreshDailyData(notify) @@ -76,21 +77,21 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) end -local function calSellReward(sell, delta, dishData) +function Diner:calSellReward(sell, delta, dishData) local reward = sell.reward or "" - local famous = sell.famous or 0 + local popular = 0 if delta <= 0 then - return reward, famous + return reward, popular end for type, value in pairs(dishData.item_normal:toNumMap()) do reward = reward:incrv(type, value * delta) end - famous = famous + dishData.famous_normal * delta + popular = popular + dishData.famous_normal * delta if sell.hot > 0 then for type, value in pairs(dishData.item_popular:toNumMap()) do reward = reward:incrv(type, value * delta) end - famous = famous + dishData.famous_popular * delta + popular = popular + dishData.famous_popular * delta end for buildType = 1, 6 do @@ -111,10 +112,10 @@ local function calSellReward(sell, delta, dishData) end end if buildData and buildData.famous_up > 0 then - famous = math.floor(famous * (100 + buildData.famous_up) / 100) + popular = math.floor(popular * (100 + buildData.famous_up) / 100) end end - return reward, famous + return reward, popular end function Diner:updateSell(slot, calOnly) @@ -138,14 +139,14 @@ function Diner:updateSell(slot, calOnly) local lastCount = sell.count - deltaCount if not calOnly then - local reward, famous = self:calSellReward(sell, deltaCount, dishData) + local reward, popular = self:calSellReward(sell, deltaCount, dishData) sell.time = skynet.timex() - deltaTime sell.count = lastCount sell.level = self:getProperty("dishTree"):getv(sell.dish, 1) sell.hot = self:getProperty("hot"):getv(sell.dish, 0) sell.reward = reward - sell.famous = famous self:setProperty("sells", json.encode(sells)) + self:incrProperty("popular",popular) end return { deltaCount = deltaCount, -- libgit2 0.21.2