源战役客户端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

142 righe
3.5 KiB

AdventureBookModel = AdventureBookModel or BaseClass(EventDispatcher)
AdventureBookModel.REQUEST_PROTOCAL = "AdventureBookModel.REQUEST_PROTOCAL"
AdventureBookModel.UPDATE_ADVENTURE_BOOK_INFO = "AdventureBookModel.UPDATE_ADVENTURE_BOOK_INFO" --更新冒险之书信息
AdventureBookModel.UPDATE_ADVENTURE_BOOK_DETAIL_VIEW = "AdventureBookModel.UPDATE_ADVENTURE_BOOK_DETAIL_VIEW" --打开详情界面
AdventureBookType = AdventureBookType or {
MAP = 1,
}
function AdventureBookModel:__init()
AdventureBookModel.Instance = self
self.book_info = {}
self.unactive_list = {}
self.need_find_way = true
end
function AdventureBookModel:getInstance()
if AdventureBookModel.Instance == nil then
AdventureBookModel.New()
end
return AdventureBookModel.Instance
end
--设置未激活冒险之书列表
function AdventureBookModel:SetUnActiveList(list)
for i, v in ipairs(list) do
self:AddUnActiveBook(v.type, v.subtype)
end
end
--增加未激活冒险之书
function AdventureBookModel:AddUnActiveBook(type, subtype)
if not self.unactive_list then
self.unactive_list = {}
end
if not self.unactive_list[type] then
self.unactive_list[type] = {}
end
local have = false
for i, v in ipairs(self.unactive_list[type]) do
if subtype == v then
have = true
break
end
end
if not have then
table.insert(self.unactive_list[type], subtype)
end
end
--移除已激活冒险之书
function AdventureBookModel:RemoveActiveBook(type, subtype)
if self.unactive_list and self.unactive_list[type] then
for i, v in ipairs(self.unactive_list[type]) do
if subtype == v then
table.remove(self.unactive_list[type], i)
break
end
end
end
end
--设置冒险之书信息
function AdventureBookModel:SetBookInfo(data)
self.book_info = self.book_info or {}
self.book_info[data.type] = data.book_list
local arg = {"subtype"}
local condition = {Array.LOWER}
SortTools.MoreKeysSorter(self.book_info[data.type], arg, condition)
end
--获取当前完成的最大索引
function AdventureBookModel:GetBookShowIndex(type)
local list = self.book_info[type]
if list then
return #list
end
return 1
end
function AdventureBookModel:GetBookListByType(type)
if not type then return {} end
return self.book_info and self.book_info[type] or {}
end
function AdventureBookModel:GetBookInfo(type, subtype)
local list = self:GetBookListByType(type)
for i, v in ipairs(list) do
if v.subtype == subtype then
return v
end
end
end
--更新冒险之书信息
function AdventureBookModel:UpdateBookInfo(list)
self.book_info = self.book_info or {}
for i, v in ipairs(list) do
self.book_info[v.type] = self.book_info[v.type] or {}
local have = false
for i2, v2 in ipairs(self.book_info[v.type]) do
if v2.subtype == v.subtype then
self.book_info[v.type][i2].progress = v.progress
self.book_info[v.type][i2].status = v.status
have = true
break
end
end
if not have then
table.insert(self.book_info[v.type], v)
end
local arg = {"subtype"}
local condition = {Array.LOWER}
SortTools.MoreKeysSorter(self.book_info[v.type], arg, condition)
self:Fire(AdventureBookModel.UPDATE_ADVENTURE_BOOK_INFO, v.type, v.subtype)
end
end
--获取配置表中所有的冒险之书
function AdventureBookModel:GetAllBookByType(type)
if not type then return {} end
local list = {}
for i, v in pairs(Config.Adventurebook) do
if v.type == type then
table.insert(list, v)
end
end
local arg = {"subtype"}
local condition = {Array.LOWER}
SortTools.MoreKeysSorter(list, arg, condition)
return list
end