using BrewMonster; using BrewMonster.Network; using UnityEngine; public partial class CECGameRun { int m_iGameState; // Game state // Logout flag (C++: m_iLogoutFlag) private int m_iLogoutFlag = -1; // Logout public void Logout() { // ASSERT(m_iGameState == GS_GAME); if (m_iGameState != (int)GameState.GS_GAME) { BMLogger.LogError($"Logout called but game state is not GS_GAME, current state: {m_iGameState}"); return; } // TODO: Check if we need to call OnLogout for UI and cross server here // overlay::GTOverlay::Instance().Logout(); // CECCrossServer::Instance().OnLogout(); bool bExitApp = false; // if (CECUIConfig::Instance().GetLoginUI().bAvoidLoginUI && m_iLogoutFlag != 1){ if( 1 == 2 && m_iLogoutFlag != 1){ // TODO: check if we need to avoid login UI based on config and logout flag here bExitApp = true; }else if (m_iLogoutFlag == 0) // Exit application directly { bExitApp = true; } else if (m_iLogoutFlag == 1) // Logout game and re-select role { UnityGameSession.ReturnToSelectRole(); // TODO: Check if we need to send switch game for mini client here // Origin C++ // StartLogin(); StartLogin(); // // // ÏÂÔØÆ÷ÏìÓ¦Í˳öÓÎϷ״̬ // if( g_pGame->GetConfigs()->IsMiniClient() ) // CECMCDownload::GetInstance().SendSwitchGame(false); // // // Goto select role interface directly // CECLoginUIMan* pLoginUIMan = m_pUIManager->GetLoginUIMan(); // if (pLoginUIMan) // { // if(GetSellingRoleID() == 0) // { // pLoginUIMan->LaunchCharacter(); // } // // g_pGame->GetGameSession()->ReLogin(true); // pLoginUIMan->SetRoleListReady(false); // if (!CECReconnect::Instance().IsReconnecting()){ // CECReconnect::Instance().SetRoleID(0); // } // } // else // { // ASSERT(pLoginUIMan); // bExitApp = true; // } } else if (m_iLogoutFlag == 2) // Logout game and goto login state { UnityGameSession.LogoutAccount(); // TODO: Check if we need to send switch game for mini client here // Origin C++ // StartLogin(); // if (CECLoginUIMan* pLoginUIMan = m_pUIManager->GetLoginUIMan()){ // g_pGame->GetGameRun()->SetSellingRoleID(0); // g_pGame->GetGameSession()->ReLogin(false); // if (CECCrossServer::Instance().IsWaitLogin()){ // pLoginUIMan->LaunchCharacter(); // pLoginUIMan->ChangeSceneByRole(); // pLoginUIMan->ReclickLoginButton(); // }else if (CECReconnect::Instance().IsReconnecting()){ // pLoginUIMan->ChangeCameraByScene(CECLoginUIMan::LOGIN_SCENE_SELCHAR); // pLoginUIMan->ReclickLoginButton(); // } } else { // ASSERT(NULL); bExitApp = true; } // if (m_pRandomMapProc) // A3DRELEASE(m_pRandomMapProc); // if (bExitApp) // { // // Exit game application // EndGameState(false); // ::PostMessage(g_pGame->GetGameInit().hWnd, WM_QUIT, 0, 0); // } } // End current game state void EndGameState(bool bReset = true/* true */) { if (m_iGameState == (int)GameState.GS_NONE) return; int iCurState = m_iGameState; m_iGameState = (int)GameState.GS_NONE; // TODO: Check if we need to call OnEndLoginState or OnEndGameState based on current state if (iCurState == (int)GameState.GS_LOGIN) OnEndLoginState(); else if (iCurState == (int)GameState.GS_GAME) OnEndGameState(); // Stop background sound and music // CELBackMusic* pBackMusic = g_pGame->GetBackMusic(); // if (pBackMusic) // { // pBackMusic->StopMusic(true, true); // pBackMusic->StopBackSFX(); // } // if (bReset) // g_pGame.Reset(); } // Start login interface bool StartLogin() { // End current game state EndGameState(); m_iGameState = (int)GameState.GS_LOGIN; // if( !CreateLoginWorld() ) // { // a_LogOutput(1, "CECGameRun::StartLogin, Failed to create login world."); // return false; // } // // // Change UI manager // if (!m_pUIManager->ChangeCurUIManager(CECUIManager::UIMAN_LOGIN)) // { // a_LogOutput(1, "CECGameRun::StartLogin, Failed to change UI manager."); // return false; // } // // m_pUIManager->GetLoginUIMan()->LaunchPreface(); // // if (!m_pLogo){ // m_pLogo = new A2DSprite; // if (!m_pLogo->Init(g_pGame->GetA3DDevice(), "logo.dds", 0)){ // A3DRELEASE(m_pLogo); // }else{ // m_pLogo->SetLinearFilter(true); // } // } // if (af_IsFileExist("surfaces\\kr.dds")) // { // if (!m_pClassification){ // m_pClassification = new A2DSprite; // if (!m_pClassification->Init(g_pGame->GetA3DDevice(), "kr.dds", 0)){ // A3DRELEASE(m_pClassification); // }else{ // m_pClassification->SetLinearFilter(true); // } // } // } // // Change cursor to default icon // g_pGame->ChangeCursor(RES_CUR_NORMAL); // // Discard current frame // g_pGame->DiscardFrame(); return true; } // End login state void OnEndLoginState() { // Release UI module // m_pUIManager.ChangeCurUIManager(-1); // Release World // ReleaseLoginWorld(); // A3DRELEASE(m_pLogo); // A3DRELEASE(m_pClassification); } // End game state void OnEndGameState() { ReleasePendingActions(); // Release UI module // m_pUIManager.ChangeCurUIManager(-1); // Release shortcuts ReleaseShortcuts(); // Release team manager // A3DRELEASE(m_pTeamMan); if (m_pTeamMan != null) { m_pTeamMan.Release(); m_pTeamMan = null; } // Release host player before world released // ReleaseHostPlayer(); // Release world // ReleaseWorld(); // Release message manager // A3DRELEASE(m_pMessageMan); // g_pGame.ReleaseInGameRes(); // Return the default memory state // m_pMemSimplify.OnEndGameState(); // CECOptimize::Instance().OnEndGameState(); } // Release shortcuts void ReleaseShortcuts() { // A3DRELEASE(m_pNormalSCS); // A3DRELEASE(m_pTeamSCS); // A3DRELEASE(m_pTradeSCS); // A3DRELEASE(m_pPoseSCS); // A3DRELEASE(m_pFactionSCS); m_pNormalSCS = null; m_pTeamSCS = null; m_pTradeSCS = null; m_pPoseSCS = null; m_pFactionSCS = null; } // Release host player void ReleaseHostPlayer() { // C++ version: // Release host player // if (m_pHostPlayer) // { // m_pHostPlayer->Release(); // delete m_pHostPlayer; // m_pHostPlayer = NULL; // } // Release host player if (m_pHostPlayer) { m_pHostPlayer.Release(); GameObject.Destroy(m_pHostPlayer.gameObject); m_pHostPlayer = null; } } // Release world void ReleaseWorld() { // m_pInputCtrl->ClearKBFilterStack(); // m_pInputCtrl->ClearMouFilterStack(); // // g_pGame->GetViewport()->SwitchCamera(false); if (m_pWorld != null) { // if (m_pHostPlayer) // m_pHostPlayer.SetPlayerMan(NULL); this.m_pWorld.Release(); // delete m_pWorld; m_pWorld = null; } } }