コード例 #1
0
        private async Task _generateOpponentAsync()
        {
            // Pick a random species from the same zone as the player's gotchi.

            List <Species> species_list = new List <Species>();

            foreach (SpeciesZone zone in await SpeciesUtils.GetZonesAsync(await SpeciesUtils.GetSpeciesAsync(player1.Gotchi.Gotchi.SpeciesId)))
            {
                species_list.AddRange((await ZoneUtils.GetSpeciesAsync(zone.Zone)).Where(x => !x.IsExtinct));
            }

            player2 = new PlayerState();

            if (species_list.Count() > 0)
            {
                player2.Gotchi = await GotchiUtils.GenerateGotchiAsync(new GotchiGenerationParameters {
                    Base            = player1.Gotchi.Gotchi,
                    Species         = species_list[BotUtils.RandomInteger(species_list.Count())],
                    MinLevel        = player1.Gotchi.Stats.Level - 3,
                    MaxLevel        = player1.Gotchi.Stats.Level + 3,
                    GenerateMoveset = true,
                    GenerateStats   = true
                });
            }

            // Set the opponent.

            if (player2.Gotchi != null)
            {
                player2.Gotchi.Gotchi.OwnerId = WildGotchiUserId;
                player2.Gotchi.Gotchi.Id      = WildGotchiId;
            }
        }
コード例 #2
0
        public async Task Migration(string genusName, string speciesName)
        {
            Species species = await BotUtils.ReplyFindSpeciesAsync(Context, genusName, speciesName);

            if (species is null)
            {
                return;
            }

            SpeciesZone[] zones = (await SpeciesUtils.GetZonesAsync(species)).OrderBy(x => x.Timestamp).ToArray();

            if (zones.Count() <= 0)
            {
                await BotUtils.ReplyAsync_Info(Context, string.Format("**{0}** is not present in any zones.", species.ShortName));
            }
            else
            {
                // Group zones changes that happened closely together (12 hours).

                List <List <SpeciesZone> > zone_groups = new List <List <SpeciesZone> >();

                long last_timestamp = zones.Count() > 0 ? zones.First().Timestamp : 0;

                foreach (SpeciesZone zone in zones)
                {
                    if (zone_groups.Count() <= 0)
                    {
                        zone_groups.Add(new List <SpeciesZone>());
                    }

                    if (zone_groups.Last().Count() <= 0 || Math.Abs(zone_groups.Last().Last().Timestamp - zone.Timestamp) < 60 * 60 * 12)
                    {
                        zone_groups.Last().Add(zone);
                    }
                    else
                    {
                        last_timestamp = zone.Timestamp;
                        zone_groups.Add(new List <SpeciesZone> {
                            zone
                        });
                    }
                }


                StringBuilder result = new StringBuilder();

                for (int i = 0; i < zone_groups.Count(); ++i)
                {
                    if (zone_groups[i].Count() <= 0)
                    {
                        continue;
                    }

                    long ts = i == 0 ? species.Timestamp : zone_groups[i].First().Timestamp;

                    if (ts <= 0)
                    {
                        ts = species.Timestamp;
                    }

                    result.Append(string.Format("{0} - ", await BotUtils.TimestampToDateStringAsync(ts, TimestampToDateStringFormat.Short)));
                    result.Append(i == 0 ? "Started in " : "Spread to ");
                    result.Append(zone_groups[i].Count() == 1 ? "Zone " : "Zones ");
                    result.Append(StringUtils.ConjunctiveJoin(", ", zone_groups[i].Select(x => x.Zone.ShortName)));

                    result.AppendLine();
                }


                await ReplyAsync(string.Format("```{0}```", result.ToString()));
            }
        }
コード例 #3
0
 private async Task <string> GetZonesTokenValueAsync()
 {
     return(string.Join(", ", (await SpeciesUtils.GetZonesAsync(Species)).Select(x => x.Zone.ShortName)));
 }
コード例 #4
0
        public static async Task ShowSpeciesInfoAsync(ICommandContext context, Species species)
        {
            if (await BotUtils.ReplyValidateSpeciesAsync(context, species))
            {
                EmbedBuilder  embed = new EmbedBuilder();
                StringBuilder descriptionBuilder = new StringBuilder();

                string embed_title = species.FullName;
                Color  embed_color = Color.Blue;

                CommonName[] common_names = await SpeciesUtils.GetCommonNamesAsync(species);

                if (common_names.Count() > 0)
                {
                    embed_title += string.Format(" ({0})", string.Join(", ", (object[])common_names));
                }

                // Show generation only if generations are enabled.

                if (OurFoodChainBot.Instance.Config.GenerationsEnabled)
                {
                    Generation gen = await GenerationUtils.GetGenerationByTimestampAsync(species.Timestamp);

                    embed.AddField("Gen", gen is null ? "???" : gen.Number.ToString(), inline: true);
                }

                embed.AddField("Owner", await SpeciesUtils.GetOwnerOrDefaultAsync(species, context), inline: true);

                SpeciesZone[] zone_list = await SpeciesUtils.GetZonesAsync(species);

                if (zone_list.Count() > 0)
                {
                    embed_color = Bot.DiscordUtils.ConvertColor((await ZoneUtils.GetZoneTypeAsync(zone_list
                                                                                                  .GroupBy(x => x.Zone.ZoneTypeId)
                                                                                                  .OrderBy(x => x.Count())
                                                                                                  .Last()
                                                                                                  .Key)).Color);
                }

                string zones_value = new SpeciesZoneCollection(zone_list).ToString(SpeciesZoneCollectionToStringOptions.Default, Bot.DiscordUtils.MaxFieldLength);

                embed.AddField("Zone(s)", string.IsNullOrEmpty(zones_value) ? "None" : zones_value, inline: true);

                // Check if the species is extinct.
                using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Extinctions WHERE species_id=$species_id;")) {
                    cmd.Parameters.AddWithValue("$species_id", species.Id);

                    DataRow row = await Database.GetRowAsync(cmd);

                    if (!(row is null))
                    {
                        embed_title = "[EXTINCT] " + embed_title;
                        embed_color = Color.Red;

                        string reason    = row.Field <string>("reason");
                        long   timestamp = (long)row.Field <decimal>("timestamp");

                        if (!string.IsNullOrEmpty(reason))
                        {
                            descriptionBuilder.AppendLine(string.Format("**Extinct ({0}):** _{1}_\n", await BotUtils.TimestampToDateStringAsync(timestamp), reason));
                        }
                    }
                }

                descriptionBuilder.Append(species.GetDescriptionOrDefault());

                embed.WithTitle(embed_title);
                embed.WithThumbnailUrl(species.Picture);
                embed.WithColor(embed_color);

                if (!string.IsNullOrEmpty(OurFoodChainBot.Instance.Config.WikiUrlFormat))
                {
                    // Discord automatically encodes certain characters in URIs, which doesn't allow us to update the config via Discord when we have "{0}" in the URL.
                    // Replace this with the proper string before attempting to call string.Format.
                    string format = OurFoodChainBot.Instance.Config.WikiUrlFormat.Replace("%7B0%7D", "{0}");

                    embed.WithUrl(string.Format(format, Uri.EscapeUriString(GetWikiPageTitleForSpecies(species, common_names))));
                }

                if (embed.Length + descriptionBuilder.Length > DiscordUtils.MaxEmbedLength)
                {
                    // If the description puts us over the character limit, we'll paginate.

                    int pageLength = DiscordUtils.MaxEmbedLength - embed.Length;

                    List <EmbedBuilder> pages = new List <EmbedBuilder>();

                    foreach (string pageText in new StringPaginator(descriptionBuilder.ToString())
                    {
                        MaxPageLength = pageLength
                    })
                    {
                        EmbedBuilder page = new EmbedBuilder();

                        page.WithTitle(embed.Title);
                        page.WithThumbnailUrl(embed.ThumbnailUrl);
                        page.WithFields(embed.Fields);
                        page.WithDescription(pageText);

                        pages.Add(page);
                    }

                    PaginatedMessageBuilder builder = new Bot.PaginatedMessageBuilder(pages);
                    builder.AddPageNumbers();
                    builder.SetColor(embed_color);

                    await DiscordUtils.SendMessageAsync(context, builder.Build());
                }
                else
                {
                    embed.WithDescription(descriptionBuilder.ToString());

                    await context.Channel.SendMessageAsync("", false, embed.Build());
                }
            }
        }