Diner.lua
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
order = {"string", "[]"}, -- 特殊订单
sells = {"string", "[]"}, -- 贩卖位置
hot = {"string", ""}, -- 今日热门
dishTree = {"string", "1=1 2=1 3=1"}, -- 料理天赋
skillTree = {"string", ""}, -- 支援天赋
}
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
-- 特殊订单
local order = {}
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
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
if self:getProperty("hot"):getv(sell.dish, 0) > 0 then
sellTime = sellTime * 1.5
end
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
if not calOnly then
if lastCount == 0 then
sell = nil
else
sell.time = skynet.timex() - deltaTime
sell.count = lastCount
sell.level = self:getProperty("dishTree"):getv(sell.dish, 1)
end
self:setProperty("sells", json.encode(sells))
end
return {
deltaCount = deltaCount,
deltaTime = deltaTime,
lastCount = lastCount,
}
end
function Diner:getMaxSlots()
local slotCount = globalCsv.diner_sell_slots_init
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
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()
local properties = {"buildL", "order", "sells", "hot", "dishTree", "skillTree"}
local data = self:getProperties(properties)
return data
end
return Diner