Exemplo n.º 1
0
        public async Task RNGGame([Summary("The minimum, inclusive bound")] int min, [Summary("The maximum, exclusive bound")] int max, int timeout = 30)
        {
            if (timeout > 300)
            {
                timeout = 0;
            }

            if (timeout > 0)
            {
                timeout = timeout * 1000;
            }
            else
            {
                timeout = 30000;
            }

            RNGGame Game = new RNGGame
            {
                Channel  = Context.Channel.Id,
                MinGuess = min,
                MaxGuess = max,
                Guesses  = new HashSet <Guess>()
            };

            if (_rngservice.StartRNGG(Game, (DiscordSocketClient)Context.Client))
            {
                await Context.Channel.SendSuccessAsync($"RNG Game (Min: {min}, Max: {max})", $"Game started! Type your guesses now! You have {timeout/1000} seconds.");

                await Task.Delay(timeout);

                await _rngservice.EndGameInChannel(Context.Guild, Context.Channel, _random);
            }
        }
Exemplo n.º 2
0
        public bool StartRNGG(RNGGame game, DiscordSocketClient client)
        {
            var rh = new RNGHandler(game, client);

            if (ActiveRNG.TryAdd(game.Channel, rh))
            {
                rh.OnVoted += Rh_onvote;
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        public async Task EndGameInChannel(IGuild guild, IMessageChannel ChannelID, FloraRandom _random)
        {
            RNGGame game = StopRNGG(ChannelID.Id);

            if (game != null)
            {
                int roll = _random.Next(game.MinGuess, game.MaxGuess + 1);
                if (game.Guesses.Select(x => x.GuessIndex == roll).FirstOrDefault())
                {
                    var        winnerID = game.Guesses.First(x => x.GuessIndex == roll);
                    IGuildUser user     = await guild.GetUserAsync(winnerID.UserID);

                    await ChannelID.BlankEmbedAsync(new EmbedBuilder().WithOkColour()
                                                    .AddField(new EmbedFieldBuilder().WithName("🎲 Roll").WithValue(roll))
                                                    .AddField(new EmbedFieldBuilder().WithName("🎉 Winner").WithValue(user.Username)).Build());
                }
                else
                {
                    await ChannelID.BlankEmbedAsync(new EmbedBuilder().WithErrorColour()
                                                    .AddField(new EmbedFieldBuilder().WithName("🎲 Roll").WithValue(roll))
                                                    .AddField(new EmbedFieldBuilder().WithName("🎉 Winner").WithValue("Nobody. That's sad.")).Build());
                }
            }
        }
Exemplo n.º 4
0
 public RNGHandler(RNGGame game, DiscordSocketClient client)
 {
     Game    = game;
     _client = client;
     _client.MessageReceived += TryGuess;
 }