Search in sources :

Example 6 with PtcCredentialProvider

use of com.pokegoapi.auth.PtcCredentialProvider in project PokeGOAPI-Java by Grover-c13.

the class TutorialHandleExample method main.

/**
	 * Goes through the tutorial with custom responses.
	 *
	 * @param args args
	 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    final PokemonGo api = new PokemonGo(http);
    try {
        // Add listener to listen for all tutorial related events, must be registered before login is called,
        // otherwise it will not be used
        api.addListener(new TutorialListener() {

            @Override
            public String claimName(PokemonGo api, String lastFailure) {
                //Last attempt to set a codename failed, set a random one by returning null
                if (lastFailure != null) {
                    System.out.println("Codename \"" + lastFailure + "\" is already taken. Using random name.");
                    return null;
                }
                System.out.println("Selecting codename");
                //Set the PTC name as the POGO username
                return ExampleConstants.LOGIN;
            }

            @Override
            public StarterPokemon selectStarter(PokemonGo api) {
                //Catch Charmander as your starter pokemon
                System.out.println("Selecting starter pokemon");
                return StarterPokemon.CHARMANDER;
            }

            @Override
            public PlayerAvatar selectAvatar(PokemonGo api) {
                System.out.println("Selecting player avatar");
                return new PlayerAvatar(PlayerGender.FEMALE, Avatar.Skin.YELLOW.id(), Avatar.Hair.BLACK.id(), Avatar.FemaleShirt.BLUE.id(), Avatar.FemalePants.BLACK_PURPLE_STRIPE.id(), Avatar.FemaleHat.BLACK_YELLOW_POKEBALL.id(), Avatar.FemaleShoes.BLACK_YELLOW_STRIPE.id(), Avatar.Eye.BROWN.id(), Avatar.FemaleBackpack.GRAY_BLACK_YELLOW_POKEBALL.id());
            }
        });
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
    } catch (RequestFailedException e) {
        Log.e("Main", "Failed to login!", e);
    }
}
Also used : PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) TutorialListener(com.pokegoapi.api.listener.TutorialListener) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) HashProvider(com.pokegoapi.util.hash.HashProvider) PlayerAvatar(com.pokegoapi.api.player.PlayerAvatar) StarterPokemon(com.pokegoapi.api.pokemon.StarterPokemon)

Example 7 with PtcCredentialProvider

use of com.pokegoapi.auth.PtcCredentialProvider in project PokeGOAPI-Java by Grover-c13.

the class UseIncenseExample method main.

/**
	 * Catches a pokemon at an area.
	 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    PokemonGo api = new PokemonGo(http, new SystemTimeImpl());
    try {
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        api.getInventories().getItemBag().useIncense();
    } 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) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) SystemTimeImpl(com.pokegoapi.util.SystemTimeImpl) HashProvider(com.pokegoapi.util.hash.HashProvider)

Example 8 with PtcCredentialProvider

use of com.pokegoapi.auth.PtcCredentialProvider in project PokeGOAPI-Java by Grover-c13.

the class TravelToPokestopExample method main.

/**
	 * Travels to a Pokestop and loots it
	 *
	 * @param args args
	 */
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);
        Set<Pokestop> pokestops = api.getMap().getMapObjects().getPokestops();
        System.out.println("Found " + pokestops.size() + " pokestops in the current area.");
        Pokestop destinationPokestop = null;
        for (Pokestop pokestop : pokestops) {
            //Check if not in range and if it is not on cooldown
            if (!pokestop.inRange() && pokestop.canLoot(true)) {
                destinationPokestop = pokestop;
                break;
            }
        }
        if (destinationPokestop != null) {
            Point destination = new Point(destinationPokestop.getLatitude(), destinationPokestop.getLongitude());
            //Use the current player position as the source and the pokestop position as the destination
            //Travel to Pokestop at 20KMPH
            Path path = new Path(api.getPoint(), destination, 20.0);
            System.out.println("Traveling to " + destination + " at 20KMPH!");
            path.start(api);
            try {
                while (!path.isComplete()) {
                    //Calculate the desired intermediate point for the current time
                    Point point = path.calculateIntermediate(api);
                    //Set the API location to that point
                    api.setLatitude(point.getLatitude());
                    api.setLongitude(point.getLongitude());
                    System.out.println("Time left: " + (int) (path.getTimeLeft(api) / 1000) + " seconds.");
                    //Sleep for 2 seconds before setting the location again
                    Thread.sleep(2000);
                }
            } catch (InterruptedException e) {
                return;
            }
            System.out.println("Finished traveling to pokestop!");
            if (destinationPokestop.inRange()) {
                System.out.println("Looting pokestop...");
                PokestopLootResult result = destinationPokestop.loot();
                System.out.println("Pokestop loot returned result: " + result.getResult());
            } else {
                System.out.println("Something went wrong! We're still not in range of the destination pokestop!");
            }
        } else {
            System.out.println("Couldn't find out of range pokestop to travel to!");
        }
    } catch (RequestFailedException e) {
        Log.e("Main", "Failed to login, captcha or server issue: ", e);
    }
}
Also used : Path(com.pokegoapi.util.path.Path) PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) Pokestop(com.pokegoapi.api.map.fort.Pokestop) HashProvider(com.pokegoapi.util.hash.HashProvider) Point(com.pokegoapi.api.map.Point) PokestopLootResult(com.pokegoapi.api.map.fort.PokestopLootResult)

Aggregations

PokemonGo (com.pokegoapi.api.PokemonGo)8 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)8 HashProvider (com.pokegoapi.util.hash.HashProvider)8 OkHttpClient (okhttp3.OkHttpClient)8 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)7 Point (com.pokegoapi.api.map.Point)3 Pokemon (com.pokegoapi.api.pokemon.Pokemon)3 Path (com.pokegoapi.util.path.Path)3 ArrayList (java.util.ArrayList)3 MapObjects (com.pokegoapi.api.map.MapObjects)2 Pokestop (com.pokegoapi.api.map.fort.Pokestop)2 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)1 PokemonId (POGOProtos.Enums.PokemonIdOuterClass.PokemonId)1 Battle (com.pokegoapi.api.gym.Battle)1 Gym (com.pokegoapi.api.gym.Gym)1 PokeBank (com.pokegoapi.api.inventory.PokeBank)1 LoginListener (com.pokegoapi.api.listener.LoginListener)1 TutorialListener (com.pokegoapi.api.listener.TutorialListener)1 PokestopLootResult (com.pokegoapi.api.map.fort.PokestopLootResult)1 NearbyPokemon (com.pokegoapi.api.map.pokemon.NearbyPokemon)1