120 lines
3.7 KiB
Lua
120 lines
3.7 KiB
Lua
local ActTimeData = class("ActTimeData", BaseData)
|
||
|
||
function ActTimeData:ctor()
|
||
self.actTimeList = {}
|
||
end
|
||
|
||
function ActTimeData:clear()
|
||
end
|
||
|
||
---- 活动改版后,服务器只会发一个活动类型的当前或下一次的数据,不是想之前一样无脑把activity表转过来
|
||
function ActTimeData:init(data)
|
||
if EDITOR_MODE then
|
||
Logger.logHighlight("活动时间初始化-------------------" .. tostring(data ~= nil))
|
||
-- Logger.printTable(data)
|
||
end
|
||
data = data or {}
|
||
self.actTimeList = data
|
||
self:refreshActTime()
|
||
end
|
||
|
||
function ActTimeData:refreshActTime()
|
||
local curTime = Time:getServerTime()
|
||
self.actTypeTimeList = {}
|
||
for _, info in ipairs(self.actTimeList) do
|
||
local actId = info.id
|
||
if ModuleManager.ActivityManager:getActivityInCfg(actId) then
|
||
if EDITOR_MODE then
|
||
Logger.logHighlight("活动id:" .. info.id .. " 类型:" .. info.type .. " 开启:" .. info.start_at .. " 结束:" .. info.end_at .. " 额外:" .. info.extra_at)
|
||
end
|
||
local actType = info.type
|
||
local startTime = info.start_at or 0
|
||
if startTime < 0 then
|
||
startTime = 0
|
||
end
|
||
|
||
local endTime = info.end_at
|
||
if endTime < 0 then
|
||
endTime = 0
|
||
end
|
||
|
||
local extraTime = info.extra_at
|
||
if extraTime < endTime then
|
||
extraTime = endTime
|
||
end
|
||
|
||
local actGifts = info.gifts or {}
|
||
local data = info.data
|
||
if curTime < extraTime then -- 在有效期内
|
||
if self.actTypeTimeList[actType] == nil or self.actTypeTimeList[actType].endTime > endTime then
|
||
self.actTypeTimeList[actType] = {actId = actId, actType = actType, startTime = startTime, endTime = endTime, extraTime = extraTime, actGifts = actGifts, data = data}
|
||
self:initActivityData(actType, self.actTypeTimeList[actType])
|
||
end
|
||
else
|
||
if EDITOR_MODE then
|
||
Logger.logHighlight("活动暂未开启:" .. info.id)
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
|
||
function ActTimeData:getActTimeList()
|
||
return self.actTimeList
|
||
end
|
||
|
||
function ActTimeData:getActTimeInfoByActId(id)
|
||
for _, info in ipairs(self.actTimeList) do
|
||
if info.id == id then
|
||
return info
|
||
end
|
||
end
|
||
end
|
||
|
||
function ActTimeData:getActStartTime(actId)
|
||
for _, info in ipairs(self.actTimeList) do
|
||
if info.id == actId then
|
||
return info.start_at
|
||
end
|
||
end
|
||
end
|
||
|
||
function ActTimeData:getActEndTime(actId)
|
||
for _, info in ipairs(self.actTimeList) do
|
||
if info.id == actId then
|
||
local extraTime = info.extra_at
|
||
if extraTime < info.end_at then
|
||
extraTime = info.end_at
|
||
end
|
||
return extraTime
|
||
end
|
||
end
|
||
end
|
||
|
||
function ActTimeData:getActExtraTime(actId)
|
||
for _, info in ipairs(self.actTimeList) do
|
||
if info.id == actId then
|
||
local extraTime = info.extra_at
|
||
if extraTime < info.end_at then
|
||
extraTime = info.end_at
|
||
end
|
||
return extraTime
|
||
end
|
||
end
|
||
end
|
||
|
||
function ActTimeData:getActTypeTimeList()
|
||
return self.actTypeTimeList or {}
|
||
end
|
||
|
||
function ActTimeData:initActivityData(actType, info)
|
||
local data = DataManager[GConst.ActivityConst.ACTIVITY_TYPE_DATA[actType]]
|
||
if data then
|
||
if data.initActInfo then
|
||
data:initActInfo(info)-- 初始化基类方法
|
||
end
|
||
data:setActivityInfo(info)-- 初始化子类方法
|
||
end
|
||
end
|
||
|
||
return ActTimeData |