示例#1
0
        public async Task FightAsync(CommandContext ctx,
                                     [Description("Member whose chicken to fight.")] DiscordMember member)
        {
            if (this.Shared.GetEventInChannel(ctx.Channel.Id) is ChickenWar ambush)
            {
                throw new CommandFailedException("There is a chicken war running in this channel. No fights are allowed before the war finishes.");
            }

            if (member.Id == ctx.User.Id)
            {
                throw new CommandFailedException("You can't fight against your own chicken!");
            }

            Chicken chicken1 = await this.Database.GetChickenAsync(ctx.User.Id, ctx.Guild.Id);

            if (chicken1 != null)
            {
                if (chicken1.Stats.TotalVitality < 25)
                {
                    throw new CommandFailedException($"{ctx.User.Mention}, your chicken is too weak to start a fight with another chicken! Heal it using {Formatter.InlineCode("chicken heal")} command.");
                }
            }
            else
            {
                throw new CommandFailedException("You do not own a chicken!");
            }

            Chicken chicken2 = await this.Database.GetChickenAsync(member.Id, ctx.Guild.Id);

            if (chicken2 == null)
            {
                throw new CommandFailedException("The specified user does not own a chicken!");
            }

            if (Math.Abs(chicken1.Stats.TotalStrength - chicken2.Stats.TotalStrength) > 50)
            {
                throw new CommandFailedException("The bare strength difference is too big (50 max)! Please find a more suitable opponent.");
            }

            string header = $"{Formatter.Bold(chicken1.Name)} ({chicken1.Stats.ToShortString()}) {StaticDiscordEmoji.DuelSwords} {Formatter.Bold(chicken2.Name)} ({chicken2.Stats.ToShortString()}) {StaticDiscordEmoji.Chicken}\n\n";

            Chicken winner = chicken1.Fight(chicken2);

            winner.Owner = winner.OwnerId == ctx.User.Id ? ctx.User : member;
            Chicken loser = winner == chicken1 ? chicken2 : chicken1;
            int     gain  = winner.DetermineStrengthGain(loser);

            winner.Stats.BareStrength    += gain;
            winner.Stats.BareMaxVitality -= gain;
            if (winner.Stats.TotalVitality == 0)
            {
                winner.Stats.BareVitality = 1;
            }
            loser.Stats.BareVitality -= 50;

            await this.Database.ModifyChickenAsync(winner, ctx.Guild.Id);

            if (loser.Stats.TotalVitality > 0)
            {
                await this.Database.ModifyChickenAsync(loser, ctx.Guild.Id);
            }
            else
            {
                await this.Database.RemoveChickenAsync(loser.OwnerId, ctx.Guild.Id);
            }

            await this.Database.IncreaseBankAccountBalanceAsync(winner.OwnerId, ctx.Guild.Id, gain * 2000);

            await this.InformAsync(ctx, StaticDiscordEmoji.Chicken,
                                   header +
                                   $"{StaticDiscordEmoji.Trophy} Winner: {Formatter.Bold(winner.Name)}\n\n" +
                                   $"{Formatter.Bold(winner.Name)} gained {Formatter.Bold(gain.ToString())} strength!\n" +
                                   (loser.Stats.TotalVitality > 0 ? $"{Formatter.Bold(loser.Name)} lost {Formatter.Bold("50")} HP!" : $"{Formatter.Bold(loser.Name)} died in the battle!") +
                                   $"\n\n{winner.Owner.Mention} won {gain * 200} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}."
                                   , important : true
                                   );
        }