Search in sources :

Example 1 with PokemonId

use of POGOProtos.Enums.PokemonIdOuterClass.PokemonId in project PokeGOAPI-Java by Grover-c13.

the class Evolutions method initialize.

/**
	 * Initializes these evolutions from PokemonSettings
	 *
	 * @param templates the templates to initialize from
	 */
public static void initialize(List<ItemTemplate> templates) {
    EVOLUTIONS.clear();
    for (ItemTemplate template : templates) {
        if (template.hasPokemonSettings()) {
            PokemonSettings settings = template.getPokemonSettings();
            PokemonId pokemon = settings.getPokemonId();
            if (!EVOLUTIONS.containsKey(pokemon)) {
                addEvolution(null, pokemon);
            }
        }
    }
}
Also used : PokemonId(POGOProtos.Enums.PokemonIdOuterClass.PokemonId) PokemonSettings(POGOProtos.Settings.Master.PokemonSettingsOuterClass.PokemonSettings) ItemTemplate(POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate)

Example 2 with PokemonId

use of POGOProtos.Enums.PokemonIdOuterClass.PokemonId in project PokeGOAPI-Java by Grover-c13.

the class CheckEvolutionExample method main.

/**
 * Displays pokemon evolutions
 *
 * @param args Not used
 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    final PokemonGo api = new PokemonGo(http);
    try {
        // Login and set location
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        // Get the evolution meta from the item templates received from the game server
        Evolutions evolutionMeta = api.itemTemplates.evolutions;
        System.out.println("Evolutions: ");
        for (PokemonId pokemon : PokemonId.values()) {
            List<PokemonId> evolutions = evolutionMeta.getEvolutions(pokemon);
            if (evolutions.size() > 0) {
                System.out.println(pokemon + " -> " + evolutions);
            }
        }
        System.out.println();
        System.out.println("Most basic: ");
        for (PokemonId pokemon : PokemonId.values()) {
            List<PokemonId> basic = evolutionMeta.getBasic(pokemon);
            if (basic.size() > 0) {
                // Check this is not the most basic pokemon
                if (!(basic.size() == 1 && basic.contains(pokemon))) {
                    System.out.println(pokemon + " -> " + basic);
                }
            }
        }
        System.out.println();
        System.out.println("Highest: ");
        for (PokemonId pokemon : PokemonId.values()) {
            List<PokemonId> highest = evolutionMeta.getHighest(pokemon);
            if (highest.size() > 0) {
                // Check this is not the highest pokemon
                if (!(highest.size() == 1 && highest.contains(pokemon))) {
                    System.out.println(pokemon + " -> " + highest);
                }
            }
        }
    } catch (RequestFailedException e) {
        // failed to login, invalid credentials, auth issue or server issue.
        Log.e("Main", "Failed to login, captcha or server issue: ", e);
    }
}
Also used : PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) PokemonId(POGOProtos.Enums.PokemonIdOuterClass.PokemonId) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) HashProvider(com.pokegoapi.util.hash.HashProvider) Evolutions(com.pokegoapi.api.pokemon.Evolutions)

Example 3 with PokemonId

use of POGOProtos.Enums.PokemonIdOuterClass.PokemonId in project PokeGOAPI-Java by Grover-c13.

the class TransferMultiplePokemon method main.

/**
 * Transfers all bad pokemon from the player's inventory.
 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    PokemonGo api = new PokemonGo(http);
    try {
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        PokeBank pokebank = api.inventories.pokebank;
        List<Pokemon> pokemons = pokebank.pokemons;
        List<Pokemon> transferPokemons = new ArrayList<>();
        // Find all pokemon of bad types or with IV less than 25%
        for (Pokemon pokemon : pokemons) {
            PokemonId id = pokemon.getPokemonId();
            double iv = pokemon.getIvInPercentage();
            if (iv < 90) {
                if (id == PokemonId.RATTATA || id == PokemonId.PIDGEY || id == PokemonId.CATERPIE || id == PokemonId.WEEDLE || id == PokemonId.MAGIKARP || id == PokemonId.ZUBAT || iv < 25) {
                    transferPokemons.add(pokemon);
                }
            }
        }
        System.out.println("Releasing " + transferPokemons.size() + " pokemon.");
        Pokemon[] transferArray = transferPokemons.toArray(new Pokemon[transferPokemons.size()]);
        Map<PokemonFamilyId, Integer> responses = pokebank.releasePokemon(transferArray);
        // Loop through all responses and find the total amount of candies earned for each family
        Map<PokemonFamilyId, Integer> candies = new HashMap<>();
        for (Map.Entry<PokemonFamilyId, Integer> entry : responses.entrySet()) {
            int candyAwarded = entry.getValue();
            PokemonFamilyId family = entry.getKey();
            Integer candy = candies.get(family);
            if (candy == null) {
                // candies map does not yet contain the amount if null, so set it to 0
                candy = 0;
            }
            // Add the awarded candies from this request
            candy += candyAwarded;
            candies.put(family, candy);
        }
        for (Map.Entry<PokemonFamilyId, Integer> entry : candies.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue() + " candies awarded");
        }
    } catch (RequestFailedException e) {
        // failed to login, invalid credentials, auth issue or server issue.
        Log.e("Main", "Failed to login. Invalid credentials, captcha or server issue: ", e);
    }
}
Also used : PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) PokeBank(com.pokegoapi.api.inventory.PokeBank) OkHttpClient(okhttp3.OkHttpClient) PokemonId(POGOProtos.Enums.PokemonIdOuterClass.PokemonId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PokemonFamilyId(POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) HashProvider(com.pokegoapi.util.hash.HashProvider) Pokemon(com.pokegoapi.api.pokemon.Pokemon) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with PokemonId

use of POGOProtos.Enums.PokemonIdOuterClass.PokemonId in project PokeGOAPI-Java by Grover-c13.

the class Evolutions method getHighest.

/**
 * Gets the highest evolution pokemon in the given evolution chain.
 *
 * @param pokemon the pokemon to find the highest evolution for
 * @return the highest evolution for the given pokemon
 */
public List<PokemonId> getHighest(PokemonId pokemon) {
    List<PokemonId> highest = new ArrayList<>();
    Evolution evolution = getEvolution(pokemon);
    if (evolution != null) {
        if (evolution.evolutions != null && evolution.evolutions.size() > 0) {
            for (PokemonId child : evolution.evolutions) {
                highest.addAll(getHighest(child));
            }
        } else {
            highest.add(pokemon);
        }
        return highest;
    } else {
        highest.add(pokemon);
        return highest;
    }
}
Also used : PokemonId(POGOProtos.Enums.PokemonIdOuterClass.PokemonId) ArrayList(java.util.ArrayList)

Example 5 with PokemonId

use of POGOProtos.Enums.PokemonIdOuterClass.PokemonId in project PokeGOAPI-Java by Grover-c13.

the class Evolutions method addEvolution.

/**
 * Auxiliar method to add the evolution by recursion in the EVOLUTIONS Map
 *
 * @param parent the parent of this pokemon
 * @param pokemon the pokemon that evolution will be added
 */
private void addEvolution(PokemonId parent, PokemonId pokemon) {
    Evolution evolution = new Evolution(itemTemplates, parent, pokemon);
    evolutions.put(pokemon, evolution);
    for (PokemonId poke : evolution.evolutions) {
        addEvolution(pokemon, poke);
    }
}
Also used : PokemonId(POGOProtos.Enums.PokemonIdOuterClass.PokemonId)

Aggregations

PokemonId (POGOProtos.Enums.PokemonIdOuterClass.PokemonId)5 PokemonGo (com.pokegoapi.api.PokemonGo)2 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)2 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)2 HashProvider (com.pokegoapi.util.hash.HashProvider)2 ArrayList (java.util.ArrayList)2 OkHttpClient (okhttp3.OkHttpClient)2 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)1 ItemTemplate (POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate)1 PokemonSettings (POGOProtos.Settings.Master.PokemonSettingsOuterClass.PokemonSettings)1 PokeBank (com.pokegoapi.api.inventory.PokeBank)1 Evolutions (com.pokegoapi.api.pokemon.Evolutions)1 Pokemon (com.pokegoapi.api.pokemon.Pokemon)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1