示例#1
0
        public async Task Save(string Throw, params string[] args)
        {
            Character c;

            if (args.Length >= 1 && args.Contains("-c"))
            {
                c = GetCompanion();
                if (c == null)
                {
                    await ReplyAsync("You have no active companion.");

                    return;
                }
            }
            else
            {
                c = GetCharacter();
                if (c == null)
                {
                    await ReplyAsync("You have no active character.");

                    return;
                }
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (!int.TryParse(args[i], out int a) && args[i].ToLower() != "-c" && args[i].ToLower() != "-f")
                {
                    args[i] = " ";
                }
            }
            string arguments = string.Join(" ", args).Replace("-c", "");

            var sheet = await SheetService.GetFullSheet(c);

            var values = await SheetService.GetValues(c);

            if (values == null || sheet == null)
            {
                var err = new EmbedBuilder()
                          .WithTitle("Click here")
                          .WithUrl("https://character.pf2.tools/?" + c.RemoteId)
                          .WithDescription("Seems like we cannot fetch " + c.Name + "'s values. This is due to the fact values are only updated when you open the sheet in pf2.tools. To fix this, click the link above to generate those values.");
                await ReplyAsync("", err.Build());

                return;
            }
            var    embed   = new EmbedBuilder();
            int    bonus   = 0;
            string message = "";

            if (args.Contains("-f"))
            {
                if (c.Familiar.NullorEmpty())
                {
                    await ReplyAsync("You have no named familiars.");

                    return;
                }
                if (Saves.TryGetValue(Throw.ToLower(), out int value))
                {
                    switch (value)
                    {
                    case 1:
                        bonus   = (int)values["famfort " + c.Familiar]["bonus"] - (int)values["famfort " + c.Familiar]["penalty"];
                        message = c.Name + "'s familiar makes a fortitude check!";
                        break;

                    case 2:
                        bonus   = (int)values["famref " + c.Familiar]["bonus"] - (int)values["famref " + c.Familiar]["penalty"];
                        message = c.Name + "'s familiar makes a reflex check!";
                        break;

                    case 3:
                        bonus   = (int)values["famwill " + c.Familiar]["bonus"] - (int)values["famwill " + c.Familiar]["penalty"];
                        message = c.Name + "'s familiar makes a will check!";
                        break;
                    }
                }
                else
                {
                    await ReplyAsync(Context.User.Mention + ", invalid saving throw.");
                }
                arguments = arguments.Replace("-f", "");
                embed.WithThumbnailUrl(c.FamImg);
            }
            else
            {
                if (Saves.TryGetValue(Throw.ToLower(), out int value))
                {
                    switch (value)
                    {
                    case 1:
                        bonus   = (int)values["fortitude"]["bonus"] - (int)values["fortitude"]["penalty"];
                        message = c.Name + " makes a fortitude check!";
                        break;

                    case 2:
                        bonus   = (int)values["reflex"]["bonus"] - (int)values["reflex"]["penalty"];
                        message = c.Name + " makes a reflex check!";
                        break;

                    case 3:
                        bonus   = (int)values["will"]["bonus"] - (int)values["will"]["penalty"];
                        message = c.Name + " makes a will check!";
                        break;
                    }
                }
                else
                {
                    await ReplyAsync(Context.User.Mention + ", invalid saving throw.");
                }
                embed.WithThumbnailUrl(c.ImageUrl);
            }

            var result = Roller.Roll("d20 + " + bonus + arguments);

            embed.WithTitle(message)
            .WithDescription(result.ParseResult() + "\nTotal = `" + result.Value + "`")
            .WithFooter((c.ValuesLastUpdated.Outdated() ? "⚠️ Couldn't retrieve updated values. Roll might not be accurate" : DateTime.Now.ToString()));

            Random randonGen   = new Random();
            Color  randomColor = new Color(randonGen.Next(255), randonGen.Next(255),
                                           randonGen.Next(255));

            embed.WithColor(randomColor);

            if (c.Color != null)
            {
                embed.WithColor(new Color(c.Color[0], c.Color[1], c.Color[2]));
            }

            await ReplyAsync(" ", embed.Build());
        }