Daily.lua 4.81 KB
-- 日常数据

local Daily = class("Daily", require("shared.ModelBaseMysql"))
local DailyPlugin = import(".DailyPlugin")  --宝藏相关
DailyPlugin.bind(Daily)

function Daily:ctor(properties)
	Daily.super.ctor(self, properties)
end

Daily.schema = {
	id 				= {"number", 0, "pri"},		-- 角色id
	commentHero		= {"string", "", "blob"},		-- 单日评论食灵记录 type=1
	hangQC			= {"number", 0},		-- 挂机快速次数
	dinerQC			= {"number", 0},		-- 贩卖加速次数
	advElC			= {"number", 0},		-- 无尽次数(消耗体力)
	advBC			= {"number", 0},		-- 冒险次数购买次数(冒险体力购买次数)
	advElBC			= {"number", 0},		-- 无尽次数购买次数(冒险体力购买次数)
	advWs			= {"table", {}}, 		-- 冒险队工坊
	bonusC			= {"table", {}}, 		-- 奖励副本 次数 {[type] = {c = 0, b = 0}} 修改为 {c=0, b=0}
	giveFP			= {"table", {}},		-- 给谁送过心心
	getFP			= {"table", {}},		-- 领过谁的心心
	pvpFree			= {"number", 0},		-- pvp使用免费次数
	pvpFreeH		= {"number", 0},		-- 高级pvp使用免费次
	pvpBought		= {"number", 0},		-- 门票购买次数

	dailySDC		= {"table", {}},		-- daily shop diamond  count {[id] = count} -- 每日商城购买次数统计
	dailySDD		= {"table", {}},		-- daily shop diamond  disount {[id] = 1} -- 每日商城折扣统计

	advSupRe		= {"number", 0}, 		-- 冒险支援效果刷新次数
	goldBuyT		= {"number", 0}, 		-- 金币购买次数

	unlockPool		= {"table", {}},		-- 解锁的属性卡池
	curPool 		= {"number", 0},		-- 属性卡池当前索引
	drawHeroCnt		= {"number", 0},		-- 每日抽卡次数

	treasureBase	= {"number", 0}, 		-- 资源值
	treasureList 	= {"table", {}}, 		--挂机图鉴

	treasureListExtra 	= {"table", {}}, 	--额外宝藏,挂机图鉴扩展功能
	treasureExtraCount 	= {"number", 0}, 	--每日发现额外宝藏使用次数(累计),隔天清零
	treasureBaseExtra 	= {"number", 0}, 	--额外宝藏资源值

	chatTimes 		= {"number", 0},		--每日发言次数
}

function Daily:updateProperty(params)
	local type, default = table.unpack(self.schema[params.field])

	if params.delta then
		self:incrProperty(params.field, params.delta)
		if not params.notNotify then
			self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
		end
		return true
	end
	if params.value then
		self:setProperty(params.field, params.value)
		if not params.notNotify then
			self.owner:notifyUpdateProperty(params.field, self:getProperty(params.field))
		end
		return true
	end
	return false
end

function Daily:refreshDailyData(notify)
	redisproxy:del(FRIEND_POINT:format(self.owner:getProperty("id")))
	local dataMap = {}
	for field, schema in pairs(self.schema) do
		if field == "advElC" then
			if self:getProperty(field) > 0 then
				dataMap[field] = 0
			end
		elseif field == "id" then
            -- skip
		elseif field == "treasureBase" then
			dataMap[field] = globalCsv.idle_treasure_base + self.owner:getBnousTreasureBaseMaximum()
		elseif field == "treasureList" then
			dataMap[field] = self:getTreasureList()
		elseif field == "treasureExtraCount" then
			dataMap[field] = 0
		elseif field == "pvpBought" then
			dataMap[field] = 0
		elseif field ~= "key" then
			local typ, def = table.unpack(schema)
			dataMap[field] = def
		end
	end
	-- 每日折扣搞一下
	local dailySDD = {}
	local sddPool = {}
	for id, data in pairs(csvdb["shop_normalCsv"]) do
		if data.shop == 1 and data.disount ~= 0 then
			table.insert(sddPool, id)
		end
	end
	for i = 1, math.min(#sddPool, globalCsv.shop_diamond_disount_count) do
		local idx = math.randomInt(1, #sddPool)
		dailySDD[sddPool[idx]] = 1
		table.remove(sddPool, idx)
	end
	dataMap["dailySDD"] = dailySDD
	self:setProperties(dataMap)
	if notify then
		self.owner:notifyUpdateProperties(self:data())
	end
end

function Daily:data()
	return {
		hangQC = self:getProperty("hangQC"),
		dinerQC = self:getProperty("dinerQC"),
		advBC = self:getProperty("advBC"),
		advElC = self:getProperty("advElC"),
		advElBC = self:getProperty("advElBC"),
		advWs = self:getProperty("advWs"),
		bonusC = self:getProperty("bonusC"),
		giveFP = self:getProperty("giveFP"),
		getFP = self:getProperty("getFP"),
		pvpFree = self:getProperty("pvpFree"),
		pvpFreeH = self:getProperty("pvpFreeH"),
		pvpBought = self:getProperty("pvpBought"),
		dailySDC = self:getProperty("dailySDC"),
		dailySDD = self:getProperty("dailySDD"),
		advSupRe = self:getProperty("advSupRe"),
		goldBuyT = self:getProperty("goldBuyT"),
		unlockPool = self:getProperty("unlockPool"),
		curPool = self:getProperty("curPool"),
		treasureBase = self:getProperty("treasureBase"),
		treasureList = self:getProperty("treasureList"),
		treasureListExtra = self:getProperty("treasureListExtra"),
		treasureExtraCount = self:getProperty("treasureExtraCount"),
		treasureBaseExtra = self:getProperty("treasureBaseExtra"),
		chatTimes = self:getProperty("chatTimes"),
	}
end

return Daily