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

420 righe
14 KiB

4 settimane fa
  1. require("game.proto.500.Require500")
  2. require("game.escort.EscortModel")
  3. require("game.escort.EscortConst")
  4. require("game.escort.EscortMainView")
  5. require("game.escort.EscortItem")--主界面的item
  6. require("game.escort.EscortResultView")--结算界面
  7. require("game.escort.EscortStageResultView")--一阶段结算界面
  8. require("game.escort.EscortSceneView")--场景界面
  9. EscortController = EscortController or BaseClass(BaseController)
  10. function EscortController:__init()
  11. EscortController.Instance = self
  12. self.model = EscortModel:getInstance()
  13. self:InitEvent()
  14. self:RegisterAllProtocals()
  15. end
  16. function EscortController:InitEvent()
  17. local function onRequestHandler(...)
  18. local args_list = {...}
  19. self.igonre_once = false
  20. if args_list[1] == 50010 or args_list[1] == 50003 or args_list[1] == 50001 or args_list[1] == 50002 then
  21. self:SendFmtToGame(args_list[1], "c", args_list[2])
  22. else
  23. self:SendFmtToGame(args_list[1])
  24. end
  25. end
  26. self.model:Bind(EscortConst.REQUEST_SCMD_EVENT, onRequestHandler)
  27. local function gameStartHandler()
  28. if GetModuleIsOpen(500) then
  29. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50000)
  30. end
  31. end
  32. GlobalEventSystem:Bind(EventName.GAME_START, gameStartHandler)
  33. GlobalEventSystem:Bind(EventName.CHANE_DAY, gameStartHandler)
  34. local function show_left()
  35. self.model:SetEscortSceneLeftHideState(false)
  36. end
  37. GlobalEventSystem:Bind(EventName.FINISHED_COM_DIALOGUE_SHOW_ANIM, show_left)
  38. local function onOpenEscortView(show)
  39. if show then
  40. if self.EscortMainView == nil then
  41. self.EscortMainView = EscortMainView.New()
  42. end
  43. self.EscortMainView:Open()
  44. else
  45. if self.EscortMainView and self.EscortMainView:HasOpen() then
  46. self.EscortMainView:Close()
  47. end
  48. end
  49. end
  50. GlobalEventSystem:Bind(EscortConst.OPEN_ESCORT_VIEW, onOpenEscortView)
  51. local function scene_change_func()
  52. self:ChangeScene()
  53. end
  54. GlobalEventSystem:Bind(EventName.SCENE_LOAD_VIEW_COMPLETE, scene_change_func)
  55. local function on_activity_change( ... )
  56. -- local rob_id = RoleManager.Instance:GetMainRoleVo():GetFlagsByKey(RoleVo.Act_Flag.CONVOY_ROB)
  57. -- local scene_mgr = SceneManager:getInstance()
  58. -- if rob_id > 0 and scene_mgr:IsEscortScene() then--打劫id大于0 且在护送2阶段场景 才显示
  59. -- if self.EscortSceneView == nil then
  60. -- self.EscortSceneView = EscortSceneView.New()
  61. -- end
  62. -- if not self.EscortSceneView:HasOpen() then
  63. -- self.EscortSceneView:Open()
  64. -- end
  65. -- self:SetMainUIVisible(false)
  66. -- end
  67. end
  68. RoleManager:getInstance():GetMainRoleVo():BindOne("activity_flags", on_activity_change)
  69. local function on_open_escort_result_view(show, data)
  70. if show then
  71. if self.EscortResultView == nil then
  72. self.EscortResultView = EscortResultView.New()
  73. end
  74. self.EscortResultView:Open(data)
  75. else
  76. if self.EscortResultView and self.EscortResultView:HasOpen() then
  77. self.EscortResultView:Close()
  78. end
  79. end
  80. end
  81. self.model:Bind(EscortConst.OPEN_ESCORT_RESULT_VIEW, on_open_escort_result_view)
  82. local function on_open_stage_result_view( show )
  83. if show then
  84. if self.EscortStageResultView == nil then
  85. self.EscortStageResultView = EscortStageResultView.New()
  86. end
  87. self.EscortStageResultView:Open()
  88. else
  89. if self.EscortStageResultView and self.EscortStageResultView:HasOpen() then
  90. self.EscortStageResultView:Close()
  91. end
  92. end
  93. end
  94. self.model:Bind(EscortConst.OPEN_STAGE_ESCORT_RESULT_VIEW, on_open_stage_result_view)
  95. local function on_fly_to_npc( )
  96. self.model:FlyToNpc()
  97. end
  98. self.model:Bind(EscortConst.FLY_TO_NPC, on_fly_to_npc)
  99. local function on_change_scene()
  100. self:ChangeScene()
  101. end
  102. self.model:Bind(EscortConst.CHANGE_SCENE, on_change_scene)
  103. end
  104. function EscortController:TipsCall( )
  105. local main_vo = RoleManager.Instance.mainRoleInfo
  106. local temp_head_name = main_vo.name
  107. local head_type = "100"..main_vo.career
  108. local str = string.format("后面的路程会有一点危险,请集中注意力!")
  109. local data = {
  110. head_type = head_type,
  111. desc = str,
  112. head_name = temp_head_name or "",
  113. hide_time = 5,
  114. dalay_time = 1,
  115. is_task_type = true,
  116. }
  117. self.model:SetEscortSceneLeftHideState(true)
  118. GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
  119. end
  120. function EscortController:ChangeScene()
  121. local scene_mgr = SceneManager.Instance
  122. if self.model:IsEscortState() and scene_mgr:IsEscortAllScene() then
  123. if self.EscortSceneView == nil then
  124. self.EscortSceneView = EscortSceneView.New()
  125. end
  126. if not self.EscortSceneView:HasOpen() then
  127. self.EscortSceneView:Open()
  128. end
  129. self:SetMainUIVisible(false)
  130. elseif scene_mgr:IsEscortAllScene(scene_mgr:GetLastSceneId()) then -- 上一个场景是护送
  131. if self.EscortSceneView then
  132. self.EscortSceneView:Close()
  133. end
  134. self:SetMainUIVisible(true)
  135. else
  136. if self.EscortSceneView then
  137. self.EscortSceneView:Close()
  138. end
  139. -- 非自己场景由其他模块负责判断主界面ui可见性
  140. -- self:SetMainUIVisible(true)
  141. end
  142. if scene_mgr:IsEscortScene() and self.model:IsEscortState() then
  143. -- self:TipsCall()
  144. Scene:getInstance():CleanEscortInfo()--切了场景 需要清空一下跟车状态
  145. self.model.not_pause = false--暂停一下
  146. local function delay_method( )
  147. self.model.not_pause = true
  148. end
  149. setTimeout(delay_method, 2)
  150. local function delay_method( )
  151. self.model:GoEscortNpc()
  152. end
  153. setTimeout(delay_method, 1)
  154. end
  155. if self.model.need_find_npc then
  156. self.model.need_find_npc = false
  157. local function delay_method( )
  158. self.model:GoEscortNpc(0, true)
  159. end
  160. setTimeout(delay_method, 1)
  161. end
  162. end
  163. function EscortController:SetMainUIVisible(value)
  164. self:Fire(EventName.HIDE_TASK_TEAM_VIEW, not value)--任务栏
  165. GlobalEventSystem:Fire(EventName.CHANGE_RIGHT_TIP_ICON, not value, MainUIModel.OTHER_MODE) --菜单伸展
  166. end
  167. function EscortController:RegisterAllProtocals( )
  168. self:RegisterProtocal(50000, "Handle50000")--打开护送信息
  169. self:RegisterProtocal(50001, "Handle50001")--刷新护送品质
  170. self:RegisterProtocal(50002, "Handle50002")--开始护送
  171. self:RegisterProtocal(50003, "Handle50003")--完成阶段护送
  172. self:RegisterProtocal(50004, "Handle50004")--结算
  173. self:RegisterProtocal(50008, "Handle50008")--取消护送
  174. self:RegisterProtocal(50009, "Handle50009")--切换到任务NPC
  175. self:RegisterProtocal(50010, "Handle50010")--通知场景的人玩家开始护送
  176. end
  177. -- ########### 打开护送信息 ##########
  178. -- protocol=50000
  179. -- {
  180. -- c2s{
  181. -- }
  182. -- s2c{
  183. -- object_id:int32 // 对象ID
  184. -- convoy_counts:int8 // 今天护送次数
  185. -- is_convoy:int8 // 是否护送状态
  186. -- }
  187. -- }
  188. function EscortController:Handle50000( )
  189. local scmd = SCMD50000.New(true)
  190. print("HWR:EscortController [start:207] scmd:", scmd)
  191. PrintTable(scmd)
  192. print("HWR:EscortController [end]")
  193. self.model:SetEscortBaseInfo(scmd)
  194. self.model:Fire(EscortConst.ANS_BASIC_INFO)
  195. self:ChangeScene()
  196. end
  197. -- ########### 刷新护送品质 ##########
  198. -- protocol=50001
  199. -- {
  200. -- c2s{
  201. -- auto_buy:int8 // 是否自动购买
  202. -- }
  203. -- s2c{
  204. -- code:int32 // 错误码
  205. -- object_id:int32 // 新的对象id
  206. -- pray_val:int16 // 祝福值
  207. -- reward_list:arr_object_list // 消耗列表
  208. -- }
  209. -- }
  210. function EscortController:Handle50001( )
  211. local scmd = SCMD50001.New(true)
  212. print("HWR:EscortController [start:225] scmd:", scmd)
  213. PrintTable(scmd)
  214. print("HWR:EscortController [end]")
  215. local base_info = self.model:GetEscortBaseInfo()
  216. local cur_pray_val = base_info.pray_val or 0
  217. local up_pray_val = scmd.pray_val - cur_pray_val
  218. if scmd.object_id ~= 0 then
  219. self.model:SetEscortObjectId(scmd.object_id, scmd.pray_val)
  220. end
  221. local str = "消耗%s刷新"
  222. local len = #scmd.reward_list
  223. if len > 0 then
  224. local use_goods = false
  225. local use_money = 0
  226. if len > 0 then
  227. for i,v in ipairs(scmd.reward_list) do
  228. if v.style == 2 or v.style == 1 then
  229. use_money = use_money + 1
  230. elseif v.style == 0 then
  231. use_goods = true
  232. end
  233. end
  234. end
  235. --如果花钱了 就优先提示花钱多少
  236. --没花钱就提示消耗道具
  237. local count = 0
  238. for i,v in ipairs(scmd.reward_list) do
  239. if use_money > 0 then--如果是花了钱的就不提示物品了
  240. if v.style ~= 0 then
  241. count = count + 1
  242. local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(v.style, v.typeId)
  243. local goods_name,colorStr = GoodsModel:getInstance():getGoodsName(typeId, true)
  244. if count < use_money then--到最后一个元素了没
  245. str = string.format(str, goods_name..HtmlColorTxt("x"..v.count, colorStr).."、%s")
  246. else
  247. str = string.format(str, goods_name..HtmlColorTxt("x"..v.count, colorStr))
  248. end
  249. end
  250. else
  251. local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(v.style, v.typeId)
  252. local goods_name,colorStr = GoodsModel:getInstance():getGoodsName(typeId, true)
  253. str = string.format(str, goods_name..HtmlColorTxt("x"..v.count, colorStr))
  254. end
  255. end
  256. end
  257. if scmd.code == 1 and len > 0 then
  258. if scmd.pray_val == 0 then
  259. self.model:Fire(EscortConst.UPGRADE_SUCCESS, scmd.object_id)
  260. Message.show("提升品质成功")
  261. else
  262. local text = string.format("提升失败,获得%s点祝福值", up_pray_val)
  263. Message.show(text)
  264. end
  265. Message.show(str,"success")
  266. elseif len > 0 then
  267. Message.show(str)
  268. ErrorCodeShow(scmd.code)
  269. else
  270. ErrorCodeShow(scmd.code)
  271. end
  272. end
  273. -- ########### 开始护送 ##########
  274. -- protocol=50002
  275. -- {
  276. -- c2s{
  277. -- is_double:int8 // 是否双倍 0否|1是
  278. -- }
  279. -- s2c{
  280. -- code:int32 // 错误码
  281. -- convoy_id:int32 // 护送id
  282. -- is_double:int8 // 是否双倍 0否|1是
  283. -- }
  284. -- }
  285. function EscortController:Handle50002( )
  286. local scmd = SCMD50002.New(true)
  287. self.model.is_go_on = true
  288. if scmd.code == 1 then
  289. GlobalEventSystem:Fire(EventName.HIDE_HORSE)
  290. GlobalEventSystem:Fire(EscortConst.OPEN_ESCORT_VIEW, false)
  291. local str = "护送开始"
  292. Message.show(str,"success")
  293. self:ChangeScene()
  294. self.model:GoEscortNpc(1)
  295. self.model:SetEscortCarFollow(true)
  296. local main_vo = RoleManager.Instance.mainRoleInfo
  297. local cfg = Config.Convoyobject[scmd.convoy_id]
  298. local name = ""
  299. if cfg then
  300. name = Trim(cfg.name)
  301. end
  302. local temp_head_name = main_vo.name
  303. local head_type = "100"..main_vo.career
  304. local str = string.format("运气不错!接取了%s护送 任务!让我们开始护送吧!", name)
  305. local data = {
  306. head_type = head_type,
  307. desc = str,
  308. head_name = temp_head_name or "",
  309. hide_time = 5,
  310. dalay_time = 1,
  311. is_task_type = true,
  312. }
  313. GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
  314. self.model:SetEscortSceneLeftHideState(true)
  315. TaskModel:getInstance():SetNeedTaskFlag(false)
  316. self.model.not_show_go_ask_indeed = self.model.not_show_go_ask
  317. self.model:SetIsLastDouble(scmd.is_double, true)
  318. else
  319. ErrorCodeShow(scmd.code)
  320. end
  321. end
  322. -- ########### 完成阶段护送 ##########
  323. -- protocol=50003
  324. -- {
  325. -- c2s{
  326. -- type:int8 // 1阶段一|2阶段二
  327. -- }
  328. -- s2c{
  329. -- result:int32 // 返回码
  330. -- type:int8 // 1阶段一|2阶段二
  331. -- }
  332. -- }
  333. function EscortController:Handle50003( )
  334. local scmd = SCMD50003.New(true)
  335. print("HWR:EscortController [start:337] scmd:", scmd)
  336. PrintTable(scmd)
  337. print("HWR:EscortController [end]")
  338. if scmd.result == 1 and scmd.type == 2 then
  339. Message.show("运送完成")
  340. elseif scmd.result ~= 1 then
  341. ErrorCodeShow(scmd.result)
  342. end
  343. end
  344. -- ########### 结算 ##########
  345. -- protocol=50004
  346. -- {
  347. -- s2c{
  348. -- result:int8 // 1完美|2损坏|3超时|4主动取消护送
  349. -- stage:int8 // 1第一阶段 2第二阶段
  350. -- object_id:int32 // 对象ID
  351. -- convoy_counts:int8 // 今天护送次数
  352. -- }
  353. -- }
  354. function EscortController:Handle50004( )
  355. local scmd = SCMD50004.New(true)
  356. if scmd.result ~= 3 then
  357. self.model:Fire(EscortConst.OPEN_ESCORT_RESULT_VIEW, true, scmd)
  358. -- self:ChangeScene()
  359. -- self:SetMainUIVisible(true)
  360. self.model:SetEscortBaseInfo({})
  361. else
  362. self:SetMainUIVisible(true)
  363. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50000)
  364. self.model:SetEscortBaseInfo({})
  365. end
  366. if scmd.stage == 1 then
  367. elseif scmd.stage == 2 then
  368. self:SetMainUIVisible(true)
  369. end
  370. end
  371. function EscortController:Handle50008( )
  372. -- self.model:SetEscortStageInfo({})
  373. self.model:SetEscortBaseInfo({})
  374. self:ChangeScene()
  375. OperateManager.Instance:StopMove()
  376. end
  377. -- ########### 切换到任务NPC##########
  378. function EscortController:Handle50009( )
  379. local scmd = SCMD50009.New(true)
  380. if scmd.code ~= 1 then
  381. ErrorCodeShow(scmd.code)
  382. end
  383. end
  384. -- ########### 通知场景的人玩家开始护送 ##########
  385. function EscortController:Handle50010( )
  386. local scmd = SCMD50010.New(true)
  387. local scene_mgr = SceneManager:getInstance()
  388. local roleVo = scene_mgr:GetRoleVo(scmd.role_id)
  389. if roleVo ~= nil then
  390. roleVo:ChangeVar("escort_state", scmd.angel_id, nil, true)
  391. else
  392. end
  393. end