Beispiel #1
0
    public IEnumerator CheckForBombs()
    {
        yield return(new WaitUntil(() => (SceneManager.Instance.GameplayState.Bombs?.Count > 0)));

        yield return(null);

        List <Bomb> bombs = SceneManager.Instance.GameplayState.Bombs;

        if (settings.SkipGameplayDelay)
        {
            StartCoroutine(SkipGameplayDelay());
        }

        LogJSON("LFAEvent", new Dictionary <string, object>()
        {
            { "type", "ROUND_START" },
            { "mission", Localization.GetLocalizedString(SceneManager.Instance.GameplayState.Mission.DisplayNameTerm) },
        });

        var snoozeButton = FindObjectOfType <AlarmClock>()?.SnoozeButton;

        if (snoozeButton != null)
        {
            FixKeypadButtons(snoozeButton);
        }

        void wrapInitialBombs()
        {
            for (int i = 0; i < bombs.Count; i++)
            {
                Bomb        bomb        = bombs[i];
                BombWrapper bombWrapper = bomb.gameObject.AddComponent <BombWrapper>();
                bombWrappers.Add(bombWrapper);

                if (CurrentMode == Mode.Time)
                {
                    bombWrapper.CurrentTimer = Modes.settings.TimeModeStartingTime * 60;
                }
                else if (CurrentMode == Mode.Zen)
                {
                    bombWrapper.CurrentTimer = 0.001f;
                }
            }
        }

        if (CurrentModeCache == Mode.Zen)
        {
            GameplayMusicController gameplayMusic = MusicManager.Instance.GameplayMusicController;
            gameplayMusic.StopMusic();
            var controller = gameplayMusic.GetComponent <DarkTonic.MasterAudio.PlaylistController>();
            controller.ClearQueue();
            controller.QueuePlaylistClip(controller.CurrentPlaylist.MusicSettings[0].songName, true);
        }

        if (ReflectedTypes.FactoryRoomType != null && ReflectedTypes.StaticModeType != null)
        {
            UnityEngine.Object factoryRoom = FindObjectOfType(ReflectedTypes.FactoryRoomType);
            if (factoryRoom)
            {
                if (ReflectedTypes.FactoryRoomDataType != null && ReflectedTypes.WarningTimeField != null)
                {
                    var roomData = FindObjectOfType(ReflectedTypes.FactoryRoomDataType);
                    if (roomData != null)
                    {
                        ReflectedTypes.WarningTimeField.SetValue(roomData, CurrentMode == Mode.Zen ? 0 : 60);
                    }
                }

                object gameMode = ReflectedTypes.GameModeProperty.GetValue(factoryRoom, null);
                if (ReflectedTypes.StaticModeType != gameMode.GetType())
                {
                    IEnumerable <object> adaptations = ((IEnumerable)ReflectedTypes.AdaptationsProperty.GetValue(gameMode, null)).Cast <object>();
                    bool globalTimerDisabled         = !adaptations.Any(adaptation => ReflectedTypes.GlobalTimerAdaptationType.IsAssignableFrom(adaptation.GetType()));

                    Component getBomb() => (Component)ReflectedTypes._CurrentBombField.GetValue(gameMode);

                    yield return(new WaitUntil(() => getBomb() != null || factoryRoom == null));

                    Component currentBomb = getBomb();
                    bool      firstBomb   = true;

                    while (currentBomb != null && factoryRoom != null)
                    {
                        BombWrapper bombWrapper = currentBomb.gameObject.AddComponent <BombWrapper>();
                        bombWrappers.Add(bombWrapper);

                        if (globalTimerDisabled || firstBomb)
                        {
                            firstBomb = false;

                            if (CurrentMode == Mode.Time)
                            {
                                bombWrapper.CurrentTimer = Modes.settings.TimeModeStartingTime * 60;
                            }
                            else if (CurrentMode == Mode.Zen)
                            {
                                bombWrapper.CurrentTimer = 0.001f;
                            }
                        }

                        yield return(new WaitUntil(() => currentBomb != getBomb() || factoryRoom == null));

                        bombWrappers.Remove(bombWrapper);
                        currentBomb = getBomb();

                        if (currentBomb == null || factoryRoom == null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    wrapInitialBombs();
                }

                yield break;
            }
        }

        // This code only runs if we aren't in the Factory room.
        wrapInitialBombs();

        // If TP is enabled, let it handle managing the emergency lights.
        if (TwitchPlaysActiveCache)
        {
            yield break;
        }

        SceneManager.Instance.GameplayState.Room.PacingActions.RemoveAll(pacingAction => pacingAction.EventType == Assets.Scripts.Pacing.PaceEvent.OneMinuteLeft);
        UnityEngine.Object portalRoom = null;
        if (ReflectedTypes.PortalRoomType != null && ReflectedTypes.RedLightsMethod != null && ReflectedTypes.RoomLightField != null)
        {
            portalRoom = FindObjectOfType(ReflectedTypes.PortalRoomType);
        }

        bool        lastState = false;
        IEnumerator portalEmergencyRoutine = null;

        while (CurrentState == KMGameInfo.State.Gameplay)
        {
            bool targetState = CurrentModeCache != Mode.Zen;
            targetState &= bombWrappers.Any((BombWrapper bombWrapper) => bombWrapper.CurrentTimer < 60f && !bombWrapper.Bomb.IsSolved());
            if (targetState != lastState)
            {
                foreach (EmergencyLight emergencyLight in FindObjectsOfType <EmergencyLight>())
                {
                    if (targetState)
                    {
                        emergencyLight.Activate();
                    }
                    else
                    {
                        emergencyLight.Deactivate();
                    }
                }
                if (portalRoom != null)
                {
                    if (targetState)
                    {
                        portalEmergencyRoutine = (IEnumerator)ReflectedTypes.RedLightsMethod.Invoke(portalRoom, null);
                        StartCoroutine(portalEmergencyRoutine);
                    }
                    else
                    {
                        StopCoroutine(portalEmergencyRoutine);
                        portalEmergencyRoutine = null;
                        ((GameObject)ReflectedTypes.RoomLightField.GetValue(portalRoom)).GetComponent <Light>().color = new Color(0.5f, 0.5f, 0.5f);
                    }
                }
                lastState = targetState;
            }
            yield return(null);
        }
    }
    public IEnumerator CheckForBombs()
    {
        yield return(new WaitUntil(() => (SceneManager.Instance.GameplayState.Bombs?.Count > 0)));

        yield return(null);

        List <Bomb> bombs = SceneManager.Instance.GameplayState.Bombs;

        void wrapInitialBombs()
        {
            Array.Resize(ref bombWrappers, bombs.Count);

            for (int i = 0; i < bombs.Count; i++)
            {
                Bomb        bomb        = bombs[i];
                BombWrapper bombWrapper = new BombWrapper(bomb);
                bombWrappers[i] = bombWrapper;
                bombWrapper.holdable.OnLetGo += () => BombStatus.Instance.currentBomb = null;

                if (CurrentMode == Mode.Time)
                {
                    bombWrapper.CurrentTimer = Modes.settings.TimeModeStartingTime * 60;
                }
                else if (CurrentMode == Mode.Zen)
                {
                    bombWrapper.CurrentTimer = 0.001f;
                }
            }
        }

        if (CurrentMode == Mode.Zen)
        {
            GameplayMusicController gameplayMusic = MusicManager.Instance.GameplayMusicController;
            gameplayMusic.StopMusic();
            var controller = gameplayMusic.GetComponent <DarkTonic.MasterAudio.PlaylistController>();
            controller.ClearQueue();
            controller.QueuePlaylistClip(controller.CurrentPlaylist.MusicSettings[0].songName, true);
        }

        if (ReflectedTypes.FactoryRoomType != null && ReflectedTypes.StaticModeType != null)
        {
            UnityEngine.Object factoryRoom = FindObjectOfType(ReflectedTypes.FactoryRoomType);
            if (factoryRoom)
            {
                if (ReflectedTypes.FactoryRoomDataType != null && ReflectedTypes.WarningTimeField != null)
                {
                    var roomData = FindObjectOfType(ReflectedTypes.FactoryRoomDataType);
                    if (roomData != null)
                    {
                        ReflectedTypes.WarningTimeField.SetValue(roomData, CurrentMode == Mode.Zen ? 0 : 60);
                    }
                }

                object gameMode = ReflectedTypes.GameModeProperty.GetValue(factoryRoom, null);
                if (ReflectedTypes.StaticModeType != gameMode.GetType())
                {
                    IEnumerable <object> adaptations = ((IEnumerable)ReflectedTypes.AdaptationsProperty.GetValue(gameMode, null)).Cast <object>();
                    bool globalTimerDisabled         = !adaptations.Any(adaptation => ReflectedTypes.GlobalTimerAdaptationType.IsAssignableFrom(adaptation.GetType()));

                    Component getBomb() => (Component)ReflectedTypes._CurrentBombField.GetValue(gameMode);

                    yield return(new WaitUntil(() => getBomb() != null || factoryRoom == null));

                    Component currentBomb = getBomb();
                    bool      firstBomb   = true;

                    Array.Resize(ref bombWrappers, 1);

                    while (currentBomb != null && factoryRoom != null)
                    {
                        BombWrapper bombWrapper = new BombWrapper(currentBomb.GetComponent <Bomb>());
                        bombWrappers[0] = bombWrapper;
                        bombWrapper.holdable.OnLetGo += () => BombStatus.Instance.currentBomb = null;

                        if (globalTimerDisabled || firstBomb)
                        {
                            firstBomb = false;

                            if (CurrentMode == Mode.Time)
                            {
                                bombWrapper.CurrentTimer = Modes.settings.TimeModeStartingTime * 60;
                            }
                            else if (CurrentMode == Mode.Zen)
                            {
                                bombWrapper.CurrentTimer = 0.001f;
                            }
                        }

                        yield return(new WaitUntil(() => currentBomb != getBomb() || factoryRoom == null));

                        currentBomb = getBomb();

                        if (currentBomb == null || factoryRoom == null)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    wrapInitialBombs();
                }

                yield break;
            }
        }

        // This code only runs if we aren't in the Factory room.
        wrapInitialBombs();

        SceneManager.Instance.GameplayState.Room.PacingActions.RemoveAll(pacingAction => pacingAction.EventType == Assets.Scripts.Pacing.PaceEvent.OneMinuteLeft);
        UnityEngine.Object portalRoom = null;
        if (ReflectedTypes.PortalRoomType != null && ReflectedTypes.RedLightsMethod != null && ReflectedTypes.RoomLightField != null)
        {
            portalRoom = FindObjectOfType(ReflectedTypes.PortalRoomType);
        }
        bool        lastState = false;
        IEnumerator portalEmergencyRoutine = null;

        while (CurrentState == KMGameInfo.State.Gameplay)
        {
            bool targetState = CurrentMode != Mode.Zen && bombWrappers.Any((BombWrapper bombWrapper) => !bombWrapper.Bomb.IsSolved() && bombWrapper.CurrentTimer < 60f);
            if (targetState != lastState)
            {
                foreach (Assets.Scripts.Props.EmergencyLight emergencyLight in FindObjectsOfType <Assets.Scripts.Props.EmergencyLight>())
                {
                    if (targetState)
                    {
                        emergencyLight.Activate();
                    }
                    else
                    {
                        emergencyLight.Deactivate();
                    }
                }
                if (portalRoom != null)
                {
                    if (targetState)
                    {
                        portalEmergencyRoutine = (IEnumerator)ReflectedTypes.RedLightsMethod.Invoke(portalRoom, null);
                        StartCoroutine(portalEmergencyRoutine);
                    }
                    else
                    {
                        StopCoroutine(portalEmergencyRoutine);
                        portalEmergencyRoutine = null;
                        ((GameObject)ReflectedTypes.RoomLightField.GetValue(portalRoom)).GetComponent <Light>().color = new Color(0.5f, 0.5f, 0.5f);
                    }
                }
                lastState = targetState;
            }
            yield return(null);
        }
    }