87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
1
2
3
4
5
6
7
|
local Diner = class("Diner", require("shared.ModelBase"))
function Diner:ctor(properties)
Diner.super.ctor(self, properties)
end
Diner.schema = {
|
4288160b
gaofengduan
add Diner_getGree...
|
8
9
10
|
buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1
order = {"string", "[]"}, -- 特殊订单
sells = {"string", "[]"}, -- 贩卖位置
|
289a4927
gaofengduan
fix diner talent
|
11
|
dishTree = {"string", "1=1 101=1 201=1"}, -- 料理天赋
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
12
|
skillTree = {"string", ""}, -- 支援天赋
|
4288160b
gaofengduan
add Diner_getGree...
|
13
14
|
popular = {"number",0}, -- 累计人气
expedite = {"number",1}, --每日加速次数
|
6d272f65
zhouhaihai
餐厅 食材
|
15
|
gfood = {"table", {}}, -- 愿望食材 {{id = 123, st = 1232144},}
|
03a6166a
zhouhaihai
餐厅优化
|
16
|
task = {"table", {}}, -- 任务刷新 {et = 消失时间 id = 任务id, refuse = 0}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
17
18
|
}
|
59835765
zhouhaihai
排行榜
|
19
20
21
22
|
function Diner:rankResetData(notify)
self:updateProperty({field = "popular", value = 0, notNotify = not notify})
end
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
23
|
function Diner:refreshDailyData(notify)
|
020fc7ed
gaofengduan
fix diner expedit...
|
24
25
26
|
-- 每日加速次数
self:updateProperty({field = "expedite", value = 1, notNotify = not notify})
self:setProperty("expedite", 1)
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
27
|
-- 特殊订单
|
452d6146
gaofengduan
fix diner task
|
28
|
local orders = json.decode(self:getProperty("order"))
|
550ba7e7
zhouhaihai
订单
|
29
30
31
32
33
34
35
36
37
38
39
|
local hadTask = {}
local needCount = globalCsv.diner_task_count
for idx, temp in pairs(orders) do
if temp.lock ~= 0 then
hadTask[temp.id] = 1
needCount = needCount - 1
end
end
if needCount <= 0 then return end
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
40
41
42
|
-- 等级由订单板等级决定
local taskLevel = self:getProperty("buildL"):getv(5, 1)
local taskData = csvdb["diner_questCsv"][taskLevel]
|
550ba7e7
zhouhaihai
订单
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
if not taskData then return end
local pool = {}
for id, temp in pairs(taskData) do
if not hadTask[id] then
table.insert(pool, temp)
end
end
local needCount = math.min(#pool, needCount) -- 需要的任务个数
for idx = 1, globalCsv.diner_task_count do
local order = orders[idx]
if not order or order.lock == 0 then
if needCount > 0 then
local index = math.randWeight(pool, "chance")
local data = pool[index]
orders[idx] = {lv = taskLevel, id = data.id, n = 0, lock = 0, status = 0}
needCount = needCount - 1
table.remove(pool, index)
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
61
62
63
|
end
end
end
|
550ba7e7
zhouhaihai
订单
|
64
|
|
f5c07b1b
gaofengduan
fix diner
|
65
|
self:updateProperty({field = "order", value = json.encode(orders), notNotify = not notify})
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
66
67
68
69
|
end
function Diner:updateProperty(params)
params = params or {}
|
289a4927
gaofengduan
fix diner talent
|
70
71
|
if not self.schema[params.field] then
return
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
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
|
452d6146
gaofengduan
fix diner task
|
96
|
function Diner:checkDinerTask(typ, count, param1, param2, notNotify)
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
97
98
|
local orders = json.decode(self:getProperty("order"))
local dirty = false
|
452d6146
gaofengduan
fix diner task
|
99
|
for k, order in ipairs(orders) do
|
4864d579
zhengshouren
领取任务,锁定任务,获得特殊任务
|
100
101
102
|
local taskSet = csvdb["diner_questCsv"][order.lv]
if taskSet and taskSet[order.id] then
local data = taskSet[order.id]
|
452d6146
gaofengduan
fix diner task
|
103
104
|
if data.type == typ and data.condition1 == param1 and order.status == 1 then
orders[k].n = orders[k].n + count
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
105
106
107
108
109
|
dirty = true
end
end
end
if dirty then
|
f5c07b1b
gaofengduan
fix diner
|
110
|
self:updateProperty({field = "order", value = json.encode(orders), notNotify = notNotify})
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
111
112
113
114
|
end
return dirty
end
|
090340b9
gaofengduan
fix 餐车
|
115
|
function Diner:calSellReward(sell, delta, dishData)
|
37037eeb
zhengshouren
计算奖励
|
116
|
local reward = sell.reward or ""
|
090340b9
gaofengduan
fix 餐车
|
117
|
local popular = 0
|
37037eeb
zhengshouren
计算奖励
|
118
|
if delta <= 0 then
|
090340b9
gaofengduan
fix 餐车
|
119
|
return reward, popular
|
37037eeb
zhengshouren
计算奖励
|
120
|
end
|
f5c07b1b
gaofengduan
fix diner
|
121
122
|
for key, value in pairs(dishData.item_normal:toNumMap()) do
reward = reward:incrv(key, value * delta)
|
37037eeb
zhengshouren
计算奖励
|
123
|
end
|
090340b9
gaofengduan
fix 餐车
|
124
|
popular = popular + dishData.famous_normal * delta
|
37037eeb
zhengshouren
计算奖励
|
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
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
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
end
if buildData and buildData.famous_up > 0 then
|
090340b9
gaofengduan
fix 餐车
|
144
|
popular = math.floor(popular * (100 + buildData.famous_up) / 100)
|
37037eeb
zhengshouren
计算奖励
|
145
146
|
end
end
|
090340b9
gaofengduan
fix 餐车
|
147
|
return reward, popular
|
37037eeb
zhengshouren
计算奖励
|
148
149
|
end
|
36204e3c
zhengshouren
贩卖逻辑
|
150
151
152
153
154
155
156
157
158
159
160
161
|
function Diner:updateSell(slot, calOnly)
local sells = json.decode(self:getProperty("sells"))
local sell = sells[slot]
if not sell or sell.count <= 0 then
return
end
local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level]
local deltaTime = 0
local deltaCount = 0
local timePass = skynet.timex() - sell.time
local sellTime = dishData.sell_time
|
289a4927
gaofengduan
fix diner talent
|
162
|
|
36204e3c
zhengshouren
贩卖逻辑
|
163
164
165
166
167
168
|
deltaCount = math.floor(timePass / sellTime)
if deltaCount < sell.count then
deltaTime = math.floor(timePass - sellTime * deltaCount)
end
deltaCount = math.min(deltaCount, sell.count)
local lastCount = sell.count - deltaCount
|
2050d40d
gaofengduan
add diner expedit...
|
169
|
local reward, popular = self:calSellReward(sell, deltaCount, dishData)
|
36204e3c
zhengshouren
贩卖逻辑
|
170
|
|
fdb86cad
gaofengduan
fix diner task
|
171
|
if not calOnly and deltaCount > 0 then
|
32161569
gaofengduan
fix diner
|
172
173
174
|
sells[slot].time = skynet.timex() - deltaTime
sells[slot].count = lastCount
sells[slot].level = self:getProperty("dishTree"):getv(sell.dish, 1)
|
32161569
gaofengduan
fix diner
|
175
|
sells[slot].reward = reward
|
59835765
zhouhaihai
排行榜
|
176
|
sells[slot].popular = (sells[slot].popular or 0) + popular
|
36204e3c
zhengshouren
贩卖逻辑
|
177
|
self:setProperty("sells", json.encode(sells))
|
fdb86cad
gaofengduan
fix diner task
|
178
|
self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish)
|
77302523
zhouhaihai
任务
|
179
180
|
self:checkDinerTask(DinerTask.SellDishType, deltaCount, math.ceil(sell.dish / 100))
self:checkDinerTask(DinerTask.SellDishRare, deltaCount, dishData.rarity)
|
53e8037e
zhouhaihai
任务
|
181
|
self.owner:checkTaskEnter("FoodSell", {count = deltaCount})
|
36204e3c
zhengshouren
贩卖逻辑
|
182
183
184
185
186
|
end
return {
deltaCount = deltaCount,
deltaTime = deltaTime,
lastCount = lastCount,
|
2050d40d
gaofengduan
add diner expedit...
|
187
|
reward = reward,
|
36204e3c
zhengshouren
贩卖逻辑
|
188
|
}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
189
190
|
end
|
020fc7ed
gaofengduan
fix diner expedit...
|
191
192
193
194
195
196
197
198
199
200
|
function Diner:expediteSell(slot)
local sells = json.decode(self:getProperty("sells"))
local sell = sells[slot]
if not sell or sell.count <= 0 then
return
end
local dishData = csvdb["diner_dishCsv"][sell.dish][sell.level]
local expediteCount = 0
local expediteTime = 7200
local sellTime = dishData.sell_time
|
020fc7ed
gaofengduan
fix diner expedit...
|
201
202
203
204
|
expediteCount = math.floor(expediteTime / sellTime)
expediteCount = math.min(expediteCount, sell.count)
local lastCount = sell.count - expediteCount
local reward, popular = self:calSellReward(sell, expediteCount, dishData)
|
55289e78
gaofengduan
fix diner expedit...
|
205
|
local deltaTime = math.floor(expediteTime - sellTime * expediteCount)
|
020fc7ed
gaofengduan
fix diner expedit...
|
206
|
if expediteCount > 0 then
|
55289e78
gaofengduan
fix diner expedit...
|
207
|
sells[slot].time = sell.time - deltaTime
|
020fc7ed
gaofengduan
fix diner expedit...
|
208
209
|
sells[slot].count = lastCount
self:setProperty("sells", json.encode(sells))
|
020fc7ed
gaofengduan
fix diner expedit...
|
210
|
self:checkDinerTask(DinerTask.SellDish, expediteCount, sell.dish)
|
77302523
zhouhaihai
任务
|
211
212
|
self:checkDinerTask(DinerTask.SellDishType, expediteCount, math.ceil(sell.dish / 100))
self:checkDinerTask(DinerTask.SellDishRare, expediteCount, dishData.rarity)
|
760ed660
zhouhaihai
任务成就 增加
|
213
|
self.owner:checkTaskEnter("FoodSell", {count = expediteCount})
|
020fc7ed
gaofengduan
fix diner expedit...
|
214
215
216
217
218
219
220
221
222
|
end
return {
expediteCount = expediteCount,
lastCount = lastCount,
reward = reward,
popular = popular,
}
end
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
223
224
225
|
function Diner:getMaxSlots()
local slotCount = globalCsv.diner_sell_slots_init
|
36204e3c
zhengshouren
贩卖逻辑
|
226
227
228
229
230
231
|
local hangPass = self.owner:getProperty("hangPass")
for _, carbonId in ipairs(globalCsv.diner_sell_slots_unlock) do
if hangPass[carbonId] then
slotCount = slotCount + 1
end
end
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
232
233
234
235
236
237
238
|
return slotCount
end
function Diner:getMaxDishs()
local dishCount = globalCsv.diner_sell_dish_init
|
59835765
zhouhaihai
排行榜
|
239
240
241
242
243
244
|
-- 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
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
245
246
247
|
return dishCount
end
|
59835765
zhouhaihai
排行榜
|
248
249
250
251
252
253
254
|
function Diner:popularAdd(popular)
if popular ~= 0 then
self:updateProperty({field = "popular", delta = popular})
local dbKey = self.owner:getCurDinerRankKey()
local roleId = self.owner:getProperty("id")
-- 更新排行榜
local curPopular = self:getProperty("popular")
|
53e8037e
zhouhaihai
任务
|
255
|
self.owner:checkTaskEnter("DinerPopular", {count = curPopular})
|
59835765
zhouhaihai
排行榜
|
256
257
258
|
redisproxy:pipelining(function (red)
red:zadd(dbKey, curPopular, roleId) --更新分数
red:hset(RANK_DINER_INFO, roleId, MsgPack.pack({
|
5e0e0aff
zhouhaihai
初始等级记录错误
|
259
|
lv = self:getProperty("buildL"):getv(1, 1),
|
59835765
zhouhaihai
排行榜
|
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
name = self.owner:getProperty("name"),
headId = self.owner:getProperty("headId")
}))
end)
end
end
function Diner:getPopularRank()
local dbKey = self.owner:getCurDinerRankKey()
local list = {}
local ids = redisproxy:zrevrange(dbKey, 0 , 99, "WITHSCORES")
local redret = {}
if ids and next(ids) then
redret = redisproxy:pipelining(function (red)
for i = 1, #ids, 2 do
local roleId = ids[i]
local score = ids[i + 1]
list[#list + 1] = {score = tonumber(score), roleId = tonumber(roleId)}
red:hget(RANK_DINER_INFO, roleId)
end
end)
end
for i = 1, #redret do
local player = MsgPack.unpack(redret[i])
list[i].player = player
end
local rank = redisproxy:ZREVRANK(dbKey, self.owner:getProperty("id"))
if not rank then
rank = -1
else
rank = rank + 1
end
return {list = list, rank = rank}
end
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
295
|
function Diner:data()
|
03a6166a
zhouhaihai
餐厅优化
|
296
|
local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gfood", "task"}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
297
298
299
300
301
|
local data = self:getProperties(properties)
return data
end
return Diner
|