Exemplo n.º 1
0
        public void UpdateModMultiplier()
        {
            GameStatus gameStatus = statusManager.gameStatus;

            float energy = gameEnergyCounter.energy;

            gameStatus.modifierMultiplier = gameplayModifiersSO.GetTotalMultiplier(gameplayModiferParamsList, energy);

            gameStatus.maxScore = gameplayModifiersSO.MaxModifiedScoreForMaxRawScore(ScoreModel.MaxRawScoreForNumberOfNotes(gameplayCoreSceneSetupData.difficultyBeatmap.beatmapData.cuttableNotesCount), gameplayModiferParamsList, gameplayModifiersSO, energy);
            gameStatus.maxRank  = RankModelHelper.MaxRankForGameplayModifiers(gameplayModifiers, gameplayModifiersSO, energy).ToString();
        }
Exemplo n.º 2
0
        public void OnScoreDidChange(int scoreBeforeMultiplier, int scoreAfterMultiplier)
        {
            GameStatus gameStatus = statusManager.gameStatus;

            gameStatus.score = scoreAfterMultiplier;

            int currentMaxScoreBeforeMultiplier = ScoreModel.MaxRawScoreForNumberOfNotes(gameStatus.passedNotes);

            gameStatus.currentMaxScore = gameplayModifiersSO.MaxModifiedScoreForMaxRawScore(currentMaxScoreBeforeMultiplier, gameplayModifiers, gameplayModifiersSO);

            RankModel.Rank rank = RankModel.GetRankForScore(scoreBeforeMultiplier, gameStatus.score, currentMaxScoreBeforeMultiplier, gameStatus.currentMaxScore);
            gameStatus.rank = RankModel.GetRankName(rank);

            statusManager.EmitStatusUpdate(ChangedProperties.Performance, "scoreChanged");
        }
Exemplo n.º 3
0
        public async void OnActiveSceneChanged(Scene oldScene, Scene newScene)
        {
            GameStatus gameStatus = statusManager.gameStatus;

            gameStatus.scene = newScene.name;

            if (newScene.name == "MenuCore")
            {
                // Menu
                gameStatus.scene = "Menu";

                Gamemode.Init();

                // TODO: get the current song, mode and mods while in menu
                gameStatus.ResetMapInfo();

                gameStatus.ResetPerformance();

                // Release references for AfterCutScoreBuffers that don't resolve due to player leaving the map before finishing.
                noteCutMapping.Clear();

                statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "menu");
            }
            else if (newScene.name == "GameCore")
            {
                // In game
                gameStatus.scene = "Song";

                gamePause       = FindFirstOrDefault <GamePause>();
                scoreController = FindFirstOrDefault <ScoreController>();
                gameplayManager = Resources.FindObjectsOfTypeAll <StandardLevelGameplayManager>().FirstOrDefault() as MonoBehaviour ?? Resources.FindObjectsOfTypeAll <MissionLevelGameplayManager>().FirstOrDefault();
                beatmapObjectCallbackController  = FindFirstOrDefault <BeatmapObjectCallbackController>();
                gameplayModifiersSO              = FindFirstOrDefault <GameplayModifiersModelSO>();
                audioTimeSyncController          = FindFirstOrDefault <AudioTimeSyncController>();
                playerHeadAndObstacleInteraction = FindFirstOrDefault <PlayerHeadAndObstacleInteraction>();
                gameEnergyCounter = FindFirstOrDefault <GameEnergyCounter>();

                if (gameplayManager.GetType() == typeof(StandardLevelGameplayManager))
                {
                    Plugin.log.Info("Standard Level loaded");
                    standardLevelGameplayManager = FindFirstOrDefault <StandardLevelGameplayManager>();
                    // public event Action StandardLevelGameplayManager#levelFailedEvent;
                    standardLevelGameplayManager.levelFailedEvent += OnLevelFailed;
                    // public event Action StandardLevelGameplayManager#levelFinishedEvent;
                    standardLevelGameplayManager.levelFinishedEvent += OnLevelFinished;
                }
                else if (gameplayManager.GetType() == typeof(MissionLevelGameplayManager))
                {
                    Plugin.log.Info("Mission Level loaded");
                    missionLevelGameplayManager = FindFirstOrDefault <MissionLevelGameplayManager>();
                    // public event Action StandardLevelGameplayManager#levelFailedEvent;
                    missionLevelGameplayManager.levelFailedEvent += OnLevelFailed;
                    // public event Action StandardLevelGameplayManager#levelFinishedEvent;
                    missionLevelGameplayManager.levelFinishedEvent += OnLevelFinished;
                }

                gameplayCoreSceneSetupData = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData;

                // Register event listeners
                // public event Action GamePause#didPauseEvent;
                gamePause.didPauseEvent += OnGamePause;
                // public event Action GamePause#didResumeEvent;
                gamePause.didResumeEvent += OnGameResume;
                // public ScoreController#noteWasCutEvent<NoteData, NoteCutInfo, int multiplier> // called after AfterCutScoreBuffer is created
                scoreController.noteWasCutEvent += OnNoteWasCut;
                // public ScoreController#noteWasMissedEvent<NoteData, int multiplier>
                scoreController.noteWasMissedEvent += OnNoteWasMissed;
                // public ScoreController#scoreDidChangeEvent<int, int> // score
                scoreController.scoreDidChangeEvent += OnScoreDidChange;
                // public ScoreController#comboDidChangeEvent<int> // combo
                scoreController.comboDidChangeEvent += OnComboDidChange;
                // public ScoreController#multiplierDidChangeEvent<int, float> // multiplier, progress [0..1]
                scoreController.multiplierDidChangeEvent += OnMultiplierDidChange;
                // public event Action<BeatmapEventData> BeatmapObjectCallbackController#beatmapEventDidTriggerEvent
                beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTrigger;

                IDifficultyBeatmap diff  = gameplayCoreSceneSetupData.difficultyBeatmap;
                IBeatmapLevel      level = diff.level;

                gameStatus.partyMode = Gamemode.IsPartyActive;
                gameStatus.mode      = Gamemode.GameMode;

                gameplayModifiers = gameplayCoreSceneSetupData.gameplayModifiers;
                PlayerSpecificSettings playerSettings   = gameplayCoreSceneSetupData.playerSpecificSettings;
                PracticeSettings       practiceSettings = gameplayCoreSceneSetupData.practiceSettings;

                float songSpeedMul = gameplayModifiers.songSpeedMul;
                if (practiceSettings != null)
                {
                    songSpeedMul = practiceSettings.songSpeedMul;
                }
                float modifierMultiplier = gameplayModifiersSO.GetTotalMultiplier(gameplayModifiers);

                gameStatus.songName        = level.songName;
                gameStatus.songSubName     = level.songSubName;
                gameStatus.songAuthorName  = level.songAuthorName;
                gameStatus.levelAuthorName = level.levelAuthorName;
                gameStatus.songBPM         = level.beatsPerMinute;
                gameStatus.noteJumpSpeed   = diff.noteJumpMovementSpeed;
                // 13 is "custom_level_" and 40 is the magic number for the length of the SHA-1 hash
                gameStatus.songHash       = level.levelID.StartsWith("custom_level_") && !level.levelID.EndsWith(" WIP") ? level.levelID.Substring(13, 40) : null;
                gameStatus.levelId        = level.levelID;
                gameStatus.songTimeOffset = (long)(level.songTimeOffset * 1000f / songSpeedMul);
                gameStatus.length         = (long)(level.beatmapLevelData.audioClip.length * 1000f / songSpeedMul);
                gameStatus.start          = GetCurrentTime() - (long)(audioTimeSyncController.songTime * 1000f / songSpeedMul);
                if (practiceSettings != null)
                {
                    gameStatus.start -= (long)(practiceSettings.startSongTime * 1000f / songSpeedMul);
                }
                gameStatus.paused          = 0;
                gameStatus.difficulty      = diff.difficulty.Name();
                gameStatus.notesCount      = diff.beatmapData.notesCount;
                gameStatus.bombsCount      = diff.beatmapData.bombsCount;
                gameStatus.obstaclesCount  = diff.beatmapData.obstaclesCount;
                gameStatus.environmentName = level.environmentInfo.sceneInfo.sceneName;

                gameStatus.maxScore = gameplayModifiersSO.MaxModifiedScoreForMaxRawScore(ScoreModel.MaxRawScoreForNumberOfNotes(diff.beatmapData.notesCount), gameplayModifiers, gameplayModifiersSO);
                gameStatus.maxRank  = RankModel.MaxRankForGameplayModifiers(gameplayModifiers, gameplayModifiersSO).ToString();

                try {
                    // From https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-
                    var texture = await level.GetCoverImageTexture2DAsync(CancellationToken.None);

                    var active    = RenderTexture.active;
                    var temporary = RenderTexture.GetTemporary(
                        texture.width,
                        texture.height,
                        0,
                        RenderTextureFormat.Default,
                        RenderTextureReadWrite.Linear
                        );

                    Graphics.Blit(texture, temporary);
                    RenderTexture.active = temporary;

                    var cover = new Texture2D(texture.width, texture.height);
                    cover.ReadPixels(new Rect(0, 0, temporary.width, temporary.height), 0, 0);
                    cover.Apply();

                    RenderTexture.active = active;
                    RenderTexture.ReleaseTemporary(temporary);

                    gameStatus.songCover = System.Convert.ToBase64String(
                        ImageConversion.EncodeToPNG(cover)
                        );
                } catch {
                    gameStatus.songCover = null;
                }

                gameStatus.ResetPerformance();

                gameStatus.modifierMultiplier  = modifierMultiplier;
                gameStatus.songSpeedMultiplier = songSpeedMul;
                gameStatus.batteryLives        = gameEnergyCounter.batteryLives;

                gameStatus.modObstacles          = gameplayModifiers.enabledObstacleType.ToString();
                gameStatus.modInstaFail          = gameplayModifiers.instaFail;
                gameStatus.modNoFail             = gameplayModifiers.noFail;
                gameStatus.modBatteryEnergy      = gameplayModifiers.batteryEnergy;
                gameStatus.modDisappearingArrows = gameplayModifiers.disappearingArrows;
                gameStatus.modNoBombs            = gameplayModifiers.noBombs;
                gameStatus.modSongSpeed          = gameplayModifiers.songSpeed.ToString();
                gameStatus.modNoArrows           = gameplayModifiers.noArrows;
                gameStatus.modGhostNotes         = gameplayModifiers.ghostNotes;
                gameStatus.modFailOnSaberClash   = gameplayModifiers.failOnSaberClash;
                gameStatus.modStrictAngles       = gameplayModifiers.strictAngles;
                gameStatus.modFastNotes          = gameplayModifiers.fastNotes;

                gameStatus.staticLights = playerSettings.staticLights;
                gameStatus.leftHanded   = playerSettings.leftHanded;
                gameStatus.playerHeight = playerSettings.playerHeight;
                gameStatus.sfxVolume    = playerSettings.sfxVolume;
                gameStatus.reduceDebris = playerSettings.reduceDebris;
                gameStatus.noHUD        = playerSettings.noTextsAndHuds;
                gameStatus.advancedHUD  = playerSettings.advancedHud;
                gameStatus.autoRestart  = playerSettings.autoRestart;

                statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "songStart");
            }
        }