源战役客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

142 行
3.5 KiB

  1. AdventureBookModel = AdventureBookModel or BaseClass(EventDispatcher)
  2. AdventureBookModel.REQUEST_PROTOCAL = "AdventureBookModel.REQUEST_PROTOCAL"
  3. AdventureBookModel.UPDATE_ADVENTURE_BOOK_INFO = "AdventureBookModel.UPDATE_ADVENTURE_BOOK_INFO" --更新冒险之书信息
  4. AdventureBookModel.UPDATE_ADVENTURE_BOOK_DETAIL_VIEW = "AdventureBookModel.UPDATE_ADVENTURE_BOOK_DETAIL_VIEW" --打开详情界面
  5. AdventureBookType = AdventureBookType or {
  6. MAP = 1,
  7. }
  8. function AdventureBookModel:__init()
  9. AdventureBookModel.Instance = self
  10. self.book_info = {}
  11. self.unactive_list = {}
  12. self.need_find_way = true
  13. end
  14. function AdventureBookModel:getInstance()
  15. if AdventureBookModel.Instance == nil then
  16. AdventureBookModel.New()
  17. end
  18. return AdventureBookModel.Instance
  19. end
  20. --设置未激活冒险之书列表
  21. function AdventureBookModel:SetUnActiveList(list)
  22. for i, v in ipairs(list) do
  23. self:AddUnActiveBook(v.type, v.subtype)
  24. end
  25. end
  26. --增加未激活冒险之书
  27. function AdventureBookModel:AddUnActiveBook(type, subtype)
  28. if not self.unactive_list then
  29. self.unactive_list = {}
  30. end
  31. if not self.unactive_list[type] then
  32. self.unactive_list[type] = {}
  33. end
  34. local have = false
  35. for i, v in ipairs(self.unactive_list[type]) do
  36. if subtype == v then
  37. have = true
  38. break
  39. end
  40. end
  41. if not have then
  42. table.insert(self.unactive_list[type], subtype)
  43. end
  44. end
  45. --移除已激活冒险之书
  46. function AdventureBookModel:RemoveActiveBook(type, subtype)
  47. if self.unactive_list and self.unactive_list[type] then
  48. for i, v in ipairs(self.unactive_list[type]) do
  49. if subtype == v then
  50. table.remove(self.unactive_list[type], i)
  51. break
  52. end
  53. end
  54. end
  55. end
  56. --设置冒险之书信息
  57. function AdventureBookModel:SetBookInfo(data)
  58. self.book_info = self.book_info or {}
  59. self.book_info[data.type] = data.book_list
  60. local arg = {"subtype"}
  61. local condition = {Array.LOWER}
  62. SortTools.MoreKeysSorter(self.book_info[data.type], arg, condition)
  63. end
  64. --获取当前完成的最大索引
  65. function AdventureBookModel:GetBookShowIndex(type)
  66. local list = self.book_info[type]
  67. if list then
  68. return #list
  69. end
  70. return 1
  71. end
  72. function AdventureBookModel:GetBookListByType(type)
  73. if not type then return {} end
  74. return self.book_info and self.book_info[type] or {}
  75. end
  76. function AdventureBookModel:GetBookInfo(type, subtype)
  77. local list = self:GetBookListByType(type)
  78. for i, v in ipairs(list) do
  79. if v.subtype == subtype then
  80. return v
  81. end
  82. end
  83. end
  84. --更新冒险之书信息
  85. function AdventureBookModel:UpdateBookInfo(list)
  86. self.book_info = self.book_info or {}
  87. for i, v in ipairs(list) do
  88. self.book_info[v.type] = self.book_info[v.type] or {}
  89. local have = false
  90. for i2, v2 in ipairs(self.book_info[v.type]) do
  91. if v2.subtype == v.subtype then
  92. self.book_info[v.type][i2].progress = v.progress
  93. self.book_info[v.type][i2].status = v.status
  94. have = true
  95. break
  96. end
  97. end
  98. if not have then
  99. table.insert(self.book_info[v.type], v)
  100. end
  101. local arg = {"subtype"}
  102. local condition = {Array.LOWER}
  103. SortTools.MoreKeysSorter(self.book_info[v.type], arg, condition)
  104. self:Fire(AdventureBookModel.UPDATE_ADVENTURE_BOOK_INFO, v.type, v.subtype)
  105. end
  106. end
  107. --获取配置表中所有的冒险之书
  108. function AdventureBookModel:GetAllBookByType(type)
  109. if not type then return {} end
  110. local list = {}
  111. for i, v in pairs(Config.Adventurebook) do
  112. if v.type == type then
  113. table.insert(list, v)
  114. end
  115. end
  116. local arg = {"subtype"}
  117. local condition = {Array.LOWER}
  118. SortTools.MoreKeysSorter(list, arg, condition)
  119. return list
  120. end