예제 #1
0
        private async void SearchPokemonButtonPressed(object sender, EventArgs e)
        {
            IsBusy = true;
            var pc = new PokeClient();

            try
            {
                pokemon = await pc.Get <Pokemon>(PokemonSearchBar.Text.ToLower());

                if (pokemon != null)
                {
                    PokemonNameLabel.Text = pokemon.Name;
                    pokemonSpecies        = await pokemon.Species.GetResource(pc);

                    PokemonDescriptionLabel.Text =
                        pokemonSpecies.FlavorTextEntries.First(desc => desc.Language.Name.Equals("en")).FlavorText;
                    PkmnShape.Shape           = StringToShape(pokemonSpecies.Shape.Name);
                    ClearInfoButton.IsVisible = true;
                }
            }
            catch (Exception ett)
            {
                // Jirapi throws an exception if it does not find the resource
                PokemonNameLabel.Text        = "NOT FOUND";
                PokemonDescriptionLabel.Text = "";
                PkmnShape.Shape           = PokemonShape.None;
                ClearInfoButton.IsVisible = false;
            }
            IsBusy = false;
        }
예제 #2
0
        static async Task MainAsync()
        {
            var pokeClient = new PokeClient();

            var dexes = await pokeClient.GetResourceList <Pokedex>();

            Console.WriteLine("Pokedexes");
            foreach (var dex in dexes.Results)
            {
                Console.WriteLine(dex.Name);
            }

            var kantoDex = await dexes.Results
                           .First(d => d.Name.Equals("kanto"))
                           .GetResource();

            Console.WriteLine("Kanto dex:");
            foreach (var description in kantoDex.Descriptions)
            {
                Console.WriteLine("\t ({0}): {1}", description.Language.Name, description.Description1);
            }

            var pokemonCount = 10;

            Console.WriteLine("Primeros " + pokemonCount + " pokémons:");
            for (int i = 0; i < pokemonCount; i++)
            {
                Console.WriteLine("\t{0}.- {1}", i + 1, kantoDex.PokemonEntries[i].PokemonSpecies.Name);
            }

            Console.WriteLine("Consulta a pokémon");
            var pikachu = await pokeClient.Get <Pokemon>("pikachu");

            Console.WriteLine(pikachu.Name);

            var jirachi = await pokeClient.Get <Pokemon>(385);

            Console.WriteLine(jirachi.BaseExperience);

            var netBall = await pokeClient.GetByUrl <Item>("http://pokeapi.co/api/v2/item/6");

            Console.WriteLine(netBall.Name);
        }
예제 #3
0
        public async Task SyncPokedex(int startingDexNum, int endingDexNum)
        {
            using (var dbConnection = new Database.DatabaseConnection(Database.DatabaseID.Data))
            {
                var client = new PokeClient();

                for (var i = startingDexNum; i <= endingDexNum; i++)
                {
                    var pokemon = await client.Get <Jirapi.Resources.Pokemon>(i);

                    var species = await client.Get <Jirapi.Resources.PokemonSpecies>(i);

                    var pokedexEntry = Pokedex.GetPokemon(i);

                    pokedexEntry.Name        = species.Names.Where(x => x.Language.Name == "en").First().Name1;
                    pokedexEntry.SpeciesName = species.Genera.Where(x => x.Language.Name == "en").First().Genus1;

                    var growthGroup = species.GrowthRate.Name;
                    switch (growthGroup.ToLower())
                    {
                    case "slow":
                        pokedexEntry.GrowthGroup = Enums.GrowthGroup.Slow;
                        break;

                    case "medium":
                        pokedexEntry.GrowthGroup = Enums.GrowthGroup.Fluctuating;
                        break;

                    case "medium-slow":
                        pokedexEntry.GrowthGroup = Enums.GrowthGroup.MediumSlow;
                        break;

                    case "medium-fast":
                        pokedexEntry.GrowthGroup = Enums.GrowthGroup.MediumFast;
                        break;

                    case "fast":
                        pokedexEntry.GrowthGroup = Enums.GrowthGroup.Fast;
                        break;

                    case "erratic":
                        pokedexEntry.GrowthGroup = Enums.GrowthGroup.Erratic;
                        break;

                    default:
                        throw new NotImplementedException();
                    }

                    foreach (var eggGroup in species.EggGroups)
                    {
                        await eggGroup.FillResource();
                    }

                    if (species.EggGroups.Count > 0)
                    {
                        pokedexEntry.EggGroup1 = species.EggGroups[0].Resource.Names.Where(x => x.Language.Name == "en").First().Name1;
                    }

                    if (species.EggGroups.Count > 1)
                    {
                        pokedexEntry.EggGroup2 = species.EggGroups[1].Resource.Names.Where(x => x.Language.Name == "en").First().Name1;
                    }

                    // Load abilities
                    foreach (var ability in pokemon.Abilities)
                    {
                        await ability.Ability.FillResource();
                    }

                    for (var n = 0; n < pokemon.Forms.Count; n++)
                    {
                        var form = pokemon.Forms[n];

                        await form.FillResource();

                        PokemonForm pokedexForm;
                        if (pokedexEntry.Forms.Count > n)
                        {
                            pokedexForm = pokedexEntry.Forms[n];
                        }
                        else
                        {
                            pokedexForm = new PokemonForm();

                            pokedexEntry.Forms.Add(pokedexForm);
                        }

                        if (string.IsNullOrEmpty(form.Resource.FormName))
                        {
                            pokedexForm.FormName = "Normal";
                        }
                        else
                        {
                            pokedexForm.FormName = form.Resource.FormName;
                        }

                        pokedexForm.Weight        = pokemon.Weight;
                        pokedexForm.Height        = pokemon.Height;
                        pokedexForm.BaseRewardExp = pokemon.BaseExperience;

                        pokedexForm.BaseHP    = pokemon.Stats.Where(x => x.Stat.Name == "hp").First().BaseStat;
                        pokedexForm.BaseAtt   = pokemon.Stats.Where(x => x.Stat.Name == "attack").First().BaseStat;
                        pokedexForm.BaseDef   = pokemon.Stats.Where(x => x.Stat.Name == "defense").First().BaseStat;
                        pokedexForm.BaseSpAtt = pokemon.Stats.Where(x => x.Stat.Name == "special-attack").First().BaseStat;
                        pokedexForm.BaseSpDef = pokemon.Stats.Where(x => x.Stat.Name == "special-defense").First().BaseStat;
                        pokedexForm.BaseSpd   = pokemon.Stats.Where(x => x.Stat.Name == "speed").First().BaseStat;

                        if (pokemon.Types.Count > 0)
                        {
                            pokedexForm.Type1 = MapTypeNameToType(pokemon.Types[0].Type.Name);
                        }
                        if (pokemon.Types.Count > 1)
                        {
                            pokedexForm.Type2 = MapTypeNameToType(pokemon.Types[1].Type.Name);
                        }

                        pokedexForm.Ability1 = "None";
                        pokedexForm.Ability2 = "None";
                        pokedexForm.Ability3 = "None";
                        if (pokemon.Abilities.Count > 0)
                        {
                            pokedexForm.Ability1 = pokemon.Abilities[0].Ability.Resource.Names.Where(x => x.Language.Name == "en").First().Name1;
                        }
                        if (pokemon.Abilities.Count > 1)
                        {
                            pokedexForm.Ability2 = pokemon.Abilities[1].Ability.Resource.Names.Where(x => x.Language.Name == "en").First().Name1;
                        }
                        if (pokemon.Abilities.Count > 2)
                        {
                            pokedexForm.Ability3 = pokemon.Abilities[2].Ability.Resource.Names.Where(x => x.Language.Name == "en").First().Name1;
                        }

                        pokedexForm.LevelUpMoves.Clear();
                        pokedexForm.TMMoves.Clear();
                        pokedexForm.TutorMoves.Clear();
                        pokedexForm.EggMoves.Clear();
                        foreach (var move in pokemon.Moves)
                        {
                            var versionGroupDetails = move.VersionGroupDetails.First();

                            switch (versionGroupDetails.MoveLearnMethod.Name.ToLower())
                            {
                            case "level-up":
                            {
                                var moveId = FindMoveByName(move.Move.Name);

                                if (moveId > -1)
                                {
                                    pokedexForm.LevelUpMoves.Add(new LevelUpMove(moveId, versionGroupDetails.LevelLearnedAt));
                                }
                            }
                            break;

                            case "machine":
                            {
                                var moveId = FindMoveByName(move.Move.Name);

                                if (moveId > -1)
                                {
                                    pokedexForm.TMMoves.Add(moveId);
                                }
                            }
                            break;

                            case "tutor":
                            {
                                var moveId = FindMoveByName(move.Move.Name);

                                if (moveId > -1)
                                {
                                    pokedexForm.TutorMoves.Add(moveId);
                                }
                            }
                            break;

                            case "egg":
                            {
                                var moveId = FindMoveByName(move.Move.Name);

                                if (moveId > -1)
                                {
                                    pokedexForm.EggMoves.Add(moveId);
                                }
                            }
                            break;

                            default:
                                throw new NotImplementedException();
                            }
                        }
                    }

                    Pokedex.SavePokemon(dbConnection, i);
                }
            }
        }