public void ActiveSceneChanged(Scene from, Scene to) { try { if (!SteamAPI.isLobbyConnected()) { return; } if (to.name == "GameCore" || to.name == "MenuCore") { try { PlayerController.Instance.DestroyAvatars(); if (to.name == "GameCore" && SongListUtils.InSong) { Logger.Debug("update scoreboard"); SteamAPI.StartGame(); InvokeRepeating("UpdateSongOffset", 0f, 1f); Scoreboard.Instance.disabled = false; List <PlayerPacket> connectedPlayers = Controllers.PlayerController.Instance.GetConnectedPlayerPackets(); for (int i = 0; i < connectedPlayers.Count; i++) { Scoreboard.Instance.UpsertScoreboardEntry(connectedPlayers[i].playerId, connectedPlayers[i].playerName, 0, 0); } } else if (to.name == "MenuCore") { Scoreboard.Instance.RemoveAll(); Scoreboard.Instance.disabled = true; if (from.name == "GameCore" && SongListUtils.InSong) { StartCoroutine(RunLobbyCleanup()); } } } catch (Exception e) { Logger.Debug($"Exception: {e}"); Logger.Error(e); } } } catch (Exception e) { Logger.Error($"(OnlineController) Exception on {_currentScene} scene activation! Exception: {e}"); } }
public void UpsertPlayer(PlayerPacket info) { if (info.playerId == _playerInfo.playerId) { return; } try { if (!_connectedPlayers.Keys.Contains(info.playerId)) { _connectedPlayers.Add(info.playerId, info); if ((Config.Instance.AvatarsInLobby && Plugin.instance.CurrentScene == "MenuCore") || (Config.Instance.AvatarsInGame && Plugin.instance.CurrentScene == "GameCore")) { AvatarController avatar = new GameObject("AvatarController").AddComponent <AvatarController>(); avatar.SetPlayerPacket(info, new Vector3(0, 0, 0), info.playerId == _playerInfo.playerId); _connectedPlayerAvatars.Add(info.playerId, avatar); } MultiplayerLobby.RefreshScores(); Scoreboard.Instance.UpsertScoreboardEntry(info.playerId, info.playerName); return; } if (_connectedPlayers.ContainsKey(info.playerId)) { if (info.playerScore != _connectedPlayers[info.playerId].playerScore || info.playerComboBlocks != _connectedPlayers[info.playerId].playerComboBlocks) { Scoreboard.Instance.UpsertScoreboardEntry(info.playerId, info.playerName, (int)info.playerScore, (int)info.playerComboBlocks); MultiplayerLobby.RefreshScores(); } if (_connectedPlayerAvatars.ContainsKey(info.playerId) && (Config.Instance.AvatarsInLobby && Plugin.instance.CurrentScene == "MenuCore") || (Config.Instance.AvatarsInGame && Plugin.instance.CurrentScene == "GameCore")) { Vector3 offset = new Vector3(0, 0, 0); if (Plugin.instance.CurrentScene == "GameCore") { ulong[] playerInfosByID = new ulong[_connectedPlayers.Count + 1]; playerInfosByID[0] = _playerInfo.playerId; _connectedPlayers.Keys.ToList().CopyTo(playerInfosByID, 1); Array.Sort(playerInfosByID); offset = new Vector3((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2f, 0, Math.Abs((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2.5f)); } _connectedPlayerAvatars[info.playerId].SetPlayerPacket(info, offset, info.playerId == _playerInfo.playerId); } bool changedReady = (_connectedPlayers[info.playerId].Ready != info.Ready || _connectedPlayers[info.playerId].playerProgress != info.playerProgress); _connectedPlayers[info.playerId] = info; MockPartyViewController.Instance.UpdatePlayButton(); if (changedReady) { WaitingMenu.RefreshData(); if (SteamAPI.IsHost()) { if (info.Ready) { if (_connectedPlayers.Values.ToList().All(u => u.Ready)) { Data.Logger.Debug($"Everyone has confirmed that they are ready to play, broadcast that we want them all to start playing"); SteamAPI.StartPlaying(); } } else { if (_connectedPlayers.Values.ToList().All(u => !u.Ready)) { Data.Logger.Debug($"Everyone has confirmed they are in game, set the lobby screen to in game"); SteamAPI.StartGame(); } } } } } } catch (Exception e) { Logger.Error(e); } }