Example #1
0
        private void FinishSimulationRPC(int winnerPhotonPlayerID, int finishReason)
        {
            //Check if simulation has been already finished.
            //Simulation finish can be triggered by few events (see SimulationFinishReason enum)
            if (false == IsSimulationFinished)
            {
                //Stop time so events in game are no longer updated
                GameTimeComponent.StopTime();
                IsSimulationFinished = true;
                IsSimulationActive   = false;
                this.WinnerPlayer    = PhotonNetwork.playerList.FirstOrDefault(x => x.ID == winnerPhotonPlayerID);
                this.FinishReason    = (SimulationFinishReason)finishReason;
                string finishSimulationInfoMsg = "Game finished";

                //Check if player didnt left already
                if (null != WinnerPlayer)
                {
                    switch (this.FinishReason)
                    {
                    case SimulationFinishReason.PlayerCompanyReachedTargetBalance:
                        string winnerInfo = (WinnerPlayer.IsLocal ? "You have" : WinnerPlayer.NickName) + " won";
                        finishSimulationInfoMsg = string.Format("Game finished !\n{0}", winnerInfo);
                        break;

                    case SimulationFinishReason.PlayerCompanyReachedMinimalBalance:
                        finishSimulationInfoMsg = string.Format("Your company's balance reached minimum allowed balance ({0} $)",
                                                                SimulationSettings.MinimalBalance);
                        break;

                    case SimulationFinishReason.OnePlayerInRoom:
                        finishSimulationInfoMsg = "You are the only player left in simulation.\nYou have won !";
                        break;

                    case SimulationFinishReason.Disconnected:
                        finishSimulationInfoMsg = "You have been disconnected from server";
                        break;

                    default:
                        break;
                    }
                }

                SimulationFinished?.Invoke(winnerPhotonPlayerID, (SimulationFinishReason)finishReason);
                GameManagerComponent.FinishSession();
                InfoWindowComponent.ShowOk(finishSimulationInfoMsg, () => GameManagerComponent.LoadScene(SceneIndex.Menu));
            }
        }