87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
1
2
3
4
5
6
7
8
|
local Diner = class("Diner", require("shared.ModelBase"))
function Diner:ctor(properties)
Diner.super.ctor(self, properties)
end
Diner.schema = {
buildL = {"string", ""}, -- 家具等级 1=1 2=1 3=1
|
36204e3c
zhengshouren
贩卖逻辑
|
9
10
|
order = {"string", "[]"}, -- 特殊订单
sells = {"string", "[]"}, -- 贩卖位置
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
11
|
hot = {"string", ""}, -- 今日热门
|
36204e3c
zhengshouren
贩卖逻辑
|
12
|
dishTree = {"string", "1=1 2=1 3=1"}, -- 料理天赋
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
13
|
skillTree = {"string", ""}, -- 支援天赋
|
090340b9
gaofengduan
fix 餐车
|
14
|
popular = {"number",0}, -- 累计人气
|
020fc7ed
gaofengduan
fix diner expedit...
|
15
|
expedite = {"number",1}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
}
function Diner:refreshDailyData(notify)
-- 热门料理
local hotPool = {}
local dishTree = self:getProperty("dishTree"):toNumMap()
local hangPass = self.owner:getProperty("hangPass")
for index, dishData in ipairs(csvdb["diner_dishCsv"]) do
local check = true
local dish = dishData[1]
if dish.unlock_tree > 0 and not dishTree[dish.unlock_tree] then
check = false
end
if dish.unlock_carbon > 0 and not hangPass[dish.unlock_carbon] then
check = false
end
if check then
table.insert(hotPool, index)
end
end
if #hotPool >= 2 then
local hot = ""
for n = 1, 2 do
local index = math.random(1, #hotPool)
hot = hot:setv(hotPool[index], 1)
table.remove(hotPool, index)
end
self:updateProperty({field = "hot", value = hot, notNotify = not notify})
self:setProperty("hot", hot)
end
|
020fc7ed
gaofengduan
fix diner expedit...
|
47
48
49
|
-- 每日加速次数
self:updateProperty({field = "expedite", value = 1, notNotify = not notify})
self:setProperty("expedite", 1)
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
50
51
|
-- 特殊订单
|
452d6146
gaofengduan
fix diner task
|
52
|
local orders = json.decode(self:getProperty("order"))
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
53
54
55
56
57
58
59
60
61
|
-- 等级由订单板等级决定
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]
|
452d6146
gaofengduan
fix diner task
|
62
63
64
65
66
67
68
69
|
local order = orders[n]
if order then
if order.lock == 0 then
orders[n] = {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0}
end
else
orders[n] = {lv = taskLevel, id = data.id, n = 0, lock = 0,status = 0}
end
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
70
71
72
|
end
end
end
|
f5c07b1b
gaofengduan
fix diner
|
73
|
self:updateProperty({field = "order", value = json.encode(orders), notNotify = not notify})
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
end
function Diner:updateProperty(params)
params = params or {}
if not self.schema[params.field] then
return
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
|
104
|
function Diner:checkDinerTask(typ, count, param1, param2, notNotify)
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
105
106
|
local orders = json.decode(self:getProperty("order"))
local dirty = false
|
452d6146
gaofengduan
fix diner task
|
107
|
for k, order in ipairs(orders) do
|
4864d579
zhengshouren
领取任务,锁定任务,获得特殊任务
|
108
109
110
|
local taskSet = csvdb["diner_questCsv"][order.lv]
if taskSet and taskSet[order.id] then
local data = taskSet[order.id]
|
452d6146
gaofengduan
fix diner task
|
111
112
|
if data.type == typ and data.condition1 == param1 and order.status == 1 then
orders[k].n = orders[k].n + count
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
113
114
115
116
117
|
dirty = true
end
end
end
if dirty then
|
f5c07b1b
gaofengduan
fix diner
|
118
|
self:updateProperty({field = "order", value = json.encode(orders), notNotify = notNotify})
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
119
120
121
122
|
end
return dirty
end
|
090340b9
gaofengduan
fix 餐车
|
123
|
function Diner:calSellReward(sell, delta, dishData)
|
37037eeb
zhengshouren
计算奖励
|
124
|
local reward = sell.reward or ""
|
090340b9
gaofengduan
fix 餐车
|
125
|
local popular = 0
|
37037eeb
zhengshouren
计算奖励
|
126
|
if delta <= 0 then
|
090340b9
gaofengduan
fix 餐车
|
127
|
return reward, popular
|
37037eeb
zhengshouren
计算奖励
|
128
|
end
|
f5c07b1b
gaofengduan
fix diner
|
129
130
|
for key, value in pairs(dishData.item_normal:toNumMap()) do
reward = reward:incrv(key, value * delta)
|
37037eeb
zhengshouren
计算奖励
|
131
|
end
|
090340b9
gaofengduan
fix 餐车
|
132
|
popular = popular + dishData.famous_normal * delta
|
37037eeb
zhengshouren
计算奖励
|
133
|
if sell.hot > 0 then
|
f5c07b1b
gaofengduan
fix diner
|
134
135
|
for key, value in pairs(dishData.item_popular:toNumMap()) do
reward = reward:incrv(key, value * delta)
|
37037eeb
zhengshouren
计算奖励
|
136
|
end
|
090340b9
gaofengduan
fix 餐车
|
137
|
popular = popular + dishData.famous_popular * delta
|
37037eeb
zhengshouren
计算奖励
|
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
end
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 餐车
|
158
|
popular = math.floor(popular * (100 + buildData.famous_up) / 100)
|
37037eeb
zhengshouren
计算奖励
|
159
160
|
end
end
|
090340b9
gaofengduan
fix 餐车
|
161
|
return reward, popular
|
37037eeb
zhengshouren
计算奖励
|
162
163
|
end
|
36204e3c
zhengshouren
贩卖逻辑
|
164
165
166
167
168
169
170
171
172
173
174
175
|
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
|
1068aae9
gaofengduan
fix diner popularity
|
176
177
178
|
if slot.hot then
sellTime = sellTime * dishData.popularity
end
|
37037eeb
zhengshouren
计算奖励
|
179
|
|
36204e3c
zhengshouren
贩卖逻辑
|
180
181
182
183
184
185
|
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...
|
186
|
local reward, popular = self:calSellReward(sell, deltaCount, dishData)
|
36204e3c
zhengshouren
贩卖逻辑
|
187
|
|
fdb86cad
gaofengduan
fix diner task
|
188
|
if not calOnly and deltaCount > 0 then
|
32161569
gaofengduan
fix diner
|
189
190
191
192
193
|
sells[slot].time = skynet.timex() - deltaTime
sells[slot].count = lastCount
sells[slot].level = self:getProperty("dishTree"):getv(sell.dish, 1)
sells[slot].hot = self:getProperty("hot"):getv(sell.dish, 0)
sells[slot].reward = reward
|
36204e3c
zhengshouren
贩卖逻辑
|
194
|
self:setProperty("sells", json.encode(sells))
|
090340b9
gaofengduan
fix 餐车
|
195
|
self:incrProperty("popular",popular)
|
fdb86cad
gaofengduan
fix diner task
|
196
|
self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish)
|
36204e3c
zhengshouren
贩卖逻辑
|
197
198
199
200
201
|
end
return {
deltaCount = deltaCount,
deltaTime = deltaTime,
lastCount = lastCount,
|
2050d40d
gaofengduan
add diner expedit...
|
202
203
|
reward = reward,
popular = popular,
|
36204e3c
zhengshouren
贩卖逻辑
|
204
|
}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
205
206
|
end
|
020fc7ed
gaofengduan
fix diner expedit...
|
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
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
if slot.hot then
sellTime = sellTime * dishData.popularity
end
expediteCount = math.floor(expediteTime / sellTime)
expediteCount = math.min(expediteCount, sell.count)
local lastCount = sell.count - expediteCount
local reward, popular = self:calSellReward(sell, expediteCount, dishData)
if expediteCount > 0 then
sells[slot].count = lastCount
self:setProperty("sells", json.encode(sells))
self:incrProperty("popular",popular)
self:checkDinerTask(DinerTask.SellDish, expediteCount, sell.dish)
end
return {
expediteCount = expediteCount,
lastCount = lastCount,
reward = reward,
popular = popular,
}
end
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
239
240
241
|
function Diner:getMaxSlots()
local slotCount = globalCsv.diner_sell_slots_init
|
36204e3c
zhengshouren
贩卖逻辑
|
242
243
244
245
246
247
|
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
餐厅建筑升级逻辑
|
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
return slotCount
end
function Diner:getMaxDishs()
local dishCount = globalCsv.diner_sell_dish_init
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
return dishCount
end
function Diner:data()
|
020fc7ed
gaofengduan
fix diner expedit...
|
265
|
local properties = {"buildL", "order", "sells", "hot", "dishTree", "skillTree","popular","expedite"}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
266
267
268
269
270
|
local data = self:getProperties(properties)
return data
end
return Diner
|