Diner.lua 2.57 KB
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", ""},		-- 特殊订单
	slots 	= {"string", ""},		-- 贩卖位置
	hot		= {"string", ""},		-- 今日热门
	dishTree	= {"string", ""},		-- 料理天赋
	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:doSell(notify)
	
end

function Diner:getMaxSlots()
	local slotCount = globalCsv.diner_sell_slots_init


	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", "hot", "dishTree", "skillTree"}
	local data = self:getProperties(properties)
	return data
end

return Diner