Beispiel #1
0
    IEnumerator TwitchHandleForcedSolve()
    {
        if (!LockUnlocked)
        {
            while (DateTime.Now.ToString("mm").Any(BombInfo.GetFormattedTime().Substring(BombInfo.GetFormattedTime().Length - 2, 2).Contains) && BombInfo.GetTime() >= 60)
            {
                yield return(true);
            }
            LockBtn.OnInteract();
            yield return(new WaitForSeconds(0.1f));
        }
        if (CurrentColumn == GoalColumn && CurrentRow == GoalRow)
        {
            string paths = Maze[0][CurrentRow, CurrentColumn].Replace(" ", "");
            int    rando = Random.Range(0, paths.Length);
            if (paths[rando] == 'U')
            {
                UpBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));

                DownBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));
            }
            else if (paths[rando] == 'L')
            {
                LeftBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));

                RightBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));
            }
            else if (paths[rando] == 'D')
            {
                DownBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));

                UpBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));
            }
            else if (paths[rando] == 'R')
            {
                RightBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));

                LeftBtn.OnInteract();
                yield return(new WaitForSeconds(0.1f));
            }
        }
        else
        {
            var q          = new Queue <int[]>();
            var allMoves   = new List <Movement>();
            var startPoint = new int[] { CurrentRow, CurrentColumn };
            var target     = new int[] { GoalRow, GoalColumn };
            q.Enqueue(startPoint);
            while (q.Count > 0)
            {
                var next = q.Dequeue();
                if (next[0] == target[0] && next[1] == target[1])
                {
                    goto readyToSubmit;
                }
                string paths         = Maze[0][next[0], next[1]];
                var    cell          = paths.Replace(" ", "");
                var    allDirections = "ULRD";
                var    offsets       = new int[, ] {
                    { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 }
                };
                for (int i = 0; i < 4; i++)
                {
                    var check = new int[] { next[0] + offsets[i, 0], next[1] + offsets[i, 1] };
                    if (cell.Contains(allDirections[i]) && !allMoves.Any(x => x.start[0] == check[0] && x.start[1] == check[1]))
                    {
                        q.Enqueue(new int[] { next[0] + offsets[i, 0], next[1] + offsets[i, 1] });
                        allMoves.Add(new Movement {
                            start = next, end = new int[] { next[0] + offsets[i, 0], next[1] + offsets[i, 1] }, direction = i
                        });
                    }
                }
            }
            throw new InvalidOperationException("There is a bug in the TP autosolver.");
readyToSubmit:
            KMSelectable[] buttons = new KMSelectable[] { UpBtn, LeftBtn, RightBtn, DownBtn };
            if (allMoves.Count != 0) // Checks for position already being target
            {
                var target2       = new int[] { target[0], target[1] };
                var lastMove      = allMoves.First(x => x.end[0] == target2[0] && x.end[1] == target2[1]);
                var relevantMoves = new List <Movement> {
                    lastMove
                };
                while (lastMove.start != startPoint)
                {
                    lastMove = allMoves.First(x => x.end[0] == lastMove.start[0] && x.end[1] == lastMove.start[1]);
                    relevantMoves.Add(lastMove);
                }
                for (int i = 0; i < relevantMoves.Count; i++)
                {
                    buttons[relevantMoves[relevantMoves.Count - 1 - i].direction].OnInteract();
                    yield return(new WaitForSeconds(.1f));
                }
            }
        }
    }
Beispiel #2
0
    IEnumerator ProcessTwitchCommand(string command)
    {
        string[] parameters = command.Split(' ');
        if (Regex.IsMatch(command, @"^\s*real time\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
        {
            DateTime currenttime = DateTime.Now;
            yield return("sendtochat Current Date/Time: " + currenttime.ToString());
        }

        else if (Regex.IsMatch(command, @"^\s*bomb time\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
        {
            string BombTime = BombInfo.GetFormattedTime();
            yield return("sendtochat Current Bomb Time: " + BombTime);
        }

        else if (Regex.IsMatch(parameters[0], @"^\s*press\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
        {
            yield return(null);

            if (LockUnlocked == false)
            {
                yield return("sendtochaterror The lock is still locked. You are unable to interact with the arrows.");

                yield break;
            }

            if (parameters.Length == 2)
            {
                foreach (char c in parameters[1])
                {
                    if (!c.ToString().EqualsAny(ValidMovements))
                    {
                        yield return("sendtochaterror An invalid movement has been detected in the command. The command was not initiated.");

                        yield break;
                    }
                }

                foreach (char d in parameters[1])
                {
                    if (Regex.IsMatch(d.ToString(), @"^\s*u\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) || Regex.IsMatch(d.ToString(), @"^\s*n\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                    {
                        UpBtn.OnInteract();
                        yield return(new WaitForSeconds(0.1f));
                    }

                    else if (Regex.IsMatch(d.ToString(), @"^\s*d\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) || Regex.IsMatch(d.ToString(), @"^\s*s\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                    {
                        DownBtn.OnInteract();
                        yield return(new WaitForSeconds(0.1f));
                    }

                    else if (Regex.IsMatch(d.ToString(), @"^\s*l\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) || Regex.IsMatch(d.ToString(), @"^\s*w\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                    {
                        LeftBtn.OnInteract();
                        yield return(new WaitForSeconds(0.1f));
                    }

                    else if (Regex.IsMatch(d.ToString(), @"^\s*r\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) || Regex.IsMatch(d.ToString(), @"^\s*e\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
                    {
                        RightBtn.OnInteract();
                        yield return(new WaitForSeconds(0.1f));
                    }
                }
            }

            else
            {
                yield return("sendtochaterror Invalid parameter length.");

                yield break;
            }
        }

        else if (Regex.IsMatch(parameters[0], @"^\s*unlock\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) && parameters.Length > 1)
        {
            if (Regex.IsMatch(parameters[1], @"^\s*now\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                if (BombInfo.GetTime() < 60)
                {
                    yield return(null);

                    LockBtn.OnInteract();
                    yield break;
                }
                else
                {
                    yield return("sendtochaterror Time is not below 60 seconds. Use the command 'Unlock at' instead.");

                    yield break;
                }
            }

            else if (Regex.IsMatch(parameters[1], @"^\s*at\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                yield return(null);

                if (LockUnlocked == true)
                {
                    yield return("sendtochaterror The lock is unlocked now. You are unable to unlock it again.");

                    yield break;
                }

                if (parameters.Length == 3)
                {
                    string[] timer = parameters[2].Split(':');
                    foreach (string a in timer)
                    {
                        foreach (char b in a)
                        {
                            if (!b.ToString().EqualsAny(ValidNumbers))
                            {
                                yield return("sendtochaterror Time given contains a character which is not a number.");

                                yield break;
                            }
                        }
                    }

                    if (timer.Length != 2)
                    {
                        yield return("sendtochaterror Time length given is not valid.");

                        yield break;
                    }

                    if (!timer[1].EqualsAny(SecondsAndMinutes) || timer[0].Length < 2 || (timer[0].Length > 2 && timer[0][0] == '0'))
                    {
                        yield return("sendtochaterror Time format given is not valid.");

                        yield break;
                    }

                    while (BombInfo.GetFormattedTime() != parameters[2])
                    {
                        yield return("trycancel The unlocking command was cancelled due to a cancel request.");

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

                    LockBtn.OnInteract();
                }
                else
                {
                    yield return("sendtochaterror Invalid parameter length.");

                    yield break;
                }
            }
        }
    }