Commit cc796aaf2a03d26117de975c24c5fb50d63cd69a
1 parent
32420a89
增加餐厅任务计数逻辑
Showing
3 changed files
with
74 additions
and
3 deletions
Show diff stats
src/GlobalVar.lua
| @@ -108,4 +108,11 @@ AdvScoreType = { | @@ -108,4 +108,11 @@ AdvScoreType = { | ||
| 108 | Item = 3, | 108 | Item = 3, |
| 109 | Hurt = 4, | 109 | Hurt = 4, |
| 110 | Block = 5, | 110 | Block = 5, |
| 111 | +} | ||
| 112 | + | ||
| 113 | +DinerTask = { | ||
| 114 | + UseMaterial = 1, | ||
| 115 | + AddDish = 2, | ||
| 116 | + SellDish = 3, | ||
| 117 | + DishWithGold = 4, | ||
| 111 | } | 118 | } |
| 112 | \ No newline at end of file | 119 | \ No newline at end of file |
src/actions/DinerAction.lua
| @@ -52,6 +52,19 @@ function _M.addSellRpc( agent, data ) | @@ -52,6 +52,19 @@ function _M.addSellRpc( agent, data ) | ||
| 52 | role:costItems(cost) | 52 | role:costItems(cost) |
| 53 | role.dinerData:updateSell(slot) | 53 | role.dinerData:updateSell(slot) |
| 54 | 54 | ||
| 55 | + local dirty = false | ||
| 56 | + for type, value in pairs(cost) do | ||
| 57 | + if role.dishData:checkDinerTask(DinerTask.UseMaterial, value, type, nil, true) then | ||
| 58 | + dirty = true | ||
| 59 | + end | ||
| 60 | + end | ||
| 61 | + if role.dishData:checkDinerTask(DinerTask.AddDish, count, dish, nil, true) then | ||
| 62 | + dirty = true | ||
| 63 | + end | ||
| 64 | + if dirty then | ||
| 65 | + role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) | ||
| 66 | + end | ||
| 67 | + | ||
| 55 | local sells = json.decode(role.dinerData:getProperty("sells")) | 68 | local sells = json.decode(role.dinerData:getProperty("sells")) |
| 56 | if not sells[slot] then | 69 | if not sells[slot] then |
| 57 | sells[slot] = { | 70 | sells[slot] = { |
| @@ -118,10 +131,14 @@ end | @@ -118,10 +131,14 @@ end | ||
| 118 | function _M.getSellRewardRpc( agent, data ) | 131 | function _M.getSellRewardRpc( agent, data ) |
| 119 | local role = agent.role | 132 | local role = agent.role |
| 120 | local reward = {} | 133 | local reward = {} |
| 134 | + local dirty = false | ||
| 135 | + | ||
| 121 | local sells = json.decode(role.dinerData:getProperty("sells")) | 136 | local sells = json.decode(role.dinerData:getProperty("sells")) |
| 122 | for slot,sell in pairs(sells) do | 137 | for slot,sell in pairs(sells) do |
| 123 | role.dinerData:updateSell(slot) | 138 | role.dinerData:updateSell(slot) |
| 124 | - for k,v in pairs(sell.reward:toNumMap()) do | 139 | + |
| 140 | + local rewards = sell.reward:toNumMap() | ||
| 141 | + for k,v in pairs(rewards) do | ||
| 125 | if reward[k] then | 142 | if reward[k] then |
| 126 | reward[k] = reward[k] + v | 143 | reward[k] = reward[k] + v |
| 127 | else | 144 | else |
| @@ -129,10 +146,20 @@ function _M.getSellRewardRpc( agent, data ) | @@ -129,10 +146,20 @@ function _M.getSellRewardRpc( agent, data ) | ||
| 129 | end | 146 | end |
| 130 | end | 147 | end |
| 131 | sells[slot].reward = "" | 148 | sells[slot].reward = "" |
| 149 | + | ||
| 150 | + if rewards[ItemId.Gold] and rewards[ItemId.Gold] > 0 then | ||
| 151 | + if role.dishData:checkDinerTask(DinerTask.DishWithGold, rewards[ItemId.Gold], sell.dish, nil, true) then | ||
| 152 | + dirty = true | ||
| 153 | + end | ||
| 154 | + end | ||
| 132 | end | 155 | end |
| 133 | for k, v in pairs(reward) do | 156 | for k, v in pairs(reward) do |
| 134 | role:addItem({itemId = k,count = v}) | 157 | role:addItem({itemId = k,count = v}) |
| 135 | end | 158 | end |
| 159 | + if dirty then | ||
| 160 | + role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) | ||
| 161 | + end | ||
| 162 | + | ||
| 136 | role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) | 163 | role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) |
| 137 | SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) | 164 | SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) |
| 138 | return true | 165 | return true |
src/models/Diner.lua
| @@ -45,8 +45,22 @@ function Diner:refreshDailyData(notify) | @@ -45,8 +45,22 @@ function Diner:refreshDailyData(notify) | ||
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | -- 特殊订单 | 47 | -- 特殊订单 |
| 48 | - local order = {} | ||
| 49 | - | 48 | + local orders = {} |
| 49 | + -- 等级由订单板等级决定 | ||
| 50 | + local taskLevel = self:getProperty("buildL"):getv(5, 1) | ||
| 51 | + local taskData = csvdb["diner_questCsv"][taskLevel] | ||
| 52 | + if taskData then | ||
| 53 | + local taskPool = table.values(taskData) | ||
| 54 | + if #taskPool > 6 then | ||
| 55 | + for n = 1, 6 do | ||
| 56 | + local index = math.randWeight(taskPool, "chance") | ||
| 57 | + local data = taskPool[index] | ||
| 58 | + table.insert(orders, {lv = taskLevel, id = data.id, n = 0}) | ||
| 59 | + table.remove(taskPool, index) | ||
| 60 | + end | ||
| 61 | + end | ||
| 62 | + end | ||
| 63 | + self:updateProperty({field = "order", value = json.encode(orders)), notNotify = not notify}) | ||
| 50 | end | 64 | end |
| 51 | 65 | ||
| 52 | function Diner:updateProperty(params) | 66 | function Diner:updateProperty(params) |
| @@ -77,6 +91,25 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) | @@ -77,6 +91,25 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) | ||
| 77 | SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) | 91 | SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) |
| 78 | end | 92 | end |
| 79 | 93 | ||
| 94 | +function Diner:checkDinerTask(type, count, param1, param2, notNotify) | ||
| 95 | + local orders = json.decode(self:getProperty("order")) | ||
| 96 | + local dirty = false | ||
| 97 | + for _, data in ipairs(orders) do | ||
| 98 | + local taskSet = csvdb["diner_questCsv"][data.lv] | ||
| 99 | + if taskSet and taskSet[data.id] then | ||
| 100 | + local task = taskSet[data.id] | ||
| 101 | + if task.type == type and task.condition1 == param1 then | ||
| 102 | + data.n = data.n + count | ||
| 103 | + dirty = true | ||
| 104 | + end | ||
| 105 | + end | ||
| 106 | + end | ||
| 107 | + if dirty then | ||
| 108 | + self:updateProperty({field = "order", value = json.encode(orders)), notNotify = notNotify}) | ||
| 109 | + end | ||
| 110 | + return dirty | ||
| 111 | +end | ||
| 112 | + | ||
| 80 | function Diner:calSellReward(sell, delta, dishData) | 113 | function Diner:calSellReward(sell, delta, dishData) |
| 81 | local reward = sell.reward or "" | 114 | local reward = sell.reward or "" |
| 82 | local popular = 0 | 115 | local popular = 0 |
| @@ -147,6 +180,10 @@ function Diner:updateSell(slot, calOnly) | @@ -147,6 +180,10 @@ function Diner:updateSell(slot, calOnly) | ||
| 147 | sell.reward = reward | 180 | sell.reward = reward |
| 148 | self:setProperty("sells", json.encode(sells)) | 181 | self:setProperty("sells", json.encode(sells)) |
| 149 | self:incrProperty("popular",popular) | 182 | self:incrProperty("popular",popular) |
| 183 | + | ||
| 184 | + if deltaCount > 0 then | ||
| 185 | + self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish) | ||
| 186 | + end | ||
| 150 | end | 187 | end |
| 151 | return { | 188 | return { |
| 152 | deltaCount = deltaCount, | 189 | deltaCount = deltaCount, |