From cc796aaf2a03d26117de975c24c5fb50d63cd69a Mon Sep 17 00:00:00 2001 From: zhengshouren <448949750@qq.com> Date: Fri, 24 May 2019 17:02:34 +0800 Subject: [PATCH] 增加餐厅任务计数逻辑 --- src/GlobalVar.lua | 7 +++++++ src/actions/DinerAction.lua | 29 ++++++++++++++++++++++++++++- src/models/Diner.lua | 41 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 0a1346e..f3659d2 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -108,4 +108,11 @@ AdvScoreType = { Item = 3, Hurt = 4, Block = 5, +} + +DinerTask = { + UseMaterial = 1, + AddDish = 2, + SellDish = 3, + DishWithGold = 4, } \ No newline at end of file diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 2077f32..b959baf 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -52,6 +52,19 @@ function _M.addSellRpc( agent, data ) role:costItems(cost) role.dinerData:updateSell(slot) + local dirty = false + for type, value in pairs(cost) do + if role.dishData:checkDinerTask(DinerTask.UseMaterial, value, type, nil, true) then + dirty = true + end + end + if role.dishData:checkDinerTask(DinerTask.AddDish, count, dish, nil, true) then + dirty = true + end + if dirty then + role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) + end + local sells = json.decode(role.dinerData:getProperty("sells")) if not sells[slot] then sells[slot] = { @@ -118,10 +131,14 @@ end function _M.getSellRewardRpc( agent, data ) local role = agent.role local reward = {} + local dirty = false + 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:toNumMap()) do + + local rewards = sell.reward:toNumMap() + for k,v in pairs(rewards) do if reward[k] then reward[k] = reward[k] + v else @@ -129,10 +146,20 @@ function _M.getSellRewardRpc( agent, data ) end end sells[slot].reward = "" + + if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then + if role.dishData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then + dirty = true + end + end end for k, v in pairs(reward) do role:addItem({itemId = k,count = v}) end + if dirty then + role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) + end + role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) return true diff --git a/src/models/Diner.lua b/src/models/Diner.lua index 965ae46..47c216c 100644 --- a/src/models/Diner.lua +++ b/src/models/Diner.lua @@ -45,8 +45,22 @@ function Diner:refreshDailyData(notify) end -- 特殊订单 - local order = {} - + local orders = {} + -- 等级由订单板等级决定 + local taskLevel = self:getProperty("buildL"):getv(5, 1) + local taskData = csvdb["diner_questCsv"][taskLevel] + if taskData then + local taskPool = table.values(taskData) + if #taskPool > 6 then + for n = 1, 6 do + local index = math.randWeight(taskPool, "chance") + local data = taskPool[index] + table.insert(orders, {lv = taskLevel, id = data.id, n = 0}) + table.remove(taskPool, index) + end + end + end + self:updateProperty({field = "order", value = json.encode(orders)), notNotify = not notify}) end function Diner:updateProperty(params) @@ -77,6 +91,25 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) end +function Diner:checkDinerTask(type, count, param1, param2, notNotify) + local orders = json.decode(self:getProperty("order")) + local dirty = false + for _, data in ipairs(orders) do + local taskSet = csvdb["diner_questCsv"][data.lv] + if taskSet and taskSet[data.id] then + local task = taskSet[data.id] + if task.type == type and task.condition1 == param1 then + data.n = data.n + count + dirty = true + end + end + end + if dirty then + self:updateProperty({field = "order", value = json.encode(orders)), notNotify = notNotify}) + end + return dirty +end + function Diner:calSellReward(sell, delta, dishData) local reward = sell.reward or "" local popular = 0 @@ -147,6 +180,10 @@ function Diner:updateSell(slot, calOnly) sell.reward = reward self:setProperty("sells", json.encode(sells)) self:incrProperty("popular",popular) + + if deltaCount > 0 then + self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish) + end end return { deltaCount = deltaCount, -- libgit2 0.21.2