Search in sources :

Example 1 with StarterPokemon

use of com.pokegoapi.api.pokemon.StarterPokemon 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 2 with StarterPokemon

use of com.pokegoapi.api.pokemon.StarterPokemon in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method encounterTutorialComplete.

/**
 * Encounter tutorial complete. In other words, catch the first Pokémon
 *
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public void encounterTutorialComplete() throws RequestFailedException {
    StarterPokemon starter = StarterPokemon.random();
    List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
    for (TutorialListener listener : listeners) {
        StarterPokemon pokemon = listener.selectStarter(api);
        if (pokemon != null) {
            starter = pokemon;
            break;
        }
    }
    final EncounterTutorialCompleteMessage.Builder builder = EncounterTutorialCompleteMessage.newBuilder().setPokemonId(starter.pokemon);
    ServerRequest request = new ServerRequest(RequestType.ENCOUNTER_TUTORIAL_COMPLETE, builder.build());
    api.requestHandler.sendServerRequests(request, true);
    final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
    request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
    api.requestHandler.sendServerRequests(request, true);
    try {
        updateProfile(GetPlayerResponse.parseFrom(request.getData()));
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : GetPlayerMessage(POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage) EncounterTutorialCompleteMessage(POGOProtos.Networking.Requests.Messages.EncounterTutorialCompleteMessageOuterClass.EncounterTutorialCompleteMessage) TutorialListener(com.pokegoapi.api.listener.TutorialListener) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) StarterPokemon(com.pokegoapi.api.pokemon.StarterPokemon)

Aggregations

TutorialListener (com.pokegoapi.api.listener.TutorialListener)2 StarterPokemon (com.pokegoapi.api.pokemon.StarterPokemon)2 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)2 EncounterTutorialCompleteMessage (POGOProtos.Networking.Requests.Messages.EncounterTutorialCompleteMessageOuterClass.EncounterTutorialCompleteMessage)1 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 PokemonGo (com.pokegoapi.api.PokemonGo)1 PlayerAvatar (com.pokegoapi.api.player.PlayerAvatar)1 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)1 ServerRequest (com.pokegoapi.main.ServerRequest)1 HashProvider (com.pokegoapi.util.hash.HashProvider)1 OkHttpClient (okhttp3.OkHttpClient)1