SebastianLawe

Untitled

Oct 1st, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.93 KB | None | 0 0
  1.     void Update() {
  2.         // Are we the master client?
  3.         _server = PhotonNetwork.isMasterClient;
  4.         // Check if we need to swap levels for preview.
  5.         if (previewSwapRequested) {
  6.             // Check if the swap timer has waited 5 seconds, and the last preview loaded its level.
  7.             if (previewSwapTimer.ElapsedMilliseconds >= 5000 && (levelLoadingCheck != null ? levelLoadingCheck.isDone : true)) {
  8.                 string levelName = null;
  9.                 // Set the respective map.
  10.                 if (gameType == GameType.CTF) {
  11.                     string[] ctfMaps = MapList.CTFMaps();
  12.                     if (ctfMaps.Length < mapsDropdown.value) {
  13.                         mapsDropdown.value = 0;
  14.                     }
  15.                     levelName = ctfMaps[mapsDropdown.value];
  16.                 }
  17.                 if (gameType == GameType.Territores) {
  18.                     string[] territoriesMap = MapList.TerritoriesMaps();
  19.                     if (territoriesMap.Length < mapsDropdown.value) {
  20.                         mapsDropdown.value = 0;
  21.                     }
  22.                     levelName = territoriesMap[mapsDropdown.value];
  23.                 }
  24.                 if (gameType == GameType.Elimination) {
  25.                     string[] eliminationMaps = MapList.EliminationMaps();
  26.                     if (eliminationMaps.Length < mapsDropdown.value) {
  27.                         mapsDropdown.value = 0;
  28.                     }
  29.                     levelName = eliminationMaps[mapsDropdown.value];
  30.                 }
  31.                 // Has this level been loaded before?
  32.                 if (lastLevelLoaded != levelName) {
  33.                     // Load the level.
  34.                     LoadLevel(levelName);
  35.                     // Set the skybox.
  36.                     rotator.GetComponent<Camera>().clearFlags = CameraClearFlags.Skybox;
  37.                 }
  38.                 // Reset everything.
  39.                 previewSwapRequested = false;
  40.                 hasSpawnedMainMenuLevel = true;
  41.                 previewSwapTimer.Reset();
  42.             }
  43.         }
  44.         // Is this server manager a dummy?
  45.         if (!isDud) {
  46.             // Are we matchmaking, and the master client?
  47.             if (isMatchMaking && PhotonNetwork.isMasterClient) {
  48.                 // Check if the matchmaking timer isn't running.
  49.                 if (!matchmakingTimer.IsRunning) {
  50.                     // If it isn't, we have to start it.
  51.                     matchmakingTimer.Start();
  52.                 }
  53.                 // Have we waited 10 seconds?
  54.                 if (matchmakingTimer.ElapsedMilliseconds >= 10000) {
  55.                     // If so, lets check to see if we have enough players to start a match.
  56.                     photonView.RPC("CheckPlayers", PhotonTargets.AllBufferedViaServer);
  57.                 }
  58.             }
  59.             // Check to see if we have enough players, and are matchmaking, or that this is a custom game and we can start the room.
  60.             if ((PhotonNetwork.playerList.Length >= playersRequiredToStartMatch && isMatchMaking)
  61.                 || (isCustomGame && isReadyToStartGame && PhotonNetwork.connectedAndReady)) {
  62.                 if (isMatchMaking) {
  63.                     if (_server) {
  64.                         if (playersRequiredToStartMatch >= 4) {
  65.                             // PhotonNetwork.room.open = false;
  66.                         }
  67.                     }
  68.                 }
  69.                 // Make sure we're connected to a room
  70.                 if (PhotonNetwork.connectionStateDetailed == PeerState.Joined) {
  71.                     // Is this a custom game?
  72.                     if (isCustomGame) {
  73.                         // Are we the master server or offline?
  74.                         if (PhotonNetwork.isMasterClient || PhotonNetwork.offlineMode) {
  75.                             // Do we still have plans to load a level?
  76.                             if (!sentLevelLoadRequest) {
  77.                                 if (!previewSwapTimer.IsRunning) {
  78.                                     previewSwapTimer.Start();
  79.                                 }
  80.                                 // Check to see that we've waited 5 seconds, and that the last level finished loading.
  81.                                 if (previewSwapTimer.ElapsedMilliseconds >= 5000 && levelLoadingCheck.isDone) {
  82.                                     levelLoaded = false;
  83.                                     string levelName = null;
  84.                                     // Get the name of the respective map.
  85.                                     if (gameType == GameType.CTF) {
  86.                                         string[] ctfMaps = MapList.CTFMaps();
  87.                                         if (ctfMaps.Length < mapsDropdown.value) {
  88.                                             mapsDropdown.value = 0;
  89.                                         }
  90.                                         levelName = ctfMaps[mapsDropdown.value];
  91.                                     }
  92.                                     if (gameType == GameType.Territores) {
  93.                                         string[] territoriesMap = MapList.TerritoriesMaps();
  94.                                         if (territoriesMap.Length < mapsDropdown.value) {
  95.                                             mapsDropdown.value = 0;
  96.                                         }
  97.                                         levelName = territoriesMap[mapsDropdown.value];
  98.                                     }
  99.                                     if (gameType == GameType.Elimination) {
  100.                                         string[] eliminationMaps = MapList.EliminationMaps();
  101.                                         if (eliminationMaps.Length < mapsDropdown.value) {
  102.                                             mapsDropdown.value = 0;
  103.                                         }
  104.                                         levelName = eliminationMaps[mapsDropdown.value];
  105.                                     }
  106.                                     // Did we load this map aready?
  107.                                     if (lastLevelLoaded != levelName) {
  108.                                         // Load the map.
  109.                                         photonView.RPC("LoadLevel", PhotonTargets.AllBufferedViaServer, levelName);
  110.                                     }
  111.                                     // We've loaded our map.
  112.                                     sentLevelLoadRequest = true;
  113.                                 }
  114.                             }
  115.                         }
  116.                     } else {
  117.                         // Are we the server?
  118.                         if (PhotonNetwork.isMasterClient || PhotonNetwork.offlineMode) {
  119.                             // Do we still have plans to load a level?
  120.                             if (!sentLevelLoadRequest) {
  121.                                 levelLoaded = false;
  122.                                 string levelName = "";
  123.                                 // Get the respective level name.
  124.                                 if (gameType == GameType.CTF) {
  125.                                     string[] maps = MapList.CTFMaps();
  126.                                     levelName = maps[Mathf.RoundToInt(UnityEngine.Random.Range(0f, (100f * (float)maps.Length)) / 100f)];
  127.                                 }
  128.                                 if (gameType == GameType.Territores) {
  129.                                     string[] maps = MapList.TerritoriesMaps();
  130.                                     levelName = maps[Mathf.RoundToInt(UnityEngine.Random.Range(0f, (100f * (float)maps.Length)) / 100f)];
  131.                                 }
  132.                                 if (gameType == GameType.Elimination) {
  133.                                     string[] maps = MapList.EliminationMaps();
  134.                                     levelName = maps[Mathf.RoundToInt(UnityEngine.Random.Range(0f, (100f * (float)maps.Length)) / 100f)];
  135.                                 }
  136.                                 // Has this map been loaded already?
  137.                                 if (lastLevelLoaded != levelName) {
  138.                                     // Load the map.
  139.                                     photonView.RPC("LoadLevel", PhotonTargets.AllBufferedViaServer, levelName);
  140.                                 }
  141.                                 // We've loaded the map.
  142.                                 sentLevelLoadRequest = true;
  143.                             }
  144.                         }
  145.                     }
  146.                     if (levelTimer == null) {
  147.                         levelTimer = new Stopwatch();
  148.                     }
  149.                     if (!levelLoaded) {
  150.                         levelTimer.Start();
  151.                     }
  152.                     // Have we loaded a map at all?
  153.                     if (levelLoadingCheck != null) {
  154.                         // Has the map finished loading?
  155.                         if (levelLoadingCheck.isDone) {
  156.                             // Disable the selection menu.
  157.                             DisableMenus();
  158.                             //UnityEngine.Debug.Log("Level Loaded.");
  159.                             levelLoaded = true;
  160.                             if (matchStarted != null) {
  161.                                 matchStarted(this, EventArgs.Empty);
  162.                             }
  163.                             // Has the team manager figured out the team colours, or are we a client?
  164.                             if (teamManager.hasAssignedColors || !PhotonNetwork.isMasterClient) {
  165.                                 levelTimer.Reset();
  166.                                 // Have any players been created yet?
  167.                                 if (!_playerCreated) {
  168.                                     // Get the spawn points.
  169.                                     Spawn[] spawns = FindObjectsOfType<Spawn>();
  170.                                     _playerCount = 0;
  171.                                     // Is there mouse and keyboard as an input, or no controllers plugged in?
  172.                                     if (ControllerConfig.HasMouseKeyboardConfigured || ControllerConfig.NoControllers) {
  173.                                         // Increment the player count.
  174.                                         _playerCount++;
  175.                                     }
  176.                                     // Add however many controllers are connected to the player count.
  177.                                     _playerCount += GamePadManager.GamePadCount;
  178.                                     int currentSpawn = 0;
  179.                                     // Spawn all the players.
  180.                                     for (int i = 0; i < _playerCount; i++) {
  181.                                         SpawnPlayer(spawns[currentSpawn++].transform.position);
  182.                                     }
  183.  
  184.                                     // Are we the server, not matchmaking, and offline?
  185.                                     if (PhotonNetwork.isMasterClient && !isMatchMaking && PhotonNetwork.offlineMode) {
  186.                                         // How many players are there?
  187.                                         int playerCount = FindObjectsOfType<PlayerController>().Length;
  188.  
  189.                                         // Spawn enough AI players to fill the max player limit.
  190.                                         if (playerCount < maxPlayers) {
  191.                                             for (int i = 0; i < maxPlayers - playerCount; i++) {
  192.                                                 botsSpawned++;
  193.                                                 SpawnAI(spawns[currentSpawn++].transform.position, i);
  194.                                             }
  195.                                         }
  196.                                     }
  197.                                     // Players are done being spawned.
  198.                                     _playerCreated = true;
  199.                                 }
  200.                             }
  201.                         }
  202.                     }
  203.                 }
  204.             }
  205.         }
  206.     }
Advertisement
Add Comment
Please, Sign In to add comment