miduo_client/Assets/ManagedResources/~Lua/Modules/GlobalActTimeCtrl/ActTimeCtrlManager.lua

594 lines
20 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

--- 管理游戏所有功能的开关状态
--- Created by Steven.
--- DateTime: 2019/5/9 16:07
ActTimeCtrlManager = {};
local this = ActTimeCtrlManager
local AllActSetConfig = ConfigManager.GetConfig(ConfigName.GlobalSystemConfig)
local censorshipConfig = ConfigManager.GetConfig(ConfigName.MainLevelConfig)
local gameSetConfig = ConfigManager.GetConfig(ConfigName.GameSetting)
local vipConfig = ConfigManager.GetConfig(ConfigName.VipLevelConfig)
local GuideConfig = ConfigManager.GetConfig(ConfigName.GuideConfig)
-- 整数的服务器时间
this.serTime = 0
local lastTime
local count = 0
local sendTime = 0
--时间间隔
local fixedTime = 1
local noVersion = {}
-- 服务数据
this.serData = {}
function this.Initialize()
lastTime = this.serTime
this.hasSendMsg = false
-- 工坊等级提升
Game.GlobalEvent:AddEvent(GameEvent.WorkShow.WorkShopLvChange, function()
local lv = WorkShopManager.WorkShopData.lv
this.CheckFuncActiveByType(3, lv)
end)
-- 等级提升
Game.GlobalEvent:AddEvent(GameEvent.Player.OnLevelChange, function()
local lv = PlayerManager.level
this.CheckFuncActiveByType(2, lv)
end)
-- 关卡解锁
Game.GlobalEvent:AddEvent(GameEvent.Mission.OnOpenFight, function(fightId)
--Log("关卡通关id = "..fightId)
this.CheckFuncActiveByType(1, fightId)
end)
end
-- 当功能解锁条件变化时检测
function this.CheckFuncActiveByType(activeType, params)
local ids = {}
for id, funcData in pairs(this.serData) do
local funcInfo = ConfigManager.GetConfigData(ConfigName.GlobalSystemConfig, id)
if funcInfo.OpenRules[1] == activeType then
local typeId = funcInfo.IsIDdSame
local isActive = this.SingleFuncState(typeId)
--Log("检测功能是否已解锁id = "..id..", isActive = "..tostring(isActive))
local aGuideId = AllActSetConfig[typeId].GuideId
if AllActSetConfig[aGuideId] and AllActSetConfig[aGuideId].IsOpen and AllActSetConfig[aGuideId].IsOpen> 0 then
if ActivityGiftManager.IsActivityTypeOpen(ActivityGiftManager.GetActivityTypeFromId(GuideConfig[aGuideId].IsOpen)) then
table.insert(ids,typeId)
end
elseif not funcData.isActive and isActive then
--Log(">>>>>>功能解锁id = "..funcInfo.Id..", name = "..funcInfo.Name)
-- 未解锁,但是判断已解锁
--Game.GlobalEvent:DispatchEvent(GameEvent.FunctionCtrl.OnFunctionOpen, typeId)
table.insert(ids,typeId)
elseif funcData.isActive and not isActive then
--Log(">>>>>>功能关闭id = "..funcInfo.Id..", name = "..funcInfo.Name)
-- 已解锁但是判断未解锁
--Game.GlobalEvent:DispatchEvent(GameEvent.FunctionCtrl.OnFunctionClose, typeId)
table.insert(ids,typeId)
end
-- 保存状态
funcData.isActive = isActive
end
end
table.sort(ids,function(a,b)
local aGuideId = AllActSetConfig[a].GuideId
local bGuideId = AllActSetConfig[b].GuideId
if (GuideConfig[aGuideId] and GuideConfig[bGuideId]) then
return GuideConfig[aGuideId].Sort < GuideConfig[bGuideId].Sort
elseif (not GuideConfig[aGuideId] and not GuideConfig[aGuideId]) then
return a < b
else
return GuideConfig[aGuideId] and not GuideConfig[bGuideId]
end
end)
for i = 1 ,#ids do
Game.GlobalEvent:DispatchEvent(GameEvent.FunctionCtrl.OnFunctionOpen, ids[i])
end
end
-- 初始化服务器数据
function this.InitMsg(msg)
if #msg.functionOfTime == 0 then Log(Language[10765]) return end
for i = 1, #msg.functionOfTime do
local t = msg.functionOfTime[i]
local id = t.functionId
local startTime = t.startTime
local endTime = t.endTime
local restTime = t.interval
local switch = t.switch
this.serData[id] = {}
this.serData[id].id = id
this.serData[id].startTime = startTime
this.serData[id].endTime = endTime
this.serData[id].restTime = restTime
this.serData[id].switch = switch
LogGreen(string.format("--- 功能解锁数据 id = %s, startTime = %s, endTime = %s, switch = %s",id, startTime, endTime, switch))
-- 用于标记是否解锁使用
local typeId = AllActSetConfig[id].IsIDdSame
this.serData[id].isActive = this.SingleFuncState(typeId)
end
this.WatchFuncState()
end
-- 根据活动类型获取当前活动表数据
local ActTypeConfigList = {} -- 做一个缓存避免重复遍历表数据
function this.GetTableDataByTypeId(typeId)
if not ActTypeConfigList[typeId] then
ActTypeConfigList[typeId] = ConfigManager.GetAllConfigsDataByKey(ConfigName.GlobalSystemConfig, "IsIDdSame", typeId)
end
return ActTypeConfigList[typeId]
end
-- 根据活动类型获取当前活动得数据
function this.GetSerDataByTypeId(typeId)
local configList = this.GetTableDataByTypeId(typeId)
for _, config in ipairs(configList) do
local actId = config.Id
if this.serData[actId] then
return this.serData[actId]
end
end
end
-- ////////////////////////////////////////////////////////////////////////////
-- 根据服务器时间更新
function this.Updata()
if this.serTime ~= lastTime then
lastTime = this.serTime
this.FixedUpDate()
end
end
-- 1秒更新一次
function this.FixedUpDate()
count = count + 1
this.WatchFuncState()
if count == fixedTime then -- 每fixedTime更新一次
count = 0
-- do something
end
if this.hasSendMsg then
sendTime = sendTime + 1
if sendTime >= 5 then
sendTime = 0
this.hasSendMsg = false
end
end
end
-- ///////////////////////////////////////////////////////////////////////////
-- 监测所有活动状态
function this.WatchFuncState()
for i, v in pairs(this.serData) do
local typeId = AllActSetConfig[i].IsIDdSame
if this.IsQualifiled(typeId) then
local timeType = ""
if this.serTime >= v.startTime and this.serTime < v.endTime then
--活动结束倒计时
local closeTime = v.endTime - this.serTime
--local showStr = os.date("%d天%H时%M分%S秒",closeTime)
local showStr = FormatSecond(closeTime)
timeType = Language[10766] .. showStr
else
local openTime = 0
openTime = v.startTime - this.serTime
if openTime > 0 then
--local showStr = os.date("%Y年%M月%d日%H时%M分%S秒", 30)
local showStr = FormatSecond(openTime)
timeType = Language[10767] .. showStr
end
end
this.serData[i].countDown = timeType -- 活动计时文字
this.serData[i].isOpen = this.SingleFuncState(typeId) -- 活动开启状态
-- 活动开启前同步一次状态
if this.serTime == v.startTime + 1 then
if not this.hasSendMsg then
this.hasSendMsg = true
NetManager.GetAllFunState(function ()
Log("服务器返回活动消息")
Game.GlobalEvent:DispatchEvent(GameEvent.FunctionCtrl.OnFunctionOpen, typeId)
end)
end
end
-- 活动结束前同步一次状态
if this.serTime == v.endTime + 1 then
if not this.hasSendMsg then
this.hasSendMsg = true
NetManager.GetAllFunState(function ()
Log("服务器返回活动消息")
Game.GlobalEvent:DispatchEvent(GameEvent.FunctionCtrl.OnFunctionClose, typeId)
end)
end
end
end
end
end
-- ///////////////////////////////////////////////////////////////////////////
-- 检测某一活动开启与否
function this.FuncTimeJudge(id)
local isActive = false
local serData = this.GetSerDataByTypeId(id)
if serData then
local startTime = serData.startTime
local endTime = serData.endTime
if this.serTime >= startTime and this.serTime <= endTime then
isActive = true
else
isActive = false
end
else
end
return isActive
end
-- 活动状态, 返回提示文字
function this.GetFuncTip(id)
local tip = ""
local qualifiled = this.IsQualifiled(id)
local isActive = this.FuncTimeJudge(id)
if noVersion[id] then
tip = Language[10768]
return tip
end
if not qualifiled then
-- 相同活动类型解锁数据相同,所以只用第一个进行判断
local data = this.GetTableDataByTypeId(id)[1]
local rules = data.OpenRules
if rules[1] == 1 then
tip = string.format(Language[10769], GetLanguageStrById(censorshipConfig[rules[2]].Name))
elseif rules[1] == 2 then
tip = string.format(Language[10279], rules[2])
elseif rules[1] == 3 then
tip = string.format("鸿蒙阵共鸣英雄等级达到%s开启", rules[2])
end
else
if not isActive then
if id == FUNCTION_OPEN_TYPE.ARENA then
tip = Language[10772]
else
tip = Language[10773]
end
end
end
return tip
end
-- 活动总状态
function this.SingleFuncState(id)
if id==42066 then
local t=1
end
local isOpen = false
local qualifiled = this.IsQualifiled(id)
local isOpen = this.IsSwitchOpen(id)
local isActive = this.FuncTimeJudge(id)
local isSpecialActive = this.IsSpecialActive(id)
if isOpen and qualifiled and isActive and isSpecialActive then
isOpen = true
else
isOpen = false
end
return isOpen
end
-- 传入活动的ID, 显示活动期间文字
function this.ShowActText(id)
local serData = this.GetSerDataByTypeId(id)
if not serData then return end
-- 如果活动正在进行,返回活动开启结束文字
if this.FuncTimeJudge(id)then
local beginStr = os.date(Language[10774],this.serData[id].startTime)
local endStr = os.date(Language[10774],this.serData[id].endTime)
return beginStr, endStr
else
return Language[10775]
end
end
-- 玩家是否有资格开启
function this.IsQualifiled(id)
-- 相同类型活动解锁类型相同,所以只判断第一个
if id==26001 then
local t=1
end
local data = this.GetTableDataByTypeId(id)[1]
if not data then return false end
if data.IsOpen == 0 then
--Log("此功能不在版本范围内!")
noVersion[id] = true
return false
else
noVersion[id] = false
end
-- 当前玩家等级
local qualifiled = false
local playerLv = PlayerManager.level
local openRule = data.OpenRules
if openRule[1] == 1 then -- 关卡开启
qualifiled = FightPointPassManager.IsFightPointPass(openRule[2])
elseif openRule[1] == 2 then -- 等级开启
qualifiled = playerLv >= openRule[2]
elseif openRule[1] == 3 then -- 鸿蒙阵神将共鸣等级
qualifiled = HarmonyManager.GetSingleAdditions(HarmonyAddType.AddLv) >= openRule[2]
end
--1#创角
--2#开服
-- local curTime=GetTimeStamp()
-- if data.IfOpen then
-- local type=data.IfOpen[1]
-- local dayNum=data.IfOpen[2]
-- if type==1 then
-- if curTime<PlayerManager.userCreateTime+dayNum*24*60*60 then
-- return false
-- end
-- elseif type==2 then
-- if curTime<PlayerManager.GetServerOpenTime()+dayNum*24*60*60 then
-- return false
-- end
-- end
-- end
return qualifiled
end
-- 判断功能是否真的开放
function this.IsSwitchOpen(id)
local serData = this.GetSerDataByTypeId(id)
if serData then
return serData.switch == 0
end
return false
end
--
local SwitchOpenStr = {
[1] = "创角第%s天",
[2] = "开服第%s天"
}
function this.GetSwitchOpenTip(id)
local data = this.GetTableDataByTypeId(id)[1]
if data then
if data.IfOpen then
local t = data.IfOpen[1]
return string.format(SwitchOpenStr[t], data.IfOpen[2])
end
end
return
end
--传入需要锁上的功能, state 为true需要置灰
function this.SetFuncLockState(obj, id, state,isWorkShop)
local isOpen = this.SingleFuncState(id)
if(isWorkShop==true) then
if not isOpen then
if state then
Util.GetGameObject(obj.transform, "maskImage"):SetActive(true)
local data = this.GetTableDataByTypeId(id)[1]
local rules = data.OpenRules
Util.GetGameObject(obj.transform, "maskImage/unLockText"):GetComponent("Text").text=string.format(Language[10771], rules[2])
else
obj:SetActive(false)
end
else
obj:SetActive(true)
Util.GetGameObject(obj.transform, "maskImage"):SetActive(false)
end
else
if not isOpen then
if state then
Util.SetGray(obj, true)
else
obj:SetActive(false)
end
else
obj:SetActive(true)
Util.SetGray(obj, false)
end
end
end
-- ==================== 编队设置 ===============
-- 最大上阵人数
function this.MaxArmyNum()
local num = 0
local formatData = GetLanguageStrById(gameSetConfig[1].HeroLocation)
for i = 1, #formatData do
local judgeType = formatData[i][1]
local value = formatData[i][2]
if judgeType == 1 then -- 关卡判断
local isPass = FightPointPassManager.IsFightPointPass(value)
if isPass then
num = num + 1
end
elseif judgeType == 2 then -- 等级判断
local isPass = PlayerManager.level >= value
if isPass then
num = num + 1
end
end
end
return num
end
-- 上阵位置解锁条件
function this.UnLockCondition(index)
local tip = Language[10776]
local formatData = GetLanguageStrById(gameSetConfig[1].HeroLocation)
local judgeType = formatData[index][1]
local value = formatData[index][2]
if judgeType == 1 then -- 关卡判断
tip = Language[10309] .. GetLanguageStrById(censorshipConfig[value].Name)
elseif judgeType == 2 then -- 等级判断
tip = Language[10777] .. tostring(value) .. Language[10065]
end
return tip
end
-- 下一个解锁可上阵的条件
function this.NextArmCondition()
-- 当前已经解锁的数量
local nextIndex = this.MaxArmyNum() + 1
if nextIndex>= this.MaxArmyNum() then
nextIndex= this.MaxArmyNum()
end
local formatData = GetLanguageStrById(gameSetConfig[1].HeroLocation)
local judgeType = formatData[nextIndex][1]
local value = formatData[nextIndex][2]
local nextTip = Language[10778]
if judgeType == 1 then -- 关卡判断
nextTip = Language[10309] .. GetLanguageStrById(censorshipConfig[value].Name) .. Language[10779]
elseif judgeType == 2 then -- 等级判断
nextTip = Language[10777] .. tostring(value) .. Language[10780]
end
return nextTip
end
-- 获取某模块剩余开放时间 -1 表示未开放/已关闭
function this.GetActLeftTime(typeId)
-- 检测数据正确性
local serData = this.GetSerDataByTypeId(typeId)
if not typeId or not serData then return -1 end
-- 判断时间戳
local curTimeStamp = GetTimeStamp()---毫秒
if curTimeStamp < serData.startTime then --- 时间未到
return -1
end
-- 计算剩余时间
local leftTime = math.floor(serData.endTime - curTimeStamp)
return leftTime
end
-- 获取某模块剩余开放时间 -1 表示未开放/已关闭
function this.GetActEndTime(typeId)
-- 检测数据正确性
local serData = this.GetSerDataByTypeId(typeId)
if not typeId or not serData then return -1 end
return serData.endTime
end
function this.GetActOpenTime(id)
local serData = this.GetSerDataByTypeId(id)
if not serData then return end
if this.SingleFuncState(id) then return end
local openTime = serData.startTime - this.serTime
local str = FormatSecond(openTime)
return str
end
-- 最大上阵异妖数量
function this.MaxDemonNum()
local maxNum = 0
local gameSettingConFig = ConfigManager.GetConfigData(ConfigName.GameSetting,1).DifferLocation
for i = 1, #gameSettingConFig do
if gameSettingConFig[i][1] == 1 then--关卡判断
if FightPointPassManager.IsFightPointPass(gameSettingConFig[i][2]) then
maxNum = maxNum + 1
end
elseif gameSettingConFig[i][1] == 2 then--等级判断
if PlayerManager.level >= gameSettingConFig[i][2] then
maxNum = maxNum + 1
end
end
end
return maxNum
end
-- 开启下一个位置需要的VIP等级, 只有未解锁的才有用
function this.DemonNeedVipLv(index,srtType)
local gameSettingConFig = ConfigManager.GetConfigData(ConfigName.GameSetting,1).DifferLocation
for i = 1, #gameSettingConFig do
if i == index then
if gameSettingConFig[i][1] == 1 then--关卡判断
local str = ""
if srtType == 1 then
str = Language[10309]..string.gsub(GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.MainLevelConfig,gameSettingConFig[i][2]).Name),"-","|")
else
str = Language[10309]..GetLanguageStrById(ConfigManager.GetConfigData(ConfigName.MainLevelConfig,gameSettingConFig[i][2]).Name)
end
return str
elseif gameSettingConFig[i][1] == 2 then--等级判断
return Language[10781]..gameSettingConFig[i][2]
end
end
end
end
-- 异妖上阵数量提示内容
function this.TipText(index)
local tip = this.DemonNeedVipLv(index,2) .. Language[10782]
return tip
end
-- 恶心的副本的单独提示
function this.CarbonOpenTip()
local minFight = 99999
local minLevel = 99999
local openRuleList = {}
-- table.insert(openRuleList, AllActSetConfig[17].OpenRules)
-- table.insert(openRuleList, AllActSetConfig[18].OpenRules)
-- table.insert(openRuleList, AllActSetConfig[30].OpenRules)
-- table.insert(openRuleList, AllActSetConfig[46].OpenRules)
--根据副本里面功能 等级最低的设置提示
table.insert(openRuleList, AllActSetConfig[44].OpenRules)
for i = 1, #openRuleList do
local openRule = openRuleList[i][1]
local openValue = openRuleList[i][2]
if openRule == 1 then
minFight = minFight < openValue and minFight or openValue
elseif openRule == 2 then
minLevel = minLevel < openRule and minLevel or openValue
end
end
local str = ""
if minLevel < 99999 and minFight ~= 99999 then
str = string.format(Language[10783], GetLanguageStrById(censorshipConfig[minFight].Name), minLevel)
elseif minLevel == 99999 then
str = string.format(Language[10784], GetLanguageStrById(censorshipConfig[minFight].Name))
elseif minFight == 99999 then
str = string.format(Language[10785], minLevel)
end
return str
end
--系统开启规则提示 type 开启系统类型
function this.SystemOpenTip(type)
local str=""
if AllActSetConfig[type].OpenRules[1]==1 then
str=string.format(Language[10786],GetLanguageStrById(censorshipConfig[AllActSetConfig[type].OpenRules[2]].Name))
elseif AllActSetConfig[type].OpenRules[1]==2 then
str=string.format(Language[10787],AllActSetConfig[type].OpenRules[2])
elseif AllActSetConfig[type].OpenRules[1]==3 then
str=string.format("鸿蒙阵共鸣英雄等级达到%s开启",AllActSetConfig[type].OpenRules[2])
end
return str
end
-- 一些功能特殊判断
function this.IsSpecialActive(id)
if id == FUNCTION_OPEN_TYPE.WEEK_CARD then
return WeekCardManager.IsWeekCardOpen()
end
return true
end
return this