public async Task <PokemonApi> recuperarPokemonAPI(string nombrePokemon)
        {
            try
            {
                PokemonApi     pokemonApi    = new PokemonApi();
                PokemonSpecies pokemonSpecie = await DataFetcher.GetNamedApiObject <PokemonSpecies>(nombrePokemon.ToLower());

                if (pokemonSpecie != null)
                {
                    pokemonApi.Id     = pokemonSpecie.ID;
                    pokemonApi.Nombre = pokemonSpecie.Name;


                    PokeAPI.Pokemon pokemon = await DataFetcher.GetNamedApiObject <PokeAPI.Pokemon>(pokemonSpecie.ID.ToString());

                    if (pokemon.Types != null)
                    {
                        pokemonApi.Tipo = pokemon.Types[0].Type.Name;
                    }

                    return(pokemonApi);
                }
            }
            catch (Exception error) { }
            return(null);
        }
Exemple #2
0
        public async Task Team()
        {
            MySqlConnection conn = DatabaseHelper.GetClosedConnection();

            if (!await conn.IsUserRegistered(Context.User.Id))
            {
                return;
            }

            IUserMessage msg;

            if (Private)
            {
                msg = await(await Context.User.GetOrCreateDMChannelAsync()).SendMessageAsync("Loading Data...");
            }
            else
            {
                msg = await Context.Channel.SendMessageAsync("Loading Data...");
            }

            Models.Team     t    = (await conn.GetXMLFromDatabaseAsync("Team", "Trainers", Context.User.Id)).Deserialize <Models.Team>();
            Models.Pokemon  p    = t.First();
            PokeAPI.Pokemon pApi = await DataFetcher.GetApiObject <PokeAPI.Pokemon>(p.ID);

            EmbedBuilder builder = new EmbedBuilder()
            {
                Title        = $"{(Context.User as IGuildUser).Nickname ?? Context.User.Username}'s {p.Nickname ?? pApi.Name.Capatalize()}",
                Color        = Color.Teal,
                Description  = p.ToString(pApi.Name),
                ThumbnailUrl = $"https://img.pokemondb.net/sprites/black-white/anim/normal/{pApi.Name}.gif"
            };

            await msg.ModifyAsync(x => { x.Content = ""; x.Embed = builder.Build(); });
        }
Exemple #3
0
            public async Task Purge(int ID)
            {
                IUserMessage msg = await Context.Channel.SendMessageAsync("Fetching Data...");

                try
                {
                    PokeAPI.Pokemon p = await DataFetcher.GetApiObject <PokeAPI.Pokemon>(ID);

                    EmbedBuilder builder = new EmbedBuilder()
                    {
                        Title = "Pokemon Request by ID", Color = Color.DarkGreen, ThumbnailUrl = p.Sprites.FrontMale
                    };

                    builder.Description = $"{FormatHelper.Capatalize(p.Name)} the {FormatHelper.Capatalize((await DataFetcher.GetApiObject<PokemonSpecies>(ID)).Genera[2].Name)}";

                    EmbedFieldBuilder field = new EmbedFieldBuilder()
                    {
                        Name     = "Base Stats",
                        IsInline = true
                    };

                    foreach (PokemonStats stat in p.Stats)
                    {
                        field.Value += $"{FormatHelper.Capatalize(stat.Stat.Name)}: {stat.BaseValue.ToString()}\n";
                    }

                    builder.AddField(field);

                    await msg.ModifyAsync(x => { x.Content = ""; x.Embed = builder.Build(); });
                }
                catch
                {
                    await msg.ModifyAsync(x => x.Content = "Could find pokemon with ID: " + ID);
                }
            }
        public DamageBuff(PokeAPI.Move movetype, PokeAPI.Pokemon pokemontype)
        {
            MoveType       = movetype;
            PokemonType    = pokemontype;
            DamageModifier = 1;

            TypeWeaknessMap BattleTypes = new TypeWeaknessMap();

            TypeComparison(BattleTypes);
        }
Exemple #5
0
        // Fetch by ID
        public void Fetch(int PokemonID)
        {
            if (PokemonID == 132)
            {
                PokemonID++;
            }
            Task <PokeAPI.Pokemon> PokeTask = FetchPokemon(PokemonID);

            Poke = PokeTask.Result;
        }
Exemple #6
0
        private async Task <EmbedBuilder> GetFirstPokemon()
        {
            Models.Team     t    = (await DatabaseHelper.GetClosedConnection().GetXMLFromDatabaseAsync("Team", "Trainers", Context.User.Id)).Deserialize <Models.Team>();
            Models.Pokemon  p    = t.First();
            PokeAPI.Pokemon pApi = await DataFetcher.GetApiObject <PokeAPI.Pokemon>(p.ID);

            EmbedBuilder builder = new EmbedBuilder()
            {
                Title        = $"{(Context.User as IGuildUser).Nickname ?? Context.User.Username}'s {p.Nickname ?? pApi.Name.Capatalize()}",
                Color        = Color.Teal,
                Description  = p.ToString(pApi.Name),
                ThumbnailUrl = $"https://img.pokemondb.net/sprites/black-white/anim/normal/{pApi.Name}.gif"
            };

            return(builder);
        }
        private async Task <string> CreateStarterPokemonXMLAsync(string starterName)
        {
            PRPGDiscordBot.Models.Team team = new Models.Team();

            PokeAPI.Pokemon p = await DataFetcher.GetNamedApiObject <PokeAPI.Pokemon>(starterName.ToLower());

            Models.Pokemon pokemon = new Models.Pokemon()
            {
                ID = p.ID, Level = 5, PokeBallType = Models.PokeBallType.PokeBall, Form = 0, Happiness = 70, Nickname = "", Shiny = false, Status = Models.Status.None
            };
            pokemon.Stats        = Models.Pokemon.GenerateStarterStats(p);
            pokemon.Moves        = Models.Pokemon.GenerateStarterMoves(p);
            pokemon.Ability.Name = p.Abilities[0].Ability.Name;

            team.Add(pokemon);

            return(team.Serialize());
        }
Exemple #8
0
        public static async Task <List <int> > GetEvolutionIDs(PokeAPI.Pokemon poke)
        {
            List <int>     ids = new List <int>();
            EvolutionChain evs;

            try
            {
                evs = await DataFetcher.GetApiObject <EvolutionChain>(poke.ID);
            }
            catch (Exception) { return(ids); }

            if (evs.Chain.Details.Count() > 0)
            {
                /* ids.Add(_pokemons.First(x => x.Name == evs.Chain.EvolvesTo[0].Species.Name).ID);
                 * if(( l = evs.Chain.EvolvesTo[0].EvolvesTo).Count() > 0)
                 *    ids.AddRange(await GetEvolutionIDs(_pokemons.First(x => x.Name == l[0].Species.Name)));  */
            }
            return(ids);
        }
        /* This method asyncronously downloads the first 721 Pokemon species from PokeAPI. */
        public static async void DownloadPokemon()
        {
            for (int k = 0; k <= 721; k++)
            {
                /* Both the relevant PokeAPI.Pokemon and the PokeAPI.PokemonSpecies objects are downloaded from PokeAPI. */
                api.Pokemon p = await api.DataFetcher.GetApiObject <api.Pokemon>(k);

                api.PokemonSpecies ps = await api.DataFetcher.GetApiObject <api.PokemonSpecies>(k);

                /* The PokemonData's EvYield is created using the PokeAPI.Pokemon's stat effort values. */
                EvYield evYield = new EvYield((byte)p.Stats[5].Effort, (byte)p.Stats[4].Effort, (byte)p.Stats[3].Effort, (byte)p.Stats[2].Effort, (byte)p.Stats[1].Effort, (byte)p.Stats[0].Effort);

                /* The constructor for the new PokemonData is called with different parameters depending on whether it's a dual type and has two egg groups. */
                if (p.Types.Length == 1)
                {
                    if (ps.EggGroups.Length == 1)
                    {
                        /* This constructor is used if the Types and EggGroups both have a length of one. Null is passed as the second type and second egg group. */
                        PokemonDataManager.PokemonData.Add((ushort)p.ID, new PokemonData(p.Name, (byte)p.Stats[5].BaseValue, (byte)p.Stats[4].BaseValue, (byte)p.Stats[3].BaseValue, (byte)p.Stats[2].BaseValue, (byte)p.Stats[1].BaseValue, (byte)p.Stats[0].BaseValue, (ushort)p.ID, ParseEnum <PkmnType>(p.Types[0].Type.Name), null, ps.FemaleToMaleRate != -1, ps.Genera[0].Name, (double)p.Height / 10, (double)p.Height / 10, ParseEnum <EggGroup>(FixEnum(ps.EggGroups[0].Name)), null, (ushort)p.BaseExperience, (byte)ps.CaptureRate, (byte)ps.BaseHappiness, ParseEnum <GrowthRate>(FixEnum(ps.GrowthRate.Name)), (byte)ps.HatchCounter, (byte)(100 - (byte)(ps.FemaleToMaleRate * 100)), (byte)(ps.FemaleToMaleRate * 100), evYield));
                    }
                    else // ps.EggGroups.Length == 2
                    {
                        /* This constructor is used if the Pokemon is single type and has two egg groups. */
                        PokemonDataManager.PokemonData.Add((ushort)p.ID, new PokemonData(p.Name, (byte)p.Stats[5].BaseValue, (byte)p.Stats[4].BaseValue, (byte)p.Stats[3].BaseValue, (byte)p.Stats[2].BaseValue, (byte)p.Stats[1].BaseValue, (byte)p.Stats[0].BaseValue, (ushort)p.ID, ParseEnum <PkmnType>(p.Types[0].Type.Name), null, ps.FemaleToMaleRate != -1, ps.Genera[0].Name, (double)p.Height / 10, (double)p.Height / 10, ParseEnum <EggGroup>(FixEnum(ps.EggGroups[0].Name)), ParseEnum <EggGroup>(FixEnum(ps.EggGroups[1].Name)), (ushort)p.BaseExperience, (byte)ps.CaptureRate, (byte)ps.BaseHappiness, ParseEnum <GrowthRate>(FixEnum(ps.GrowthRate.Name)), (byte)ps.HatchCounter, (byte)(100 - (byte)(ps.FemaleToMaleRate * 100)), (byte)(ps.FemaleToMaleRate * 100), evYield));
                    }
                }
                else // p.Types.Length == 2
                {
                    if (ps.EggGroups.Length == 1)
                    {
                        /* Similarly, this constructor call creates a Pokemon with dual type and one egg group. */
                        PokemonDataManager.PokemonData.Add((ushort)p.ID, new PokemonData(p.Name, (byte)p.Stats[5].BaseValue, (byte)p.Stats[4].BaseValue, (byte)p.Stats[3].BaseValue, (byte)p.Stats[2].BaseValue, (byte)p.Stats[1].BaseValue, (byte)p.Stats[0].BaseValue, (ushort)p.ID, ParseEnum <PkmnType>(p.Types[0].Type.Name), ParseEnum <PkmnType>(p.Types[1].Type.Name), ps.FemaleToMaleRate != -1, ps.Genera[0].Name, (double)p.Height / 10, (double)p.Height / 10, ParseEnum <EggGroup>(FixEnum(ps.EggGroups[0].Name)), null, (ushort)p.BaseExperience, (byte)ps.CaptureRate, (byte)ps.BaseHappiness, ParseEnum <GrowthRate>(FixEnum(ps.GrowthRate.Name)), (byte)ps.HatchCounter, (byte)(100 - (byte)(ps.FemaleToMaleRate * 100)), (byte)(ps.FemaleToMaleRate * 100), evYield));
                    }
                    else // ps.EggGroups.Length == 2
                    {
                        /* Finally, this constructor call creates a Pokemon with dual type and two egg groups. */
                        PokemonDataManager.PokemonData.Add((ushort)p.ID, new PokemonData(p.Name, (byte)p.Stats[5].BaseValue, (byte)p.Stats[4].BaseValue, (byte)p.Stats[3].BaseValue, (byte)p.Stats[2].BaseValue, (byte)p.Stats[1].BaseValue, (byte)p.Stats[0].BaseValue, (ushort)p.ID, ParseEnum <PkmnType>(p.Types[0].Type.Name), ParseEnum <PkmnType>(p.Types[1].Type.Name), ps.FemaleToMaleRate != -1, ps.Genera[0].Name, (double)p.Height / 10, (double)p.Height / 10, ParseEnum <EggGroup>(FixEnum(ps.EggGroups[0].Name)), ParseEnum <EggGroup>(FixEnum(ps.EggGroups[1].Name)), (ushort)p.BaseExperience, (byte)ps.CaptureRate, (byte)ps.BaseHappiness, ParseEnum <GrowthRate>(FixEnum(ps.GrowthRate.Name)), (byte)ps.HatchCounter, (byte)(100 - (byte)(ps.FemaleToMaleRate * 100)), (byte)(ps.FemaleToMaleRate * 100), evYield));
                    }
                }
                Console.WriteLine("Pokemon # " + k + " (" + p.Name + ") has been added.");
            }
        }
 private static int GetDescriptionId(Pokemon pokemon)
 {
     var lastOrDefault = pokemon.Descriptions[0].ResourceUri.Segments.LastOrDefault();
     return int.Parse(lastOrDefault?.Replace("/", ""));
 }
Exemple #11
0
        // Fetch by name
        public void Fetch(string PokemonName)
        {
            Task <PokeAPI.Pokemon> PokeTask = FetchPokemonByName(PokemonName);

            Poke = PokeTask.Result;
        }