// ReSharper restore InconsistentNaming
    // ReSharper restore UnusedMember.Global
#pragma warning restore 414

    private IEnumerator ProcessTwitchCommand(string command)
    {
        var originalCommand = command;

        command = command.ToLowerInvariant();
        var commandUsed = false;
        var forcedSolve = false;

        if (command.Contains(_forcedSolvePassword.ToLowerInvariant()))
        {
            if (!_forcedSolve)
            {
                yield return("antitroll Sorry, I am not going to allow you to use the back door password to solve the module.");

                yield return("solve");

                StartCoroutine(TwitchHandleForcedSolve());
                yield break;
            }
            else
            {
                command     = command.Replace(_forcedSolvePassword.ToLowerInvariant(), "");
                forcedSolve = true;
            }
        }

        if (command.Equals("colorblind"))
        {
            EnableColorblindMode(true);
            yield break;
        }

        if (command.Equals("colorcommands"))
        {
            yield return(@"sendtochat You can change which colors I flash the message with using ""UseDefaultColors"", ""UseEasyColors"", or ""UseCruelColors"" anywhere in the command. You can also change how I present the solve state with ""UseGreenOnSolve"", ""UseRedOnSolve"", ""UseOffOnSolve"" or ""UseRandomOnSolve"".");

            yield break;
        }

        /*if (command.StartsWith("realstrike "))
         * {
         *  yield return null;
         *  yield return null;
         *  yield return "multiple strikes";
         *  command = originalCommand.Substring(11);
         *  var mdn = BombModule.ModuleDisplayName;
         *  BombModule.ModuleDisplayName = command;
         *  BombModule.HandleStrike();
         *  BombModule.ModuleDisplayName = mdn;
         *  yield break;
         * }*/

        if (command.StartsWith("fakestrike"))
        {
            yield return("antitroll Sorry, I am not going to cause a fake strike");

            yield return("multiple strikes");

            Audio.PlayGameSoundAtTransform(KMSoundOverride.SoundEffect.Strike, transform);
            FakeStatusLight.FlashStrike();
            Audio.HandlePlaySoundAtTransform(GlassBreak.name, transform);
            yield break;
        }

        if (command.Contains("usedefaultcolors"))
        {
            var colorblind = GetComponent <KMColorblindMode>().ColorblindModeActive;
            command = command.Replace("usedefaultcolors", "").Trim();
            FakeStatusLight.PassColor          = StatusLightState.Off;
            FakeStatusLight.MorseTransmitColor = colorblind ? StatusLightState.Off : StatusLightState.Red;
            FakeStatusLight.OffColor           = colorblind ? (Random.value < 0.5f ? StatusLightState.Red : StatusLightState.Green) : StatusLightState.Green;
            FakeStatusLight.FailColor          = StatusLightState.Off;
            commandUsed = true;
        }
        else if (command.Contains("useeasycolors"))
        {
            command = command.Replace("useeasycolors", "").Trim();
            FakeStatusLight.PassColor          = StatusLightState.Green;
            FakeStatusLight.MorseTransmitColor = StatusLightState.Green;
            FakeStatusLight.OffColor           = StatusLightState.Off;
            FakeStatusLight.FailColor          = StatusLightState.Red;
            commandUsed = true;
        }
        else if (command.Contains("usecruelcolors"))
        {
            var colorblind = GetComponent <KMColorblindMode>().ColorblindModeActive;
            command = command.Replace("usecruelcolors", "").Trim();
            FakeStatusLight.PassColor          = StatusLightState.Random;
            FakeStatusLight.FailColor          = StatusLightState.Random;
            FakeStatusLight.OffColor           = StatusLightState.Random;
            FakeStatusLight.MorseTransmitColor = StatusLightState.Random;
            FakeStatusLight.PlayWord(null).MoveNext();
            if (colorblind && ((FakeStatusLight.MorseTransmitColor == StatusLightState.Red && FakeStatusLight.OffColor == StatusLightState.Green) ||
                               (FakeStatusLight.MorseTransmitColor == StatusLightState.Green && FakeStatusLight.OffColor == StatusLightState.Red)))
            {
                if (Random.value < 0.5f)
                {
                    FakeStatusLight.OffColor = StatusLightState.Off;
                }
                else
                {
                    FakeStatusLight.MorseTransmitColor = StatusLightState.Off;
                }
            }
            commandUsed = true;
        }

        if (command.Contains("useredonsolve"))
        {
            command = command.Replace("useredonsolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Red;
            commandUsed = true;
        }
        else if (command.Contains("usegreenonsolve"))
        {
            command = command.Replace("usegreenonsolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Green;
            commandUsed = true;
        }
        else if (command.Contains("useoffonsolve"))
        {
            command = command.Replace("useoffonsolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Off;
            commandUsed = true;
        }
        else if (command.Contains("userandomonsolve"))
        {
            command = command.Replace("userandomonsolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Random;
            commandUsed = true;
        }

        /*
         * if (command.Contains("forceunicorn"))
         * {
         *  command = command.Replace("forceunicorn", "").Trim();
         *  commandUsed = true;
         *  _unicorn = true;
         * }*/


        if (command.StartsWith("move ", StringComparison.InvariantCultureIgnoreCase))
        {
            command = command.Substring(5);
        }

        command = command.Replace("north", " u ").Replace("south", " d ").Replace("west", " l ").Replace("east", " r ");
        command = command.Replace("up", " u ").Replace("down", " d ").Replace("left", " l ").Replace("right", " r ");
        command = command.Replace("n", " u ").Replace("s", " d ").Replace("w", " l ").Replace("e", " r ");

        if (_solved)
        {
            yield return("sendtochat I don't need any further directions on how to reach the exit.");

            yield break;
        }

        MatchCollection matches = Regex.Matches(command, @"[udlr]", RegexOptions.IgnoreCase);

        if (matches.Count == 0)
        {
            if (commandUsed)
            {
                yield return(string.Format("sendtochat I have changed my colors as specified by {0} successfully.", originalCommand));
            }
            else
            {
                yield return("sendtochaterror please tell me where the exit is without running me into walls.");
            }
            yield break;
        }

        foreach (char c in command)
        {
            if (!"udlr ,;".Contains(c))
            {
                yield return(string.Format("sendtochaterror I don't know how to move in the '{0}' direction.", c));
            }
        }

        yield return(null);

        if (matches.Count > 35 || Movements.Processing)
        {
            yield return("elevator music");
        }

        while (Movements.Processing)
        {
            if (forcedSolve)
            {
                yield return(true);
            }
            else
            {
                yield return("trywaitcancel 0.1");
            }
        }
        if (matches.Count <= 35)
        {
            yield return("end elevator music");
        }

        var moved = false;
        var safe  = true;

        foreach (Match move in matches)
        {
            moved = true;
            if (!safe)
            {
                while (Movements.Processing)
                {
                    yield return("trycancel");

                    yield return(new WaitForSeconds(0.1f));
                }
            }

            safe = true;
            switch (move.Value.ToLowerInvariant())
            {
            case "u":
                safe = MoveUp();
                if (!safe)
                {
                    yield return("strikemessage running me into a wall north of " + _currentLocation.parent.name + _currentLocation.name);
                }
                break;

            case "d":
                safe = MoveDown();
                if (!safe)
                {
                    yield return("strikemessage running me into a wall south of " + _currentLocation.parent.name + _currentLocation.name);
                }
                break;

            case "l":
                safe = MoveLeft();
                if (!safe)
                {
                    yield return("strikemessage running me into a wall west of " + _currentLocation.parent.name + _currentLocation.name);
                }
                break;

            case "r":
                safe = MoveRight();
                if (!safe)
                {
                    yield return("strikemessage running me into a wall east of " + _currentLocation.parent.name + _currentLocation.name);
                }
                break;

            default:
                continue;
            }
            if (!safe)
            {
                if (!TwitchPlays.Installed() && _unicorn)
                {
                    yield return("multiple strikes");

                    yield return("award strikes 0");
                }
                else
                {
                    yield return("strike");
                }
                if (forcedSolve)
                {
                    yield break;
                }
            }
            if (_solved)
            {
                yield return("solve");

                yield break;
            }
            yield return("trycancel");

            yield return(new WaitForSeconds(0.1f));
        }
        if (moved)
        {
            yield return("solve");
        }
    }
示例#2
0
    // ReSharper restore InconsistentNaming
#pragma warning restore 414
    private IEnumerator ProcessTwitchCommand(string command)
    {
        TwitchPlaysDetected = true;
        var originalCommand = command;
        var commandUsed     = false;

        if (command.Contains("UseDefaultColors"))
        {
            command = command.Replace("UseDefaultColors", "").Trim();
            FakeStatusLight.PassColor          = StatusLightState.Off;
            FakeStatusLight.MorseTransmitColor = StatusLightState.Red;
            FakeStatusLight.OffColor           = StatusLightState.Green;
            FakeStatusLight.FailColor          = StatusLightState.Off;
            yield return(new WaitForSeconds(0.1f));

            commandUsed = true;
        }
        else if (command.Contains("UseEasyColors"))
        {
            command = command.Replace("UseEasyColors", "").Trim();
            FakeStatusLight.PassColor          = StatusLightState.Green;
            FakeStatusLight.MorseTransmitColor = StatusLightState.Green;
            FakeStatusLight.OffColor           = StatusLightState.Off;
            FakeStatusLight.FailColor          = StatusLightState.Red;
            yield return(new WaitForSeconds(0.1f));

            commandUsed = true;
        }
        else if (command.Contains("UseCruelColors"))
        {
            command = command.Replace("UseCruelColors", "").Trim();
            FakeStatusLight.PassColor          = StatusLightState.Random;
            FakeStatusLight.FailColor          = StatusLightState.Random;
            FakeStatusLight.OffColor           = StatusLightState.Random;
            FakeStatusLight.MorseTransmitColor = StatusLightState.Random;
            yield return(new WaitForSeconds(0.1f));

            commandUsed = true;
        }

        if (command.Contains("UseRedOnSolve"))
        {
            command = command.Replace("UseRedOnSolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Red;
            yield return(new WaitForSeconds(0.1f));

            commandUsed = true;
        }
        else if (command.Contains("UseGreenOnSolve"))
        {
            command = command.Replace("UseGreenOnSolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Green;
            yield return(new WaitForSeconds(0.1f));

            commandUsed = true;
        }
        else if (command.Contains("UseOffOnSolve"))
        {
            command = command.Replace("UseOffOnSolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Off;
            yield return(new WaitForSeconds(0.1f));

            commandUsed = true;
        }
        else if (command.Contains("UseRandomOnSolve"))
        {
            command = command.Replace("UseOffOnSolve", "").Trim();
            FakeStatusLight.PassColor = StatusLightState.Random;
            yield return(new WaitForSeconds(0.1f));

            commandUsed = true;
        }

        /*
         * if (command.Contains("ForceUnicorn"))
         * {
         *  yield return null;
         *  commandUsed = true;
         *  _unicorn = true;
         *
         * }*/


        if (!command.StartsWith("move ", StringComparison.InvariantCultureIgnoreCase))
        {
            if (commandUsed)
            {
                yield return("sendtochat " + originalCommand + " processed successfully");
            }
            yield break;
        }

        if (_solved)
        {
            yield return("solve");

            yield break;
        }

        command = command.Substring(5);
        MatchCollection matches = Regex.Matches(command, @"[udlr]", RegexOptions.IgnoreCase);

        if (matches.Count == 0)
        {
            yield break;
        }

        yield return(null);

        if (matches.Count > 35 || _movements.Processing)
        {
            yield return("elevator music");
        }

        while (_movements.Processing)
        {
            yield return("trycancel");

            yield return(new WaitForSeconds(0.1f));
        }

        var moved = false;

        foreach (Match move in matches)
        {
            moved = true;
            bool safe;

            switch (move.Value.ToLowerInvariant())
            {
            case "u":
                safe = MoveUp();
                break;

            case "d":
                safe = MoveDown();
                break;

            case "l":
                safe = MoveLeft();
                break;

            case "r":
                safe = MoveRight();
                break;

            default:
                continue;
            }
            if (!safe)
            {
                if (!TwitchPlays.Installed() && _unicorn)
                {
                    yield return("multiple strikes");

                    yield return("award strikes 0");
                }
                else
                {
                    yield return("strike");
                }
                yield break;
            }
            if (_solved)
            {
                yield return("solve");

                yield break;
            }
            yield return("trycancel");

            yield return(new WaitForSeconds(0.1f));
        }
        if (moved)
        {
            yield return("solve");
        }
    }