2023-07-14 19:35:33 +00:00
|
|
|
|
XDlcConfig = XDlcConfig or {}
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
local TABLE_DLC_LIST_PATH = "Client/DlcRes/DlcList.tab"
|
|
|
|
|
local TABLE_PATHC_CONFIG_PATH = "Client/DlcRes/PatchConfig.tab"
|
2023-07-14 19:35:33 +00:00
|
|
|
|
local TABLE_UNPATCH_CONFIG_PATH = "Client/DlcRes/UnPatchConfig.tab"
|
|
|
|
|
|
|
|
|
|
local DlcListConfig = nil
|
|
|
|
|
local PatchConfig = nil
|
|
|
|
|
local UnPatchConfig = nil
|
|
|
|
|
|
|
|
|
|
local EntryDlcIdMap = nil
|
|
|
|
|
local StageIdMap = nil
|
2024-09-01 20:49:41 +00:00
|
|
|
|
local RootId2DlcListIds -- 根节点 -> 子节点列表
|
2023-07-14 19:35:33 +00:00
|
|
|
|
|
|
|
|
|
local EntryType = {
|
2024-09-01 20:49:41 +00:00
|
|
|
|
MainChapter = 1, -- 主线 参数:章节id(chapterMain.Id),配置在 Share/Fuben/MainLine/ChapterMain.tab
|
|
|
|
|
ShortStory = 2, -- 浮点纪实 参数:章节id 配置:Share/Fuben/ShortStory/ShortStoryChapter.tab
|
|
|
|
|
Prequel = 3, -- 间章旧闻 参数:章节ChapterId 配置:Share/Fuben/Prequel/Chapter.tab
|
|
|
|
|
FestivalActivity = 4, -- 活动记录 参数:活动Id 配置:Share/Fuben/Festival/FestivalActivity.tab
|
|
|
|
|
CharacterTower = 5, -- 本我回廊 参数:活动Id 配置:Share/Fuben/CharacterTower/CharacterTower.tab
|
|
|
|
|
ExtraChapter = 6, -- 外篇旧闻 参数:活动Id 配置:Share/Fuben/ExtraChapter/ChapterExtra.tab
|
|
|
|
|
Challenge = 7, -- 挑战 参数:挑战类型(XFubenManager.ChapterType),定义在 Share/Fuben/FubenChallengeBanner.tab
|
|
|
|
|
Archive = 8, -- 图鉴 参数:默认0
|
|
|
|
|
CharacterVoice = 9, -- 角色语音 参数:默认0
|
2023-07-14 19:35:33 +00:00
|
|
|
|
}
|
|
|
|
|
XDlcConfig.EntryType = EntryType
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XDlcConfig.DownloadState = {
|
|
|
|
|
Ready = 1, --准备下载
|
|
|
|
|
InProgress = 2, --下载中
|
|
|
|
|
Pause = 3, --暂停
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XDlcConfig.RoodId = {
|
|
|
|
|
MainLine = 100, --主线
|
|
|
|
|
BranchLine = 200, --支线
|
|
|
|
|
Challenge = 300, --挑战
|
|
|
|
|
Other = 400, --其他
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local ChapterType2EntryType
|
|
|
|
|
|
|
|
|
|
local DlcResourceType = CS.XFightResourceManager.XStageResourceType
|
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
function XDlcConfig.Init()
|
|
|
|
|
DlcListConfig = XTableManager.ReadByIntKey(TABLE_DLC_LIST_PATH, XTable.XTableDlcList, "Id")
|
|
|
|
|
PatchConfig = XTableManager.ReadByIntKey(TABLE_PATHC_CONFIG_PATH, XTable.XTablePatchConfig, "Id")
|
|
|
|
|
UnPatchConfig = XTableManager.ReadByIntKey(TABLE_UNPATCH_CONFIG_PATH, XTable.XTableUnPatchConfig, "Id")
|
|
|
|
|
|
|
|
|
|
EntryDlcIdMap = {}
|
2024-09-01 20:49:41 +00:00
|
|
|
|
RootId2DlcListIds = {}
|
2023-07-14 19:35:33 +00:00
|
|
|
|
for id, config in pairs(DlcListConfig) do
|
2024-09-01 20:49:41 +00:00
|
|
|
|
local entryType = config.EntryType
|
|
|
|
|
if not EntryDlcIdMap[entryType] then
|
|
|
|
|
EntryDlcIdMap[entryType] = {}
|
|
|
|
|
end
|
|
|
|
|
EntryDlcIdMap[entryType][config.EntryParam] = id
|
|
|
|
|
local rootId = config.RootId
|
|
|
|
|
if rootId == 0 then
|
|
|
|
|
RootId2DlcListIds[id] = RootId2DlcListIds[id] or {}
|
|
|
|
|
else
|
|
|
|
|
RootId2DlcListIds[rootId] = RootId2DlcListIds[rootId] or {}
|
|
|
|
|
table.insert(RootId2DlcListIds[rootId], id)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
XDlcConfig.InitPatchConfig()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XDlcConfig.InitPatchConfig()
|
2023-07-14 19:35:33 +00:00
|
|
|
|
StageIdMap = {}
|
2024-09-01 20:49:41 +00:00
|
|
|
|
for dlcId, config in pairs(PatchConfig) do
|
|
|
|
|
local resourceType = config.ResourceType
|
|
|
|
|
for index, rType in ipairs(resourceType or {}) do
|
|
|
|
|
local types = string.Split(rType, "|")
|
|
|
|
|
for _, t in ipairs(types or {}) do
|
|
|
|
|
if string.IsNilOrEmpty(t) then
|
|
|
|
|
goto continue
|
|
|
|
|
end
|
|
|
|
|
if DlcResourceType then
|
|
|
|
|
local enumValue = DlcResourceType.__CastFrom(tonumber(t))
|
|
|
|
|
if enumValue == DlcResourceType.File or enumValue == DlcResourceType.Directory then
|
|
|
|
|
goto continue
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local param = config.ResourceParam[index]
|
|
|
|
|
local stageIds = string.Split(param, "|")
|
|
|
|
|
for _, stageId in ipairs(stageIds or {}) do
|
|
|
|
|
local stageIdNum = not string.IsNilOrEmpty(stageId) and tonumber(stageId)
|
|
|
|
|
if stageIdNum then
|
|
|
|
|
StageIdMap[stageIdNum] = StageIdMap[stageIdNum] or {}
|
|
|
|
|
StageIdMap[stageIdNum][dlcId] = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
::continue::
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--调试模式
|
|
|
|
|
if XMain.IsDebug then
|
|
|
|
|
local checkMap = {}
|
|
|
|
|
for stageId, temp in pairs(StageIdMap) do
|
|
|
|
|
for dlcId, _ in pairs(temp) do
|
|
|
|
|
checkMap[stageId] = checkMap[stageId] or {}
|
|
|
|
|
table.insert(checkMap[stageId], dlcId)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local log = ""
|
|
|
|
|
for stageId, list in pairs(checkMap) do
|
|
|
|
|
if #list >= 2 then
|
|
|
|
|
log = string.format("%s关卡Id:%s -> PatchIdList = %s\n", log, stageId, table.concat(list, ","))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not string.IsNilOrEmpty(log) then
|
|
|
|
|
XLog.Error("PatchConfig.tab关卡Id重复:", log)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XDlcConfig.GetDlcListConfig()
|
|
|
|
|
return DlcListConfig
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XDlcConfig.GetPatchConfig()
|
|
|
|
|
return PatchConfig
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XDlcConfig.GetUnPatchConfig()
|
|
|
|
|
return UnPatchConfig
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XDlcConfig.GetListConfigById(id)
|
|
|
|
|
local config = DlcListConfig[id]
|
|
|
|
|
if not config then
|
|
|
|
|
XLog.ErrorTableDataNotFound("XDlcConfig.GetListConfigById",
|
|
|
|
|
"DlcList", TABLE_DLC_LIST_PATH, "Id", tostring(id))
|
|
|
|
|
end
|
|
|
|
|
return config
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
function XDlcConfig.GetDlcListIdsByRootId(rootId)
|
|
|
|
|
return RootId2DlcListIds[rootId] or {}
|
|
|
|
|
end
|
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
|
-- 根据功能入口获取分包id
|
|
|
|
|
function XDlcConfig.GetDlcIdsByEntry(entryType, entryParam)
|
2024-09-01 20:49:41 +00:00
|
|
|
|
entryParam = entryParam or 0
|
2023-07-14 19:35:33 +00:00
|
|
|
|
if EntryDlcIdMap[entryType] then
|
|
|
|
|
local dlcId = EntryDlcIdMap[entryType][entryParam]
|
|
|
|
|
if dlcId then
|
|
|
|
|
return DlcListConfig[dlcId].PatchConfigIds
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
XLog.Debug("尝试根据[功能入口]或取分包id, 失败: entryType:" .. tostring(entryType) .. ", entryParam:" .. tostring(entryParam))
|
|
|
|
|
end
|
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
|
--根据关卡Id获取DlcListId
|
|
|
|
|
function XDlcConfig.GetDlcListIdByStageId(stageId)
|
|
|
|
|
local dlcIdMap = StageIdMap[stageId]
|
|
|
|
|
if XTool.IsTableEmpty(dlcIdMap) then
|
|
|
|
|
return {}
|
|
|
|
|
end
|
|
|
|
|
local dlcListIds = {}
|
|
|
|
|
for dlcListId, config in pairs(DlcListConfig) do
|
|
|
|
|
local dlcIds = config.PatchConfigIds
|
|
|
|
|
for _, dId in ipairs(dlcIds or {}) do
|
|
|
|
|
if dlcIdMap[dId] then
|
|
|
|
|
table.insert(dlcListIds, dlcListId)
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
return dlcListIds
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--根据功能入口获取Id
|
|
|
|
|
function XDlcConfig.GetDlcListIdByEntry(entryType, entryParam)
|
|
|
|
|
entryParam = entryParam or 0
|
|
|
|
|
if EntryDlcIdMap[entryType] then
|
|
|
|
|
local dlcId = EntryDlcIdMap[entryType][entryParam]
|
|
|
|
|
if dlcId then
|
|
|
|
|
return dlcId
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XDlcConfig.GetEntryTypeByChapterType(chapterType)
|
|
|
|
|
if not ChapterType2EntryType then
|
|
|
|
|
ChapterType2EntryType = {
|
|
|
|
|
[XFubenConfigs.ChapterType.MainLine] = EntryType.MainChapter,
|
|
|
|
|
[XFubenConfigs.ChapterType.ShortStory] = EntryType.ShortStory,
|
|
|
|
|
[XFubenConfigs.ChapterType.Prequel] = EntryType.Prequel,
|
|
|
|
|
[XFubenConfigs.ChapterType.Festival] = EntryType.FestivalActivity,
|
|
|
|
|
[XFubenConfigs.ChapterType.CharacterTower] = EntryType.CharacterTower,
|
|
|
|
|
[XFubenConfigs.ChapterType.ExtralChapter] = EntryType.ExtraChapter,
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
local entryType = ChapterType2EntryType[chapterType]
|
|
|
|
|
if not entryType then
|
|
|
|
|
XLog.Error("[DLC] not found entryType! chapterType = " .. chapterType)
|
|
|
|
|
return 0
|
|
|
|
|
end
|
|
|
|
|
return entryType
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function XDlcConfig.GetSizeAndUnit(size)
|
|
|
|
|
local unit = "KB"
|
|
|
|
|
local num = size / 1024
|
|
|
|
|
if num > 100 then
|
|
|
|
|
unit = "MB"
|
|
|
|
|
num = num / 1024
|
2023-07-14 19:35:33 +00:00
|
|
|
|
end
|
2024-09-01 20:49:41 +00:00
|
|
|
|
return math.ceil(num), unit
|
|
|
|
|
end
|