Esempio n. 1
0
        public async Task OpenQueueAsync()
        {
            var author = Context.Message.Author as SocketGuildUser;

            if (!queues.TryGetValue(Context.Channel.Id, out RLQueue queue))
            {
                var  channel = Context.Channel as SocketGuildChannel;
                bool ranked  = Global.GetChannelRankRequirement(channel.Id) != null;

                switch (Context.Channel.Name.ToLower())
                {
                case "1v1":
                    queue = RLQueue.DuelQueue(channel, ranked);
                    break;

                case "2v2":
                    queue = RLQueue.DoublesQueue(channel, ranked);
                    break;

                case "3v3":
                    queue = RLQueue.StandardQueue(channel, ranked);
                    break;

                default:
                    await ReplyAsync("This is not valid queue type.");

                    return;
                }

                if (queues.TryAdd(Context.Channel.Id, queue))
                {
                    await ReplyAsync("The queue is open. Type \"" + RLBot.COMMAND_PREFIX + "qjoin\", to join it.");
                }
                else
                {
                    await ReplyAsync("Failed to create a new queue, please try again.");
                }
            }
            else
            {
                await ReplyAsync("There is already an active queue. Type \"" + RLBot.COMMAND_PREFIX + "qjoin\", to join it.");
            }
        }
Esempio n. 2
0
        public async Task JoinQueueAsync()
        {
            var queueChannel = await Database.GetQueueChannelAsync(Context.Guild.Id, Context.Channel.Id);

            if (queueChannel == null)
            {
                return;
            }

            var author = Context.Message.Author as SocketGuildUser;

            var userinfo = await Database.GetUserInfoAsync(Context.Guild.Id, author.Id);

            if (userinfo == null)
            {
                await ReplyAsync($"{author.Mention}, you need to register first.");

                return;
            }

            if (!queues.TryGetValue(Context.Channel.Id, out RLQueue queue))
            {
                var channel = Context.Channel as SocketGuildChannel;

                switch (queueChannel.Playlist)
                {
                case RLPlaylist.Duel:
                    queue = RLQueue.DuelQueue(channel, queueChannel.Ranked);
                    break;

                case RLPlaylist.Doubles:
                    queue = RLQueue.DoublesQueue(channel, queueChannel.Ranked);
                    break;

                case RLPlaylist.Standard:
                    queue = RLQueue.StandardQueue(channel, queueChannel.Ranked);
                    break;

                default:
                    await ReplyAsync("This is not valid queue type.");

                    return;
                }

                queues.TryAdd(Context.Channel.Id, queue);
            }

            if (queue.Users.Count < queue.GetSize())
            {
                // If it's a ranked queue, check if the player has the required elo
                if (!queue.IsLeaderboardQueue || HasRequiredElo(userinfo, queueChannel))
                {
                    if (!queue.Users.ContainsKey(author.Id))
                    {
                        if (queue.Users.TryAdd(author.Id, author))
                        {
                            await ReplyAsync("", embed : new EmbedBuilder()
                                             .WithColor(RLBot.EMBED_COLOR)
                                             .WithTitle($"{queue.Playlist} queue {queue.Users.Count}/{queue.GetSize()}")
                                             .AddField("Result", $"{author.Mention} joined.")
                                             .AddField("Current players", string.Join(", ", queue.Users.Values))
                                             .Build());
                        }
                        else
                        {
                            await ReplyAsync($"Failed to add {author.Mention} to the queue, please try again.");
                        }
                    }
                    else
                    {
                        await ReplyAsync($"{author.Mention}, you've already joined the queue.");
                    }
                }
                else
                {
                    await ReplyAsync($"{author.Mention}, you don't have the required elo to join the queue.");
                }
            }
            else
            {
                await ReplyAsync($"{author.Mention}, the queue is full.");
            }
        }