コード例 #1
0
        public void StartLevel(LevelSO level, BeatmapDifficulty difficulty, float startTime = 0f)
        {
            Client.Instance.playerInfo.playerComboBlocks = 0;
            Client.Instance.playerInfo.playerCutBlocks   = 0;
            Client.Instance.playerInfo.playerEnergy      = 0f;
            Client.Instance.playerInfo.playerScore       = 0;

            MenuSceneSetupDataSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuSceneSetupDataSO>().FirstOrDefault();

            if (menuSceneSetupData != null)
            {
                GameplayModifiers gameplayModifiers = new GameplayModifiers();

                gameplayModifiers.noFail = true;

                PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings;

                channelInfo.state = ChannelState.InGame;
                Client.Instance.playerInfo.playerState = PlayerState.Game;

                IDifficultyBeatmap difficultyBeatmap = level.GetDifficultyBeatmap(difficulty);

                if (difficultyBeatmap == null)
                {
                    difficultyBeatmap = level.GetDifficultyBeatmap(GetClosestDifficulty(level, difficulty));
                }

                Misc.Logger.Info($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={difficulty}");

                PracticeSettings practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings);
                practiceSettings.startSongTime = startTime + 1.5f;

                Client.Instance.MessageReceived -= MessageReceived;
                menuSceneSetupData.StartStandardLevel(difficultyBeatmap, gameplayModifiers, playerSettings, (startTime > 1f ? practiceSettings : null), null, (StandardLevelSceneSetupDataSO sender, LevelCompletionResults levelCompletionResults) => { InGameOnlineController.Instance.SongFinished(sender, levelCompletionResults, difficultyBeatmap, gameplayModifiers, (practiceSettings != null)); });
                return;
            }
            else
            {
                Misc.Logger.Error("SceneSetupData is null!");
            }
        }
コード例 #2
0
        public static void StartSong(LevelSO level, byte difficulty, GameplayModifiers gameplayModifiers)
        {
            if (InSong || level == null || gameplayModifiers == null)
            {
                return;
            }
            try
            {
                MenuSceneSetupDataSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuSceneSetupDataSO>().FirstOrDefault();
                if (menuSceneSetupData != null)
                {
                    PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings;
                    _gameplayModifiers = gameplayModifiers;
                    _difficultyBeatmap = level.GetDifficultyBeatmap((BeatmapDifficulty)difficulty);

                    Data.Logger.Debug($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={_difficultyBeatmap.difficulty}");
                    InSong = true;
                    menuSceneSetupData.StartStandardLevel(_difficultyBeatmap, gameplayModifiers, playerSettings, null, null, new Action <StandardLevelSceneSetupDataSO, LevelCompletionResults>(FinishSong));
                }
            } catch (Exception e)
            {
                Data.Logger.Error(e);
            }
        }
コード例 #3
0
        void SelectAndLoadSong(string name, string difficulty)
        {
            //try
            //{
            //    mainMenuViewController.HandleMenuButton(MainMenuViewController.MenuButton.SoloFreePlay);
            //}
            //catch (Exception e)
            //{

            //}
            //try
            //{
            //    soloModeSelectionViewController.HandleMenuButton(SoloModeSelectionViewController.MenuType.FreePlayMode);
            //}
            //catch (Exception e)
            //{

            //}
            LevelCollectionSO _levelCollection = SongLoader.CustomLevelCollectionSO;
            LevelSO           level            = _levelCollection.GetLevelsWithBeatmapCharacteristic(Resources.FindObjectsOfTypeAll <BeatmapCharacteristicSO>().First(x => x.characteristicName == "Standard")).First(x => x.songName == name);

            //level = listViewController.GetPrivateField<IBeatmapLevel[]>("_levels").Where(x => x.songName == name)// && x.songAuthorName == author && x.songSubName == subname)
            //    .ToList().ElementAt(0);



            Console.WriteLine("Song found:" + level.songName);

            difficultyLevel = level.GetDifficultyBeatmap(_difficulties[difficulty]);
            //////////////////////////////////////////////////////////////////
            //            THING TO GET SONG BY JUST STARTING IT             //
            //////////////////////////////////////////////////////////////////
            GameplayModifiers gameplayModifiers = new GameplayModifiers();

            gameplayModifiers.ResetToDefault();
            gameplayModifiers.noFail = true;
            PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings;

            var practiceSettings = new PracticeSettings(PracticeSettings.defaultPracticeSettings);

            practiceSettings.startSongTime = time;
            practiceSettings.songSpeedMul  = playbackSpeed;

            MenuSceneSetupDataSO menu   = Resources.FindObjectsOfTypeAll <MenuSceneSetupDataSO>().First();
            SongLoader           loader = Resources.FindObjectsOfTypeAll <SongLoader>().First();

            loader.LoadAudioClipForLevel((CustomLevel)level, delegate(CustomLevel customLevel)
            {
                menu.StartStandardLevel(difficultyLevel, gameplayModifiers, playerSettings, practiceSettings, null, null);
            });

            ///////////////////////////////////////////////////////////////////
            //          THING TO GET SONG BY NAVIGATING THROUGH MENUS        //
            ///////////////////////////////////////////////////////////////////
            //MenuSceneSetupDataSO menu = Resources.FindObjectsOfTypeAll<MenuSceneSetupDataSO>().First();

            //soloFreePlayFlowCoordinator.HandleLevelListViewControllerDidSelectLevel(listViewController, level);
            //levelListView.SelectAndScrollToLevel(level.levelID);
            //int row = levelListView.RowNumberForLevelID(level.levelID);
            //levelListView.HandleDidSelectRowEvent(levelListView.GetPrivateField<TableView>("_tableView"), row);
            //try
            //{

            //    DifficultyTableView difficultyTableView = beatmapDifficultyViewController.GetPrivateField<DifficultyTableView>("_difficultyTableView");
            //    TableView tableView = difficultyTableView.GetPrivateField<TableView>("_tableView");
            //    difficultyTableView.HandleDidSelectRowEvent(tableView, 0);
            //    tableView.SelectRow(0);
            //    difficultyTableView.SelectRow(difficultyLevel, false);
            //    soloFreePlayFlowCoordinator.HandleDifficultyViewControllerDidSelectDifficulty(beatmapDifficultyViewController, difficultyLevel);

            //    practiceController.Init(level, new PracticeSettings());

            //    GameplayModifiers gameplayModifiers = new GameplayModifiers();
            //    gameplayModifiers.ResetToDefault();
            //    gameplayModifiers.noFail = true;

            //    gameplaySetupViewController.SetData(gameplaySetupViewController.playerSettings, gameplayModifiers);
            //    soloFreePlayFlowCoordinator.HandleLevelDetailViewControllerDidPressPracticeButton(detailViewController);
            //    Console.WriteLine("loading " + difficultyLevel.level.songName);
            //    detailViewController.PracticeButtonPressed();

            //    if (!autoPlayBuffer && time > 2)
            //    {   // pause on start
            //        practiceController.HandleSongStartScrollbarOnValueChanged(time - 2);
            //    }
            //    else
            //    {   // autoplay or negative time will f**k it up
            //        practiceController.HandleSongStartScrollbarOnValueChanged(time);
            //    }
            //    Console.WriteLine("Starting song at: " + practiceController.GetPrivateField<PracticeSettings>("_practiceSettings").startSongTime);
            //    practiceController.PlayButtonPressed();
            //    soloFreePlayFlowCoordinator.HandlePracticeViewControllerDidPressPlayButton();
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e);
            //    //Console.WriteLine(e.StackTrace);
            //}
            //finally
            //{
            //    Console.WriteLine("[Mediocre Loader] Finally");
            //}

            //mainGameSceneSetupData.TransitionToScene(0.7f);
        }
コード例 #4
0
        private void PacketReceived(NetIncomingMessage msg)
        {
            CommandType commandType = (CommandType)msg.ReadByte();

            if (!joined)
            {
                if (commandType == CommandType.JoinRoom)
                {
                    switch (msg.ReadByte())
                    {
                    case 0:
                    {
                        Client.Instance.playerInfo.playerState = PlayerState.DownloadingSongs;
                        Client.Instance.RequestRoomInfo();
                        Client.Instance.SendPlayerInfo();
                        joined = true;
                        InGameOnlineController.Instance.needToSendUpdates = true;
                    }
                    break;

                    case 1:
                    {
                        _roomNavigationController.DisplayError("Unable to join room!\nRoom not found");
                    }
                    break;

                    case 2:
                    {
                        _roomNavigationController.DisplayError("Unable to join room!\nIncorrect password");
                    }
                    break;

                    case 3:
                    {
                        _roomNavigationController.DisplayError("Unable to join room!\nToo much players");
                    }
                    break;

                    default:
                    {
                        _roomNavigationController.DisplayError("Unable to join room!\nUnknown error");
                    }
                    break;
                    }
                }
            }
            else
            {
                try
                {
                    switch (commandType)
                    {
                    case CommandType.GetRoomInfo:
                    {
                        Client.Instance.playerInfo.playerState = PlayerState.Room;

                        roomInfo = new RoomInfo(msg);

                        Client.Instance.isHost = Client.Instance.playerInfo.Equals(roomInfo.roomHost);

                        UpdateUI(roomInfo.roomState);
                    }
                    break;

                    case CommandType.SetSelectedSong:
                    {
                        if (msg.LengthBytes < 16)
                        {
                            roomInfo.roomState    = RoomState.SelectingSong;
                            roomInfo.selectedSong = null;

                            PreviewPlayer.CrossfadeToDefault();

                            UpdateUI(roomInfo.roomState);

                            if (songToDownload != null)
                            {
                                songToDownload.songQueueState          = SongQueueState.Error;
                                Client.Instance.playerInfo.playerState = PlayerState.Room;
                            }
                        }
                        else
                        {
                            roomInfo.roomState = RoomState.Preparing;
                            SongInfo selectedSong = new SongInfo(msg);
                            roomInfo.selectedSong = selectedSong;

                            if (songToDownload != null)
                            {
                                songToDownload.songQueueState = SongQueueState.Error;
                            }

                            UpdateUI(roomInfo.roomState);
                        }
                    }
                    break;

                    case CommandType.TransferHost:
                    {
                        roomInfo.roomHost      = new PlayerInfo(msg);
                        Client.Instance.isHost = Client.Instance.playerInfo.Equals(roomInfo.roomHost);

                        if (Client.Instance.playerInfo.playerState == PlayerState.DownloadingSongs)
                        {
                            return;
                        }

                        UpdateUI(roomInfo.roomState);
                    }
                    break;

                    case CommandType.StartLevel:
                    {
                        if (Client.Instance.playerInfo.playerState == PlayerState.DownloadingSongs)
                        {
                            return;
                        }

                        lastSelectedSong = "";

                        Client.Instance.playerInfo.playerComboBlocks = 0;
                        Client.Instance.playerInfo.playerCutBlocks   = 0;
                        Client.Instance.playerInfo.playerEnergy      = 0f;
                        Client.Instance.playerInfo.playerScore       = 0;

                        byte     difficulty = msg.ReadByte();
                        SongInfo songInfo   = new SongInfo(msg);

                        MenuSceneSetupDataSO menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuSceneSetupDataSO>().FirstOrDefault();

                        if (menuSceneSetupData != null)
                        {
                            GameplayModifiers gameplayModifiers = new GameplayModifiers();

                            if (Config.Instance.SpectatorMode)
                            {
                                Client.Instance.playerInfo.playerState = PlayerState.Spectating;
                                gameplayModifiers.noFail = true;
                            }
                            else
                            {
                                Client.Instance.playerInfo.playerState = PlayerState.Game;
                                gameplayModifiers.noFail = roomInfo.noFail;
                            }

                            PlayerSpecificSettings playerSettings = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().FirstOrDefault().currentLocalPlayer.playerSpecificSettings;

                            roomInfo.roomState = RoomState.InGame;

                            Client.Instance.MessageReceived -= PacketReceived;

                            LevelSO            level             = _levelCollection.levels.First(x => x.levelID.StartsWith(songInfo.levelId));
                            IDifficultyBeatmap difficultyBeatmap = level.GetDifficultyBeatmap((BeatmapDifficulty)difficulty);

                            Logger.Info($"Starting song: name={level.songName}, levelId={level.levelID}, difficulty={(BeatmapDifficulty)difficulty}");

                            Client.Instance.MessageReceived -= PacketReceived;
                            menuSceneSetupData.StartStandardLevel(difficultyBeatmap, gameplayModifiers, playerSettings, null, null, (StandardLevelSceneSetupDataSO sender, LevelCompletionResults levelCompletionResults) => { InGameOnlineController.Instance.SongFinished(sender, levelCompletionResults, difficultyBeatmap, gameplayModifiers, false); });
                            return;
                        }
                        else
                        {
                            Logger.Error("SceneSetupData is null!");
                        }
                    }
                    break;

                    case CommandType.LeaveRoom:
                    {
                        LeaveRoom();
                    }
                    break;

                    case CommandType.UpdatePlayerInfo:
                    {
                        if (roomInfo != null)
                        {
                            if (roomInfo.roomState != RoomState.SelectingSong)
                            {
                                float currentTime = msg.ReadFloat();
                                float totalTime   = msg.ReadFloat();

                                int playersCount = msg.ReadInt32();

                                List <PlayerInfo> playerInfos = new List <PlayerInfo>();
                                for (int j = 0; j < playersCount; j++)
                                {
                                    try
                                    {
                                        playerInfos.Add(new PlayerInfo(msg));
                                    }
                                    catch (Exception e)
                                    {
#if DEBUG
                                        Misc.Logger.Exception($"Unable to parse PlayerInfo! Excpetion: {e}");
#endif
                                    }
                                }

                                switch (roomInfo.roomState)
                                {
                                case RoomState.InGame:
                                    playerInfos = playerInfos.Where(x => x.playerScore > 0 && x.playerState == PlayerState.Game).ToList();
                                    UpdateLeaderboard(playerInfos, currentTime, totalTime, false);
                                    break;

                                case RoomState.Results:
                                    playerInfos = playerInfos.Where(x => x.playerScore > 0 && (x.playerState == PlayerState.Game || x.playerState == PlayerState.Room)).ToList();
                                    UpdateLeaderboard(playerInfos, currentTime, totalTime, true);
                                    break;

                                case RoomState.Preparing:
                                    _roomManagementViewController.UpdatePlayerList(playerInfos);
                                    break;
                                }
                            }
                        }
                    }
                    break;

                    case CommandType.PlayerReady:
                    {
                        int playersReady = msg.ReadInt32();
                        int playersTotal = msg.ReadInt32();

                        if (roomInfo.roomState == RoomState.Preparing && _difficultySelectionViewController != null)
                        {
                            _difficultySelectionViewController.SetPlayersReady(playersReady, playersTotal);
                        }
                    }
                    break;

                    case CommandType.Disconnect:
                    {
                        InGameOnlineController.Instance.needToSendUpdates = false;
                        if (msg.LengthBytes > 3)
                        {
                            string reason = msg.ReadString();

                            PopAllViewControllers(_roomNavigationController);
                            InGameOnlineController.Instance.DestroyAvatars();
                            PreviewPlayer.CrossfadeToDefault();
                            joined           = false;
                            lastSelectedSong = "";

                            _roomNavigationController.DisplayError(reason);
                        }
                        else
                        {
                            _roomNavigationController.DisplayError("ServerHub refused connection!");
                        }
                    }
                    break;
                    }
                }catch (Exception e)
                {
                    Logger.Exception("Unable to parse packet!");
                    if (msg != null)
                    {
                        Logger.Exception($"Packet={commandType}, DataLength={msg.LengthBytes}");
                    }
                    Logger.Exception(e.ToString());
                }
            }
        }