public async Task Info([Remainder] string typeName)
            {
                PBEType?nType = PBELocalizedString.GetTypeByName(typeName);

                if (!nType.HasValue || nType.Value == PBEType.None)
                {
                    await Context.Channel.SendMessageAsync($"{Context.User.Mention} ― Invalid type!");
                }
                else
                {
                    PBEType type        = nType.Value;
                    string  description = $"{_tableStart}{_tableStart}";
                    // Build columns
                    for (PBEType other = PBEType.None + 1; other < PBEType.MAX; other++)
                    {
                        description += $"|{Utils.TypeEmotes[other]}";
                    }
                    // Build rows
                    for (int i = 0; i < 2; i++)
                    {
                        bool doOffense = i == 0;
                        description += $"\n{(doOffense ? _offense : _defense)}{Utils.TypeEmotes[type]}";
                        for (PBEType other = PBEType.None + 1; other < PBEType.MAX; other++)
                        {
                            double d = PBETypeEffectiveness.GetEffectiveness(doOffense ? type : other, doOffense ? other : type);
                            string s;
                            if (d <= 0) // (-infinity, 0]
                            {
                                s = _ineffective;
                            }
                            else if (d < 1) // (0, 1)
                            {
                                s = _notVeryEffective;
                            }
                            else if (d == 1) // [1, 1]
                            {
                                s = _effective;
                            }
                            else // (1, infinity)
                            {
                                s = _superEffective;
                            }
                            description += $"|{s}";
                        }
                    }

                    EmbedBuilder embed = new EmbedBuilder()
                                         .WithAuthor(Context.User)
                                         .WithColor(Utils.TypeColors[type])
                                         .WithTitle(PBELocalizedString.GetTypeName(type).English)
                                         .WithUrl(Utils.URL)
                                         .WithDescription(description);
                    await Context.Channel.SendMessageAsync(string.Empty, embed : embed.Build());
                }
            }
Exemple #2
0
            public async Task Info([Remainder] string input)
            {
                // Inputs for forms should be like "Giratina (Origin Forme)"
                Match  m = Regex.Match(input, @"^(\S+) \((.+)\)$");
                string speciesName;
                string?formName;

                if (m.Success)
                {
                    speciesName = m.Groups[1].Value;
                    formName    = m.Groups[2].Value;
                }
                else
                {
                    speciesName = input;
                    formName    = null;
                }
                if (!PBEDataProvider.Instance.GetSpeciesByName(speciesName, out PBESpecies? nSpecies))
                {
                    await Context.Channel.SendMessageAsync($"{Context.User.Mention} ― Invalid species!");

                    return;
                }
                PBESpecies species = nSpecies.Value;

                speciesName = PBEDataProvider.Instance.GetSpeciesName(species).English;
                PBEForm form;

                if (formName is null)
                {
                    form = 0;
                }
                else
                {
                    if (!PBEDataProvider.Instance.GetFormByName(species, formName, out PBEForm? nForm))
                    {
                        IReadOnlyList <PBEForm> forms = PBEDataUtils.GetForms(species, false);
                        string str = $"{Context.User.Mention} ― Invalid form for {speciesName}";
                        if (forms.Count > 0)
                        {
                            str += ", valid forms are:\n**" + string.Join("\n", forms.Select(f => PBEDataProvider.Instance.GetFormName(species, f).English)) + "**";
                        }
                        else
                        {
                            str += "! It has no forms!";
                        }
                        await Context.Channel.SendMessageAsync(str);

                        return;
                    }
                    form = nForm.Value;
                }
                formName = PBEDataUtils.HasForms(species, false) ? $" ({PBEDataProvider.Instance.GetFormName(species, form).English})" : string.Empty;
                IPBEPokemonData pData = PBEDataProvider.Instance.GetPokemonData(species, form);
                string          types = $"{Utils.TypeEmotes[pData.Type1]}";

                if (pData.Type2 != PBEType.None)
                {
                    types += $" {Utils.TypeEmotes[pData.Type2]}";
                }
                string ratio;

                switch (pData.GenderRatio)
                {
                case PBEGenderRatio.M7_F1: ratio = "87.5% Male, 12.5% Female"; break;

                case PBEGenderRatio.M3_F1: ratio = "75% Male, 25% Female"; break;

                case PBEGenderRatio.M1_F1: ratio = "50% Male, 50% Female"; break;

                case PBEGenderRatio.M1_F3: ratio = "25% Male, 75% Female"; break;

                case PBEGenderRatio.M0_F1: ratio = "100% Female"; break;

                case PBEGenderRatio.M1_F0: ratio = "100% Male"; break;

                case PBEGenderRatio.M0_F0: ratio = "Genderless Species"; break;

                default: throw new InvalidDataException(nameof(pData.GenderRatio));
                }
                string weaknesses  = string.Empty,
                       resistances = string.Empty,
                       immunities  = string.Empty;

                for (PBEType atk = PBEType.None + 1; atk < PBEType.MAX; atk++)
                {
                    float d = PBETypeEffectiveness.GetEffectiveness(atk, pData);
                    if (d <= 0)
                    {
                        if (immunities != string.Empty)
                        {
                            immunities += ' ';
                        }
                        immunities += Utils.TypeEmotes[atk];
                    }
                    else if (d < 1)
                    {
                        if (resistances != string.Empty)
                        {
                            resistances += ' ';
                        }
                        resistances += Utils.TypeEmotes[atk];
                    }
                    if (d > 1)
                    {
                        if (weaknesses != string.Empty)
                        {
                            weaknesses += ' ';
                        }
                        weaknesses += Utils.TypeEmotes[atk];
                    }
                }
                if (weaknesses == string.Empty)
                {
                    weaknesses = "No Weaknesses";
                }
                if (resistances == string.Empty)
                {
                    resistances = "No Resistances";
                }
                if (immunities == string.Empty)
                {
                    immunities = "No Immunities";
                }

                EmbedBuilder embed = new EmbedBuilder()
                                     .WithAuthor(Context.User)
                                     .WithColor(Utils.GetColor(pData.Type1, pData.Type2))
                                     .WithTitle($"{speciesName}{formName} ― {PBEDefaultDataProvider.Instance.GetSpeciesCategory(species).English}")
                                     .WithUrl(Utils.URL)
                                     .WithDescription(PBEDefaultDataProvider.Instance.GetSpeciesEntry(species).English.Replace('\n', ' '))
                                     .AddField("Types", types, true)
                                     .AddField("Gender Ratio", ratio, true)
                                     .AddField("Weight", $"{pData.Weight:N1} kg", true)
                                     .AddField("Abilities", string.Join(", ", pData.Abilities.Select(a => PBEDataProvider.Instance.GetAbilityName(a).English)), false)
                                     .AddField("HP", pData.BaseStats.HP, true)
                                     .AddField("Attack", pData.BaseStats.Attack, true)
                                     .AddField("Defense", pData.BaseStats.Defense, true)
                                     .AddField("Special Attack", pData.BaseStats.SpAttack, true)
                                     .AddField("Special Defense", pData.BaseStats.SpDefense, true)
                                     .AddField("Speed", pData.BaseStats.Speed, true)
                                     .AddField("Type Weaknesses", weaknesses, true)
                                     .AddField("Type Resistances", resistances, true)
                                     .AddField("Type Immunities", immunities, true)
                                     .WithImageUrl(Utils.GetPokemonSprite(species, form, PBEDataProvider.GlobalRandom.RandomShiny(), PBEDataProvider.GlobalRandom.RandomGender(pData.GenderRatio), false, false));
                await Context.Channel.SendMessageAsync(string.Empty, embed : embed.Build());
            }