Example #1
0
        /* 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.");
            }
        }
Example #2
0
 public static void Initialize(string CacheFolder = "")
 {
     if (Connector.isInitialized)
     {
         throw new Exception("PokeAPI is initialized and can only be initialized once"); //May seems a bit over kill but this is nessecery for corrent usage.
     }
     #region "Structure"
     Connector.Berries                  = new Berries();
     Connector.BerryFirmnesses          = new BerryFirmnesses();
     Connector.BerryFlavors             = new BerryFlavors();
     Connector.ContestNames             = new ContestNames();
     Connector.ContestEffects           = new ContestEffects();
     Connector.SuperContestEffects      = new SuperContestEffects();
     Connector.EncounterMethods         = new EncounterMethods();
     Connector.EncounterConditions      = new EncounterConditions();
     Connector.EncounterConditionValues = new EncounterConditionValues();
     Connector.EvolutionChains          = new EvolutionChains();
     Connector.EvolutionTrigger         = new EvolutionTrigger();
     Connector.Generations              = new Generations();
     Connector.Pokedexes                = new Pokedexes();
     Connector.Versions                 = new Versions();
     Connector.VersionGroups            = new VersionGroups();
     Connector.Items             = new Items();
     Connector.ItemAttributes    = new ItemAttributes();
     Connector.ItemCategories    = new ItemCategories();
     Connector.ItemFlingEffects  = new ItemFlingEffects();
     Connector.ItemPockets       = new ItemPockets();
     Connector.Locations         = new Locations();
     Connector.LocationAreas     = new LocationAreas();
     Connector.PalParkAreas      = new PalParkAreas();
     Connector.Regions           = new Regions();
     Connector.Machines          = new Machines();
     Connector.Moves             = new Moves();
     Connector.MoveAilments      = new MoveAilments();
     Connector.MoveBattleStyles  = new MoveBattleStyles();
     Connector.MoveCategories    = new MoveCategories();
     Connector.MoveDamageClasses = new MoveDamageClasses();
     Connector.MoveLearnMethods  = new MoveLearnMethods();
     Connector.MoveTargets       = new MoveTargets();
     Connector.Abilities         = new Abilities();
     Connector.Characteristics   = new Characteristics();
     Connector.EggGroups         = new EggGroups();
     Connector.Genders           = new Genders();
     Connector.GrowthRates       = new GrowthRates();
     Connector.Natures           = new Natures();
     Connector.PokeathlonStats   = new PokeathlonStats();
     Connector.Pokemons          = new Pokemons();
     Connector.PokemonColors     = new PokemonColors();
     Connector.PokemonForms      = new PokemonForms();
     Connector.PokemonHabitats   = new PokemonHabitats();
     Connector.PokemonShapes     = new PokemonShapes();
     Connector.PokemonSpecies    = new PokemonSpecies();
     Connector.Stats             = new Stats();
     Connector.Types             = new Types();
     Connector.Languages         = new Languages();
     #endregion
     if (CacheFolder == "")
     {
         Connector.CacheFolder = AppDomain.CurrentDomain.BaseDirectory + "pokeAPI//";
     }
     else
     {
         if (!System.IO.Directory.Exists(CacheFolder))
         {
             throw new Exception("Directory : " + CacheFolder + " was not found");
         }
         Connector.CacheFolder = CacheFolder;
     }
     Cacher.Initialize();
     Connector.isInitialized = true;
 }