RoleTimeReset.lua 4.07 KB
local RoleTimeReset = {}

RoleTimeReset.bind = function (Role)

-- 重置内容 对应 GlobalVar TimeReset
local ResetFunc = {}
ResetFunc["CrossDay"] = function(self, notify, response, now)
	self.activity:checkActivityStatus(now, true, notify)

	self.dailyData:refreshDailyData(notify)
	self.dinerData:refreshDailyData(notify)
	self.activity:refreshDailyData(notify)
	self.storeData:onCrossDay()

	self:setProperty("dTask", {})
	self:incrProperty("lday", 1)
	self:advRandomSupportEffect(not notify)

	self:checkExpireItem(not notify)
	local advMine = self:getProperty("advMine")
	if advMine[1] then
		advMine[1].co = nil
	end
	self:setProperty("advMine", advMine)

	response.dTask = {}
	response.advSup = self:getProperty("advSup")
	self:log("onLogin")
end

ResetFunc["CrossWeek"] = function(self, notify, response)
	local advMine = self:getProperty("advMine")
	if advMine[2] then
		advMine[2].co = nil
	end
	self:setProperties({
		wTask =  {}, 
		dinerS = {},
		advMine = advMine,
	})

	response.wTask = {}
	response.dinerS = {}

	self.activity:refreshWeekData(notify)
end

ResetFunc["CrossMonth"] = function(self, notify, response)
	local ltime = self:getProperty("ltime")
	if isCrossMonth(ltime, skynet.timex()) then
		self.storeData:resetStoreReored(3)		--商店跨月重置 time_reset表关联id
	end
end


ResetFunc["DinerRank"] = function(self, notify, response)
	self.dinerData:rankResetData(notify)
end

ResetFunc["PvpShop"] = function(self, notify, response)
	self:setProperty("pvpShop", {})
	response.pvpShop = {}
end

ResetFunc["PvpCross"] = function(self, notify, response)
	self:setProperty("pvpBet", {})
end


function Role:updateTimeReset(now, notify)
	local timeReset = self:getProperty("timeReset")

	local passTime = now - START_RESET_TIME

	local needResetId = {}
	for resetId, resetData in pairs(csvdb["time_resetCsv"]) do
		if resetData.interval > 0 then
			local curRound = math.floor((passTime - resetData.start) / resetData.interval)
			if not timeReset[resetId] or curRound ~= timeReset[resetId] then
				needResetId[resetId] = curRound
			end
		end
	end
	if not next(needResetId) then return end

	local resetMode = {}

	local response = {}
	for funcName, resetId in pairs(TimeReset) do
		if needResetId[resetId] and ResetFunc[funcName] then
			ResetFunc[funcName](self, notify, response, now)
			resetMode[funcName] = true
		end
		if needResetId[resetId] then
			-- 充值商城购买记录
			self.storeData:resetStoreReored(resetId)
		end
	end

	for resetId, round in pairs(needResetId) do
		timeReset[resetId] = round
	end
	self:setProperties({timeReset = timeReset, ltime = now})

	response.timeReset = timeReset
	response.ltime = now

	if notify then
		self:notifyUpdateProperties(response)
	end
	return resetMode
end

-- 持续时间取  min(interval, duration) duration 填 0 默认使用 interval 作为持续时间
local function getTimeResetDuration(rtype)
	local resetData = csvdb["time_resetCsv"][rtype]
	if not resetData then return 0 end
	return resetData.duration == 0 and resetData.interval or math.min(resetData.interval, resetData.duration)
end

--检查功能是否是在开放期
function Role:isTimeResetOpen(rtype)
	local resetData = csvdb["time_resetCsv"][rtype]
	if not resetData or getTimeResetDuration(rtype) >= resetData.interval then
		return true
	end
	
	return self:getTimeResetEndTime(rtype) > skynet.timex()
end

-- 当前轮次 开始时间
function Role:getTimeResetStartTime(rtype)
	local timeReset = self:getProperty("timeReset")
	if not timeReset[rtype] then return 0 end
	local resetData = csvdb["time_resetCsv"][rtype]
	if not resetData then return 0 end
	return START_RESET_TIME + timeReset[rtype] * resetData.interval + resetData.start
end

-- 当前轮次 结束时间
function Role:getTimeResetEndTime(rtype)
	return self:getTimeResetStartTime(rtype) + getTimeResetDuration(rtype)
end

function Role:getTimeResetRound(rtype)
	local timeReset = self:getProperty("timeReset")
	return timeReset[rtype] or 0
end

function Role:getTimeResetDataStart(rtype)
	local resetData = csvdb["time_resetCsv"][rtype]
	if not resetData then return 0 end
	return resetData.start
end







end





return RoleTimeReset