Example #1
0
        public override IList <Response> Execute(SenderSettings senderDetail, IMessageDetail args)
        {
            ServerSettings       serverSettings = senderDetail.ServerSettings;
            CultureInfo          cultureInfo    = languageHandler.GetCultureInfo(serverSettings.Language);
            CommandMessageHelper command        = new CommandMessageHelper(serverSettings.CommandSymbol, args.Message);

            string[]      commandParams = command.CommandParams;
            Discord.Color responseColor = Discord.Color.Green;

            string[] typeStrings;

            if (command.CommandDetail.Contains('-'))
            {
                // User wrote e.g. normal-flying
                typeStrings = command.CommandDetail.Split('-');
            }
            else
            {
                typeStrings = command.CommandArgs.Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
            }

            if (typeStrings.Length == 0)
            {
                // No types specified.
                return(Response.CreateArrayFromString("http://bulbapedia.bulbagarden.net/wiki/Type"));
            }

            List <string> incorrectTypes = new List <string>();
            List <string> duplicateTypes = new List <string>();

            var foundTypes = new HashSet <PokemonType>();

            // TODO - translate.
            if (typeStrings.Length == 1 && typeStrings[0].Equals("all", StringComparison.OrdinalIgnoreCase))
            {
                // Add all types.
                foreach (PokemonType t in PokemonTypeHandler.PokemonTypes)
                {
                    if (t != PokemonType.NumberOfTypes)
                    {
                        foundTypes.Add(t);
                    }
                }
            }
            else
            {
                foreach (string typeStr in typeStrings)
                {
                    bool found = PokemonTypeHandler.GetTypeFromLocalisedName(typeStr, cultureInfo, out PokemonType t);
                    if (found)
                    {
                        bool added = foundTypes.Add(t);
                        if (!added)
                        {
                            duplicateTypes.Add(typeStr);
                        }
                    }
                    else
                    {
                        incorrectTypes.Add(typeStr);
                    }
                }
            }

            bool foundAny = foundTypes.Any();

            if (!foundAny)
            {
                // Check if is actually a Pokémon.
                Pokemon pokemon = (KnowledgeBase.GetOrFetchPokémon(command.CommandDetail));
                if (pokemon != null)
                {
                    foundTypes.Add(pokemon.PrimaryType);
                    if (pokemon.SecondaryType != PokemonType.NumberOfTypes)
                    {
                        foundTypes.Add(pokemon.SecondaryType);
                    }

                    foundAny = true;

                    // Ignore the typing - it's a Pokémon.
                    incorrectTypes.Clear();
                    duplicateTypes.Clear();
                }
            }

            StringBuilder sb = new StringBuilder();

            // Incorrect types
            if (incorrectTypes.Any())
            {
                sb.Append($"{Emojis.CrossSymbol} {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Error_IncorrectParameter")}");
                sb.Append(": ");
                sb.AppendLine(string.Join(" ", incorrectTypes));
            }

            // Duplicate types
            if (duplicateTypes.Any())
            {
                sb.Append($"{Emojis.ExclamationSymbol} {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Warning_SameType")}");
                sb.Append(": ");
                sb.AppendLine(string.Join(" ", duplicateTypes));
            }

            if (foundAny)
            {
                sb.AppendLine("```objectivec");
                sb.Append("// ");

                foreach (PokemonType foundType in foundTypes)
                {
                    string foundTypeName = PokemonTypeHandler.GetLocalisedName(foundType, cultureInfo);
                    sb.Append(foundTypeName);
                    sb.Append(" ");
                }
                sb.AppendLine();

                // Attacking
                if (foundTypes.Count < 3)
                {
                    sb.AppendLine($"# {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Attacking")}");
                    foreach (PokemonType foundType in foundTypes)
                    {
                        double[] attackingType1 = PokemonTypeHandler.GetAttacking(foundType);
                        for (int i = 0; i < attackingType1.Length; i++)
                        {
                            double eff = attackingType1[i];
                            if (eff != 1.0)
                            {
                                sb.Append(eff.ToString("G", cultureInfo.NumberFormat));
                                sb.Append($"x {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Against")} ");
                                sb.Append(PokemonTypeHandler.GetLocalisedName(PokemonTypeHandler.PokemonTypes[i], cultureInfo));
                                sb.Append($" {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "WhenAttackingWith")} ");
                                sb.Append(PokemonTypeHandler.GetLocalisedName(foundType, cultureInfo));
                                sb.AppendLine();
                            }
                        }
                    }
                }
                sb.AppendLine();

                // Defending
                sb.AppendLine($"# {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "Defending")}");
                double[] defending = PokemonTypeHandler.GetDefending(foundTypes.ToArray());
                for (int i = 0; i < defending.Length; i++)
                {
                    double eff = defending[i];
                    if (eff != 1.0)
                    {
                        sb.Append(eff.ToString("G", cultureInfo.NumberFormat));
                        sb.Append($"x {languageHandler.GetPhrase(senderDetail.ServerSettings.Language, "DamageTakenFrom")} ");
                        sb.AppendLine(PokemonTypeHandler.GetLocalisedName(PokemonTypeHandler.PokemonTypes[i], cultureInfo));
                    }
                }

                // Add on status immunities.
                foreach (PokemonType foundType in foundTypes)
                {
                    string immunity = PokemonTypeHandler.GetTypeStatusImmunityString(foundType, cultureInfo);
                    if (immunity != string.Empty)
                    {
                        sb.AppendLine(immunity);
                    }
                }

                sb.Append("```");
            }

            return(Response.CreateArrayFromString(sb.ToString(), responseColor));
        }
Example #2
0
        private string MakeAPokemonString(Pokemon pokemon, CultureInfo culture, Languages language)
        {
            StringBuilder sb = new StringBuilder("```");

            sb.AppendLine(pokemon.NationalDexNumber.ToString("D3") + ": " + pokemon.Name + ": " + pokemon.FamilyDescription + " Pokémon " + (pokemon.GenerationIntroduced != 0 ? "(Gen " + pokemon.GenerationIntroduced + ")" : ""));
            if (pokemon.PrimaryType != PokemonType.NumberOfTypes)
            {
                foreach (Form form in pokemon.Forms)
                {
                    sb.AppendLine($"{form.Name} {languageHandler.GetPhrase(language, "Pokemon_Type")}: " + PokemonTypeHandler.GetLocalisedName(form.PrimaryType, culture) + (form.SecondaryType == PokemonType.NumberOfTypes ? "" : ("-" + PokemonTypeHandler.GetLocalisedName(form.SecondaryType, culture))));
                }
            }

            if (pokemon.Height != 0)
            {
                const double AVERAGE_PERSON_HEIGHT      = 1.77;
                const double AVERAGE_PERSON_WEIGHT      = 80.7;
                string       ratioToAveragePersonHeight = (pokemon.Height / AVERAGE_PERSON_HEIGHT).ToString("N2", culture.NumberFormat);
                string       ratioToAveragePersonWeight = (pokemon.Weight / AVERAGE_PERSON_WEIGHT).ToString("N2", culture.NumberFormat);

                sb.AppendLine($"{languageHandler.GetPhrase(language, "Pokemon_Height")}: " + pokemon.Height.ToString("N1", culture.NumberFormat) + "m (" + ratioToAveragePersonHeight + "x " + languageHandler.GetPhrase(language, "Pokemon_OfAnAveragePerson") + ")");
                sb.AppendLine($"{languageHandler.GetPhrase(language, "Pokemon_Weight")}: " + pokemon.Height.ToString("N1", culture.NumberFormat) + "kg (" + ratioToAveragePersonWeight + "x " + languageHandler.GetPhrase(language, "Pokemon_OfAnAveragePerson") + ")");
            }

            if (pokemon.GenderRatio != null)
            {
                sb.AppendLine($"{languageHandler.GetPhrase(language, "Pokemon_GenderRatio")}: {pokemon.GenderRatio}% {languageHandler.GetPhrase(language, "Pokemon_Male")} / {100 - pokemon.GenderRatio}% {languageHandler.GetPhrase(language, "Pokemon_Female")}");
            }
            else
            {
                sb.AppendLine($"{languageHandler.GetPhrase(language, "Pokemon_GenderRatio")}: {languageHandler.GetPhrase(language, "Pokemon_GenderlessOrUnknown")}");
            }

            if (pokemon.Abilities != null && pokemon.Abilities.Length > 0)
            {
                sb.AppendLine($"{languageHandler.GetPhrase(language, "Pokemon_Abilities")}: {string.Join(", ", pokemon.Abilities.Select(a => a.Name))}");
            }

            if (pokemon.EggGroups != null && pokemon.EggGroups.Length > 0)
            {
                sb.AppendLine($"{languageHandler.GetPhrase(language, "Pokemon_EggGroups")}: {string.Join(", ", pokemon.EggGroups.Select(a => EggGroupHandler.GetLocalisedName(a, culture)))}");
            }

            if (pokemon.HatchTime.Max != 0)
            {
                sb.AppendLine($"{languageHandler.GetPhrase(language, "Pokemon_HatchSteps")}: {pokemon.HatchTime.Average} ± 128");
            }

            if (pokemon.Stats.BaseStats.Count != 0)
            {
                const int totalPadding = 18;
                if (pokemon.Stats.BaseStats.ContainsKey(Stat.HP))
                {
                    string statName = languageHandler.GetPhrase(language, "Pokemon_BaseHP") + ": ";
                    byte   stat     = pokemon.Stats.BaseStats[Stat.HP];
                    string bar      = GetProgressBar(stat, 255); // (Blissey)
                    string statStr  = stat.ToString().PadRight(totalPadding - statName.Length);
                    sb.AppendLine(statName + statStr + bar);
                }

                if (pokemon.Stats.BaseStats.ContainsKey(Stat.Attack))
                {
                    string statName = languageHandler.GetPhrase(language, "Pokemon_BaseAttack") + ": ";
                    byte   stat     = pokemon.Stats.BaseStats[Stat.Attack];
                    string bar      = GetProgressBar(stat, 190); // (Mega Mewtwo X)
                    string statStr  = stat.ToString().PadRight(totalPadding - statName.Length);
                    sb.AppendLine(statName + statStr + bar);
                }

                if (pokemon.Stats.BaseStats.ContainsKey(Stat.Defense))
                {
                    string statName = languageHandler.GetPhrase(language, "Pokemon_BaseDefence") + ": ";
                    byte   stat     = pokemon.Stats.BaseStats[Stat.Defense];
                    string bar      = GetProgressBar(stat, 230); // (Mega Aggron)
                    string statStr  = stat.ToString().PadRight(totalPadding - statName.Length);
                    sb.AppendLine(statName + statStr + bar);
                }

                if (pokemon.Stats.BaseStats.ContainsKey(Stat.SpecialAttack))
                {
                    string statName = languageHandler.GetPhrase(language, "Pokemon_BaseSpecialAttack") + ": ";
                    byte   stat     = pokemon.Stats.BaseStats[Stat.SpecialAttack];
                    string bar      = GetProgressBar(stat, 194); // (Mega Mewtwo Y)
                    string statStr  = stat.ToString().PadRight(totalPadding - statName.Length);
                    sb.AppendLine(statName + statStr + bar);
                }

                if (pokemon.Stats.BaseStats.ContainsKey(Stat.SpecialDefense))
                {
                    string statName = languageHandler.GetPhrase(language, "Pokemon_BaseSpecialDefence") + ": ";
                    byte   stat     = pokemon.Stats.BaseStats[Stat.SpecialDefense];
                    string bar      = GetProgressBar(stat, 230); // (Shuckle)
                    string statStr  = stat.ToString().PadRight(totalPadding - statName.Length);
                    sb.AppendLine(statName + statStr + bar);
                }

                if (pokemon.Stats.BaseStats.ContainsKey(Stat.Speed))
                {
                    string statName = languageHandler.GetPhrase(language, "Pokemon_BaseSpeed") + ": ";
                    byte   stat     = pokemon.Stats.BaseStats[Stat.Speed];
                    string bar      = GetProgressBar(stat, 180); // (Deoxys (Speed))
                    string statStr  = stat.ToString().PadRight(totalPadding - statName.Length);
                    sb.AppendLine(statName + statStr + bar);
                }
            }
            sb.AppendLine("```");
            return(sb.ToString());
        }