diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 6571315..3c61358 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -57,6 +57,11 @@ actionCodes = { Hang_getRewardItemRpc = 258, Hang_getRewardCoinRpc = 259, + Diner_updateProperty = 300, + Diner_addSellRpc = 301, + Diner_getSellRewardRpc = 302, + Diner_levelUpRpc = 303, + Diner_talentUpRpc = 304, } rpcResponseBegin = 10000 diff --git a/src/RedisKeys.lua b/src/RedisKeys.lua index 949f9f1..eaf8480 100644 --- a/src/RedisKeys.lua +++ b/src/RedisKeys.lua @@ -1,9 +1,9 @@ - - -R_INCR = "role:%d:autoincr" +-- role +R_INCR = "role:%d:autoincr" R_HEROS = "role:%d:heroIds" -R_HERO = "hero:%d:%d" +R_HERO = "hero:%d:%d" R_DAILY = "role:%d:daily" +R_DINER = "role:%d:diner" -- 餐厅 -- -- role -- R_FARM_KEY = "role:%d:farm" diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua new file mode 100644 index 0000000..18a81d6 --- /dev/null +++ b/src/actions/DinerAction.lua @@ -0,0 +1,64 @@ +local ipairs = ipairs +local table = table +local math = math +local redisproxy = redisproxy +local MsgPack = MsgPack + +local _M = {} + +function _M.addSellRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + + local slot = msg.slot + if math.illegalNum(slot, 1, role.dinerData:getMaxSlots()) then + return + end + if slot > role.dinerData:getMaxSlots() then + return + end + local dish = msg.dish + local dishSet = csvdb["diner_dishCsv"][dish] + if not dishSet then + return + end + local count = msg.count + if math.illegalNum(count, 1, role.dinerData:getMaxDishs()) then + return + end + +end + +function _M.getSellRewardRpc( agent, data ) + +end + +function _M.levelUpRpc( agent, data ) + local role = agent.role + local msg = MsgPack.unpack(data) + + local index = msg.index + local buildingData = csvdb["diner_buildingCsv"][index] + if not buildingData then + return + end + + local buildL = role.dinerData:getProperty("buildL") + local curLevel = buildL:getv(index, 1) + if curLevel >= #buildingData then + return + end + + local cost = buildingData[curLevel].starCost:toNumMap() + if not role:checkItemEnough(cost) then + return + end + + role:costItems(cost, {}) + role.dinerData:updateProperty({field = "level", value = buildL:setv(index, curLevel + 1)}) + + SendPacket(actionCodes.Diner_levelUpRpc, '') + return true +end + +return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 58d6360..a8d0e4e 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -123,7 +123,7 @@ function _M.loginRpc( agent, data ) role:setProperty("ltime", now) - for _, name in ipairs({"dailyData"}) do + for _, name in ipairs({"dailyData", "dinerData"}) do response[name] = role[name]:data() end diff --git a/src/models/Daily.lua b/src/models/Daily.lua index 463f2a4..e6a6eea 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -7,8 +7,9 @@ function Daily:ctor(properties) end Daily.schema = { - commentHero = {"string", ""}, --单日评论食灵记录 type=1 - hangQC ={"number", 0}, -- 挂机快速次数 + commentHero = {"string", ""}, -- 单日评论食灵记录 type=1 + hangQC = {"number", 0}, -- 挂机快速次数 + dinerQC = {"number", 0}, -- 贩卖加速次数 } function Daily:updateProperty(params) @@ -41,8 +42,8 @@ end function Daily:data() return { - -- dailyTaskStatus = self:getProperty("dailyTaskStatus"), hangQC = self:getProperty("hangQC"), + dinerQC = self:getProperty("dinerQC"), } end diff --git a/src/models/Diner.lua b/src/models/Diner.lua new file mode 100644 index 0000000..89658a0 --- /dev/null +++ b/src/models/Diner.lua @@ -0,0 +1,108 @@ +local Diner = class("Diner", require("shared.ModelBase")) + +function Diner:ctor(properties) + Diner.super.ctor(self, properties) +end + +Diner.schema = { + buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1 + order = {"string", ""}, -- 特殊订单 + slots = {"string", ""}, -- 贩卖位置 + hot = {"string", ""}, -- 今日热门 + dishTree = {"string", ""}, -- 料理天赋 + skillTree = {"string", ""}, -- 支援天赋 +} + +function Diner:refreshDailyData(notify) + -- 热门料理 + local hotPool = {} + local dishTree = self:getProperty("dishTree"):toNumMap() + local hangPass = self.owner:getProperty("hangPass") + + for index, dishData in ipairs(csvdb["diner_dishCsv"]) do + local check = true + local dish = dishData[1] + if dish.unlock_tree > 0 and not dishTree[dish.unlock_tree] then + check = false + end + if dish.unlock_carbon > 0 and not hangPass[dish.unlock_carbon] then + check = false + end + if check then + table.insert(hotPool, index) + end + end + if #hotPool >= 2 then + local hot = "" + for n = 1, 2 do + local index = math.random(1, #hotPool) + hot = hot:setv(hotPool[index], 1) + table.remove(hotPool, index) + end + self:updateProperty({field = "hot", value = hot, notNotify = not notify}) + self:setProperty("hot", hot) + end + + -- 特殊订单 + local order = {} + +end + +function Diner:updateProperty(params) + params = params or {} + if not self.schema[params.field] then + return + end + local oldValue = self:getProperty(params.field) + if params.value then + self:setProperty(params.field, params.value) + elseif params.delta then + self:incrProperty(params.field, params.delta) + else + return + end + local newValue = self:getProperty(params.field) + if not params.notNotify then + self:notifyUpdateProperty(params.field, newValue, oldValue) + end +end + +function Diner:notifyUpdateProperty(field, newValue, oldValue) + local datas = { + key = field, + newValue = newValue, + oldValue = oldValue, + } + SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) +end + +function Diner:doSell(notify) + +end + +function Diner:getMaxSlots() + local slotCount = globalCsv.diner_sell_slots_init + + + return slotCount +end + +function Diner:getMaxDishs() + local dishCount = globalCsv.diner_sell_dish_init + + local buildingCsv = csvdb["diner_buildingCsv"] + for id, level in pairs(self:getProperty("buildL"):toNumMap()) do + if buildingCsv[id][level].storage > 0 then + dishCount = dishCount + buildingCsv[id][level].storage + end + end + return dishCount +end + +function Diner:data() + local properties = {"buildL", "order", "hot", "dishTree", "skillTree"} + local data = self:getProperties(properties) + return data +end + +return Diner \ No newline at end of file diff --git a/src/models/Hero.lua b/src/models/Hero.lua index 83a8e99..7ac0b65 100644 --- a/src/models/Hero.lua +++ b/src/models/Hero.lua @@ -6,15 +6,15 @@ HeroPlugin.bind(Hero) Hero.schema = { id = {"number"}, type = {"number", 0}, - level = {"number", 1}, -- 等级 - breakL = {"number", 0}, -- 突破等级 - wakeL = {"number", 0}, -- 觉醒等级 - skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 - talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 - battleV = {"number", 0}, -- 保存战斗力 - loveExp = {"number", 0}, --好感度经验 - loveL = {"number", 0}, --好感度等级 - skin = {"number", 0}, --皮肤 0 、 1、 2、 3 + level = {"number", 1}, -- 等级 + breakL = {"number", 0}, -- 突破等级 + wakeL = {"number", 0}, -- 觉醒等级 + skillL = {"string", ""}, -- 技能等级 1=1 2=1 3=1 + talent = {"string", ""}, -- 0=阶段 1=1 2=1 3=1 4=1 四个天赋当前阶段的等级 阶段默认为1 等级默认为0 + battleV = {"number", 0}, -- 保存战斗力 + loveExp = {"number", 0}, --好感度经验 + loveL = {"number", 0}, --好感度等级 + skin = {"number", 0}, --皮肤 0 、 1、 2、 3 } function Hero:ctor( properties ) @@ -22,18 +22,12 @@ function Hero:ctor( properties ) end function Hero:notifyUpdateProperty(field, newValue, oldValue) - local updateData = { - id = self:getProperty("id"), - datas = { - { - key = field, - newValue = newValue, - oldValue = oldValue or "", - }, - } + local datas = { + key = field, + newValue = newValue, + oldValue = oldValue, } - - SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) + self:notifyUpdateProperties(datas) end function Hero:notifyUpdateProperties(params) @@ -41,7 +35,6 @@ function Hero:notifyUpdateProperties(params) id = self:getProperty("id"), datas = params } - SendPacket(actionCodes.Hero_updateProperty, MsgPack.pack(updateData)) end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index cf21456..79a6911 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -11,6 +11,7 @@ function RolePlugin.bind(Role) function Role:loadAll() self:loadDaily() self:loadHeros() + self:loadDiner() end function Role:reloadWhenLogin() @@ -24,6 +25,7 @@ function RolePlugin.bind(Role) local response = {} self.dailyData:refreshDailyData(notify) + self.dinerData:refreshDailyData(notify) if notify then self:notifyUpdateProperties(response) @@ -171,10 +173,18 @@ function RolePlugin.bind(Role) function Role:checkItemEnough(itemCountT) local less = {} + if not next(itemCountT) then + return false, less + end for itemId, count in pairs(itemCountT) do - local last = self:getItemCount(itemId) - count - if last < 0 then - less[itemId] = -last + if count <= 0 then + -- 判断物品数量值不应该小于等于0 + less[itemId] = 0 + else + local last = self:getItemCount(itemId) - count + if last < 0 then + less[itemId] = -last + end end end return (not next(less)), less -- 是否足够,,缺什么缺多少 @@ -334,6 +344,18 @@ function RolePlugin.bind(Role) end end + function Role:loadDiner() + local roleId = self:getProperty("id") + local dataKey = string.format(R_DINER, roleId) + self.dinerData = require("models.Diner").new({key = dataKey}) + self.dinerData.owner = self + if not redisproxy:exists(dataKey) then + self.dinerData:create() + else + self.dinerData:load() + end + end + function Role:getAdvData() if not self.advData then self.advData = require("adv.Adv").new(self) -- libgit2 0.21.2