Example #1
0
    public IEnumerator RespondToCommand(string userNickName, string cmdStr, bool isWhisper, IEnumerator processCommand = null)
    {
        if (HandlerMethod == null && processCommand == null)
        {
            IRCConnection.SendMessage("Sorry @{0}, this holdable is not supported by Twitch Plays.", userNickName, !isWhisper, userNickName);
            yield break;
        }

        _disableOnStrike     = false;
        Strike               = false;
        StrikeCount          = 0;
        _currentUserNickName = userNickName;

        FloatingHoldable.HoldStateEnum holdState = Holdable.HoldState;

        if (holdState != FloatingHoldable.HoldStateEnum.Held)
        {
            if (TwitchGame.BombActive)
            {
                BombCommands.Drop(TwitchGame.Instance.Bombs[TwitchGame.Instance._currentBomb == -1 ? 0 : TwitchGame.Instance._currentBomb]);
            }
            IEnumerator holdCoroutine = Hold();
            while (holdCoroutine.MoveNext() && !Strike)
            {
                yield return(holdCoroutine.Current);
            }
        }

        DebugHelper.Log("Running RespondToCommandInternal()");
        if (HandlerMethod != null && processCommand == null)
        {
            processCommand = MakeCoroutine(HandlerMethod.Invoke(CommandComponent, new object[] { cmdStr }));
        }

        bool cancelled  = false;
        bool parseError = false;
        bool cancelling = false;

        if (processCommand == null || !processCommand.MoveNext())
        {
            if (!Strike)
            {
                SendToChat(null, userNickName, isWhisper, ref parseError);
            }
        }
        else
        {
            ProcessIEnumerators.Push(processCommand);
            ProcessIEnumerators.Push(FirstItem(processCommand.Current));
        }

        do
        {
            try
            {
                bool result = false;
                while (!result && !Strike)
                {
                    if (ProcessIEnumerators.Count > 0)
                    {
                        processCommand = ProcessIEnumerators.Pop();
                        result         = processCommand.MoveNext();
                        if (result)
                        {
                            ProcessIEnumerators.Push(processCommand);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (Strike)
                {
                    DebugHelper.Log("A strike was caused by the command. Invocation will not continue.");
                }
                if (!result || Strike)
                {
                    break;
                }
            }
            catch (Exception ex)
            {
                DebugHelper.LogException(ex, "Error processing command due to an exception. Invocation will not continue.:");
                break;
            }

            switch (processCommand.Current)
            {
            case IEnumerator iEnumerator:
                if (iEnumerator != null)
                {
                    ProcessIEnumerators.Push(iEnumerator);
                }
                continue;

            case KMSelectable kmSelectable when kmSelectable != null:
                if (HeldSelectables.Contains(kmSelectable))
                {
                    DoInteractionEnd(kmSelectable);
                    HeldSelectables.Remove(kmSelectable);
                }
                else
                {
                    DoInteractionStart(kmSelectable);
                    HeldSelectables.Add(kmSelectable);
                }
                break;

            case KMSelectable[] kmSelectables:
                foreach (KMSelectable selectable in kmSelectables)
                {
                    if (selectable != null)
                    {
                        yield return(DoInteractionClick(selectable));

                        if (Strike)
                        {
                            break;
                        }
                    }
                    else
                    {
                        yield return(new WaitForSeconds(0.1f));
                    }
                }

                break;

            case Quaternion quaternion:
                RotateByLocalQuaternion(quaternion);
                break;

            case string currentString when !string.IsNullOrEmpty(currentString):
                if (currentString.Equals("trycancel", StringComparison.InvariantCultureIgnoreCase) &&
                    CoroutineCanceller.ShouldCancel)
                {
                    CoroutineCanceller.ResetCancel();
                    cancelled = true;
                }
                else if (currentString.ToLowerInvariant().EqualsAny("elevator music", "hold music", "waiting music"))
                {
                    if (_musicPlayer == null)
                    {
                        _musicPlayer = MusicPlayer.StartRandomMusic();
                    }
                }
                else if (currentString.EqualsIgnoreCase("cancelled") && cancelling)
                {
                    CancelBool?.SetValue(CommandComponent, false);
                    CoroutineCanceller.ResetCancel();
                    cancelled = true;
                }
                else if (currentString.StartsWith("strikemessage ",
                                                  StringComparison.InvariantCultureIgnoreCase) &&
                         !string.IsNullOrEmpty(currentString.Substring(14).Trim()))
                {
                    StrikeMessage = currentString.Substring(14);
                }
                else if (currentString.Equals("strike", StringComparison.InvariantCultureIgnoreCase))
                {
                    _delegatedStrikeUserNickName = _currentUserNickName;
                }
                else if (currentString.Equals("multiple strikes", StringComparison.InvariantCultureIgnoreCase))
                {
                    _disableOnStrike = true;
                }
                else if (currentString.ToLowerInvariant().EqualsAny("detonate", "explode") && TwitchGame.BombActive)
                {
                    var bomb = TwitchGame.Instance.Bombs[0];
                    AwardStrikes(_currentUserNickName, bomb.StrikeLimit - bomb.StrikeCount);
                    bomb.CauseExplosionByModuleCommand(string.Empty,
                                                       ID);
                    Strike = true;
                }
                else if (currentString.EqualsIgnoreCase("show front"))
                {
                    ProcessIEnumerators.Push(Hold());
                }
                else if (currentString.EqualsIgnoreCase("show back"))
                {
                    ProcessIEnumerators.Push(Hold(false));
                }
                else
                {
                    SendToChat(currentString, userNickName, isWhisper, ref parseError);
                }

                break;

            case string[] currentStrings:
                if (currentStrings.Length >= 1)
                {
                    if (currentStrings[0].ToLowerInvariant().EqualsAny("detonate", "explode") &&
                        TwitchGame.BombActive)
                    {
                        TwitchBomb bombs = TwitchGame.Instance.Bombs[0];
                        AwardStrikes(_currentUserNickName, bombs.StrikeLimit - bombs.StrikeCount);
                        switch (currentStrings.Length)
                        {
                        case 2:
                            bombs.CauseExplosionByModuleCommand(currentStrings[1], ID);
                            break;

                        case 3:
                            bombs.CauseExplosionByModuleCommand(currentStrings[1], currentStrings[2]);
                            break;

                        default:
                            bombs.CauseExplosionByModuleCommand(string.Empty, ID);
                            break;
                        }
                    }
                }

                break;

            case Dictionary <string, bool> permissions:
                foreach (KeyValuePair <string, bool> pair in permissions)
                {
                    if (TwitchPlaySettings.data.ModPermissions.ContainsKey(pair.Key))
                    {
                        continue;
                    }
                    TwitchPlaySettings.data.ModPermissions.Add(pair.Key, pair.Value);
                    TwitchPlaySettings.WriteDataToFile();
                }
                break;

            case KMMission mission:
                TwitchPlaysService.Instance.RunMission(mission);
                break;

            case object[] objects:
                if (objects == null)
                {
                    break;
                }
                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (objects.Length)
                {
                case 3 when objects[0] is string objstr:
                    if (IsAskingPermission(objstr, userNickName, out bool permissionGranted))
                    {
                        if (permissionGranted)
                        {
                            switch (objects[1])
                            {
                            case Action actionTrue:
                                actionTrue.Invoke();
                                break;

                            case IEnumerator iEnumerator when iEnumerator != null:
                                ProcessIEnumerators.Push(iEnumerator);
                                yield return(null);

                                continue;
                            }
                        }
                        else
                        {
                            switch (objects[2])
                            {
                            case Action actionFalse:
                                actionFalse.Invoke();
                                break;

                            case string objStr2 when !string.IsNullOrEmpty(objStr2):
                                SendToChat(objStr2, userNickName, isWhisper, ref parseError);
                                break;

                            case IEnumerator iEnumerator when iEnumerator != null:
                                ProcessIEnumerators.Push(iEnumerator);
                                yield return(null);

                                continue;
                            }
                        }
                    }
                    break;
                }
                break;
            }
    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)
            {
                StartCoroutine(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);
        }

        // Set up some stuff for the !unclaimed command.
        GameCommands.unclaimedModules     = Modules.Where(h => h.CanBeClaimed).Shuffle().ToList();
        GameCommands.unclaimedModuleIndex = 0;

        while (OtherModes.Unexplodable)
        {
            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);
        }

        TwitchPlaysService.Instance.UpdateUiHue();
    }
Example #3
0
    private IEnumerator CheckForBomb()
    {
        yield return(new WaitUntil(() => SceneManager.Instance.GameplayState.Bombs != null && SceneManager.Instance.GameplayState.Bombs.Count > 0));

        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.");
        }

        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())
        {
            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);
        }
    }