Ejemplo n.º 1
0
        private static void OnLobbyCreated(LobbyCreated_t pCallback, bool bIOFailure)
        {
            if (!SteamManager.Initialized)
            {
                Logger.Error("CONNECTION FAILED");
                return;
            }
            if (!bIOFailure)
            {
                Scoreboard.Instance.UpsertScoreboardEntry(Controllers.PlayerController.Instance._playerInfo.playerId, Controllers.PlayerController.Instance._playerInfo.playerName);
                _lobbyInfo.LobbyID    = new CSteamID(pCallback.m_ulSteamIDLobby);
                _lobbyInfo.TotalSlots = SteamMatchmaking.GetLobbyMemberLimit(_lobbyInfo.LobbyID);
                _lobbyInfo.HostName   = GetUserName();
                Logger.Debug($"Lobby has been created");
                var hostUserId = SteamMatchmaking.GetLobbyOwner(_lobbyInfo.LobbyID);
                SteamMatchmaking.SetLobbyData(_lobbyInfo.LobbyID, "version", PACKET_VERSION);

                var me = SteamUser.GetSteamID();
                Connection = ConnectionState.CONNECTED;
                if (hostUserId.m_SteamID == me.m_SteamID)
                {
                    setLobbyStatus("Waiting In Menu");

                    SendLobbyPacket(true);
                }

                MultiplayerLobby.RefreshScores();
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }