示例#1
0
            public async Task StrengthAsync(CommandContext ctx)
            {
                if (this.Shared.GetEventInChannel(ctx.Channel.Id) is ChickenWar)
                {
                    throw new CommandFailedException("There is a chicken war running in this channel. No trainings are allowed before the war finishes.");
                }

                string result;

                using (DatabaseContext db = this.Database.CreateContext()) {
                    DatabaseChicken dbc = await db.Chickens.FindAsync((long)ctx.Guild.Id, (long)ctx.User.Id);

                    var chicken = Chicken.FromDatabaseChicken(dbc);
                    if (chicken is null)
                    {
                        throw new CommandFailedException("You do not own a chicken!");
                    }

                    if (chicken.Stats.TotalVitality < 25)
                    {
                        throw new CommandFailedException($"{ctx.User.Mention}, your chicken is too weak for that action! Heal it using {Formatter.BlockCode("chicken heal")} command.");
                    }

                    long price = chicken.TrainStrengthPrice;
                    if (!await ctx.WaitForBoolReplyAsync($"{ctx.User.Mention}, are you sure you want to train your chicken for {Formatter.Bold($"{price:n0}")} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}?\n\nNote: This action will also weaken the vitality of your chicken by 1."))
                    {
                        return;
                    }

                    if (!await db.TryDecreaseBankAccountAsync(ctx.User.Id, ctx.Guild.Id, price))
                    {
                        throw new CommandFailedException($"You do not have enough {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"} to train a chicken ({price:n0} needed)!");
                    }

                    if (chicken.TrainStrength())
                    {
                        result = $"{ctx.User.Mention}'s chicken learned alot from the training. New strength: {chicken.Stats.TotalStrength}";
                    }
                    else
                    {
                        result = $"{ctx.User.Mention}'s chicken got tired and didn't learn anything. New strength: {chicken.Stats.TotalStrength}";
                    }
                    chicken.Stats.BareVitality--;

                    dbc.Strength = chicken.Stats.BareStrength;
                    dbc.Vitality--;
                    db.Chickens.Update(dbc);

                    await db.SaveChangesAsync();
                }

                await this.InformAsync(ctx, StaticDiscordEmoji.Chicken, result);
            }
示例#2
0
        public async Task GlobalTopAsync(CommandContext ctx)
        {
            List <Chicken> chickens;

            using (DatabaseContext db = this.Database.CreateContext()) {
                chickens = db.Chickens
                           .Include(c => c.DbUpgrades)
                           .ThenInclude(u => u.DbChickenUpgrade)
                           .AsEnumerable()
                           .Select(c => Chicken.FromDatabaseChicken(c))
                           .OrderBy(c => c.Stats.TotalStrength)
                           .ToList();
            }

            foreach (Chicken chicken in chickens)
            {
                try {
                    chicken.Owner = await ctx.Client.GetUserAsync(chicken.OwnerId);
                } catch (NotFoundException) {
                    using (DatabaseContext db = this.Database.CreateContext()) {
                        db.Chickens.Remove(chicken.ToDatabaseChicken());
                        await db.SaveChangesAsync();
                    }
                } catch (Exception e) {
                    this.Shared.LogProvider.Log(LogLevel.Warning, e);
                }
            }

            if (!chickens.Any())
            {
                throw new CommandFailedException("No chickens bought.");
            }

            await ctx.SendCollectionInPagesAsync(
                "Strongest chickens globally:",
                chickens.OrderByDescending(c => c.Stats.TotalStrength),
                c => $"{Formatter.Bold(c.Name)} | {c.Owner?.Mention ?? "unknown owner (removed)"} | {c.Stats.TotalStrength} ({c.Stats.BareStrength}) STR",
                this.ModuleColor
                );
        }