Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
0
        public void Load(DatabaseConnection dbConnection)
        {
            var database = dbConnection.Database;

            string query = "SELECT pokedex_pokemon.PokemonName, pokedex_pokemon.SpeciesName, " +
                           "pokedex_pokemon.GrowthGroup, pokedex_pokemon.EggGroup1, pokedex_pokemon.EggGroup2 " +
                           "FROM pokedex_pokemon " +
                           "WHERE pokedex_pokemon.DexNum = \'" + ID + "\'";

            DataColumnCollection row = database.RetrieveRow(query);

            if (row != null)
            {
                Name        = row["PokemonName"].ValueString;
                SpeciesName = row["SpeciesName"].ValueString;
                GrowthGroup = (Enums.GrowthGroup)row["GrowthGroup"].ValueString.ToInt();
                EggGroup1   = row["EggGroup1"].ValueString;
                EggGroup2   = row["EggGroup2"].ValueString;
            }


            int formNum = 0;

            query = "SELECT pokedex_pokemonform.FormName, pokedex_pokemonform.HP, " +
                    "pokedex_pokemonform.Attack, pokedex_pokemonform.Defense, " +
                    "pokedex_pokemonform.SpecialAttack, pokedex_pokemonform.SpecialDefense, " +
                    "pokedex_pokemonform.Speed, pokedex_pokemonform.Male, pokedex_pokemonform.Female, " +
                    "pokedex_pokemonform.Height, pokedex_pokemonform.Weight, " +
                    "pokedex_pokemonform.Type1, pokedex_pokemonform.Type2, " +
                    "pokedex_pokemonform.Ability1, pokedex_pokemonform.Ability2, pokedex_pokemonform.Ability3, " +
                    "pokedex_pokemonform.ExpYield " +
                    "FROM pokedex_pokemonform " +
                    "WHERE pokedex_pokemonform.DexNum = \'" + ID + "\' " +
                    "AND pokedex_pokemonform.FormNum = \'" + formNum + "\'";

            row = database.RetrieveRow(query);
            while (row != null)
            {
                PokemonForm form = new PokemonForm();
                form.FormIndex     = formNum;
                form.FormName      = row["FormName"].ValueString;
                form.BaseHP        = row["HP"].ValueString.ToInt();
                form.BaseAtt       = row["Attack"].ValueString.ToInt();
                form.BaseDef       = row["Defense"].ValueString.ToInt();
                form.BaseSpAtt     = row["SpecialAttack"].ValueString.ToInt();
                form.BaseSpDef     = row["SpecialDefense"].ValueString.ToInt();
                form.BaseSpd       = row["Speed"].ValueString.ToInt();
                form.MaleRatio     = row["Male"].ValueString.ToInt();
                form.FemaleRatio   = row["Female"].ValueString.ToInt();
                form.Height        = row["Height"].ValueString.ToDbl();
                form.Weight        = row["Weight"].ValueString.ToDbl();
                form.Type1         = (Enums.PokemonType)row["Type1"].ValueString.ToInt();
                form.Type2         = (Enums.PokemonType)row["Type2"].ValueString.ToInt();
                form.Ability1      = row["Ability1"].ValueString;
                form.Ability2      = row["Ability2"].ValueString;
                form.Ability3      = row["Ability3"].ValueString;
                form.BaseRewardExp = row["ExpYield"].ValueString.ToInt();

                form.LoadAppearance(dbConnection, ID, formNum);
                form.LoadMoves(dbConnection, ID, formNum);
                Forms.Add(form);

                formNum++;
                query = "SELECT pokedex_pokemonform.FormName, pokedex_pokemonform.HP, " +
                        "pokedex_pokemonform.Attack, pokedex_pokemonform.Defense, " +
                        "pokedex_pokemonform.SpecialAttack, pokedex_pokemonform.SpecialDefense, " +
                        "pokedex_pokemonform.Speed, pokedex_pokemonform.Male, pokedex_pokemonform.Female, " +
                        "pokedex_pokemonform.Height, pokedex_pokemonform.Weight, " +
                        "pokedex_pokemonform.Type1, pokedex_pokemonform.Type2, " +
                        "pokedex_pokemonform.Ability1, pokedex_pokemonform.Ability2, pokedex_pokemonform.Ability3, " +
                        "pokedex_pokemonform.ExpYield " +
                        "FROM pokedex_pokemonform " +
                        "WHERE pokedex_pokemonform.DexNum = \'" + ID + "\' " +
                        "AND pokedex_pokemonform.FormNum = \'" + formNum + "\'";
                row = database.RetrieveRow(query);
            }
        }
Ejemplo n.º 3
0
        /*
        public void Load() {
            int formNum = 0;
            while (IO.IO.FileExists(IO.Paths.PokedexFolder + ID + "-" + formNum + ".xml")) {
                PokemonForm form = new PokemonForm();
                form.FormIndex = formNum;
                form.Load(ID);
                Forms.Add(form);
                formNum++;
            }
        }

        public void Save() {
            foreach(PokemonForm form in Forms) {
                form.Save(ID);
            }
        }
        */
        public void Load(DatabaseConnection dbConnection)
        {
            MySql database = dbConnection.Database;

            string query = "SELECT pokedex_pokemon.PokemonName, pokedex_pokemon.SpeciesName, " +
                "pokedex_pokemon.GrowthGroup, pokedex_pokemon.EggGroup1, pokedex_pokemon.EggGroup2 " +
                "FROM pokedex_pokemon " +
                "WHERE pokedex_pokemon.DexNum = \'" + ID + "\'";

            DataColumnCollection row = database.RetrieveRow(query);
            if (row != null)
            {
                Name = row["PokemonName"].ValueString;
                SpeciesName = row["SpeciesName"].ValueString;
                GrowthGroup = (Enums.GrowthGroup)row["GrowthGroup"].ValueString.ToInt();
                EggGroup1 = row["EggGroup1"].ValueString;
                EggGroup2 = row["EggGroup2"].ValueString;
            }

            int formNum = 0;
            query = "SELECT pokedex_pokemonform.FormName, pokedex_pokemonform.HP, " +
                "pokedex_pokemonform.Attack, pokedex_pokemonform.Defense, " +
                "pokedex_pokemonform.SpecialAttack, pokedex_pokemonform.SpecialDefense, " +
                "pokedex_pokemonform.Speed, pokedex_pokemonform.Male, pokedex_pokemonform.Female, " +
                "pokedex_pokemonform.Height, pokedex_pokemonform.Weight, " +
                "pokedex_pokemonform.Type1, pokedex_pokemonform.Type2, " +
                "pokedex_pokemonform.Ability1, pokedex_pokemonform.Ability2, pokedex_pokemonform.Ability3, " +
                "pokedex_pokemonform.ExpYield " +
                "FROM pokedex_pokemonform " +
                "WHERE pokedex_pokemonform.DexNum = \'" + ID + "\' " +
                "AND pokedex_pokemonform.FormNum = \'" + formNum + "\'";

            row = database.RetrieveRow(query);
            while (row != null)
            {
                PokemonForm form = new PokemonForm();
                form.FormName = row["FormName"].ValueString;
                form.BaseHP = row["HP"].ValueString.ToInt();
                form.BaseAtt = row["Attack"].ValueString.ToInt();
                form.BaseDef = row["Defense"].ValueString.ToInt();
                form.BaseSpAtt = row["SpecialAttack"].ValueString.ToInt();
                form.BaseSpDef = row["SpecialDefense"].ValueString.ToInt();
                form.BaseSpd = row["Speed"].ValueString.ToInt();
                form.MaleRatio = row["Male"].ValueString.ToInt();
                form.FemaleRatio = row["Female"].ValueString.ToInt();
                form.Height = row["Height"].ValueString.ToDbl();
                form.Weight = row["Weight"].ValueString.ToDbl();
                form.Type1 = (Enums.PokemonType)row["Type1"].ValueString.ToInt();
                form.Type2 = (Enums.PokemonType)row["Type2"].ValueString.ToInt();
                form.Ability1 = row["Ability1"].ValueString;
                form.Ability2 = row["Ability2"].ValueString;
                form.Ability3 = row["Ability3"].ValueString;
                form.BaseRewardExp = row["ExpYield"].ValueString.ToInt();

                form.LoadAppearance(dbConnection, ID, formNum);
                form.LoadMoves(dbConnection, ID, formNum);
                Forms.Add(form);

                formNum++;
                query = "SELECT pokedex_pokemonform.FormName, pokedex_pokemonform.HP, " +
                "pokedex_pokemonform.Attack, pokedex_pokemonform.Defense, " +
                "pokedex_pokemonform.SpecialAttack, pokedex_pokemonform.SpecialDefense, " +
                "pokedex_pokemonform.Speed, pokedex_pokemonform.Male, pokedex_pokemonform.Female, " +
                "pokedex_pokemonform.Height, pokedex_pokemonform.Weight, " +
                "pokedex_pokemonform.Type1, pokedex_pokemonform.Type2, " +
                "pokedex_pokemonform.Ability1, pokedex_pokemonform.Ability2, pokedex_pokemonform.Ability3, " +
                "pokedex_pokemonform.ExpYield " +
                "FROM pokedex_pokemonform " +
                "WHERE pokedex_pokemonform.DexNum = \'" + ID + "\' " +
                "AND pokedex_pokemonform.FormNum = \'" + formNum + "\'";
                row = database.RetrieveRow(query);
            }
        }