From ed322ed236b8d4e4a901889198835e653a8ce539 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Mon, 16 Mar 2020 11:41:28 +0800 Subject: [PATCH] 餐厅 顾客 系统 --- src/ProtocolCode.lua | 2 ++ src/actions/DinerAction.lua | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/models/Diner.lua | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 3 files changed, 220 insertions(+), 15 deletions(-) diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 9bc60e3..516c71c 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -115,6 +115,8 @@ actionCodes = { Diner_initTaskRpc = 313, Diner_handleTaskRpc = 314, Diner_rankRpc = 315, + Diner_entrustRpc = 316, + Diner_collectRpc = 317, Tower_roleFormatRpc = 350, Tower_startBattleRpc = 351, diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 11d9fe8..2ca10a0 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -74,6 +74,37 @@ function _M.addSellRpc( agent, data ) sells[slot].level = dishLevel sells[slot].count = count sells[slot].time = skynet.timex() - calSell.deltaTime + + -- 检查解锁的顾客 + local had = {} + for _, sell in pairs(sells) do + if sell.dish then + had[sell.dish] = sell.level + end + end + + local customer = self.dinerData:getProperty("customer") + local change = false + for cId, cData in pairs(csvdb["diner_customerCsv"]) do + if not customer[cId] then + local unlock = true + for needId, lv in pairs(cData.unlock:toNumMap()) do + if not had[needId] or had[needId] < lv then + unlock = false + break + end + end + if unlock then + change = true + customer[cId] = 0 + end + end + end + + if change then + role.dinerData:updateProperty({field = "customer", value = customer}) + end + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) SendPacket(actionCodes.Diner_addSellRpc, "") return true @@ -713,5 +744,94 @@ function _M.rankRpc(agent , data) return true end +function _M.entrustRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local ctype = msg.ctype + + local entrust = role.dinerData:getProperty("entrust") + if not entrust[1] then return end + + local reward + if ctype == 1 then -- 完成 + local curData = csvdb["diner_missionCsv"][entrust[1]] + if not curData then return end + + if curData.type == 1 then + local cost = curData.condition:toNumMap() + if not role:checkItemEnough(cost) then return end + role:costItems(cost) + elseif curData.type == 2 then + -- todo 数据校验 + else + return + end + + reward = role:award(curData.reward) + elseif ctype == 2 then -- 放弃 + table.remove(entrust, 1) + else + return + end + role.dinerData:updateProperty({field = "entrust", value = entrust}) + + SendPacket(actionCodes.Diner_entrustRpc, MsgPack.pack({reward = reward})) + return true +end + +function _M.collectRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local id = msg.id + if not id or not csvdb["diner_customerCsv"][id] then return end + local customer = role.dinerData:getProperty("customer") + if customer[id] ~= 0 then + return + end + + -- 完成前更新一波 后面 加成可能不一样 + local sells = json.decode(role.dinerData:getProperty("sells")) + for slot, _ in pairs(sells) do + role.dinerData:updateSell(slot) + end + + customer[id] = 1 + role.dinerData:updateProperty({field = "customer", value = customer}) -- 解锁了 + + SendPacket(actionCodes.Diner_collectRpc, '') + return true +end + +function _M.comboRewardRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local id = msg.id + + local comboData = csvdb["diner_customer_comboCsv"][id] + if not id or not comboData then return end + local comboStatus = role.dinerData:getProperty("comboStatus") + if comboStatus[id] == -1 then return end + + local customer = role.dinerData:getProperty("customer") + + for _, nId in ipairs(comboData.customer:toArray(true, "=")) do + if customer[nId] ~= 1 then + return + end + end + + comboStatus[id] = 1 + role:award(comboData.reward) + + role.dinerData:updateProperty({field = "comboStatus", value = comboStatus}) -- 解锁了 + + SendPacket(actionCodes.Diner_comboRewardRpc, '') + return true +end + + return _M \ No newline at end of file diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 2e646d2..2c52bb4 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -14,6 +14,10 @@ Diner.schema = { expedite = {"number",1}, --每日加速次数 gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},} task = {"table", {}}, -- 任务刷新 {et = 消失时间 id = 任务id, refuse = 0} + entrustB = {"table", {}}, -- 委托完成过的记录 {id = 1} + entrust = {"table", {}}, -- 委托 {id, id, id} + customer = {"table", {}}, -- 解锁的顾客 {id = 1} -- 1 (已解锁) 0(达成条件 可解锁 服务器用) + comboStatus = {"table", {}}, -- 组合领取奖励状态 {id = -1} --有表示已经领取奖励 } function Diner:rankResetData(notify) @@ -21,9 +25,55 @@ function Diner:rankResetData(notify) end function Diner:refreshDailyData(notify) + + -- 委托 + local entrust = self:getProperty("entrust") + local hangPass = self.owner:getProperty("hangPass") + local entrustB = self:getProperty("entrustB") + local had = {} + local pool = {} + local change = false + for i = 1, 3 do + if not entrust[i] then + if not next(pool) then + for id, data in pairs(csvdb["diner_missionCsv"]) do + local show = true + if data.show ~= "" then + -- 不填=默认刷出,1=达成前置任务,2=通关关卡 + local showC = data.show:toArray(true, "=") + if showC[1] == 1 then + if not hangPass[showC[2]] then + show = false + end + elseif showC[1] == 2 then + if not entrustB[showC[2]] then + show = false + end + end + end + if show then + table.insert(pool, id) + end + end + end + + if #pool > 0 then + local idx = math.randomInt(1, #pool) + entrust[i] = pool[idx] + change = true + table.remove(pool, idx) + end + if not next(pool) then + break + end + else + had[entrust[i]] = 1 + end + end + self:updateProperty({field = "entrust", value = entrust, notNotify = not notify}) + -- 每日加速次数 self:updateProperty({field = "expedite", value = 1, notNotify = not notify}) - self:setProperty("expedite", 1) -- 特殊订单 local orders = json.decode(self:getProperty("order")) local hadTask = {} @@ -118,32 +168,52 @@ function Diner:calSellReward(sell, delta, dishData) if delta <= 0 then return reward, popular end + local addReward = {} for key, value in pairs(dishData.item_normal:toNumMap()) do - reward = reward:incrv(key, value * delta) + addReward[key] = (addReward[key] or 0) + value * delta end - popular = popular + dishData.famous_normal * delta + popular = dishData.famous_normal * delta + + local upValue = {} + -- 建筑加成 for buildType = 1, 6 do local level = self:getProperty("buildL"):getv(buildType, 1) local buildData = csvdb["diner_buildingCsv"][buildType][level] if buildData.gold_up > 0 then - local value = reward:getv(ItemId.Gold, 0) - value = math.floor(value * (100 + buildData.gold_up) / 100) - if value > 0 then - reward = reward:setv(ItemId.Gold, value) - end + upValue[ItemId.Gold] = (upValue[ItemId.Gold] or 0) + buildData.gold_up end if buildData.item_up > 0 then - local value = reward:getv(ItemId.DinerCoin, 0) - value = math.floor(value * (100 + buildData.item_up) / 100) - if value > 0 then - reward = reward:setv(ItemId.DinerCoin, value) - end + upValue[ItemId.DinerCoin] = (upValue[ItemId.DinerCoin] or 0) + buildData.gold_up end if buildData and buildData.famous_up > 0 then - popular = math.floor(popular * (100 + buildData.famous_up) / 100) + upValue[-1] = (upValue[-1] or 0) + buildData.famous_up + end + end + + -- 收集加成 + local collectCount = 0 + for _id , status in pairs(self:getProperty("customer")) do + if status == 1 then + collectCount = collectCount + 1 end end + local collectAdd = 0 + for _, collectData in ipairs(csvdb["diner_customer_collectCsv"]) do + if collectData.num <= collectCount then + collectAdd = collectData.bonus + else + break + end + end + upValue[-1] = (upValue[-1] or 0) + collectAdd + + for id, count in pairs(addReward) do + addReward[id] = math.floor(count * (1 + (upValue[id] or 0) / 100)) + reward = reward:incrv(id, addReward[id]) + end + popular = math.floor(popular * (1 + (upValue[-1] or 0) / 100)) + return reward, popular end @@ -293,7 +363,20 @@ function Diner:getPopularRank() end function Diner:data() - local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood", "task"} + local properties = { + "buildL", + "order", + "sells", + "dishTree", + "skillTree", + "popular", + "expedite", + "gfood", + "task", + "entrust", + "customer", + "comboStatus", + } local data = self:getProperties(properties) return data end -- libgit2 0.21.2