Exemple #1
0
        protected void Update()
        {
            if (Network.isServer && _state != MatchState.Ended)
            {
                MatchState previousState = _state;
                int        team1Count    = TeamHelper.GetPlayersCountInTeam(1);
                int        team2Count    = TeamHelper.GetPlayersCountInTeam(2);

                // Checks if there is missing players
                if ((team1Count < NumberOfPlayersRequiredInTeam || team2Count < NumberOfPlayersRequiredInTeam) && !BypassWaiting)
                {
                    // If so, set the state to Waiting for players
                    _state = MatchState.WaitingForPlayers;
                }
                else
                {
                    _state = MatchState.Running;

                    // Otherwise increases the timer
                    _timeElapsed += Time.deltaTime;
                    _networkView.RPC("SetTimer", RPCMode.OthersBuffered, _timeElapsed);

                    // If the time allotted for the game is elapsed, ended the match
                    if (_timeElapsed > MaxTime && false) // enless matches, edited by Damien
                    {
                        _state = MatchState.Ended;

                        // Figures which team has won
                        int team1Kills = _registeredKills[1];
                        int team2Kills = _registeredKills[2];

                        if (team1Kills > team2Kills)
                        {
                            _resultState = MatchResultState.Victory_Team1;
                        }
                        else if (team2Kills > team1Kills)
                        {
                            _resultState = MatchResultState.Victory_Team2;
                        }
                        else
                        {
                            _resultState = MatchResultState.Draw;
                        }

                        // Updates the clients' MatchResultState
                        _networkView.RPC("SetMatchResultState", RPCMode.OthersBuffered, (int)_resultState);
                    }
                }

                if (previousState != _state)
                {
                    // Updates the clients' MatchState
                    _networkView.RPC("SetMatchState", RPCMode.OthersBuffered, (int)_state);
                }
            }
        }