Exemple #1
0
        private async Task SetStickAsyncImpl(SwitchStick s, short x, short y, ushort ms, BotSource <PokeBotConfig> bot)
        {
            if (!Enum.IsDefined(typeof(SwitchStick), s))
            {
                await ReplyAsync($"Unknown stick: {s}").ConfigureAwait(false);

                return;
            }

            await bot.Bot.Connection.SendAsync(SwitchCommand.SetStick(s, x, y), bot.Bot.Config.ConnectionType, CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{bot.Bot.Connection.Name} has performed: {s}").ConfigureAwait(false);

            await Task.Delay(ms).ConfigureAwait(false);

            await bot.Bot.Connection.SendAsync(SwitchCommand.ResetStick(s), bot.Bot.Config.ConnectionType, CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{bot.Bot.Connection.Name} has reset the stick position.").ConfigureAwait(false);
        }
        private async Task SetStickAsyncImpl(SwitchStick s, short x, short y, ushort ms)
        {
            if (!Enum.IsDefined(typeof(SwitchStick), s))
            {
                await ReplyAsync($"Unknown stick: {s}").ConfigureAwait(false);

                return;
            }

            var b = Bot;
            await b.Connection.SendAsync(SwitchCommand.SetStick(s, x, y, b.UseCRLF), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has performed: {s}").ConfigureAwait(false);

            await Task.Delay(ms).ConfigureAwait(false);

            await b.Connection.SendAsync(SwitchCommand.ResetStick(s, b.UseCRLF), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has reset the stick position.").ConfigureAwait(false);
        }
Exemple #3
0
    public async Task DoSocketQueue(bool isNetwork, CancellationToken token)
    {
        while (!token.IsCancellationRequested)
        {
            if (ExecutionQueue.TryDequeue(out var item))
            {
                byte[] command = Array.Empty <byte>();
                switch (item.PType)
                {
                case PressType.ButtonPress: command = SwitchCommand.Hold(item.ButtonToPress, isNetwork); break;

                case PressType.ButtonRelease: command = SwitchCommand.Release(item.ButtonToPress, isNetwork); break;

                case PressType.Joystick: command = SwitchCommand.SetStick(item.StickToMove, item.X, item.Y); break;
                }
                try { Connection.CurrentConnection.SendBytes(command); } catch { }
            }

            await Task.Delay(1, token).ConfigureAwait(false);
        }
    }
Exemple #4
0
        private async Task SetStickAsyncImpl(SwitchStick s, short x, short y, ushort ms, BotSource <PokeBotState> bot)
        {
            if (!Enum.IsDefined(typeof(SwitchStick), s))
            {
                await ReplyAsync($"Unknown stick: {s}").ConfigureAwait(false);

                return;
            }

            var b = bot.Bot;
            var crlf = b is SwitchRoutineExecutor <PokeBotState> {
                UseCRLF : true
            };
            await b.Connection.SendAsync(SwitchCommand.SetStick(s, x, y, crlf), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has performed: {s}").ConfigureAwait(false);

            await Task.Delay(ms).ConfigureAwait(false);

            await b.Connection.SendAsync(SwitchCommand.ResetStick(s, crlf), CancellationToken.None).ConfigureAwait(false);

            await ReplyAsync($"{b.Connection.Name} has reset the stick position.").ConfigureAwait(false);
        }
    }