UIStoryMgr.lua 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. local UIStoryMgr = class("UIStoryMgr")
  2. local storyPlayStatus = false
  3. local curStoryData
  4. local storyList = {}
  5. function UIStoryMgr:ctor()
  6. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UISTORY_CONDITION_TRIGGER, self, self.StoryConditionTrigger)
  7. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UISTORY_UI_START_OR_OVER, self, self.StoryUIStartOrOver)
  8. end
  9. function UIStoryMgr:StoryConditionTrigger(type, ...)
  10. local params = {...}
  11. local storyData
  12. local storyDatas = ManagerContainer.DataMgr.StoryData:GetStoryDatas()
  13. local condition = params[1]
  14. local storyId = params[2]
  15. if type == Enum.UIStoryCondType.FirstSceneEnter then
  16. local storyCfgData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
  17. if storyCfgData == nil then
  18. return
  19. end
  20. if storyCfgData.Condition ~= nil then
  21. if storyCfgData.Condition[2] == condition then
  22. storyData = storyCfgData
  23. end
  24. end
  25. local record = UIStoryMgr:CheckRecord(storyId)
  26. if record then
  27. return
  28. end
  29. else
  30. local storyCfgDatas = ManagerContainer.CfgMgr:GetAllStoryDatasByType(type)
  31. if storyCfgDatas ~= nil then
  32. for _,v in pairs(storyCfgDatas) do
  33. if v.Condition ~= nil then
  34. if v.Condition[2] == condition then
  35. storyData = v
  36. local record = UIStoryMgr:CheckRecord(v.Id)
  37. if record then
  38. return
  39. end
  40. end
  41. end
  42. end
  43. end
  44. end
  45. if storyData == nil then
  46. return
  47. end
  48. self:StoryCheckData(storyData)
  49. if condition == storyData.Condition[2] then
  50. storyList[#storyList + 1] = storyData
  51. self:StartStory()
  52. end
  53. end
  54. function UIStoryMgr:MapStartStoryByStoryId(storyId)
  55. local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
  56. if storyData == nil then
  57. LogError("hurui: "..tostring(storyId) .." storyId isnt exist")
  58. return
  59. end
  60. self:StoryCheckData(storyData)
  61. storyData.isMap = true
  62. storyList[#storyList + 1] = storyData
  63. self:StartStory()
  64. end
  65. function UIStoryMgr:StartStoryByStoryId(storyId, skipCheckCache)
  66. local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
  67. if storyData == nil then
  68. LogError("hurui: "..tostring(storyId) .." storyId isnt exist")
  69. --LuaBattleBridge.CurStoryOver(storyId)
  70. return
  71. end
  72. local record = false
  73. if not skipCheckCache then
  74. record = UIStoryMgr:CheckRecord(storyId)
  75. end
  76. if not record then
  77. self:StoryCheckData(storyData)
  78. storyList[#storyList + 1] = storyData
  79. self:StartStory()
  80. end
  81. end
  82. function UIStoryMgr:GetNextStory(storyId)
  83. local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
  84. local storyDatas = ManagerContainer.DataMgr.StoryData:GetStoryDatas()
  85. storyId = storyData.SelectionNext[storyDatas[storyId]]
  86. storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
  87. if storyData then
  88. if storyDatas[storyId] ~= nil then
  89. if storyData.SelectionNext == nil then
  90. if storyDatas[storyId] >= 0 then
  91. return nil
  92. end
  93. else
  94. return self:GetNextStory(storyId)
  95. end
  96. else
  97. return storyData
  98. end
  99. end
  100. return nil
  101. end
  102. function UIStoryMgr:CheckRecord(storyId)
  103. local storyData
  104. local list = ManagerContainer.CfgMgr:GetSameStoryGroupDatasById(storyId)
  105. local storyDatas = ManagerContainer.DataMgr.StoryData:GetStoryDatas()
  106. if list == nil then
  107. if storyDatas[storyId] ~= nil then
  108. storyData = self:GetNextStory(storyId)
  109. if storyData == nil then
  110. --LogError("hurui: "..storyId .." story is recorded")
  111. LuaBattleBridge.CurStoryOver(storyId)
  112. return true
  113. end
  114. end
  115. else
  116. for _,v in pairs(list) do
  117. if storyDatas[v.Id] ~= nil then
  118. storyData = self:GetNextStory(v.Id)
  119. if storyData == nil then
  120. --LogError("hurui: "..storyId .." story is recorded")
  121. LuaBattleBridge.CurStoryOver(storyId)
  122. return true
  123. end
  124. end
  125. end
  126. end
  127. return false
  128. end
  129. function UIStoryMgr:StoryCheckData(storyData)
  130. if storyData.Group ~= nil and storyData.DataCheck ~= nil then
  131. local list = ManagerContainer.CfgMgr:GetSameStoryGroupDatasById(storyData.Id)
  132. if list ~= nil then
  133. for k,v in pairs(list) do
  134. if ManagerContainer.DataMgr.StoryData:CheckDataConditions(v.DataCheck) then
  135. storyData = v
  136. break
  137. end
  138. end
  139. end
  140. end
  141. end
  142. function UIStoryMgr:StartStory()
  143. if storyPlayStatus then
  144. return
  145. end
  146. if #storyList == 0 then
  147. return
  148. end
  149. curStoryData = storyList[1]
  150. table.remove(storyList, 1)
  151. if ManagerContainer.LuaBattleMgr:GetBattleMode() == 1 then
  152. LogError("open story "..curStoryData.Id .." 困难模式退出剧情")
  153. return
  154. end
  155. storyPlayStatus = true
  156. --LogError("open story "..curStoryData.Id)
  157. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIStory, curStoryData)
  158. end
  159. function UIStoryMgr:NeedNextStory()
  160. return #storyList > 0
  161. end
  162. function UIStoryMgr:ImmediateRecord(storyId, idx)
  163. local storyData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
  164. if storyData == nil then
  165. return
  166. end
  167. local default = storyData.SelectionTexts ~= nil and 1 or 0
  168. idx = idx or default
  169. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ROLE_STORY_REQ, {story_id = {key = storyId, value = idx}})
  170. end
  171. function UIStoryMgr:StartNextStory(storyId)
  172. if curStoryData == nil then return end
  173. if curStoryData.ProgramControl and not curStoryData.isMap then
  174. LuaBattleBridge.CurStoryOver(curStoryData.Id)
  175. end
  176. if curStoryData.NeedSave then
  177. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ROLE_STORY_REQ, {story_id = {key = curStoryData.Id, value = idx or 0}})
  178. end
  179. if storyId ~= nil and storyId > 0 then
  180. curStoryData = ManagerContainer.CfgMgr:GetStoryDataById(storyId)
  181. if curStoryData ~= nil then
  182. return curStoryData
  183. end
  184. end
  185. if #storyList == 0 then
  186. return
  187. end
  188. curStoryData = storyList[1]
  189. table.remove(storyList, 1)
  190. storyPlayStatus = true
  191. return curStoryData
  192. end
  193. function UIStoryMgr:StoryUIStartOrOver(status, idx)
  194. if curStoryData == nil then return end
  195. if curStoryData.HideUi then
  196. ManagerContainer.LuaUIMgr:StoryHideUIStatus(not status)
  197. end
  198. if not status then
  199. if curStoryData.ProgramControl and not curStoryData.isMap then
  200. LuaBattleBridge.CurStoryOver(curStoryData.Id)
  201. end
  202. if curStoryData.NeedSave then
  203. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ROLE_STORY_REQ, {story_id = {key = curStoryData.Id, value = idx or 0}})
  204. end
  205. local storyId = curStoryData.Id
  206. storyPlayStatus = false
  207. curStoryData = nil
  208. --ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FORCE_GUIDE_TRIGGER, Enum.ForceGuideTriggerEnum.Story, storyId)
  209. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIStory)
  210. end
  211. end
  212. function UIStoryMgr:Dispose()
  213. storyPlayStatus = false
  214. curStoryData = nil
  215. storyList = {}
  216. ManagerContainer.LuaUIMgr:CloseInputMask()
  217. end
  218. function UIStoryMgr:Destroy()
  219. self:Dispose()
  220. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UISTORY_CONDITION_TRIGGER, self, self.StoryConditionTrigger)
  221. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UISTORY_UI_START_OR_OVER, self, self.StoryUIStartOrOver)
  222. if tolua.getpeer(self) ~= nil then
  223. tolua.setpeer(self, nil)
  224. end
  225. end
  226. return UIStoryMgr