Commit cc796aaf2a03d26117de975c24c5fb50d63cd69a
1 parent
32420a89
增加餐厅任务计数逻辑
Showing
3 changed files
with
74 additions
and
3 deletions
Show diff stats
src/GlobalVar.lua
src/actions/DinerAction.lua
... | ... | @@ -52,6 +52,19 @@ function _M.addSellRpc( agent, data ) |
52 | 52 | role:costItems(cost) |
53 | 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 | 68 | local sells = json.decode(role.dinerData:getProperty("sells")) |
56 | 69 | if not sells[slot] then |
57 | 70 | sells[slot] = { |
... | ... | @@ -118,10 +131,14 @@ end |
118 | 131 | function _M.getSellRewardRpc( agent, data ) |
119 | 132 | local role = agent.role |
120 | 133 | local reward = {} |
134 | + local dirty = false | |
135 | + | |
121 | 136 | local sells = json.decode(role.dinerData:getProperty("sells")) |
122 | 137 | for slot,sell in pairs(sells) do |
123 | 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 | 142 | if reward[k] then |
126 | 143 | reward[k] = reward[k] + v |
127 | 144 | else |
... | ... | @@ -129,10 +146,20 @@ function _M.getSellRewardRpc( agent, data ) |
129 | 146 | end |
130 | 147 | end |
131 | 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 | 155 | end |
133 | 156 | for k, v in pairs(reward) do |
134 | 157 | role:addItem({itemId = k,count = v}) |
135 | 158 | end |
159 | + if dirty then | |
160 | + role.dishData:notifyUpdateProperty("order", role.dinerData:getProperty("order")) | |
161 | + end | |
162 | + | |
136 | 163 | role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) |
137 | 164 | SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) |
138 | 165 | return true | ... | ... |
src/models/Diner.lua
... | ... | @@ -45,8 +45,22 @@ function Diner:refreshDailyData(notify) |
45 | 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 | 64 | end |
51 | 65 | |
52 | 66 | function Diner:updateProperty(params) |
... | ... | @@ -77,6 +91,25 @@ function Diner:notifyUpdateProperty(field, newValue, oldValue) |
77 | 91 | SendPacket(actionCodes.Diner_updateProperty, MsgPack.pack(datas)) |
78 | 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 | 113 | function Diner:calSellReward(sell, delta, dishData) |
81 | 114 | local reward = sell.reward or "" |
82 | 115 | local popular = 0 |
... | ... | @@ -147,6 +180,10 @@ function Diner:updateSell(slot, calOnly) |
147 | 180 | sell.reward = reward |
148 | 181 | self:setProperty("sells", json.encode(sells)) |
149 | 182 | self:incrProperty("popular",popular) |
183 | + | |
184 | + if deltaCount > 0 then | |
185 | + self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish) | |
186 | + end | |
150 | 187 | end |
151 | 188 | return { |
152 | 189 | deltaCount = deltaCount, | ... | ... |