c1_lua/lua/app/userdata/activity/act_base_data.lua
2025-09-25 20:12:22 +08:00

178 lines
3.7 KiB
Lua

local ActBaseData = class("ActBaseData", BaseData)
-- 必须重写 --------------------------------------------------------------------------------------------------------------
function ActBaseData:setActivityInfo()
Logger.logFatal("不能被调用,必须重写")
end
function ActBaseData:getActNameStr()
return ""
end
-- 通用逻辑 --------------------------------------------------------------------------------------------------------------
function ActBaseData:initActInfo(data)
if self.actId ~= data.actId then
self:tryResetGift(true)
self:tryResetProBought()
self:clear()
end
self.actId = data.actId
self.startTime = data.startTime
self.endTime = data.endTime
self.extraTime = data.extraTime
end
function ActBaseData:getActId()
return self.actId
end
function ActBaseData:setActId(id)
self.actId = id
end
function ActBaseData:clearActId()
self:setActId(nil)
end
function ActBaseData:getStartTime()
return self.startTime
end
function ActBaseData:getEndTime()
return self.endTime
end
function ActBaseData:getExtraTime()
return self.extraTime
end
function ActBaseData:getRemainTime()
if not self:getStartTime() then
return 0
end
local nowTime = Time:getServerTime()
if self:getExtraTime() < nowTime then
return 0
end
return self:getExtraTime() - nowTime
end
function ActBaseData:getNormalRemainTime()
local nowTime = Time:getServerTime()
if self:getEndTime() < nowTime then
return 0
end
return self:getEndTime() - nowTime
end
function ActBaseData:getTotalRemainTime()
local remainTime = self:getNormalRemainTime()
if remainTime <= 0 then
remainTime = self:getRemainTime()
end
return remainTime
end
function ActBaseData:getIsLastDay()
if not self:getStartTime() then
return false
end
local nowTime = Time:getServerTime()
if self:getExtraTime() > nowTime and nowTime >= self:getEndTime() then
return true
end
return false
end
function ActBaseData:getActivityDay()
local time = Time:getDayBeginTimeStamp(self:getStartTime())
return (Time:getServerTime() - time) // GConst.SECONDS_PRE_DAY + 1
end
function ActBaseData:getTimeOpen()
if not self:getStartTime() then
return false
end
local nowTime = Time:getServerTime()
if self:getStartTime() <= nowTime and nowTime <= self:getExtraTime() then
return true
end
return false
end
function ActBaseData:getIsOpen()
if GFunc.isShenhe() then
return false
end
if not ModuleManager:getIsOpen(DataManager.ActivityData:getActOpenKey(), true) then
return false
end
local actId = self:getActId()
if not actId or actId <= 0 then
return false
end
return self:getTimeOpen()
end
function ActBaseData:setLoginRp()
self.loginRp = true
end
function ActBaseData:getLoginRp()
if DataManager.PaymentData:getIsSkipAd() then
return true
end
return not self.loginRp
end
-- 重置礼包购买次数
-- force true重置所有礼包 false只重置免费礼包
function ActBaseData:tryResetGift(force)
local actId = self:getActId()
if not actId or actId <= 0 then
return
end
if EDITOR_MODE then
Logger.logHighlight("重置活动礼包数据 act_id = " .. tostring(actId))
end
DataManager.ActGiftData:tryResetGift(actId, force)
end
function ActBaseData:tryResetProBought()
local actId = self:getActId()
if not actId or actId <= 0 then
return
end
if EDITOR_MODE then
Logger.logHighlight("重置活动战令数据 act_id = " .. tostring(actId))
Logger.logHighlight("重置轮次数据 act_id = " .. tostring(actId))
end
DataManager.ActBountyData:tryResetProBought(actId)
DataManager.ActRoundTaskData:tryResetProBought(actId)
end
-- 今日已买次数
function ActBaseData:getTodayExchangeCount(id)
return DataManager.ActivityData:getExchangeCount(id)
end
return ActBaseData