local ActivityData = class("ActivityData", BaseData) function ActivityData:ctor() end function ActivityData:clear() self.checkedUIMap = nil self.taskData = nil self.taskIds = nil end function ActivityData:setDirty() self.data.isDirty = not self.data.isDirty end function ActivityData:getActOpenKey() return ModuleManager.MODULE_KEY.ACT_ALL_OPEN end function ActivityData:init(data) data = data or {} end function ActivityData:initActivityData(actId, data) if EDITOR_MODE then Logger.logHighlight("初始化活动任务数据:" .. actId) Logger.printTable(data) end if self.taskData == nil then self.taskData = {} end for i, info in pairs(data) do if self.taskData[actId] == nil then self.taskData[actId] = {} end self.taskData[actId][info.id] = info end end --region 兑换相关 function ActivityData:initExchangeData(data) if EDITOR_MODE then Logger.logHighlight("活动的兑换数据") Logger.printTable(data) end self.exchangeData = data and data.exchange_count or {} self.exchangeTime = data and data.exchange_at or {} end -- 获取已兑换次数 function ActivityData:getExchangeCount(id) if self.exchangeData == nil then return 0 end return self.exchangeData[id] or 0 end function ActivityData:onActivityExchange(id, count) if self.exchangeData == nil then return end if not self.exchangeData[id] then self.exchangeData[id] = 0 end self.exchangeData[id] = self.exchangeData[id] + (count or 0) self.exchangeTime[id] = Time:getServerTime() self:setDirty() end function ActivityData:getExchangeTime(id) if self.exchangeTime == nil then return 1 end return self.exchangeTime[id] or 1 end --endregion --region 任务 function ActivityData:initTaskData(scoreData, normalData) scoreData = scoreData or {} normalData = normalData or {} if EDITOR_MODE then Logger.logHighlight("活动任务数据") Logger.printTable(scoreData) Logger.printTable(normalData) end self.taskData = self.taskData or {} self.taskDataScore = self.taskDataScore or {} for i, info in ipairs(normalData.task_data) do self.taskData[info.activity_id] = self.taskData[info.activity_id] or {} self.taskData[info.activity_id][info.data.id] = info.data end for i, info in ipairs(scoreData.task_data) do self.taskDataScore[info.activity_id] = self.taskDataScore[info.activity_id] or {} self.taskDataScore[info.activity_id] = info self.taskDataScore[info.activity_id].claimedMap = {} for _, taskId in ipairs(info.claimed) do self.taskDataScore[info.activity_id].claimedMap[taskId] = true end end if not self.isInit then self.isInit = true -- 监听任务 for id, info in pairs(self:getTaskConfig()) do ModuleManager.TaskManager:registerTask("ActivityData", info.type, function(count) self:addTaskProgressCallback(info.type, count) self:addTaskProgressCallbackScore(info.type, count) end) end -- 跨天 DataManager:registerCrossDayFunc("ActivityData", function() self:setDirty() end) end end --region 普通任务 function ActivityData:addTaskProgressCallback(taskType, count) for actId, data in pairs(self.taskData) do for i, taskId in ipairs(self:getAllTaskIdsByActId(actId)) do if self:getTaskType(taskId) == taskType and self:getTaskDisplay(taskId) == 2 then self:addTaskProgress(actId, taskId, count) end end end end -- 添加任务进度 function ActivityData:addTaskProgress(actId, taskId, count) if not self:isTaskFinished(actId, taskId) then local taskType = self:getTaskType(taskId) local data = self:getTaskData(actId, taskId) if table.containValue(GConst.TaskConst.RELPACE_TASK_TYPE, taskType) then data.progress = math.max(data.progress or 0, count) else data.progress = (data.progress or 0) + count end end self:setDirty() end function ActivityData:getTaskData(actId, taskId) if taskId then self.taskData[actId] = self.taskData[actId] or {} if self.taskData[actId][taskId] == nil then self.taskData[actId][taskId] = {id = taskId, progress = 0, claimed = 0} end return self.taskData[actId][taskId] else return self.taskData[actId] end end -- 获取活动全部任务id function ActivityData:getAllTaskIdsByActId(actId) self.taskIds = self.taskIds or {} if self.taskIds[actId] == nil then self.taskIds[actId] = {} for id, info in pairs(self:getTaskConfig()) do if self:getActId(id) == actId then table.insert(self.taskIds[actId], id) end end table.sort(self.taskIds, function(a, b) return a.id < b.id end) end return self.taskIds[actId] end -- 获取任务当前进度 function ActivityData:getTaskProg(actId, taskId) taskId = tonumber(taskId) local data = self:getTaskData(actId, taskId) return data and data.progress or 0 end -- 任务是否已领取 function ActivityData:isTaskReceived(actId, taskId) taskId = tonumber(taskId) local data = self:getTaskData(actId, taskId) return data and data.claimed and data.claimed > 0 end -- 任务是否已完成 function ActivityData:isTaskFinished(actId, taskId) return self:getTaskProg(actId, taskId) >= self:getTaskTarget(taskId) end -- 任务是否可领取 function ActivityData:canClaimTask(actId, taskId) return self:isTaskFinished(actId, taskId) and not self:isTaskReceived(actId, taskId) end -- 重置任务数据 function ActivityData:resetTaskData(actId) for taskId, data in pairs(self:getTaskData(actId)) do data.claimed = 0 data.progress = 0 end self:setDirty() end -- 领奖成功 function ActivityData:onTaskClaimed(actId, taskId) local data = self:getTaskData(actId, taskId) data.claimed = 1 self:setDirty() end -- 普通任务列表 function ActivityData:getTaskSortList(actId) local list = {} local cfg = self:getTaskConfig() for taskId, info in pairs(cfg) do if info.activity == actId and info.display == 2 then local info = {} info.id = taskId info._sort = 1000000 - taskId if self:canClaimTask(actId, taskId) then info._sort = info._sort + 100000000 end if not self:isTaskFinished(actId, taskId) then info._sort = info._sort + 10000000 end table.insert(list, info) end end table.sort(list, function(a, b) -- 已完成(可领奖) > 进行中 > 已完成(已领奖) > id return a._sort > b._sort end) return list end --endregion --region 积分任务 -- 达标任务 function ActivityData:getTaskIdListScore(actId) local cfg = self:getTaskConfig() local actTaskList = {} for taskId, info in pairs(cfg) do if info.activity == actId and info.display == 1 then table.insert(actTaskList, taskId) end end return actTaskList end function ActivityData:addTaskProgressCallbackScore(taskType, count) for actId, data in pairs(self.taskDataScore) do local actTaskList = self:getTaskIdListScore(actId) if actTaskList and actTaskList[1] then if self:getTaskType(actTaskList[1]) == taskType then data.score = (data.score or 0) + count end end end end -- 添加任务进度 function ActivityData:addTaskProgressScore(actId, taskId, count) if not self:isTaskFinishedScore(actId, taskId) then self.taskDataScore[actId].score = (self.taskDataScore[actId].score or 0) + count end self:setDirty() end function ActivityData:getTaskNumScore(actId, actTaskId) if self:getTaskDisplay(actTaskId) == 1 then return self.taskDataScore[actId].score or 0 else return self.taskData[actTaskId] or 0 end end function ActivityData:getMaxTurnScore(actId) return GConst.ActSprintConst.ACT_ROUND_LIMIT[actId] end function ActivityData:getRewardsgetMaxTurnScore(actId) return GConst.ActSprintConst.ACT_ROUND_REWARD[actId] end function ActivityData:getHasGotTaskRewardScore(actId, actTaskId) return self.taskDataScore[actId].round >= self:getMaxTurnScore(actId) or self.taskDataScore[actId].claimedMap[actTaskId] end function ActivityData:getTaskDataScore(actId) return self.taskDataScore[actId] or {activity_id = actId, score = 0, total_score = 0, round = 0, round_claimed = 0, claimed = {}} end -- 获取任务当前进度 function ActivityData:getTaskProgScore(actId) local data = self:getTaskDataScore(actId) return data and data.score or 0 end -- 任务是否已完成 function ActivityData:isTaskFinishedScore(actId, taskId) return self:getTaskProgScore(actId) >= self:getTaskTarget(taskId) end function ActivityData:getTurnLimitScore(actId) local scoreLimit = 0 local list = self:getTaskIdListScore(actId) for _, id in ipairs(list) do local cfg = self:getTaskConfig(id) if cfg then if self:getTaskTarget(id) > scoreLimit then scoreLimit = self:getTaskTarget(id) end end end return scoreLimit end -- 特定任务是否可领奖 function ActivityData:getCanGetTaskRewardScore(actId, actTaskId) if not self:getHasGotTaskRewardScore(actId, actTaskId) and self:getTaskNumScore(actId, actTaskId) >= self:getTaskTarget(actTaskId) then return true else return false end end function ActivityData:getCanGetTurnRewardScore(actId) actId = actId or self.actId -- 当前任务全部领取 未领取当前波次奖励 if (self:getClaimedTurnScore(actId) < self:getTurnScore(actId)) then return true else return false end end -- 是否已经领完了全部的轮次奖励 function ActivityData:getGotAllTurnRewardScore(actId) local claimed = self:getClaimedTurnScore(actId) or 0 local maxTurn = self:getMaxTurnScore(actId) return claimed >= maxTurn end function ActivityData:getTurnScore(actId) return self.taskDataScore[actId].round or 0 end function ActivityData:getClaimedTurnScore(actId) return self.taskDataScore[actId].round_claimed or 0 end -- 成功领取轮次奖励 function ActivityData:onGetTurnRewardScore(actId) self.taskDataScore[actId].round_claimed = (self.taskDataScore[actId].round_claimed or 0) + 1 self:setDirty() end -- 领取任务成功 function ActivityData:onTaskSuccessScore(actId, actTaskId) self.taskDataScore[actId] = self.taskDataScore[actId] or {} if actTaskId and actTaskId > 0 then self.taskDataScore[actId].claimedMap[actTaskId] = true else local list = self:getTaskIdListScore(actId) for _, id in ipairs(list) do if self:getCanGetTaskRewardScore(actId, id) then self.taskDataScore[actId].claimedMap[id] = true end end end -- 如果所有任务都领取了 增加轮次 local list = self:getTaskIdListScore(actId) local isAllGot = true for _, id in ipairs(list) do if not self:getHasGotTaskRewardScore(actId, id) then isAllGot = false break end end if isAllGot then self.taskDataScore[actId].round = (self.taskDataScore[actId].round or 0) + 1 self.taskDataScore[actId].claimedMap = {} self.taskDataScore[actId].score = self.taskDataScore[actId].score - self:getTurnLimitScore(actId) end self:setDirty() end -- 达标任务列表 function ActivityData:getActTaskListScore(actId) local list = {} local cfg = self:getTaskConfig() for taskId, info in pairs(cfg) do if info.activity == actId and info.display == 1 then table.insert(list, taskId) end end table.sort(list, function(a, b) -- 已完成(可领奖) > 进行中 > 已完成(已领奖) > id local canGetA = self:getCanGetTaskRewardScore(actId, a) local canGetB = self:getCanGetTaskRewardScore(actId, b) if canGetA == canGetB then local gotA = self:getHasGotTaskRewardScore(actId, a) local gotB = self:getHasGotTaskRewardScore(actId, b) if gotA == gotB then return a < b else return gotB end else return canGetA end end) return list end --endregion --endregion --region 任务配置 function ActivityData:getTaskConfig(taskId) if taskId then return ConfigManager:getConfig("act_task")[taskId] else return ConfigManager:getConfig("act_task") end end -- 获取任务活动id function ActivityData:getActId(taskId) return self:getTaskConfig(taskId).activity end -- 获取任务类型 function ActivityData:getTaskType(taskId) return self:getTaskConfig(taskId).type end -- 获取任务目标 function ActivityData:getTaskTarget(taskId) return self:getTaskConfig(taskId).number_1 end -- 获取任务奖励 function ActivityData:getTaskReward(taskId) return self:getTaskConfig(taskId).reward end -- 获取任务展示要求 function ActivityData:getTaskDisplay(taskId) return self:getTaskConfig(taskId).display end function ActivityData:getTaskI18NName(taskId) return ConfigManager:getConfig("act_task")[taskId].desc end --endregion --endregion function ActivityData:initSkipPopInfo() self.loginPopSkipFlag = false local flag = LocalData:getSkipPopFlag() self.loginPopSkipFlag = flag == 1 local lastTime = LocalData:getSkipPopUITime() if lastTime ~= Time:getBeginningOfServerToday() then self.loginPopSkipFlag = false self.theDayFirstLogin = true flag = 0 else self.theDayFirstLogin = false end LocalData:setSkipPopFlag(flag) LocalData:setSkipPopUITime() end function ActivityData:getLoginPopSkipFlag() -- if not GFunc.IsGotServerTime() then -- return false -- end if self.loginPopSkipFlag == nil then self:initSkipPopInfo() end return self.loginPopSkipFlag end function ActivityData:setLoginPopSkipFlag(value) if self.loginPopSkipFlag == value then return end self.loginPopSkipFlag = value local flag = 0 if self.loginPopSkipFlag then flag = 1 end LocalData:setSkipPopFlag(flag) LocalData:setSkipPopUITime() end function ActivityData:getTheDayFirstLogin() -- if not GFunc.IsGotServerTime() then -- return false -- end if self.theDayFirstLogin == nil then self:initSkipPopInfo() end return self.theDayFirstLogin end ---- 进入过某个界面 function ActivityData:getCheckUI(moduleName) if not self.checkedUIMap then return false end return self.checkedUIMap[moduleName] end function ActivityData:setCheckUI(moduleName) if not moduleName then return end if not self.checkedUIMap then self.checkedUIMap = {} end self.checkedUIMap[moduleName] = true end ---- 活动通用接口 function ActivityData:getActConfig(actId) if actId then return ConfigManager:getConfig("activity")[actId] else return ConfigManager:getConfig("activity") end end -- 判定活动是否存在 function ActivityData:getActExist(actId) return self:getActConfig(actId) ~= nil end -- 判定活动类型 function ActivityData:getActType(actId) if not self:getActExist(actId) then return end return self:getActConfig(actId).act_type end -- 获取活动ui类型 function ActivityData:getActUIType(actId) if not self:getActExist(actId) then return end return self:getActConfig(actId).ui_type end -- 获得活动时间类型 function ActivityData:getActTimeType(actId) if not self:getActExist(actId) then return end return self:getActConfig(actId).time_type end function ActivityData:getActCfgStartTime(actId) if not self:getActExist(actId) then return 0 end return self:getActConfig(actId).start_time_1 or 0 end function ActivityData:getActCfgEndTime(actId) if not self:getActExist(actId) then return 0 end return self:getActConfig(actId).end_time_1 or 0 end function ActivityData:getActCfgExtraTime(actId) if not self:getActExist(actId) then return 0 end return self:getActConfig(actId).extra_time_1 or 0 end function ActivityData:getActCfgStartTime2(actId) if not self:getActExist(actId) then return 0 end return self:getActConfig(actId).start_time_2 end function ActivityData:getActCfgEndTime2(actId) if not self:getActExist(actId) then return 0 end return self:getActConfig(actId).end_time_2 end function ActivityData:getActCfgExtraTime2(actId) if not self:getActExist(actId) then return 0 end return self:getActConfig(actId).extra_time_2 end function ActivityData:getTurntableAdCount(actId) if not self:getActExist(actId) then return 0 end return self:getActConfig(actId).ad_times or 0 end function ActivityData:getActFuncOpen(actId) if not self:getActExist(actId) then return end return self:getActConfig(actId).func_open end -- 获取活动开始是否忽略创号天数 function ActivityData:getActIgnoreCreateDay(actId) if not self:getActExist(actId) then return end return self:getActConfig(actId).circle_limit end -- 获取活动相关内容是否可展示 function ActivityData:canShowActContent(actId) if actId == nil then return true end if not self:getActExist(actId) then return true end local startTime, endTime, extraTime = self:getActTimeInfo(actId) local hour = GFunc.getConstIntValue("act_show_cultivation_time") return Time:getServerTime() >= (startTime - hour * 3600) end -- 获取活动时间配置信息 function ActivityData:getActTimeInfo(actId) if actId == nil then return nil, nil, nil end if not self:getActExist(actId) then return nil, nil, nil end local startDay = self:getActCfgStartTime(actId) local endDay = self:getActCfgEndTime(actId) local extraDay = self:getActCfgExtraTime(actId) local startDay2 = self:getActCfgStartTime2(actId) local endDay2 = self:getActCfgEndTime2(actId) local extraDay2 = self:getActCfgExtraTime2(actId) local timeType = self:getActTimeType(actId) local startTime = 0 local endTime = 0 local extraTime = 0 if timeType == 1 then -- 开服时间 startTime = DataManager.PlayerData:getServerOpenBeginTime() startTime = startTime + (startDay - 1) * 86400 endTime = startTime + endDay * 86400 extraTime = endTime + extraDay * 86400 elseif timeType == 2 then -- 建号时间 startTime = DataManager.PlayerData:getCreatePlayerBeginTime() startTime = startTime + (startDay - 1) * 86400 endTime = startTime + endDay * 86400 extraTime = endTime + extraDay * 86400 elseif timeType == 3 then -- 固定时间 startTime = Time:getCertainTimeByStr(startDay2) endTime = Time:getCertainTimeByStr(endDay2) extraTime = Time:getCertainTimeByStr(extraDay2) end -- Logger.logHighlight(actId) -- Logger.logHighlight(startTime) -- Logger.logHighlight(endTime) return startTime, endTime, extraTime end -- 活动是否在开启时间 function ActivityData:getActIsOpen(actId) local startTime, endTime = self:getActTimeInfo(actId) if startTime == nil or endTime == nil then return false end return Time:getServerTime() >= startTime and Time:getServerTime() <= endTime end -- 活动是否已经结束 function ActivityData:getActIsOver(actId) local startTime, endTime = self:getActTimeInfo(actId) if startTime == nil or endTime == nil then return false end return Time:getServerTime() >= endTime end -- 获得活动时间戳, 返回即将开的下一次的时间戳 function ActivityData:getActStampTime(actId, customStartTime) if not self:getActExist(actId) then return end local config = self:getActConfig(actId) local duration local pause if config.circle then duration = config.circle[1] pause = config.circle[2] end local startDay = self:getActCfgStartTime(actId) local endDay = self:getActCfgEndTime(actId) local extraDay = self:getActCfgExtraTime(actId) local timeType = self:getActTimeType(actId) local openDay = 1 if timeType == 1 then -- 开服时间 openDay = DataManager.PlayerData:getServerOpenDay() elseif timeType == 2 then -- 建号时间 openDay = DataManager.PlayerData:getCreateDay() else pause = nil end if pause then if customStartTime then local startTime = customStartTime + duration * 86400 + pause * 86400 local endTime = startTime + duration * 86400 local extraTime = endTime + extraDay * 86400 return startTime, endTime, extraTime end while (startDay <= endDay) do if startDay >= openDay then -- 即将开 break -- elseif startDay <= openDay and (endDay + extraDay) > openDay then -- 正在开 -- break else startDay = startDay + duration + pause end end end local startTime = 0 local endTime = 0 local extraTime = 0 if timeType == 1 then -- 开服时间 startTime = DataManager.PlayerData:getServerOpenBeginTime() startTime = startTime + (startDay - 1) * 86400 endTime = startTime + endDay * 86400 extraTime = endTime + extraDay * 86400 elseif timeType == 2 then -- 建号时间 startTime = DataManager.PlayerData:getCreatePlayerBeginTime() startTime = startTime + (startDay - 1) * 86400 endTime = startTime + endDay * 86400 extraTime = endTime + extraDay * 86400 elseif timeType == 3 then -- 固定时间 startTime = DataManager.ActTimeData:getActStartTime(actId) or 0 endTime = DataManager.ActTimeData:getActEndTime(actId) or 0 extraTime = DataManager.ActTimeData:getActExtraTime(actId) or 0 if startTime < Time:getServerTime() then -- 只需要即将开的 startTime = 0 endTime = 0 extraTime = 0 end elseif timeType == 4 then -- 基于固定时间顺延(服务器已处理,同3一样即可) startTime = DataManager.ActTimeData:getActStartTime(actId) or 0 endTime = DataManager.ActTimeData:getActEndTime(actId) or 0 extraTime = DataManager.ActTimeData:getActExtraTime(actId) or 0 if startTime < Time:getServerTime() then -- 只需要即将开的 startTime = 0 endTime = 0 extraTime = 0 end end return startTime, endTime, extraTime end function ActivityData:getActPushInfo() if not ModuleManager:getIsOpen(DataManager.ActivityData:getActOpenKey(), true) then return end local nextOpenInfo = {} local nextExtraInfo = {} -- 只会在当前开着的活动中查找 local ids = self:getCurVersionIDs() local curTime = Time:getServerTime() for actType, info in pairs(DataManager.ActTimeData:getActTypeTimeList()) do local config = self:getActConfig(info.actId) if config.begin_mail and info.startTime > curTime then table.insert(nextOpenInfo, {actId = info.actId, actType = config.act_type, startTime = info.startTime, endTime = info.endTime, extraTime = info.extraTime}) elseif config.end_mail and info.startTime <= curTime and info.endTime > curTime then table.insert(nextExtraInfo, {actId = info.actId, actType = config.act_type, startTime = info.startTime, endTime = info.endTime, extraTime = info.extraTime}) else for _, id in ipairs(ids) do local newConfig = self:getActConfig(id) if newConfig.begin_mail and id >= info.actId and newConfig.type == actType then local startTime, endTime, extraTime = self:getActStampTime(id, info.startTime) if startTime and startTime > curTime then table.insert(nextOpenInfo, {actId = id, actType = config.act_type, startTime = startTime, endTime = endTime, extraTime = extraTime}) end end end end end return nextOpenInfo, nextExtraInfo end function ActivityData:getCurVersionIDs() if not self.curVersionIds then self.curVersionIds = {} local versionIds = {} for id, info in pairs(self:getActConfig()) do if info.version then if not versionIds[info.version] then versionIds[info.version] = {} end table.insert(versionIds[info.version], id) end end local version = 0 for v, list in pairs(versionIds) do if v > version then self.curVersionIds = list end end end return self.curVersionIds end function ActivityData:tryResetActItem(actId) local cfg = self:getActConfig(actId) if cfg and cfg.parameter then local clearItemIds = cfg.parameter for i, id in ipairs(clearItemIds) do DataManager.BagData.ItemData:clearItemById(id) end end end return ActivityData