public override IEnumerator SlowUpdate() { if (IsLocalPlayer) { this.gameObject.tag = "playerManager"; yield return(new WaitForSeconds(0.4f));//wait for scene pollManager = GameObject.FindGameObjectWithTag("poll"); lobbyScript = pollManager.GetComponent <Lobby>(); lobbyScript.AddClient(NetId); managerScript = GameObject.FindGameObjectWithTag("manager").GetComponent <RecipeManagerScript>(); int tempId = MyCore.LocalPlayerId; //Debug.Log("My core local="+tempId); SendCommand("NID", tempId.ToString()); otherOrder = true; this.transform.GetChild(0).gameObject.SetActive(true); // turn on UI } if (IsServer) { playerIsLeft = false; playerIsRight = false; //for string to prefab transfrom array foodDictionary = new Dictionary <string, int>(); foodDictionary.Add("Watermelon", 9); foodDictionary.Add("Egg", 18); foodDictionary.Add("Toast", 20); foodDictionary.Add("Daikon", 16); foodDictionary.Add("Tea", 10); cookwareDictionary = new Dictionary <string, int>(); cookwareDictionary.Add("Cup", 8); cookwareDictionary.Add("Plate", 11); cookwareDictionary.Add("Pan", 17); cookwareDictionary.Add("Pot", 15); //spawnPos = GameObject.FindGameObjectWithTag("spawn").transform; spawnManager = GameObject.FindGameObjectWithTag("spawnManger").GetComponent <SpawnManagerScript>(); } //true update while (IsServer) { if (playerIsLeft) { SendUpdate("LTS", "X"); } else if (playerIsRight) { SendUpdate("RTS", "X"); } yield return(new WaitForSeconds(0.5f)); //potentially slower } }
/// <summary> /// Sorts a client into a new or existing lobby. /// </summary> /// <param name="client">The client to be sorted.</param> /// <returns>Returns the lobby that the client was sorted into.</returns> public Lobby LobbySorter(Client client, out ServerInfo serverInfo) { //Check existing lobbies int maxScore = -1; Lobby lobbyMaxScore = null; for (int i = 0; i < lobbies.Count; i++) { //Ensure lobby is joinable if (lobbies[i].IsJoinable) { //Check for compare score int compareScore = client.ClientInfo.LobbyInfo.CompareTo(lobbies[i].HostClient.ClientInfo.LobbyInfo); if (compareScore > maxScore) { //Is better lobby choice lobbyMaxScore = lobbies[i]; maxScore = compareScore; } } } //Determine if lobby of minimum requirement has been found if (lobbyMaxScore != null && maxScore >= 0 && lobbyMaxScore.AddClient(client)) { //Added to existing lobby Console.WriteLine("Client added to existing lobby."); serverInfo = new ServerInfo(lobbyMaxScore.LobbySeed, (byte)(lobbyMaxScore.Clients.Length - 1)); return(lobbyMaxScore); } else { //Add to new lobby Console.WriteLine("Client added to new lobby."); Lobby newLobby = new Lobby(client, lobbies, new Client.Print((b) => { Console.WriteLine(b); }), serverRandom); lobbies.Add(newLobby); serverInfo = new ServerInfo(newLobby.LobbySeed, 0); return(newLobby); } }