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);
        }
    }
예제 #2
0
    public IEnumerator RespondToCommand(string userNickName, string message)
    {
        DisableOnStrike      = false;
        Strike               = false;
        StrikeCount          = 0;
        _currentUserNickName = userNickName;

        FloatingHoldable.HoldStateEnum holdState = Holdable.HoldState;

        if (holdState == FloatingHoldable.HoldStateEnum.Held)
        {
        }
        else
        {
            IEnumerator holdCoroutine = HoldableCommander.Hold();
            while (holdCoroutine.MoveNext() && !Strike)
            {
                yield return(holdCoroutine.Current);
            }
        }

        IEnumerator processCommand = RespondToCommandCommon(message);

        if (processCommand == null || !processCommand.MoveNext())
        {
            DebugHelper.Log("Running RespondToCommandInternal()");
            processCommand = RespondToCommandInternal(message);
            bool cancelled  = false;
            bool parseError = false;
            bool cancelling = false;

            if (processCommand == null || !processCommand.MoveNext())
            {
                if (!Strike)
                {
                    SendToChat(null, userNickName, 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:
                    HoldableCommander.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.ToLowerInvariant().Equals("cancelled") && cancelling)
                    {
                        CancelBool?.SetValue(CommandComponent, false);
                        CoroutineCanceller.ResetCancel();
                        cancelled = true;
                    }
                    else if (currentString.StartsWith("strikemessage ", StringComparison.InvariantCultureIgnoreCase) &&
                             currentString.Substring(14).Trim() != string.Empty)
                    {
                        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") && BombMessageResponder.BombActive)
                    {
                        BombCommander BombCommander = BombMessageResponder.Instance.BombCommanders[0];
                        AwardStrikes(_currentUserNickName, BombCommander.StrikeLimit - BombCommander.StrikeCount);
                        BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(string.Empty, HoldableCommander.ID);
                        Strike = true;
                    }
                    else if (currentString.ToLowerInvariant().Equals("show front"))
                    {
                        processIEnumerators.Push(HoldableCommander.Hold(true));
                    }
                    else if (currentString.ToLowerInvariant().Equals("show back"))
                    {
                        processIEnumerators.Push(HoldableCommander.Hold(false));
                    }
                    else
                    {
                        SendToChat(currentString, userNickName, ref parseError);
                    }
                    break;

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

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

                            default:
                                BombCommander.twitchBombHandle.CauseExplosionByModuleCommand(string.Empty, HoldableCommander.ID);
                                break;
                            }
                            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:
                    MiscellaneousMessageResponder.Instance.RunMission(mission);
                    break;

                case object[] objects:
                    if (objects == null)
                    {
                        break;
                    }
                    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, ref parseError);
                                    break;

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

                                    continue;
                                }
                            }
                        }
                        break;
                    }
                    break;