private IEnumerator CheckForBomb()
    {
        yield return(new WaitUntil(() => SceneManager.Instance.GameplayState.Bombs != null && SceneManager.Instance.GameplayState.Bombs.Count > 0));

        yield return(null);

        var bombs = SceneManager.Instance.GameplayState.Bombs;

        try
        {
            ModuleCameras = Instantiate(moduleCamerasPrefab);
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, "Failed to instantiate the module camera system due to an exception:");
            ModuleCameras = null;
        }

        if (GameRoom.GameRoomTypes.Where((t, i) => t() != null && GameRoom.CreateRooms[i](FindObjectsOfType(t()), out GameRoom.Instance)).Any())
        {
            GameRoom.Instance.InitializeBombs(bombs);
        }
        ModuleCameras?.ChangeBomb(Bombs[0]);

        try
        {
            GameRoom.Instance.InitializeBombNames();
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, "An exception has occurred while setting the bomb names");
        }
        StartCoroutine(GameRoom.Instance.ReportBombStatus());
        StartCoroutine(GameRoom.Instance.InterruptLights());

        try
        {
            if (GameRoom.Instance.HoldBomb)
            {
                TwitchPlaysService.Instance.CoroutineQueue.AddToQueue(BombCommands.Hold(Bombs[0]));
            }
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, "An exception has occurred attempting to hold the bomb.");
        }

        NotesDictionary.Clear();
        CommandQueue.Clear();
        ModuleCameras?.SetNotes();

        if (EnableDisableInput())
        {
            TwitchModule.SolveUnsupportedModules(true);
        }

        while (OtherModes.ZenModeOn)
        {
            foreach (var bomb in Bombs)
            {
                if (bomb.Bomb.GetTimer() != null && bomb.Bomb.GetTimer().GetRate() > 0)
                {
                    bomb.Bomb.GetTimer().SetRateModifier(-bomb.Bomb.GetTimer().GetRate());
                }
            }
            yield return(null);
        }
    }
    private IEnumerator CheckForBomb()
    {
        TwitchComponentHandle.ResetId();

        Bomb[] bombs;
        do
        {
            yield return(null);

            bombs = FindObjectsOfType <Bomb>();
            if (bombs.Length > 0)
            {
                yield return(new WaitForSeconds(0.1f));

                bombs = FindObjectsOfType <Bomb>();
            }

            for (int i = 0; i < GameRoom.GameRoomTypes.Length; i++)
            {
                if (GameRoom.GameRoomTypes[i]() != null && GameRoom.CreateRooms[i](FindObjectsOfType(GameRoom.GameRoomTypes[i]()), out GameRoom.Instance))
                {
                    break;
                }
            }
            _currentBomb = bombs.Length == 1 ? -1 : 0;
            for (int i = 0; i < bombs.Length; i++)
            {
                SetBomb(bombs[i], _currentBomb == -1 ? -1 : i);
            }
            GameRoom.Instance.InitializeBombNames(_bombHandles);
            StartCoroutine(GameRoom.Instance.ReportBombStatus(_bombHandles));

            if (GameRoom.Instance.HoldBomb)
            {
                _coroutineQueue.AddToQueue(_bombHandles[0].OnMessageReceived(_bombHandles[0].nameText.text, "red", "!bomb hold"), _currentBomb);
            }
        } while (bombs.Length == 0);

        AlarmClock[] clocks;
        do
        {
            yield return(null);

            clocks = FindObjectsOfType <AlarmClock>();
        } while (clocks == null || clocks.Length == 0);
        alarmClock = clocks[0];

        try
        {
            moduleCameras = Instantiate <ModuleCameras>(moduleCamerasPrefab);
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, "Failed to Instantiate the module Camera system due to an Exception: ");
            moduleCameras = null;
        }

        for (int i = 0; i < 4; i++)
        {
            _notes[i] = TwitchPlaySettings.data.NotesSpaceFree;
            moduleCameras?.SetNotes(i, TwitchPlaySettings.data.NotesSpaceFree);
        }

        if (EnableDisableInput())
        {
            TwitchComponentHandle.SolveUnsupportedModules();
        }
    }
    private IEnumerator CheckForBomb()
    {
        yield return(new WaitUntil(() => (SceneManager.Instance.GameplayState.Bombs != null && SceneManager.Instance.GameplayState.Bombs.Count > 0)));

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

        for (int i = 0; i < GameRoom.GameRoomTypes.Length; i++)
        {
            if (GameRoom.GameRoomTypes[i]() != null && GameRoom.CreateRooms[i](FindObjectsOfType(GameRoom.GameRoomTypes[i]()), out GameRoom.Instance))
            {
                GameRoom.Instance.InitializeBombs(bombs);
                break;
            }
        }

        try
        {
            GameRoom.Instance.InitializeBombNames();
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, "An exception has occured while setting the bomb names");
        }
        StartCoroutine(GameRoom.Instance.ReportBombStatus());

        try
        {
            if (GameRoom.Instance.HoldBomb)
            {
                _coroutineQueue.AddToQueue(BombHandles[0].OnMessageReceived(BombHandles[0].nameText.text, "red", "bomb hold"), _currentBomb);
            }
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, "An exception has occured attempting to hold the bomb.");
        }

        try
        {
            moduleCameras = Instantiate <ModuleCameras>(moduleCamerasPrefab);
        }
        catch (Exception ex)
        {
            DebugHelper.LogException(ex, "Failed to Instantiate the module camera system due to an exception:");
            moduleCameras = null;
        }
        moduleCameras?.ChangeBomb(BombCommanders[0]);

        for (int i = 0; i < 4; i++)
        {
            _notesDictionary[i] = (OtherModes.ZenModeOn && i == 3) ? TwitchPlaySettings.data.ZenModeFreeSpace : TwitchPlaySettings.data.NotesSpaceFree;
            moduleCameras?.SetNotes(i, _notesDictionary[i]);
        }

        if (EnableDisableInput())
        {
            TwitchComponentHandle.SolveUnsupportedModules(true);
        }

        while (OtherModes.ZenModeOn)
        {
            foreach (BombCommander bomb in BombCommanders)
            {
                if (bomb.timerComponent == null || bomb.timerComponent.GetRate() < 0)
                {
                    continue;
                }
                bomb.timerComponent.SetRateModifier(-bomb.timerComponent.GetRate());
            }
            yield return(null);
        }
    }
 public ModuleCamera(Camera instantiatedCamera, ModuleCameras parentInstance)
 {
     cameraInstance     = instantiatedCamera;
     parent             = parentInstance;
     originalCameraRect = cameraInstance.rect;
 }
    private IEnumerator CheckForBomb()
    {
        TwitchComponentHandle.ResetId();

        UnityEngine.Object[] bombs;
        do
        {
            yield return(null);

            bombs = FindObjectsOfType(CommonReflectedTypeInfo.BombType);
            if (bombs.Length > 0)
            {
                yield return(new WaitForSeconds(0.1f));

                bombs = FindObjectsOfType(CommonReflectedTypeInfo.BombType);
            }

            System.Random rand = new System.Random();

            if (bombs.Length == 1)
            {
                _currentBomb = -1;
                SetBomb((MonoBehaviour)bombs[0], -1);

                if (rand.NextDouble() < specialNameProbability)
                {
                    _bombHandles[0].nameText.text = singleNames[rand.Next(0, singleNames.Length - 1)];
                }
                _coroutineQueue.AddToQueue(_bombHandles[0].OnMessageReceived(_bombHandles[0].nameText.text, "red", "!bomb hold"), -1);
            }
            else
            {
                _currentBomb = 0;
                int id = 0;
                for (var i = bombs.Length - 1; i >= 0; i--)
                {
                    SetBomb((MonoBehaviour)bombs[i], id++);
                }

                if (rand.NextDouble() < specialNameProbability)
                {
                    int    nameIndex = rand.Next(0, doubleNames.Length - 1);
                    string nameText  = null;
                    for (int i = 0; i < 2; i++)
                    {
                        nameText = doubleNames[nameIndex, i];
                        if (nameText != null)
                        {
                            _bombHandles[i].nameText.text = nameText;
                        }
                    }
                }
                else
                {
                    _bombHandles[1].nameText.text = "The Other Bomb";
                }
                _coroutineQueue.AddToQueue(_bombHandles[0].OnMessageReceived(_bombHandles[0].nameText.text, "red", "!bomb hold"), 0);
            }
        } while (bombs == null || bombs.Length == 0);

        moduleCameras = Instantiate <ModuleCameras>(moduleCamerasPrefab);
    }