c1_lua/lua/app/server/data/server_chapter_data.lua
2023-04-20 22:39:43 +08:00

82 lines
1.9 KiB
Lua

local ServerChapterData = class("ServerChapterData", ServerBaseData)
local MIN_CHAPTER_ID = 1
function ServerChapterData:init(data)
self.data.maxChapterId = data and data.maxChapterId or (MIN_CHAPTER_ID - 1)
self.data.chapterBoxInfo = data and data.chapterBoxInfo or {}
self.data.chapterFightInfo = data and data.chapterFightInfo or {}
end
function ServerChapterData:fightChapter(id, victory, wave)
local idStr = tostring(id)
if not self.data.chapterFightInfo[idStr] then
self.data.chapterFightInfo[idStr] = {
victory = false,
maxWave = 0
}
end
local passBefore = self.data.chapterFightInfo[idStr].victory
if victory then
self.data.chapterFightInfo[idStr].victory = victory
end
if wave > self.data.chapterFightInfo[idStr].maxWave then
self.data.chapterFightInfo[idStr].maxWave = wave
end
if not passBefore and victory then
if id > self.data.maxChapterId then
self.data.maxChapterId = id
end
end
end
function ServerChapterData:getChapterBoxRewardGot(chapterId, index)
local idStr = tostring(chapterId)
local list = self.data.chapterBoxInfo[idStr]
if not list then
return false
end
for _, idx in ipairs(list) do
if idx == index then
return true
end
end
return false
end
function ServerChapterData:getChapterBoxRewards(chapterId, index)
local cfg = ConfigManager:getConfig("chapter")[chapterId]
if not cfg then
return
end
return cfg["box_reward_" .. index]
end
function ServerChapterData:openChapterBox(chapterId, index)
local idStr = tostring(chapterId)
local list = self.data.chapterBoxInfo[idStr]
if not list then
self.data.chapterBoxInfo[idStr] = {}
else
for _, idx in ipairs(list) do
if idx == index then
return false
end
end
end
table.insert(self.data.chapterBoxInfo[idStr], index)
return true
end
function ServerChapterData:getMaxChapterId()
return self.data.maxChapterId
end
return ServerChapterData