LeaveWorldCommand.lua 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. local LeaveWorldCommand = class('LeaveWorldCommand', framework.SimpleCommand)
  2. function LeaveWorldCommand:ctor()
  3. end
  4. function LeaveWorldCommand:execute(note)
  5. local data = note:getBody()
  6. -- SL
  7. SLBridge:onLeaveWorld()
  8. -- ssr
  9. ssr.ssrBridge:onLeaveWorld()
  10. --语音通知退出
  11. local VoiceManagerProxy = global.Facade:retrieveProxy( global.ProxyTable.VoiceManagerProxy )
  12. if VoiceManagerProxy then
  13. VoiceManagerProxy:VoiceExit()
  14. end
  15. local NativeBridgeProxy = global.Facade:retrieveProxy(global.ProxyTable.NativeBridgeProxy)
  16. if NativeBridgeProxy then
  17. NativeBridgeProxy:GN_Game_Duration_State({isGameDuration=false})
  18. -- 小退 通知易盾登出
  19. NativeBridgeProxy:GN_DetachSucceedByServer()
  20. NativeBridgeProxy:GN_Game_Duration_State({isGameDuration=false})
  21. end
  22. -- 数据上报 游戏时长
  23. local DataRePortProxy = global.Facade:retrieveProxy( global.ProxyTable.DataRePortProxy )
  24. DataRePortProxy:PlayGame()
  25. if global.isWindows then
  26. if global.DesignSize_Win.width < global.MMO.TradingBankDesignSize.width or global.DesignSize_Win.height < global.MMO.TradingBankDesignSize.height then
  27. local glview = global.Director:getOpenGLView()
  28. glview:setFrameSize(global.DesignSize_Win.width, global.DesignSize_Win.height)
  29. glview:setFrameZoomFactor(global.DeviceZoom_Win)
  30. end
  31. end
  32. global.Facade:sendNotification(global.NoticeTable.Delay_Exit_Game_Window_Leave_World)
  33. global.Facade:sendNotification(global.NoticeTable.ChangeGameState, global.MMO.GAME_STATE_ROLE)
  34. global.Facade:sendNotification(global.NoticeTable.Layer_Login_Role_EnterGame_Delay)
  35. -- 发个小退消息给服务器
  36. local LoginProxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  37. local netClient = global.gameEnvironment:GetNetClient()
  38. LoginProxy:RequestLeaveWorldNotify()
  39. LoginProxy:RegisterMsgHandler()
  40. LoginProxy:ClearRoles()
  41. LoginProxy:SetTipsContent("")
  42. ---
  43. local TradingBankProxy = global.Facade:retrieveProxy(global.ProxyTable.TradingBankProxy)
  44. TradingBankProxy:RegisterMsgHandler()
  45. local OtherTradingBankProxy = global.Facade:retrieveProxy(global.ProxyTable.OtherTradingBankProxy)
  46. OtherTradingBankProxy:RegisterMsgHandler()
  47. OtherTradingBankProxy:setGameToken("")--清理token
  48. OtherTradingBankProxy:LoginOut()
  49. if global.darkNodeManager then
  50. global.darkNodeManager:clearAllNodes()
  51. end
  52. --VerificationProxy
  53. local VerificationProxy = global.Facade:retrieveProxy(global.ProxyTable.VerificationProxy)
  54. VerificationProxy:RegisterMsgHandler()
  55. local SUIComponentProxy = global.Facade:retrieveProxy(global.ProxyTable.SUIComponentProxy)
  56. SUIComponentProxy:RegisterMsgHandler()
  57. SUIComponentProxy:ClearData()
  58. self:InitDebug()
  59. PerformWithDelayGlobal(function()
  60. netClient:Disconnect()
  61. --
  62. local ip = LoginProxy:GetSelectedServerIp()
  63. local port = LoginProxy:GetRolePort()
  64. local proxyport = LoginProxy:GetSelectedServerProxyPort()
  65. local connectIP = tostring(ip)
  66. local connectPort = tonumber(proxyport or port)
  67. local Connect = function (param1Ex)
  68. netClient:Connect(connectIP, connectPort)
  69. local specialData = LoginProxy:GetNetMsgSpecialData()
  70. LoginProxy:RequestRoleInfo(specialData, param1Ex)
  71. end
  72. if proxyport then
  73. GET_NET_MSG_STAMP_HEAD_PARAM1_NEW(function (param1Ex)
  74. Connect(param1Ex)
  75. local LoginProxy = global.Facade:retrieveProxy(global.ProxyTable.Login)
  76. LoginProxy.param1Ex = nil
  77. end)
  78. else
  79. Connect()
  80. end
  81. end, 0.5)
  82. end
  83. function LeaveWorldCommand:InitDebug()
  84. -- DEBUG. reload some lua, for fast edit ui
  85. if global.isDebugMode or global.isGMMode then
  86. local keycodeFunc = {
  87. {
  88. -- reload lua files
  89. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_F5},
  90. func = function()
  91. package.loaded[ "init/initReload" ] = nil
  92. require("init/initReload")
  93. reload_script_files()
  94. UpateGUIValueCfg()
  95. end
  96. },
  97. {
  98. -- preview anim
  99. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_F4},
  100. func = function()
  101. package.loaded["game/view/layersui/test_layer/PreviewAnimMediator"] = nil
  102. global.Facade:sendNotification( global.NoticeTable.PreviewAnimOpen )
  103. end
  104. },
  105. {
  106. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_F9},
  107. func = function()
  108. releaseLayerGUI("GUIEditor")
  109. global.Facade:sendNotification(global.NoticeTable.Layer_GUIEditor_Open)
  110. end
  111. },
  112. {
  113. -- test layer
  114. keycode = {cc.KeyCode.KEY_CTRL,cc.KeyCode.KEY_F10},
  115. func = function()
  116. global.Facade:sendNotification( global.NoticeTable.Layer_RichTextTest_Open )
  117. end
  118. },
  119. {
  120. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_F12},
  121. func = function()
  122. releaseLayerGUI("GUITXTEditor")
  123. global.Facade:sendNotification(global.NoticeTable.Layer_GUITXTEditor_Open)
  124. end
  125. },
  126. {
  127. -- debug map
  128. keycode = {cc.KeyCode.KEY_0},
  129. func = function()
  130. global.Facade:sendNotification( global.NoticeTable.DebugMapSwitch )
  131. end
  132. },
  133. {
  134. -- restart game
  135. keycode = {cc.KeyCode.KEY_SHIFT, cc.KeyCode.KEY_ESCAPE},
  136. func = function()
  137. global.Facade:sendNotification(global.NoticeTable.RestartGame)
  138. end
  139. },
  140. {
  141. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_Z},
  142. func = function()
  143. local AutoProxy = global.Facade:retrieveProxy(global.ProxyTable.Auto)
  144. if AutoProxy:IsAFKState() then
  145. LuaSendMsg(global.MsgType.MSG_CS_AUTOPLAYGAME_REQUEST,2)
  146. global.Facade:sendNotification(global.NoticeTable.AFKEnd)
  147. else
  148. LuaSendMsg(global.MsgType.MSG_CS_AUTOPLAYGAME_REQUEST,1)
  149. global.Facade:sendNotification(global.NoticeTable.AFKBegin)
  150. end
  151. end
  152. },
  153. {
  154. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_F11},
  155. func = function()
  156. package.loaded["game/view/layersui/test_layer/SUIEditor"] = nil
  157. global.Facade:sendNotification(global.NoticeTable.SUIEditorOpen)
  158. end
  159. },
  160. {
  161. keycode = {cc.KeyCode.KEY_TAB, cc.KeyCode.KEY_F5},
  162. func = function()
  163. if ssrGlobal_F5FUNC then
  164. ssrGlobal_F5FUNC()
  165. end
  166. end
  167. },
  168. {
  169. -- CTRL+F6 打开配置表设置界面
  170. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_F6},
  171. func = function()
  172. global.Facade:sendNotification(global.NoticeTable.Layer_ConfigSetting_Open)
  173. end
  174. },
  175. {
  176. -- CTRL+F7 打开新增颜色编辑器
  177. keycode = {cc.KeyCode.KEY_CTRL, cc.KeyCode.KEY_F7},
  178. func = function()
  179. global.Facade:sendNotification(global.NoticeTable.Layer_ExtraColorEditor_Open)
  180. end
  181. },
  182. }
  183. local inputKeyCode = {}
  184. local function compareKeyCode(k1, k2)
  185. return (table.concat(k1, "+") == table.concat(k2, "+"))
  186. end
  187. local function calcEvent()
  188. for _, v in ipairs(keycodeFunc) do
  189. if compareKeyCode(inputKeyCode, v.keycode) then
  190. v.func()
  191. break
  192. end
  193. end
  194. end
  195. local function pressed_callback(keycode, evt)
  196. table.insert(inputKeyCode, keycode)
  197. calcEvent()
  198. end
  199. local function released_callback(keycode, evt)
  200. for k, v in pairs(inputKeyCode) do
  201. if v == keycode then
  202. table.remove(inputKeyCode, k)
  203. end
  204. end
  205. end
  206. local listener = cc.EventListenerKeyboard:create()
  207. local eventDispatcher = cc.Director:getInstance():getEventDispatcher()
  208. listener:registerScriptHandler(pressed_callback, cc.Handler.EVENT_KEYBOARD_PRESSED)
  209. listener:registerScriptHandler(released_callback, cc.Handler.EVENT_KEYBOARD_RELEASED)
  210. eventDispatcher:addEventListenerWithFixedPriority(listener, 1)
  211. end
  212. end
  213. return LeaveWorldCommand