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
15
|
popular = {"number",0}, -- 累计人气
expedite = {"number",1}, --每日加速次数
gTime = {"number",skynet.timex()}, --温室最后一次领取时间
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
16
17
18
|
}
function Diner:refreshDailyData(notify)
|
020fc7ed
gaofengduan
fix diner expedit...
|
19
20
21
|
-- 每日加速次数
self:updateProperty({field = "expedite", value = 1, notNotify = not notify})
self:setProperty("expedite", 1)
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
22
23
|
-- 特殊订单
|
452d6146
gaofengduan
fix diner task
|
24
|
local orders = json.decode(self:getProperty("order"))
|
550ba7e7
zhouhaihai
订单
|
25
26
27
28
29
30
31
32
33
34
35
|
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
增加餐厅任务计数逻辑
|
36
37
38
|
-- 等级由订单板等级决定
local taskLevel = self:getProperty("buildL"):getv(5, 1)
local taskData = csvdb["diner_questCsv"][taskLevel]
|
550ba7e7
zhouhaihai
订单
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
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
增加餐厅任务计数逻辑
|
57
58
59
|
end
end
end
|
550ba7e7
zhouhaihai
订单
|
60
|
|
f5c07b1b
gaofengduan
fix diner
|
61
|
self:updateProperty({field = "order", value = json.encode(orders), notNotify = not notify})
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
62
63
64
65
|
end
function Diner:updateProperty(params)
params = params or {}
|
289a4927
gaofengduan
fix diner talent
|
66
67
|
if not self.schema[params.field] then
return
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
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
|
92
|
function Diner:checkDinerTask(typ, count, param1, param2, notNotify)
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
93
94
|
local orders = json.decode(self:getProperty("order"))
local dirty = false
|
452d6146
gaofengduan
fix diner task
|
95
|
for k, order in ipairs(orders) do
|
4864d579
zhengshouren
领取任务,锁定任务,获得特殊任务
|
96
97
98
|
local taskSet = csvdb["diner_questCsv"][order.lv]
if taskSet and taskSet[order.id] then
local data = taskSet[order.id]
|
452d6146
gaofengduan
fix diner task
|
99
100
|
if data.type == typ and data.condition1 == param1 and order.status == 1 then
orders[k].n = orders[k].n + count
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
101
102
103
104
105
|
dirty = true
end
end
end
if dirty then
|
f5c07b1b
gaofengduan
fix diner
|
106
|
self:updateProperty({field = "order", value = json.encode(orders), notNotify = notNotify})
|
cc796aaf
zhengshouren
增加餐厅任务计数逻辑
|
107
108
109
110
|
end
return dirty
end
|
090340b9
gaofengduan
fix 餐车
|
111
|
function Diner:calSellReward(sell, delta, dishData)
|
37037eeb
zhengshouren
计算奖励
|
112
|
local reward = sell.reward or ""
|
090340b9
gaofengduan
fix 餐车
|
113
|
local popular = 0
|
37037eeb
zhengshouren
计算奖励
|
114
|
if delta <= 0 then
|
090340b9
gaofengduan
fix 餐车
|
115
|
return reward, popular
|
37037eeb
zhengshouren
计算奖励
|
116
|
end
|
f5c07b1b
gaofengduan
fix diner
|
117
118
|
for key, value in pairs(dishData.item_normal:toNumMap()) do
reward = reward:incrv(key, value * delta)
|
37037eeb
zhengshouren
计算奖励
|
119
|
end
|
090340b9
gaofengduan
fix 餐车
|
120
|
popular = popular + dishData.famous_normal * delta
|
37037eeb
zhengshouren
计算奖励
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
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 餐车
|
140
|
popular = math.floor(popular * (100 + buildData.famous_up) / 100)
|
37037eeb
zhengshouren
计算奖励
|
141
142
|
end
end
|
090340b9
gaofengduan
fix 餐车
|
143
|
return reward, popular
|
37037eeb
zhengshouren
计算奖励
|
144
145
|
end
|
36204e3c
zhengshouren
贩卖逻辑
|
146
147
148
149
150
151
152
153
154
155
156
157
|
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
|
158
|
|
36204e3c
zhengshouren
贩卖逻辑
|
159
160
161
162
163
164
|
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...
|
165
|
local reward, popular = self:calSellReward(sell, deltaCount, dishData)
|
36204e3c
zhengshouren
贩卖逻辑
|
166
|
|
fdb86cad
gaofengduan
fix diner task
|
167
|
if not calOnly and deltaCount > 0 then
|
32161569
gaofengduan
fix diner
|
168
169
170
|
sells[slot].time = skynet.timex() - deltaTime
sells[slot].count = lastCount
sells[slot].level = self:getProperty("dishTree"):getv(sell.dish, 1)
|
32161569
gaofengduan
fix diner
|
171
|
sells[slot].reward = reward
|
36204e3c
zhengshouren
贩卖逻辑
|
172
|
self:setProperty("sells", json.encode(sells))
|
7fa175d5
zhouhaihai
餐厅知名度
|
173
|
self:updateProperty({field = "popular", delta = popular})
|
fdb86cad
gaofengduan
fix diner task
|
174
|
self:checkDinerTask(DinerTask.SellDish, deltaCount, sell.dish)
|
77302523
zhouhaihai
任务
|
175
176
|
self:checkDinerTask(DinerTask.SellDishType, deltaCount, math.ceil(sell.dish / 100))
self:checkDinerTask(DinerTask.SellDishRare, deltaCount, dishData.rarity)
|
36204e3c
zhengshouren
贩卖逻辑
|
177
178
179
180
181
|
end
return {
deltaCount = deltaCount,
deltaTime = deltaTime,
lastCount = lastCount,
|
2050d40d
gaofengduan
add diner expedit...
|
182
183
|
reward = reward,
popular = popular,
|
36204e3c
zhengshouren
贩卖逻辑
|
184
|
}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
185
186
|
end
|
020fc7ed
gaofengduan
fix diner expedit...
|
187
188
189
190
191
192
193
194
195
196
|
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...
|
197
198
199
200
|
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...
|
201
|
local deltaTime = math.floor(expediteTime - sellTime * expediteCount)
|
020fc7ed
gaofengduan
fix diner expedit...
|
202
|
if expediteCount > 0 then
|
55289e78
gaofengduan
fix diner expedit...
|
203
|
sells[slot].time = sell.time - deltaTime
|
020fc7ed
gaofengduan
fix diner expedit...
|
204
205
|
sells[slot].count = lastCount
self:setProperty("sells", json.encode(sells))
|
33db89b8
zhouhaihai
营业加速
|
206
|
self:updateProperty({field = "popular", delta = popular})
|
020fc7ed
gaofengduan
fix diner expedit...
|
207
|
self:checkDinerTask(DinerTask.SellDish, expediteCount, sell.dish)
|
77302523
zhouhaihai
任务
|
208
209
|
self:checkDinerTask(DinerTask.SellDishType, expediteCount, math.ceil(sell.dish / 100))
self:checkDinerTask(DinerTask.SellDishRare, expediteCount, dishData.rarity)
|
020fc7ed
gaofengduan
fix diner expedit...
|
210
211
212
213
214
215
216
217
218
|
end
return {
expediteCount = expediteCount,
lastCount = lastCount,
reward = reward,
popular = popular,
}
end
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
219
220
221
|
function Diner:getMaxSlots()
local slotCount = globalCsv.diner_sell_slots_init
|
36204e3c
zhengshouren
贩卖逻辑
|
222
223
224
225
226
227
|
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
餐厅建筑升级逻辑
|
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
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()
|
2445248d
zhouhaihai
去掉热门料理
|
245
|
local properties = {"buildL", "order", "sells", "dishTree", "skillTree","popular","expedite","gTime"}
|
87cc3a35
zhengshouren
餐厅建筑升级逻辑
|
246
247
248
249
250
|
local data = self:getProperties(properties)
return data
end
return Diner
|