private void OnEnterGameSrv(Pack pack) { Debug.Log("enter game srv resp"); EnterGameSrv resp = Serializer.Deserialize <EnterGameSrv>(new MemoryStream(pack.buffer)); if (resp == null) { Debug.LogError("no EnterGameSrv resp"); return; } NetworkManager mgr = GameSystem.Instance.mNetworkManager; mgr.m_gameMsgHandler.UnregisterHandler(MsgID.EnterGameSrvRespID, OnEnterGameSrv); EnterGameReq req = new EnterGameReq(); req.acc_id = MainPlayer.Instance.AccountID; req.type = ToMatchType(leagueType, m_config.type); req.game_mode = ToGameMode(leagueType); GameSystem.Instance.mNetworkManager.m_gameConn.SendPack(0, req, MsgID.EnterGameReqID); }
public void EnterGame() { if (respInfo == null) { Debug.LogError("Enter game failed with empty info"); return; } MainPlayer.Instance.AccountID = respInfo.acc_id; MainPlayer.Instance.CreateStep = respInfo.create_step; MainPlayer.Instance.SetBaseInfo(respInfo.info); Debug.Log("EnterGame, create_step:" + respInfo.create_step); Debug.Log("EnterGame, loadedLevel:" + Application.loadedLevel); if (Application.loadedLevelName == GlobalConst.SCENE_STARTUP) // scene startup { GameSystem.Instance.mClient.Reset(); if (respInfo.create_step == 1) //进入基础操作练习 { PractiseData practise = GameSystem.Instance.PractiseConfig.GetConfig(20001); GameSystem.Instance.mClient.CreateMatch(practise, 0ul); GameMatch_Practise match = GameSystem.Instance.mClient.mCurMatch as GameMatch_Practise; match.onBehaviourCreated = () => { PractiseBehaviourGuide behaviour = match.practise_behaviour as PractiseBehaviourGuide; behaviour.onOver = () => { CreateStepIn req = new CreateStepIn(); req.acc_id = respInfo.acc_id; GameSystem.Instance.mNetworkManager.m_platConn.SendPack(0, req, MsgID.CreateStepInID); }; }; } else { MainPlayer.Instance.HpRestoreTime = DateTime.Now + new TimeSpan(0, 0, (int)respInfo.hp_restore_remain); //老玩家,进入大厅界面 LuaTable tScene = LuaScriptMgr.Instance.GetLuaTable("Scene"); tScene.Set("targetUI", "UIHall"); tScene.Set("subID", null); tScene.Set("params", null); SceneManager.Instance.ChangeScene(GlobalConst.SCENE_HALL); } } else { GameMatch curMatch = GameSystem.Instance.mClient.mCurMatch; if (curMatch == null) { GameSystem.Instance.mClient.Reset(); } else // In match, resend EnterGameReq { Debug.Log("EnterGame, Curr league type:" + curMatch.GetConfig().leagueType); if (curMatch.GetConfig().leagueType == GameMatch.LeagueType.eQualifying) { GameSystem.Instance.mClient.Reset(); LuaTable tScene = LuaScriptMgr.Instance.GetLuaTable("Scene"); tScene.Set("targetUI", "UIQualifying"); tScene.Set("subID", null); tScene.Set("params", null); SceneManager.Instance.ChangeScene(GlobalConst.SCENE_MATCH); } else if (curMatch.GetConfig().leagueType == GameMatch.LeagueType.ePVP) { LuaScriptMgr.Instance.CallLuaFunction("jumpToUI", new object[] { "UIHall", null, null }); } else if (curMatch.GetConfig().leagueType == GameMatch.LeagueType.eQualifyingNewer) { LuaTable tQualifyingNewer = LuaScriptMgr.Instance.GetLuaTable("QualifyingNewer"); tQualifyingNewer.Set("inBackToLadder", false); tQualifyingNewer.Set("isJoinLadder", false); tQualifyingNewer.Set("isWinShowIncStarAnim", false); LuaScriptMgr.Instance.CallLuaFunction("jumpToUI", new object[] { "UIHall", null, null }); } else if (curMatch.leagueType == GameMatch.LeagueType.eRegular1V1 || curMatch.leagueType == GameMatch.LeagueType.eQualifyingNew || curMatch.leagueType == GameMatch.LeagueType.ePractise1vs1) { MatchStateOver over = curMatch.m_stateMachine.m_curState as MatchStateOver; if (over == null) { GameSystem.Instance.mClient.Reset(); if (curMatch.leagueType == GameMatch.LeagueType.eRegular1V1) { SceneManager.Instance.ChangeScene(GlobalConst.SCENE_HALL); } else if (curMatch.leagueType == GameMatch.LeagueType.eQualifyingNew) { LuaScriptMgr.Instance.CallLuaFunction("jumpToUI", new object[] { "UIHall", null, null }); } } else { if (curMatch.m_stateMachine.m_curState.m_eState != MatchState.State.eOver || (over != null && !over.matchResultSent) ) { Debug.Log("Resend cached EnterGameReq from new"); MatchType type = GameMatch_PVP.ToMatchType(curMatch.leagueType, curMatch.m_config.type); if (curMatch.leagueType == GameMatch.LeagueType.ePractise1vs1) { EnterGameReq req = new EnterGameReq(); req.acc_id = MainPlayer.Instance.AccountID; req.type = type; req.game_mode = fogs.proto.msg.GameMode.GM_Practice1On1; req.practice_pve = new BeginPracticePve(); req.practice_pve.id = 1; req.practice_pve.fight_list = new FightRoleInfo(); req.practice_pve.fight_list.game_mode = fogs.proto.msg.GameMode.GM_Practice1On1; FightRole fr = new FightRole(); fr.role_id = curMatch.mainRole.m_id; fr.status = FightStatus.FS_MAIN; req.practice_pve.fight_list.fighters.Add(fr); over.SendEnterGamePractise1vs1(req); } else { over.SendEnterGame(type); } } } } else if (PlatNetwork.Instance.cachedEnterGameReq != null) { if (curMatch.m_stateMachine.m_curState.m_eState != MatchState.State.eOver || !(curMatch.m_stateMachine.m_curState as MatchStateOver).matchResultSent) { Debug.Log("Resend cached EnterGameReq"); LuaHelper.SendPlatMsgFromLua((uint)MsgID.EnterGameReqID, PlatNetwork.Instance.cachedEnterGameReq); } } } } if (respInfo.create_step >= GameSystem.Instance.CommonConfig.GetUInt("gMaxCreateStep")) { // after renaming step( the last step), mark as login. MainPlayer.Instance.AddCreateNewRoleLog(true); } else { MainPlayer.Instance.AddCreateNewRoleLog(false); } }