Exemplo n.º 1
0
    private IEnumerator ProcessQueueCoroutine()
    {
        CoroutineCanceller.ResetCancel();

        while (_coroutineQueue.Count > 0)
        {
            IEnumerator coroutine = _coroutineQueue.Dequeue();
            if (_bombIDProcessed.Count > 0)
            {
                CurrentBombID = _bombIDProcessed.Dequeue();
            }
            bool result = true;
            while (result)
            {
                try
                {
                    result = coroutine.MoveNext();
                }
                catch (Exception e)
                {
                    DebugHelper.LogException(e, "An exception occurred while executing a queued coroutine:");
                    result = false;
                }
                if (result)
                {
                    yield return(coroutine.Current);
                }
            }
        }

        _processing      = false;
        _activeCoroutine = null;

        CoroutineCanceller.ResetCancel();
    }
 public WaitForSecondsWithCancel(float seconds, CoroutineCanceller canceller, bool resetCancel = true)
 {
     _seconds      = seconds;
     _canceller    = canceller;
     _startingTime = Time.time;
     _resetCancel  = resetCancel;
 }
Exemplo n.º 3
0
    private IEnumerator ProcessQueueCoroutine()
    {
        CoroutineCanceller.ResetCancel();

        while (_coroutineQueue.Count > 0)
        {
            IEnumerator coroutine = _coroutineQueue.Dequeue();
            if (_bombIDProcessed.Count > 0)
            {
                CurrentBombID = _bombIDProcessed.Dequeue();
            }
            bool result = true;
            while (result)
            {
                try
                {
                    result = coroutine.MoveNext();
                }
                catch
                {
                    result = false;
                }
                if (result)
                {
                    yield return(coroutine.Current);
                }
            }
        }

        _processing      = false;
        _activeCoroutine = null;

        CoroutineCanceller.ResetCancel();
    }
    protected internal override IEnumerator RespondToCommandInternal(string inputCommand)
    {
        inputCommand = inputCommand.Trim();
        if (!inputCommand.StartsWith("press ", StringComparison.InvariantCultureIgnoreCase))
        {
            yield break;
        }
        inputCommand = inputCommand.Substring(6);

        string sequence = "pressing ";

        foreach (Match move in Regex.Matches(inputCommand, @"(\b(red|blue|green|yellow)\b|[rbgy])", RegexOptions.IgnoreCase))
        {
            SimonButton button = _buttons[buttonIndex[move.Value.Substring(0, 1).ToLowerInvariant()]];

            if (button != null)
            {
                yield return(move.Value);

                sequence += move.Value + " ";

                if (CoroutineCanceller.ShouldCancel)
                {
                    CoroutineCanceller.ResetCancel();
                    yield break;
                }

                yield return(DoInteractionClick(button, sequence));
            }
        }
    }
Exemplo n.º 5
0
    public void SetupResponder(IRCConnection ircConnection, CoroutineQueue coroutineQueue, CoroutineCanceller coroutineCanceller)
    {
        _ircConnection      = ircConnection;
        _coroutineQueue     = coroutineQueue;
        _coroutineCanceller = coroutineCanceller;

        _ircConnection.OnMessageReceived.AddListener(OnInternalMessageReceived);
    }
Exemplo n.º 6
0
    public static IEnumerator DefaultCommand(TwitchModule module, string user, string cmd)
    {
        if (cmd.RegexMatch(out Match match, @"(?<zoom>zoom *(?<time>\d*\.?\d+)?)? *(?<tilt>tilt *(?<direction>[uptobmdwnlefrigh]+|-?\d+)?)? *(?:send *to *module)? *(?<command>.+)?"))
        {
            var groups  = match.Groups;
            var timed   = groups["time"].Success;
            var zoom    = groups["zoom"].Success;
            var tilt    = groups["tilt"].Success;
            var command = groups["command"].Success;

            // Both a time and a command can't be entered. And either a zoom or tilt needs to take place otherwise, we should let the command run normally.
            if ((!timed || !command) && (zoom || tilt))
            {
                MusicPlayer musicPlayer = null;
                int         delay       = 2;
                if (timed)
                {
                    delay = groups["time"].Value.TryParseInt() ?? 2;
                    delay = Math.Max(2, delay);
                    if (delay >= 15)
                    {
                        musicPlayer = MusicPlayer.StartRandomMusic();
                    }
                }

                object toYield = command ? (object)RunModuleCommand(module, user, groups["command"].Value) : delay;

                IEnumerator routine = null;
                if (tilt)
                {
                    routine = Tilt(module, toYield, groups["direction"].Value);
                }

                if (zoom)
                {
                    routine = Zoom(module, user, routine ?? toYield);
                }

                yield return(routine);

                if (CoroutineCanceller.ShouldCancel)
                {
                    CoroutineCanceller.ResetCancel();
                    IRCConnection.SendMessage($"Sorry @{user}, your request to hold up the bomb for {delay} seconds has been cut short.");
                }

                if (musicPlayer != null)
                {
                    musicPlayer.StopMusic();
                }

                yield break;
            }
        }

        yield return(RunModuleCommand(module, user, cmd));
    }
Exemplo n.º 7
0
    public ComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller)
    {
        BombCommander = bombCommander;
        BombComponent = bombComponent;
        Selectable    = (MonoBehaviour)bombComponent.GetComponent(_selectableType);
        IRCConnection = ircConnection;
        Canceller     = canceller;

        HookUpEvents();
    }
Exemplo n.º 8
0
    public ComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller)
    {
        BombCommander = bombCommander;
        BombComponent = bombComponent;
        Selectable    = bombComponent.GetComponent <Selectable>();
        IRCConnection = ircConnection;
        Canceller     = canceller;

        HookUpEvents();
    }
Exemplo n.º 9
0
    private void Start()
    {
        _gameInfo = GetComponent <KMGameInfo>();
        _gameInfo.OnStateChange += OnStateChange;

        _modSettings = GetComponent <KMModSettings>();

        ModSettingsJSON settings = JsonConvert.DeserializeObject <ModSettingsJSON>(_modSettings.Settings);

        if (settings == null)
        {
            DebugHelper.LogError("Failed to read connection settings from mod settings.");
            return;
        }

        DebugMode = (settings.debug == true);

        _ircConnection = new IRCConnection(settings.authToken, settings.userName, settings.channelName, settings.serverName, settings.serverPort);
        _ircConnection.Connect();

        _coroutineCanceller = new CoroutineCanceller();

        _coroutineQueue = GetComponent <CoroutineQueue>();
        _coroutineQueue.coroutineCanceller = _coroutineCanceller;

        logUploader = GetComponent <LogUploader>();
        logUploader.ircConnection = _ircConnection;

        urlHelper = GetComponent <UrlHelper>();
        urlHelper.ChangeMode(settings.shortUrls == true);

        _leaderboard = new Leaderboard();
        _leaderboard.LoadDataFromFile();

        ModuleData.LoadDataFromFile();
        ModuleData.WriteDataToFile();

        TwitchPlaySettings.LoadDataFromFile();

        UserAccess.AddUser(settings.userName, AccessLevel.Streamer | AccessLevel.SuperUser | AccessLevel.Admin | AccessLevel.Mod);
        UserAccess.AddUser(settings.channelName.Replace("#", ""), AccessLevel.Streamer | AccessLevel.SuperUser | AccessLevel.Admin | AccessLevel.Mod);
        UserAccess.WriteAccessList();

        SetupResponder(bombMessageResponder);
        SetupResponder(postGameMessageResponder);
        SetupResponder(missionMessageResponder);
        SetupResponder(miscellaneousMessageResponder);

        bombMessageResponder.leaderboard          = _leaderboard;
        postGameMessageResponder.leaderboard      = _leaderboard;
        miscellaneousMessageResponder.leaderboard = _leaderboard;

        bombMessageResponder.parentService = this;
    }
Exemplo n.º 10
0
    public void StopQueue()
    {
        if (_activeCoroutine != null)
        {
            StopCoroutine(_activeCoroutine);
            _activeCoroutine = null;
        }

        _processing = false;

        CoroutineCanceller.ResetCancel();
    }
Exemplo n.º 11
0
    public static IEnumerator Zoom(TwitchModule module, string user, [Group(1)] float?duration)
    {
        MusicPlayer musicPlayer = null;
        var         delay       = duration ?? 2;

        delay = Math.Max(2, delay);
        module.Solver._zoom = true;
        if (delay >= 15)
        {
            musicPlayer = MusicPlayer.StartRandomMusic();
        }

        var zoomCoroutine = TwitchGame.ModuleCameras?.ZoomCamera(module, 1);

        if (zoomCoroutine != null)
        {
            while (zoomCoroutine.MoveNext())
            {
                yield return(zoomCoroutine.Current);
            }
        }

        yield return(new WaitForSecondsWithCancel(delay, false, module.Solver));

        if (CoroutineCanceller.ShouldCancel)
        {
            CoroutineCanceller.ResetCancel();
            IRCConnection.SendMessage($"Sorry @{user}, your request to hold up the bomb for {delay} seconds has been cut short.");
        }

        if (musicPlayer != null)
        {
            musicPlayer.StopMusic();
        }

        var unzoomCoroutine = TwitchGame.ModuleCameras?.UnzoomCamera(module, 1);

        if (unzoomCoroutine != null)
        {
            while (unzoomCoroutine.MoveNext())
            {
                yield return(unzoomCoroutine.Current);
            }
        }
    }
Exemplo n.º 12
0
    private IEnumerator ProcessQueueCoroutine()
    {
        while (_coroutineQueue.Count > 0)
        {
            CoroutineCanceller.ResetCancel();

            IEnumerator coroutine = _coroutineQueue.First.Value;
            if (_bombIDProcessed.Count > 0)
            {
                CurrentBombID = _bombIDProcessed.Dequeue();
            }

            yield return(ProcessCoroutine(coroutine));

            _coroutineQueue.RemoveFirst();
        }

        _processing      = false;
        _activeCoroutine = null;

        CoroutineCanceller.ResetCancel();
    }
Exemplo n.º 13
0
 public void StopCommands()
 {
     CoroutineCanceller.SetCancel();
     TwitchPlaysService.Instance.CoroutineQueue.CancelFutureSubcoroutines();
     SetCurrentBomb();
 }
 public AlphabetComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
     base(bombCommander, bombComponent, ircConnection, canceller)
 {
     _buttons = bombComponent.GetComponent <KMSelectable>().Children;
     modInfo  = ComponentSolverFactory.GetModuleInfo(GetModuleType());
 }
 public NeedyRotaryPhoneComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
     base(bombCommander, bombComponent, ircConnection, canceller)
 {
     _buttons    = new MonoBehaviour[10];
     _buttons[0] = (MonoBehaviour)_button0Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[1] = (MonoBehaviour)_button1Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[2] = (MonoBehaviour)_button2Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[3] = (MonoBehaviour)_button3Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[4] = (MonoBehaviour)_button4Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[5] = (MonoBehaviour)_button5Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[6] = (MonoBehaviour)_button6Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[7] = (MonoBehaviour)_button7Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[8] = (MonoBehaviour)_button8Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     _buttons[9] = (MonoBehaviour)_button9Field.GetValue(bombComponent.GetComponent(_componentSolverType));
     modInfo     = ComponentSolverFactory.GetModuleInfo(GetModuleType());
 }
 public SafetySafeComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
     base(bombCommander, bombComponent, ircConnection, canceller)
 {
     _buttons = (MonoBehaviour[])_buttonsField.GetValue(bombComponent.GetComponent(_componentType));
     _lever   = (MonoBehaviour)_leverField.GetValue(bombComponent.GetComponent(_componentType));
     modInfo  = ComponentSolverFactory.GetModuleInfo(GetModuleType());
 }
Exemplo n.º 17
0
    public static IEnumerator DefaultCommand(TwitchModule module, string user, string cmd)
    {
        if ((Votes.Active && Votes.CurrentVoteType == VoteTypes.Solve && Votes.voteModule == module) || module.Votesolving)
        {
            IRCConnection.SendMessage($"Sorry @{user}, the module you are trying to interact with is being votesolved.");
            yield break;
        }
        if (cmd.RegexMatch(out Match match, @"(?:(?<zoom>zoom *(?<time>\d*\.?\d+)?)|(?<superzoom>superzoom *(?<factor>\d*\.?\d+) *(?<x>\d*\.?\d+)? *(?<y>\d*\.?\d+)? *(?<stime>\d*\.?\d+)?))? *(?:(?<tilt>tilt *(?<direction>[uptobmdwnlefrigh]+|-?\d+)?)|(?<show>show)?)? *(?:send *to *module)? *(?<command>.+)?"))
        {
            var groups  = match.Groups;
            var timed   = groups["time"].Success || groups["stime"].Success;
            var zooming = groups["zoom"].Success || groups["superzoom"].Success;
            var tilt    = groups["tilt"].Success;
            var show    = groups["show"].Success;
            var command = groups["command"].Success;

            if (!timed && !zooming && !command && show)
            {
                yield return(Show(module, 0.5));

                yield break;
            }
            // Both a time and a command can't be entered. And either a zoom, show or tilt needs to take place otherwise, we should let the command run normally.
            if ((!timed || !command) && (zooming || tilt || show))
            {
                MusicPlayer musicPlayer = null;
                float       delay       = 2;
                if (timed)
                {
                    delay = groups["time"].Value.TryParseInt() ?? groups["stime"].Value.TryParseInt() ?? 2;
                    delay = Math.Max(2, delay);
                }

                object toYield = command ? (object)RunModuleCommand(module, user, groups["command"].Value) : delay;

                IEnumerator routine = null;
                if (show)
                {
                    routine = Show(module, toYield);
                }
                if (tilt)
                {
                    routine = Tilt(module, toYield, groups["direction"].Value.ToLowerInvariant());
                }

                if (zooming)
                {
                    var zoomData = new SuperZoomData(
                        groups["factor"].Value.TryParseFloat() ?? 1,
                        groups["x"].Value.TryParseFloat() ?? 0.5f,
                        groups["y"].Value.TryParseFloat() ?? 0.5f
                        );
                    routine = Zoom(module, zoomData, routine ?? toYield);
                }

                if (delay >= 15)
                {
                    musicPlayer = MusicPlayer.StartRandomMusic();
                }

                yield return(routine);

                if (CoroutineCanceller.ShouldCancel)
                {
                    CoroutineCanceller.ResetCancel();
                    IRCConnection.SendMessage($"Sorry @{user}, your request to hold up the bomb for {delay} seconds has been cut short.");
                }

                if (musicPlayer != null)
                {
                    musicPlayer.StopMusic();
                }

                yield break;
            }
        }

        yield return(RunModuleCommand(module, user, cmd));
    }
Exemplo n.º 18
0
    public NumberPadComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
        base(bombCommander, bombComponent, ircConnection, canceller)
    {
        Component component = bombComponent.GetComponent("NumberPadModule");

        if (component == null)
        {
            throw new NotSupportedException("Could not get NumberPadModule Component from bombComponent");
        }

        Type componentType = component.GetType();

        if (componentType == null)
        {
            throw new NotSupportedException("Could not get componentType from NumberPadModule Component");
        }

        FieldInfo buttonsField = componentType.GetField("buttons", BindingFlags.Public | BindingFlags.Instance);

        if (buttonsField == null)
        {
            throw new NotSupportedException("Could not find the KMSelectable fields in component Type");
        }

        _buttons = (KMSelectable[])buttonsField.GetValue(component);
        if (_buttons == null)
        {
            throw new NotSupportedException("Component had null KMSelectables.");
        }

        modInfo = ComponentSolverFactory.GetModuleInfo(GetModuleType());
    }
    public TurnTheKeyAdvancedComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
        base(bombCommander, bombComponent, ircConnection, canceller)
    {
        _leftKey  = (MonoBehaviour)_leftKeyField.GetValue(bombComponent.GetComponent(_componentType));
        _rightKey = (MonoBehaviour)_rightKeyField.GetValue(bombComponent.GetComponent(_componentType));
        modInfo   = ComponentSolverFactory.GetModuleInfo(GetModuleType());

        ((KMSelectable)_leftKey).OnInteract  = () => HandleKey(LeftBeforeA, LeftAfterA, _leftKeyTurnedField, _rightKeyTurnedField, _beforeLeftKeyField, _onLeftKeyTurnMethod);
        ((KMSelectable)_rightKey).OnInteract = () => HandleKey(RightBeforeA, RightAfterA, _rightKeyTurnedField, _leftKeyTurnedField, _beforeRightKeyField, _onRightKeyTurnMethod);
    }
Exemplo n.º 20
0
 public static void Cancel() => CoroutineCanceller.SetCancel();
 public RoundKeypadComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
     base(bombCommander, bombComponent, ircConnection, canceller)
 {
     _buttons    = (Array)_buttonsField.GetValue(bombComponent.GetComponent(_componentType));
     helpMessage = "Solve the module with !{0} press 2 4 6 7 8. Button 1 is the top most botton, and are numbered in clockwise order.";
 }
    public ShapeShiftComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
        base(bombCommander, bombComponent, ircConnection, canceller)
    {
        object _component = bombComponent.GetComponent(_componentType);

        _buttons = (KMSelectable[])_buttonsField.GetValue(_component);
        bombComponent.StartCoroutine(GetDisplay(_component));
        helpMessage = "Submit your anwser with !{0} submit point round. Reset to initial state with !{0} reset. Valid shapes: flat, point, round and ticket.";
    }
    public OrientationCubeComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
        base(bombCommander, bombComponent, ircConnection, canceller)
    {
        _submit = (MonoBehaviour)_submitField.GetValue(bombComponent.GetComponent(_componentType));
        _left   = (MonoBehaviour)_leftField.GetValue(bombComponent.GetComponent(_componentType));
        _right  = (MonoBehaviour)_rightField.GetValue(bombComponent.GetComponent(_componentType));
        _ccw    = (MonoBehaviour)_ccwField.GetValue(bombComponent.GetComponent(_componentType));
        _cw     = (MonoBehaviour)_cwField.GetValue(bombComponent.GetComponent(_componentType));

        helpMessage = "Move the cube with !{0} press cw l set.  The buttons are l, r, cw, ccw, set.";
    }
Exemplo n.º 24
0
    public UnsupportedModComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller)
        : base(bombCommander, bombComponent, ircConnection, canceller)
    {
        bombModule  = bombComponent.GetComponent <KMBombModule>();
        needyModule = bombComponent.GetComponent <KMNeedyModule>();

        modInfo = new ModuleInformation {
            moduleScore = 0, builtIntoTwitchPlays = true, DoesTheRightThing = true, helpText = $"Solve this {(bombModule != null ? "module" : "needy")} with !{{0}} solve", moduleDisplayName = $"Unsupported Twitchplays Module  ({bombComponent.GetModuleDisplayName()})", moduleID = "UnsupportedTwitchPlaysModule"
        };

        UnsupportedModule = true;

        Selectable selectable = bombComponent.GetComponent <Selectable>();

        Selectable[]         selectables       = bombComponent.GetComponentsInChildren <Selectable>();
        HashSet <Selectable> selectableHashSet = new HashSet <Selectable>(selectables)
        {
            selectable
        };


        selectable.OnInteract += () => { ComponentHandle?.canvasGroupUnsupported?.gameObject.SetActive(false); return(true); };
        selectable.OnDeselect += (x) => { ComponentHandle?.canvasGroupUnsupported?.gameObject.SetActive(x == null || !selectableHashSet.Contains(x)); };
    }
Exemplo n.º 25
0
    public TurnTheKeyAdvancedComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
        base(bombCommander, bombComponent, ircConnection, canceller)
    {
        _leftKey  = (MonoBehaviour)_leftKeyField.GetValue(bombComponent.GetComponent(_componentType));
        _rightKey = (MonoBehaviour)_rightKeyField.GetValue(bombComponent.GetComponent(_componentType));

        helpMessage = "Turn the left key with !{0} turn left. Turn the right key with !{0} turn right.";
    }
Exemplo n.º 26
0
 public CryptographyComponentSolver(BombCommander bombCommander, BombComponent bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
     base(bombCommander, bombComponent, ircConnection, canceller)
 {
     _buttons = (KMSelectable[])_keysField.GetValue(bombComponent.GetComponent(_componentType));
     modInfo  = ComponentSolverFactory.GetModuleInfo(GetModuleType());
 }
 public ListeningComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
     base(bombCommander, bombComponent, ircConnection, canceller)
 {
     _bc         = bombComponent.GetComponent(_componentType);
     _buttons    = new MonoBehaviour[4];
     helpMessage = "Listen to the sound with !{0} press play. Enter the response with !{0} press $ & * * #.";
 }
Exemplo n.º 28
0
 public CrazyTalkComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
     base(bombCommander, bombComponent, ircConnection, canceller)
 {
     _toggle     = (MonoBehaviour)_toggleField.GetValue(bombComponent.GetComponent(_componentType));
     helpMessage = "Toggle the switch down and up with !{0} toggle 4 5. The order is down, then up.";
 }
    public SafetySafeComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
        base(bombCommander, bombComponent, ircConnection, canceller)
    {
        _buttons = (MonoBehaviour[])_buttonsField.GetValue(bombComponent.GetComponent(_componentType));
        _lever   = (MonoBehaviour)_leverField.GetValue(bombComponent.GetComponent(_componentType));

        helpMessage = "Listen to the dials with !{0} cycle. Listen to a single dial with !{0} cycle BR. Make a correction to a single dial with !{0} BM 3. Enter the solution with !{0} 6 0 6 8 2 5. Submit the answer with !{0} submit. Dial positions are TL, TM, TR, BL, BM, BR.";
    }
    public InvisibleWallsComponentSolver(BombCommander bombCommander, MonoBehaviour bombComponent, IRCConnection ircConnection, CoroutineCanceller canceller) :
        base(bombCommander, bombComponent, ircConnection, canceller)
    {
        _buttons = (IList)_buttonsField.GetValue(bombComponent);

        helpMessage = "!{0} move up down left right, !{0} move udlr [make a series of white icon moves]";
        manualCode  = "Mazes";
    }