protected override IEnumerator RespondToCommandInternal(string command)
    {
        IEnumerator handler = (IEnumerator)HandlerMethod.Invoke(CommandComponent, new object[] { command });

        CancelBool?.SetValue(CommandComponent, false);
        while (handler.MoveNext())
        {
            yield return(handler.Current);
        }
    }
Esempio n. 2
0
    protected override IEnumerator RespondToCommandInternal(string command)
    {
        KMSelectable[] selectables = (KMSelectable[])HandlerMethod.Invoke(CommandComponent, new object[] { command });
        if (selectables == null)
        {
            yield break;
        }
        yield return(null);

        yield return(selectables);
    }
Esempio n. 3
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;
            }