137 lines
3.1 KiB
Lua
137 lines
3.1 KiB
Lua
local ChapterData = class("ChapterData", BaseData)
|
|
|
|
local MIN_CHAPTER_ID = 1
|
|
|
|
function ChapterData:ctor()
|
|
self.data.chapterId = MIN_CHAPTER_ID
|
|
self.data.maxChapterId = 0
|
|
self.data.isDirty = false
|
|
self.data.chapterBoxInfo = {}
|
|
self.data.chapterFightInfo = {}
|
|
end
|
|
|
|
function ChapterData:clear()
|
|
self.data.chapterId = MIN_CHAPTER_ID
|
|
self.data.maxChapterId = 0
|
|
self.data.chapterBoxInfo = {}
|
|
self.data.chapterFightInfo = {}
|
|
end
|
|
|
|
function ChapterData:init(data)
|
|
self.data.chapterId = data and data.chapterId or MIN_CHAPTER_ID
|
|
self.data.maxChapterId = data and data.maxChapterId or self.data.chapterId - 1
|
|
self.data.chapterBoxInfo = data and data.chapterBoxInfo or {}
|
|
self.data.chapterFightInfo = data and data.chapterFightInfo or {}
|
|
end
|
|
|
|
function ChapterData:setDirty()
|
|
self.data.isDirty = not self.data.isDirty
|
|
end
|
|
|
|
function ChapterData:getChapterId()
|
|
return self.data.chapterId
|
|
end
|
|
|
|
function ChapterData:setChapterId(chapterId)
|
|
self.data.chapterId = chapterId
|
|
end
|
|
|
|
function ChapterData:goNextChapter()
|
|
local chapterInfo = self:getChapterCfg()[self.data.chapterId]
|
|
if chapterInfo == nil then
|
|
return false
|
|
end
|
|
local chapterId = chapterInfo.next_chapter
|
|
if chapterId == nil then
|
|
return false
|
|
end
|
|
self.data.chapterId = chapterId
|
|
return true
|
|
end
|
|
|
|
function ChapterData:goLastChapter()
|
|
local chapterInfo = self:getChapterCfg()[self.data.chapterId]
|
|
if chapterInfo == nil then
|
|
return false
|
|
end
|
|
local chapterId = chapterInfo.before_chapter
|
|
if chapterId == nil then
|
|
return false
|
|
end
|
|
self.data.chapterId = chapterId
|
|
return true
|
|
end
|
|
|
|
function ChapterData:getChapterCfg()
|
|
if self.chapterCfg == nil then
|
|
self.chapterCfg = ConfigManager:getConfig("chapter")
|
|
end
|
|
return self.chapterCfg
|
|
end
|
|
|
|
function ChapterData:getChapterBoxCount(chapterId)
|
|
chapterId = chapterId or self:getChapterId()
|
|
local cfg = self:getChapterCfg()[chapterId]
|
|
if cfg and cfg.box_num then
|
|
return #cfg.box_num
|
|
end
|
|
|
|
return 1
|
|
end
|
|
|
|
function ChapterData:getChapterBoxNum(chapterId, index)
|
|
chapterId = chapterId or self:getChapterId()
|
|
local cfg = self:getChapterCfg()[chapterId]
|
|
if cfg and cfg.box_num then
|
|
return cfg.box_num[index]
|
|
end
|
|
end
|
|
|
|
function ChapterData:getChapterBoxRewardGot(chapterId, index)
|
|
chapterId = tostring(chapterId or self:getChapterId())
|
|
local list = self.data.chapterBoxInfo[chapterId]
|
|
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 ChapterData:getChapterBoxRewards(chapterId, index)
|
|
chapterId = chapterId or self:getChapterId()
|
|
if not self:getChapterBoxNum(chapterId, index) then
|
|
return
|
|
end
|
|
|
|
local cfg = self:getChapterCfg()[chapterId]
|
|
if cfg then
|
|
return cfg["box_reward_" .. index]
|
|
end
|
|
end
|
|
|
|
function ChapterData:getChapterMaxWave(chapterId)
|
|
chapterId = tostring(chapterId or self:getChapterId())
|
|
if self.data.chapterFightInfo[chapterId] then
|
|
return self.data.chapterFightInfo[chapterId].maxWave
|
|
end
|
|
|
|
return 0
|
|
end
|
|
|
|
function ChapterData:getFightCost(chapterId)
|
|
chapterId = chapterId or self:getChapterId()
|
|
local cfg = self:getChapterCfg()[chapterId]
|
|
if cfg and cfg.cost then
|
|
return cfg.cost.num
|
|
end
|
|
|
|
return 0
|
|
end
|
|
|
|
return ChapterData |