源战役客户端
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.

311 righe
12 KiB

4 settimane fa
  1. require("game.proto.424.Require424")
  2. require("game.treasureMap.TreasureMapConst")
  3. require("game.treasureMap.TreasureMapModel")
  4. require("game.treasureMap.TreasureMapDescView") -- 藏宝图介绍界面
  5. require("game.treasureMap.TreasureMapDescScrollItem") -- 藏宝图介绍界面节点
  6. require("game.treasureMap.TreasureMapQuizView") -- 藏宝图答题界面
  7. require("game.treasureMap.TreasureMapShopView") -- 藏宝图限时商城界面
  8. require("game.treasureMap.TreasureMapShopItem") -- 藏宝图限时商城界面item
  9. require("game.treasureMap.TreasureMapStorageShopView") -- 藏宝图限时商城界面(收纳)
  10. require("game.treasureMap.TreasureMapStorageShopItem") -- 藏宝图限时商城界面item(收纳)
  11. require("game.treasureMap.TreasureMapNormalRollView") -- 普通藏宝图结算界面
  12. require("game.treasureMap.TreasureMapAdvanceRollView") -- 高级藏宝图抽奖界面
  13. require("game.treasureMap.TreasureMapRewardPreviewView") -- 藏宝图奖池预览界面
  14. require("game.treasureMap.TreasureMapFeedbackView") -- 藏宝图遗宝馈赠界面
  15. require("game.treasureMap.TreasureMapFeedbackItem") -- 藏宝图遗宝馈赠界面
  16. TreasureMapController = TreasureMapController or BaseClass(BaseController, true)
  17. local TreasureMapController = TreasureMapController
  18. function TreasureMapController:__init()
  19. TreasureMapController.Instance = self
  20. self.model = TreasureMapModel:getInstance()
  21. self:AddEvents()
  22. self:RegisterAllProtocal()
  23. end
  24. function TreasureMapController:__delete()
  25. end
  26. function TreasureMapController:RegisterAllProtocal( )
  27. local register_cfg = {
  28. [42401] = { -- 使用藏宝图
  29. handler = function(self, vo)
  30. if vo.errcode == 1 then
  31. self.model:SetCurrentTreasureData(vo, vo.need_find_way == 1)
  32. else
  33. ErrorCodeShow(vo.errcode)
  34. end
  35. end,
  36. },
  37. [42402] = { -- 获取藏宝[这个只会处理开箱和转盘两种藏宝类型,其他的走其他协议]
  38. handler = function(self, vo)
  39. if vo.errcode == 1 then
  40. self.model._tm_can_fly_goods = false -- 收到协议之后禁止道具飞入表现
  41. if vo.event == TreasureMapConst.EventType.Normal then -- 普通宝箱
  42. self.model:Fire(TreasureMapConst.OPEN_NORMAL_EVENT_RESULT_VIEW, true, vo)
  43. elseif vo.event == TreasureMapConst.EventType.Roll then -- 转盘
  44. self.model:Fire(TreasureMapConst.OPEN_ROLL_EVENT_RESULT_VIEW, true, vo)
  45. end
  46. -- 清除藏宝图数据
  47. self.model:SetCurrentTreasureData(nil)
  48. else
  49. self.model._tm_can_fly_goods = true
  50. ErrorCodeShow(vo.errcode)
  51. end
  52. end,
  53. },
  54. [42403] = { -- 普通藏宝图使用次数
  55. handler = function(self, vo)
  56. self.model:SetNormalTreasureMapTimes(vo.daily_count)
  57. end,
  58. },
  59. [42405] = { -- 高级藏宝图月度次数信息
  60. handler = function(self, vo)
  61. self.model:SetAdvTreasureMapMonthTimesData(vo)
  62. self.model:CheckTreasureMapRed(TreasureMapConst.RedType.MonthReward)
  63. self.model:Fire(TreasureMapConst.UPDATE_MONTH_TIMES_DATA)
  64. end,
  65. },
  66. [42406] = { -- 领取高级藏宝图月度次数奖励
  67. handler = function(self, vo)
  68. if vo.errcode == 1 then
  69. self.model:UpdateAdvTreasureMapMonthTimesData(vo)
  70. self.model:CheckTreasureMapRed(TreasureMapConst.RedType.MonthReward)
  71. self.model:Fire(TreasureMapConst.UPDATE_MONTH_TIMES_DATA)
  72. else
  73. ErrorCodeShow(vo.errcode)
  74. end
  75. end,
  76. },
  77. [42407] = { -- 获取题目
  78. handler = function(self, vo)
  79. if vo.errcode == 1 then
  80. self.model:Fire(TreasureMapConst.OPEN_TREASUREMAP_QUIZ_VIEW, true, vo)
  81. -- 清空藏宝图数据
  82. self.model:SetCurrentTreasureData(nil)
  83. else
  84. ErrorCodeShow(vo.errcode)
  85. end
  86. end,
  87. },
  88. [42408] = { -- 提交答案
  89. handler = function(self, vo)
  90. if vo.errcode == 1 then
  91. self.model:Fire(TreasureMapConst.UPDATE_QUIZ_VIEW)
  92. else
  93. ErrorCodeShow(vo.errcode)
  94. end
  95. end,
  96. },
  97. [42409] = { -- 获取限时商城信息
  98. handler = function(self, vo)
  99. if vo.errcode == 1 then
  100. self.model:SetTreasureMapShopData(vo)
  101. self.model:CheckTreasureMapRed(TreasureMapConst.RedType.Shop)
  102. self.model:Fire(TreasureMapConst.OPEN_TREASUREMAP_SHOP_VIEW, true, vo)
  103. -- 清空藏宝图数据
  104. self.model:SetCurrentTreasureData(nil)
  105. else
  106. ErrorCodeShow(vo.errcode)
  107. end
  108. end,
  109. },
  110. [42410] = { -- 购买限时商店道具
  111. handler = function(self, vo)
  112. if vo.errcode == 1 then
  113. Message.show("购买成功", "success")
  114. self.model:SetTreasureMapShopRestNumData(vo)
  115. self.model:Fire(TreasureMapConst.UPDATE_TREASUREMAP_SHOP_VIEW, true)
  116. else
  117. ErrorCodeShow(vo.errcode)
  118. end
  119. end,
  120. },
  121. [42411] = { -- 挖宝后触发怪物事件
  122. handler = function(self, vo)
  123. if vo.errcode == 1 then
  124. self.model._check_tm_tips = TreasureMapConst.Normal
  125. self.model:CheckTreasureTipUseViewOpen()
  126. -- 清空藏宝图数据
  127. self.model:SetCurrentTreasureData(nil)
  128. else
  129. ErrorCodeShow(vo.errcode)
  130. end
  131. end,
  132. },
  133. [42412] = { -- 购买限时商店的免费物品
  134. handler = function(self, vo)
  135. if vo.errcode == 1 then
  136. Message.show("购买成功", "success")
  137. self.model:Fire(TreasureMapConst.UPDATE_SHOP_FREE_RECEIVE_STATUS, true)
  138. else
  139. ErrorCodeShow(vo.errcode)
  140. end
  141. end,
  142. },
  143. [42413] = { -- 批量使用普通藏宝图
  144. handler = function(self, vo)
  145. if vo.errcode == 1 then
  146. Message.show("批量使用成功", "success")
  147. else
  148. ErrorCodeShow(vo.errcode)
  149. end
  150. end,
  151. },
  152. [42414] = { -- 收纳后限时未过期道具信息
  153. handler = function(self, vo)
  154. self.model:SetTreasureMapStorageShopData(vo)
  155. self.model:CheckStorageShopIcon(false)
  156. end,
  157. },
  158. [42415] = { -- 收纳限时道具购买
  159. handler = function(self, vo)
  160. if vo.errcode == 1 then
  161. self.model:UpdateTreasureMapStorageShopData(vo)
  162. self.model:CheckStorageShopIcon(true)
  163. self.model:Fire(TreasureMapConst.UPDATE_STORAGE_SHOP_DATA, vo)
  164. else
  165. ErrorCodeShow(vo.errcode)
  166. end
  167. end,
  168. },
  169. }
  170. self:RegisterProtocalByCFG(register_cfg)
  171. end
  172. function TreasureMapController:AddEvents()
  173. local function onGameStart()
  174. self.model:Reset()
  175. local function delay_method( )
  176. if GetModuleIsOpen(424) then
  177. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42401, 0) -- 查询进行中的藏宝图
  178. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42403) -- 查询普通藏宝图每日次数信息
  179. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42405) -- 查询高级藏宝图月度次数信息
  180. self.model:Fire(TreasureMapConst.REQUEST_CCMD_EVENT, 42414) -- 查询藏宝图限时商城信息
  181. end
  182. end
  183. setTimeout(delay_method, 1)
  184. end
  185. GlobalEventSystem:Bind(EventName.GAME_START, onGameStart)
  186. --请求基本信息
  187. local function onRequestEvent(...)
  188. local args = {...}
  189. if args[1] == 42401 then
  190. self:SendFmtToGame(args[1], "c", args[2])
  191. elseif args[1] == 42402 then
  192. self.model._tm_can_fly_goods = false -- 发送协议前,先禁止道具飞入表现
  193. self:SendFmtToGame(args[1], "cc", args[2], args[3])
  194. elseif args[1] == 42406 then
  195. self:SendFmtToGame(args[1], "h", args[2])
  196. elseif args[1] == 42408 then
  197. self:SendFmtToGame(args[1], "hc", args[2], args[3])
  198. elseif args[1] == 42410 then
  199. self:SendFmtToGame(args[1], "hch", args[2], args[3], args[4])
  200. elseif args[1] == 42413 then
  201. self:SendFmtToGame(args[1], "h", args[2])
  202. elseif args[1] == 42415 then
  203. self:SendFmtToGame(args[1], "ihch", args[2], args[3], args[4], args[5])
  204. else
  205. self:SendFmtToGame(args[1])
  206. end
  207. end
  208. self.model:Bind(TreasureMapConst.REQUEST_CCMD_EVENT, onRequestEvent)
  209. local function openDescView(show)
  210. self:OpenView("TreasureMapDescView", show)
  211. end
  212. self.model:Bind(TreasureMapConst.OPEN_DESC_VIEW, openDescView)
  213. local function openTMQuizView(show, vo)
  214. if (show and vo) or not show then
  215. self:OpenView("TreasureMapQuizView", show, vo)
  216. if show then
  217. GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_USE_TIP_VIEW, false)
  218. end
  219. end
  220. end
  221. self.model:Bind(TreasureMapConst.OPEN_TREASUREMAP_QUIZ_VIEW, openTMQuizView)
  222. local function openTMShopView(show, vo)
  223. if (show and vo) or not show then
  224. self:OpenView("TreasureMapShopView", show, vo)
  225. if show then
  226. GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_USE_TIP_VIEW, false)
  227. end
  228. end
  229. end
  230. self.model:Bind(TreasureMapConst.OPEN_TREASUREMAP_SHOP_VIEW, openTMShopView)
  231. local function openTMStorageShopView(show)
  232. self:OpenView("TreasureMapStorageShopView", show)
  233. end
  234. self.model:Bind(TreasureMapConst.OPEN_TREASUREMAP_STORAGE_SHOP_VIEW, openTMStorageShopView)
  235. local function openNormalResultView(show, vo)
  236. if (show and vo) or not show then
  237. self:OpenView("TreasureMapNormalRollView", show, vo)
  238. if show then
  239. GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_USE_TIP_VIEW, false)
  240. end
  241. end
  242. end
  243. self.model:Bind(TreasureMapConst.OPEN_NORMAL_EVENT_RESULT_VIEW, openNormalResultView)
  244. local function openRollResultView(show, vo)
  245. if (show and vo) or not show then
  246. self:OpenView("TreasureMapAdvanceRollView", show, vo)
  247. if show then
  248. GlobalEventSystem:Fire(EventName.OPEN_TREASUREMAP_USE_TIP_VIEW, false)
  249. end
  250. end
  251. end
  252. self.model:Bind(TreasureMapConst.OPEN_ROLL_EVENT_RESULT_VIEW, openRollResultView)
  253. local function openRewardPreviewView(show, index)
  254. self:OpenView("TreasureMapRewardPreviewView", show, index)
  255. end
  256. self.model:Bind(TreasureMapConst.OPEN_REWARD_PERVIEW_VIEW, openRewardPreviewView)
  257. local function openFeedbackView(show)
  258. self:OpenView("TreasureMapFeedbackView", show)
  259. end
  260. self.model:Bind(TreasureMapConst.OPEN_FEEDBACK_VIEW, openFeedbackView)
  261. -- 当藏宝商城的按钮被删除之后,需要重新获取缓存中的未过期道具再尝试创建一次按钮
  262. local function checkStorageShopIcon(icon_type)
  263. if icon_type and icon_type == 42414 then
  264. local function delay_method( )
  265. self.model:CheckStorageShopIcon(true)
  266. end
  267. setTimeout(delay_method, 3)
  268. end
  269. end
  270. GlobalEventSystem:Bind(ActivityIconManager.DELETE_ICON, checkStorageShopIcon)
  271. local function scene_change_func()
  272. if self.model.tm_need_refind_way then -- 需要重新寻路
  273. local function delay_method( )
  274. self.model:TreasureMapFindWay()
  275. end
  276. setTimeout(delay_method, 2)
  277. end
  278. end
  279. GlobalEventSystem:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE, scene_change_func)
  280. end
  281. ----请求基本信息
  282. --function TreasureMapController:Handle35025( )
  283. -- if not TreasureMapController.IsDebug then
  284. -- else
  285. --
  286. -- end
  287. --end