Search in sources :

Example 1 with PokeBank

use of com.pokegoapi.api.inventory.PokeBank 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.getInventories().getPokebank();
        List<Pokemon> pokemons = pokebank.getPokemons();
        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 2 with PokeBank

use of com.pokegoapi.api.inventory.PokeBank in project PokeGOAPI-Java by Grover-c13.

the class CatchPokemonAtAreaExample method catchArea.

private static void catchArea(PokemonGo api) throws RequestFailedException, NoSuchItemException {
    ItemBag bag = api.getInventories().getItemBag();
    try {
        //Wait until map is updated for the current location
        api.getMap().awaitUpdate();
        Set<CatchablePokemon> catchablePokemon = api.getMap().getMapObjects().getPokemon();
        System.out.println("Pokemon in area: " + catchablePokemon.size());
        Random random = new Random();
        PokeBank pokebank = api.getInventories().getPokebank();
        for (CatchablePokemon cp : catchablePokemon) {
            // Encounter this pokemon
            Encounter encounter = cp.encounter();
            // If the encounter was successful, attempt to catch this pokemon
            if (encounter.isSuccessful()) {
                System.out.println("Encountered: " + cp.getPokemonId());
                List<Pokeball> usablePokeballs = bag.getUsablePokeballs();
                if (usablePokeballs.size() > 0) {
                    //Select pokeball with smart selector to print what pokeball is used
                    double probability = encounter.getCaptureProbability();
                    Pokeball pokeball = PokeballSelector.SMART.select(usablePokeballs, probability);
                    System.out.println("Attempting to catch: " + cp.getPokemonId() + " with " + pokeball + " (" + probability + ")");
                    // Throw pokeballs until capture or flee
                    while (encounter.isActive()) {
                        // Wait between Pokeball throws
                        Thread.sleep(500 + random.nextInt(1000));
                        // If no item is active, use a razzberry
                        int razzberryCount = bag.getItem(ItemId.ITEM_RAZZ_BERRY).getCount();
                        if (encounter.getActiveItem() == null && razzberryCount > 0) {
                            encounter.useItem(ItemId.ITEM_RAZZ_BERRY);
                        }
                        // Throw pokeball with random properties
                        encounter.throwPokeball(PokeballSelector.SMART, ThrowProperties.random());
                        if (encounter.getStatus() == CatchStatus.CATCH_SUCCESS) {
                            // Print pokemon stats
                            Pokemon pokemon = pokebank.getPokemonById(encounter.getCapturedPokemon());
                            if (pokemon != null) {
                                double iv = pokemon.getIvInPercentage();
                                int number = pokemon.getPokemonId().getNumber();
                                String name = PokeDictionary.getDisplayName(number, Locale.ENGLISH);
                                System.out.println("====" + name + "====");
                                System.out.println("CP: " + pokemon.getCp());
                                System.out.println("IV: " + iv + "%");
                                System.out.println("Height: " + pokemon.getHeightM() + "m");
                                System.out.println("Weight: " + pokemon.getWeightKg() + "kg");
                                System.out.println("Move 1: " + pokemon.getMove1());
                                System.out.println("Move 2: " + pokemon.getMove2());
                                //Rename the pokemon to <Name> IV%
                                pokemon.renamePokemon(name + " " + iv + "%");
                                //Set pokemon with IV above 90% as favorite
                                if (iv > 90) {
                                    pokemon.setFavoritePokemon(true);
                                }
                            }
                        }
                    }
                } else {
                    System.out.println("Skipping Pokemon, we have no Pokeballs!");
                }
                // Wait for animation before catching next pokemon
                Thread.sleep(3000 + random.nextInt(1000));
            } else {
                System.out.println("Failed to encounter pokemon: " + encounter.getEncounterResult());
            }
        }
    } catch (InterruptedException e) {
        return;
    }
}
Also used : PokeBank(com.pokegoapi.api.inventory.PokeBank) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) Point(com.pokegoapi.api.map.Point) ItemBag(com.pokegoapi.api.inventory.ItemBag) Random(java.util.Random) Encounter(com.pokegoapi.api.map.pokemon.Encounter) NearbyPokemon(com.pokegoapi.api.map.pokemon.NearbyPokemon) Pokemon(com.pokegoapi.api.pokemon.Pokemon) CatchablePokemon(com.pokegoapi.api.map.pokemon.CatchablePokemon) Pokeball(com.pokegoapi.api.inventory.Pokeball)

Aggregations

PokeBank (com.pokegoapi.api.inventory.PokeBank)2 Pokemon (com.pokegoapi.api.pokemon.Pokemon)2 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)1 PokemonId (POGOProtos.Enums.PokemonIdOuterClass.PokemonId)1 PokemonGo (com.pokegoapi.api.PokemonGo)1 ItemBag (com.pokegoapi.api.inventory.ItemBag)1 Pokeball (com.pokegoapi.api.inventory.Pokeball)1 Point (com.pokegoapi.api.map.Point)1 CatchablePokemon (com.pokegoapi.api.map.pokemon.CatchablePokemon)1 Encounter (com.pokegoapi.api.map.pokemon.Encounter)1 NearbyPokemon (com.pokegoapi.api.map.pokemon.NearbyPokemon)1 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 HashProvider (com.pokegoapi.util.hash.HashProvider)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 OkHttpClient (okhttp3.OkHttpClient)1