예제 #1
0
 private void ProcessGameEnd(GameEndMessage item)
 {
     _gameServer.Simulation.SetEndGame(item.SenderId, item.HasWon);
     if (_gameServer.Simulation.HasGameEnded())
     {
         InfoLog.Write("Game " + _gameServer.Name + " has finished.");
         _gameServer.EndServerGame();
         //_gameServer.StopGameServer();
     }
 }
예제 #2
0
    private void SendGameEndOrder()
    {
        // 게임 종료 전환 메시지는 호스트에서만 보냄
        Debug.Log("Make GameResult & Send Game End Order");
        GameManager.instance.gameState = GameManager.GameState.Over;

        foreach (SessionId session in BackEndMatchManager.instance.sessionIdList)
        {
            if (players[session].isActive && !gameRecord.Contains(session))
            {
                Debug.Log(gameRecord.Count + " : " + session);
                gameRecord.Push(session);
            }
        }
        GameEndMessage message = new GameEndMessage(gameRecord);

        BackEndMatchManager.instance.SendDataToInGame(message);
    }
예제 #3
0
        private void OnGameEnd(NetworkMessage msg)
        {
            GameEndMessage message      = msg.ReadMessage <GameEndMessage>();
            bool           isConclusive = message.IsHostWinner || message.IsGuestWinner;
            bool           isWinResult  = IsHost ? message.IsHostWinner : message.IsGuestWinner;

            if (!isConclusive || !IsPlayer)
            {
                SceneManager.LoadSceneAsync("endgame");
            }
            else if (isWinResult)
            {
                SceneManager.LoadSceneAsync("wingame");
            }
            else
            {
                SceneManager.LoadSceneAsync("losegame");
            }
        }
예제 #4
0
    public void OnGameStart()
    {
        if (BackEndMatchManager.instance.isHost)
        {
            Debug.Log("플레이어 세션정보 확인");

            if (BackEndMatchManager.instance.IsSessionListNull())
            {
                Debug.Log("Player Index Not Exist!");
                // 호스트 기준 세션데이터가 없으면 게임을 바로 종료한다.
                foreach (var session in BackEndMatchManager.instance.sessionIdList)
                {
                    // 세션 순서대로 스택에 추가
                    gameRecord.Push(session);
                }
                GameEndMessage gameEndMessage = new GameEndMessage(gameRecord);
                BackEndMatchManager.instance.SendDataToInGame(gameEndMessage);
                return;
            }
        }
        SetPlayerInfo();
    }
예제 #5
0
        void Simulation_GameEnd(int winTeamId)
        {
            InfoLog.WriteInfo("Game End Event", EPrefix.ClientInformation);

            //GameGraphics.GameGraphicsChanged -= new EventHandler(gg_GameGraphicsChanged);
            //mapView.Paint -= new PaintEventHandler(openGLView_Paint);

            GameGraphics.DeinitGL();

            _gameLogic.Simulation.AbortSimulation();

            _gameLogic.Simulation.BuildingCompleted -= new ClientSimulation.BuildingCreationHandler(Simulation_OnBuildingCompleted);
            _gameLogic.Simulation.UnitCompleted     -= new ClientSimulation.UnitHandler(Simulation_OnUnitCompleted);
            //_gameLogic.Simulation.onTurnEnd -= new SimulationHandler(Simulation_onTurnEnd);
            _gameLogic.Simulation.OnCreditsUpdate -= new ClientSimulation.OnCreditsHandler(UpdateCredits);
            _gameLogic.Simulation.InvalidBuild    -= new ClientSimulation.InvalidBuildHandler(_buildManager.OnBadLocation);
            //_gameLogic.Simulation.onTurnEnd -= new SimulationHandler(_buildManager.ProcessTurn);
            _gameLogic.Simulation.BuildingDestroyed -= new ClientSimulation.BuildingHandler(Simulation_BuildingDestroyed);
            _gameLogic.Simulation.UpdateStripItem   -= new ClientSimulation.UpdateStripItemHandler(this.UpdateStrip);
            _gameLogic.OnBadLocation -= new GameLogic.BadLocationHandler(_buildManager.OnBadLocation);
            _gameLogic.GameEnd       -= new GameLogic.GameEndHandler(Simulation_GameEnd);
            _gameLogic.PauseResume   -= new GameLogic.PauseResumeHandler(this.onPauseResume);

            GameMessageHandler.Instance.GameInitialization -= new GameInitEventHandler(Instance_GameInitialization);

            bool   isWinner           = false;
            string endGameInformation = string.Empty;

            if (winTeamId == _gameLogic.CurrentPlayer.TeamID)
            {
                isWinner = true;
            }

            /* Playing proper music */
            if (isWinner)
            {
                endGameInformation = "Congratulations, you won!";
                AudioEngine.Instance.Music.Play(MusicType.Win);
                AudioEngine.Instance.Sound.PlayHouse(_gameLogic.CurrentPlayer.House, HouseSoundType.Win);
            }
            else
            {
                endGameInformation = "Unfortunately you lost!";
                AudioEngine.Instance.Music.Play(MusicType.Lose);
                AudioEngine.Instance.Sound.PlayHouse(_gameLogic.CurrentPlayer.House, HouseSoundType.Lose);
            }

            /*
             * KŒ: tu jest burdel, GameForm nie jest od przepinania handlerów, ani od zarz¹dzania okienkami w aplikacji
             * nie mo¿na wyœwietliæ GameForm jako okna modalnego, albo zrobiæ w nim event?
             */

            /* Sending message to server */
            GameEndMessage gameEndMessage = (GameEndMessage)Utils.CreateMessageWithSenderId(MessageType.EndGame);

            gameEndMessage.HasWon = isWinner;

            /* Managing the UI */
            MainMenuForm mainMenuForm = FormPool.GetForm(Views.ChatForm) as MainMenuForm;

            if (mainMenuForm != null)
            {
                mainMenuForm.MenuMessageHandler.Suspend();
            }

            Connection.Instance.MessageHandler = mainMenuForm.MenuMessageHandler;
            Connection.Instance.SendMessage(gameEndMessage);
            this.OnMessageBoxShow(endGameInformation, "Game End", MessageBoxButtons.OK, MessageBoxIcon.Information);
            /* Stop playing music */
            AudioEngine.Instance.Music.Stop();

            this.GameFormClose = true;
            if (this.InvokeRequired)
            {
                this.Invoke(new MethodInvoker(this.Close));
            }
            else
            {
                this.Close();
            }

            // dosyc nieladne, bo to moze byc przejscie i z pause i z gamemenu (bo moga byc nad gameform)
            OnMenuOptionChange(new MenuOptionArg(MenuOption.Exit, this, true));

            if (mainMenuForm != null)
            {
                mainMenuForm.MenuMessageHandler.Resume();
            }

            //_gameLogic.Simulation.AbortSimulation();
        }
예제 #6
0
    public void OnRecieve(MatchRelayEventArgs args)
    {
        if (args.BinaryUserData == null)
        {
            Debug.LogWarning(string.Format("빈 데이터가 브로드캐스팅 되었습니다.\n{0} - {1}", args.From, args.ErrInfo));
            // 데이터가 없으면 그냥 리턴
            return;
        }
        Message msg = DataParser.ReadJsonData <Message>(args.BinaryUserData);

        if (msg == null)
        {
            return;
        }
        //if (BackEndMatchManager.instance.isHost != true && args.From.SessionId == myPlayerIndex)
        //{
        //    Debug.Log("패킷 받기 안됨");
        //    return;
        //}
        if (players == null)
        {
            Debug.Log("패킷 받기 안됨");
            return;
        }

        Debug.Log("패킷 받기 : " + (int)msg.type);
        switch (msg.type)
        {
        case Protocol.Type.StartCount:
            // 아무것도 못하게 하기
            StartCountMessage startCount = DataParser.ReadJsonData <StartCountMessage>(args.BinaryUserData);
            if (startCount.time == 0)
            {
                GameUI.instance.SetStartText("게임 시작");
            }
            else
            {
                GameUI.instance.SetStartText(startCount.time.ToString());
            }
            break;

        case Protocol.Type.GameStart:
            // 플레이 가능하게 하기
            GameManager.instance.ChangeState(GameManager.GameState.InGame);
            GameUI.instance.baseObj.SetActive(true);
            GameUI.instance.fadeObj.SetActive(false);
            StartCoroutine(GameUI.instance.gameTimeCheck(BackEndMatchManager.instance.matchInfos[0].matchMinute));
            break;

        case Protocol.Type.GameEnd:
            GameEndMessage endMessage = DataParser.ReadJsonData <GameEndMessage>(args.BinaryUserData);
            SetGameRecord(endMessage.count, endMessage.sessionList);
            break;

        case Protocol.Type.Idle:
            PlayerIdleMessage idleMsg = DataParser.ReadJsonData <PlayerIdleMessage>(args.BinaryUserData);
            ProcessPlayerData(idleMsg);
            break;

        case Protocol.Type.WeakAttack:
            PlayerWeakAttackMessage weakattackMsg = DataParser.ReadJsonData <PlayerWeakAttackMessage>(args.BinaryUserData);
            ProcessPlayerData(weakattackMsg);
            break;

        case Protocol.Type.StrongAttack:
            PlayerStrongAttackMessage strongattackMsg = DataParser.ReadJsonData <PlayerStrongAttackMessage>(args.BinaryUserData);
            ProcessPlayerData(strongattackMsg);
            break;

        case Protocol.Type.Defense:
            PlayerDefenseMessage defenseMsg = DataParser.ReadJsonData <PlayerDefenseMessage>(args.BinaryUserData);
            ProcessPlayerData(defenseMsg);
            break;

        case Protocol.Type.Stun:
            PlayerStunMessage stunMsg = DataParser.ReadJsonData <PlayerStunMessage>(args.BinaryUserData);
            ProcessPlayerData(stunMsg);
            break;

        case Protocol.Type.AttackEnd:
            PlayerAttackEndMessage endMsg = DataParser.ReadJsonData <PlayerAttackEndMessage>(args.BinaryUserData);
            ProcessPlayerData(endMsg);
            break;

        case Protocol.Type.GameSync:
            GameSyncMessage syncMessage = DataParser.ReadJsonData <GameSyncMessage>(args.BinaryUserData);
            ProcessSyncData(syncMessage);
            break;

        case Protocol.Type.GameMySync:
            Debug.Log("싱크 맞추기");
            GameMySyncMessage mySyncMessage = DataParser.ReadJsonData <GameMySyncMessage>(args.BinaryUserData);
            ProcessSyncData(mySyncMessage);
            break;

        case Protocol.Type.Calculation:
            CalculationMessage calMessage = DataParser.ReadJsonData <CalculationMessage>(args.BinaryUserData);
            ProcessCalData(calMessage);
            break;

        case Protocol.Type.Damaged:
            PlayerDamagedMessage damMessage = DataParser.ReadJsonData <PlayerDamagedMessage>(args.BinaryUserData);
            ProcessPlayerData(damMessage);
            break;

        case Protocol.Type.Stamina:
            PlayerStaminaMessage staMessage = DataParser.ReadJsonData <PlayerStaminaMessage>(args.BinaryUserData);
            ProcessPlayerData(staMessage);
            break;

        default:
            Debug.Log("Unknown protocol type");
            return;
        }
    }