Search in sources :

Example 1 with TutorialListener

use of com.pokegoapi.api.listener.TutorialListener 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.getPokemon());
    ServerRequest request = new ServerRequest(RequestType.ENCOUNTER_TUTORIAL_COMPLETE, builder.build());
    api.getRequestHandler().sendServerRequests(request, true);
    final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
    request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
    api.getRequestHandler().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)

Example 2 with TutorialListener

use of com.pokegoapi.api.listener.TutorialListener in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method setupAvatar.

/**
	 * Setup an avatar for the current account
	 *
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public void setupAvatar() throws RequestFailedException {
    SecureRandom random = new SecureRandom();
    PlayerGender gender = random.nextInt(100) % 2 == 0 ? PlayerGender.FEMALE : PlayerGender.MALE;
    PlayerAvatar avatar = new PlayerAvatar(gender, random.nextInt(PlayerAvatar.getAvailableSkins()), random.nextInt(PlayerAvatar.getAvailableHair()), random.nextInt(PlayerAvatar.getAvailableShirts(gender)), random.nextInt(PlayerAvatar.getAvailablePants(gender)), random.nextInt(PlayerAvatar.getAvailableHats()), random.nextInt(PlayerAvatar.getAvailableShoes()), random.nextInt(PlayerAvatar.getAvailableEyes()), random.nextInt(PlayerAvatar.getAvailableBags(gender)));
    List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
    for (TutorialListener listener : listeners) {
        PlayerAvatar listenerAvatar = listener.selectAvatar(api);
        if (listenerAvatar != null) {
            avatar = listenerAvatar;
            break;
        }
    }
    final SetAvatarMessage setAvatarMessage = SetAvatarMessage.newBuilder().setPlayerAvatar(avatar.getAvatar()).build();
    ServerRequest request = new ServerRequest(RequestType.SET_AVATAR, setAvatarMessage);
    api.getRequestHandler().sendServerRequests(request, true);
    try {
        SetAvatarResponse setAvatarResponse = SetAvatarResponse.parseFrom(request.getData());
        playerData = setAvatarResponse.getPlayerData();
        updateProfile(playerData);
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    markTutorial(TutorialStateOuterClass.TutorialState.AVATAR_SELECTION);
    api.getAssetDigest();
}
Also used : TutorialListener(com.pokegoapi.api.listener.TutorialListener) SetAvatarMessage(POGOProtos.Networking.Requests.Messages.SetAvatarMessageOuterClass.SetAvatarMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SecureRandom(java.security.SecureRandom) ServerRequest(com.pokegoapi.main.ServerRequest) SetAvatarResponse(POGOProtos.Networking.Responses.SetAvatarResponseOuterClass.SetAvatarResponse)

Example 3 with TutorialListener

use of com.pokegoapi.api.listener.TutorialListener in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method claimCodeName.

/**
	 * Setup an user name for our account
	 *
	 * @param lastFailure the last name used that was already taken; null for first try.
	 * @return the claimed codename
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public String claimCodeName(String lastFailure) throws RequestFailedException {
    if (getPlayerData().getRemainingCodenameClaims() <= 0) {
        throw new RuntimeException("You have no remaining codename claims!");
    }
    String name = randomCodenameGenerator();
    List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
    for (TutorialListener listener : listeners) {
        String listenerName = listener.claimName(api, lastFailure);
        if (listenerName != null) {
            name = listenerName;
            break;
        }
    }
    ClaimCodenameMessage claimCodenameMessage = ClaimCodenameMessage.newBuilder().setCodename(name).build();
    ServerRequest request = new ServerRequest(RequestType.CLAIM_CODENAME, claimCodenameMessage);
    api.getRequestHandler().sendServerRequests(request, true);
    String updatedCodename;
    try {
        ClaimCodenameResponse claimCodenameResponse = ClaimCodenameResponse.parseFrom(request.getData());
        if (claimCodenameResponse.getStatus() != ClaimCodenameResponse.Status.SUCCESS) {
            return claimCodeName(name);
        }
        updatedCodename = claimCodenameResponse.getCodename();
        if (claimCodenameResponse.hasUpdatedPlayer()) {
            updateProfile(claimCodenameResponse.getUpdatedPlayer());
        }
        if (updatedCodename != null) {
            markTutorial(TutorialStateOuterClass.TutorialState.NAME_SELECTION);
            final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
            request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
            api.getRequestHandler().sendServerRequests(request, true);
            updateProfile(GetPlayerResponse.parseFrom(request.getData()));
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return updatedCodename;
}
Also used : GetPlayerMessage(POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage) TutorialListener(com.pokegoapi.api.listener.TutorialListener) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ClaimCodenameResponse(POGOProtos.Networking.Responses.ClaimCodenameResponseOuterClass.ClaimCodenameResponse) ServerRequest(com.pokegoapi.main.ServerRequest) ClaimCodenameMessage(POGOProtos.Networking.Requests.Messages.ClaimCodenameMessageOuterClass.ClaimCodenameMessage)

Example 4 with TutorialListener

use of com.pokegoapi.api.listener.TutorialListener 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)

Aggregations

TutorialListener (com.pokegoapi.api.listener.TutorialListener)4 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 ServerRequest (com.pokegoapi.main.ServerRequest)3 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)2 StarterPokemon (com.pokegoapi.api.pokemon.StarterPokemon)2 ClaimCodenameMessage (POGOProtos.Networking.Requests.Messages.ClaimCodenameMessageOuterClass.ClaimCodenameMessage)1 EncounterTutorialCompleteMessage (POGOProtos.Networking.Requests.Messages.EncounterTutorialCompleteMessageOuterClass.EncounterTutorialCompleteMessage)1 SetAvatarMessage (POGOProtos.Networking.Requests.Messages.SetAvatarMessageOuterClass.SetAvatarMessage)1 ClaimCodenameResponse (POGOProtos.Networking.Responses.ClaimCodenameResponseOuterClass.ClaimCodenameResponse)1 SetAvatarResponse (POGOProtos.Networking.Responses.SetAvatarResponseOuterClass.SetAvatarResponse)1 PokemonGo (com.pokegoapi.api.PokemonGo)1 PlayerAvatar (com.pokegoapi.api.player.PlayerAvatar)1 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)1 HashProvider (com.pokegoapi.util.hash.HashProvider)1 SecureRandom (java.security.SecureRandom)1 OkHttpClient (okhttp3.OkHttpClient)1