Exemple #1
0
            public async Task ExecuteGroupAsync(CommandContext ctx)
            {
                if (this.Service.IsEventRunningInChannel(ctx.Channel.Id))
                {
                    if (this.Service.GetEventInChannel(ctx.Channel.Id) is RussianRouletteGame)
                    {
                        await this.JoinAsync(ctx);
                    }
                    else
                    {
                        throw new CommandFailedException(ctx, "cmd-err-evt-dup");
                    }
                    return;
                }

                var game = new RussianRouletteGame(ctx.Client.GetInteractivity(), ctx.Channel);

                this.Service.RegisterEventInChannel(game, ctx.Channel.Id);
                try {
                    await ctx.ImpInfoAsync(this.ModuleColor, Emojis.Clock1, "str-game-rr-start", RussianRouletteGame.MaxParticipants);

                    await this.JoinAsync(ctx);

                    await Task.Delay(TimeSpan.FromSeconds(30));

                    if (game.ParticipantCount > 1)
                    {
                        GameStatsService gss = ctx.Services.GetRequiredService <GameStatsService>();
                        await game.RunAsync(this.Localization);

                        if (game.Survivors.Any())
                        {
                            await ctx.ImpInfoAsync(this.ModuleColor, Emojis.Trophy, "fmt-winners", game.Survivors.Select(u => u.Mention).JoinWith(", "));

                            await Task.WhenAll(game.Survivors.Select(u => gss.UpdateStatsAsync(u.Id, s => s.RussianRoulettesWon++)));
                        }
                        else
                        {
                            await ctx.ImpInfoAsync(this.ModuleColor, Emojis.Dead, "str-game-rr-alldead");
                        }
                    }
                    else
                    {
                        await ctx.ImpInfoAsync(this.ModuleColor, Emojis.AlarmClock, "str-game-rr-none");
                    }
                } finally {
                    this.Service.UnregisterEventInChannel(ctx.Channel.Id);
                }
            }
Exemple #2
0
            public async Task ExecuteGroupAsync(CommandContext ctx)
            {
                if (this.Shared.IsEventRunningInChannel(ctx.Channel.Id))
                {
                    if (this.Shared.GetEventInChannel(ctx.Channel.Id) is RussianRouletteGame)
                    {
                        await this.JoinAsync(ctx);
                    }
                    else
                    {
                        throw new CommandFailedException("Another event is already running in the current channel.");
                    }
                    return;
                }

                var game = new RussianRouletteGame(ctx.Client.GetInteractivity(), ctx.Channel);

                this.Shared.RegisterEventInChannel(game, ctx.Channel.Id);
                try {
                    await this.InformAsync(ctx, StaticDiscordEmoji.Clock1, $"The russian roulette game will start in 30s or when there are 10 participants. Use command {Formatter.InlineCode("game russianroulette")} to join the pool.");

                    await this.JoinAsync(ctx);

                    await Task.Delay(TimeSpan.FromSeconds(30));

                    if (game.ParticipantCount > 1)
                    {
                        await game.RunAsync();

                        if (game.Survivors.Any())
                        {
                            await this.InformAsync(ctx, StaticDiscordEmoji.Trophy, $"Survivors:\n\n{string.Join("\n", game.Survivors.Select(u => u.Mention))}");
                        }
                        else
                        {
                            await this.InformAsync(ctx, StaticDiscordEmoji.Dead, "Nobody survived!");
                        }
                    }
                    else
                    {
                        await this.InformAsync(ctx, StaticDiscordEmoji.AlarmClock, "Not enough users joined the Russian roulette pool.");
                    }
                } finally {
                    this.Shared.UnregisterEventInChannel(ctx.Channel.Id);
                }
            }