Search in sources :

Example 26 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Encounter method encounter.

/**
	 * Encounters this pokemon
	 *
	 * @return the result from the attempted encounter
	 * @throws RequestFailedException if the encounter request fails
	 */
protected EncounterResult encounter() throws RequestFailedException {
    EncounterMessage message = EncounterMessage.newBuilder().setEncounterId(pokemon.getEncounterId()).setSpawnPointId(pokemon.getSpawnPointId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest request = new ServerRequest(RequestType.ENCOUNTER, message);
    ByteString responseData = api.getRequestHandler().sendServerRequests(request, true);
    try {
        EncounterResponse response = EncounterResponse.parseFrom(responseData);
        encounterResult = EncounterResult.from(response.getStatus());
        activeItem = response.getActiveItem();
        captureProbabilities = response.getCaptureProbability();
        encounteredPokemon = response.getWildPokemon().getPokemonData();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return encounterResult;
}
Also used : EncounterResponse(POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse) UseItemEncounterResponse(POGOProtos.Networking.Responses.UseItemEncounterResponseOuterClass.UseItemEncounterResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) EncounterMessage(POGOProtos.Networking.Requests.Messages.EncounterMessageOuterClass.EncounterMessage) UseItemEncounterMessage(POGOProtos.Networking.Requests.Messages.UseItemEncounterMessageOuterClass.UseItemEncounterMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 27 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class Encounter method useItem.

/**
	 * Uses an item in this encounter
	 *
	 * @param itemId the item to use
	 * @return the result from this action
	 * @throws RequestFailedException if the use request fails
	 */
public UseItemEncounterResponse.Status useItem(ItemId itemId) throws RequestFailedException {
    if (isActive()) {
        ItemBag bag = api.getInventories().getItemBag();
        Item item = bag.getItem(itemId);
        if (item.getCount() > 0) {
            if (activeItem == null) {
                UseItemEncounterMessage message = UseItemEncounterMessage.newBuilder().setEncounterId(pokemon.getEncounterId()).setSpawnPointGuid(pokemon.getSpawnPointId()).setItem(itemId).build();
                ServerRequest request = new ServerRequest(RequestType.USE_ITEM_ENCOUNTER, message);
                ByteString responseData = api.getRequestHandler().sendServerRequests(request, true);
                try {
                    UseItemEncounterResponse response = UseItemEncounterResponse.parseFrom(responseData);
                    activeItem = response.getActiveItem();
                    captureProbabilities = response.getCaptureProbability();
                    if (response.getStatus() == Status.SUCCESS) {
                        item.setCount(item.getCount() - 1);
                    }
                    return response.getStatus();
                } catch (InvalidProtocolBufferException e) {
                    throw new RequestFailedException(e);
                }
            } else {
                return UseItemEncounterResponse.Status.ACTIVE_ITEM_EXISTS;
            }
        } else {
            return UseItemEncounterResponse.Status.NO_ITEM_IN_INVENTORY;
        }
    }
    return UseItemEncounterResponse.Status.ALREADY_COMPLETED;
}
Also used : Item(com.pokegoapi.api.inventory.Item) UseItemEncounterResponse(POGOProtos.Networking.Responses.UseItemEncounterResponseOuterClass.UseItemEncounterResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) UseItemEncounterMessage(POGOProtos.Networking.Requests.Messages.UseItemEncounterMessageOuterClass.UseItemEncounterMessage) ItemBag(com.pokegoapi.api.inventory.ItemBag)

Example 28 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException 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 29 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.

the class RequestHandler method sendServerRequests.

/**
	 * Sends a single ServerRequest
	 *
	 * @param request the request to send
	 * @param commons whether this request should include commons
	 * @param commonExclusions the common requests to exclude from this request
	 * @return the result from this request
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public ByteString sendServerRequests(ServerRequest request, boolean commons, RequestType... commonExclusions) throws RequestFailedException {
    ServerRequestEnvelope envelope = ServerRequestEnvelope.create();
    envelope.add(request);
    envelope.setCommons(commons);
    envelope.excludeCommons(commonExclusions);
    AsyncHelper.toBlocking(sendAsyncServerRequests(envelope));
    try {
        return request.getData();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException)

Example 30 with InvalidProtocolBufferException

use of com.google.protobuf.InvalidProtocolBufferException 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)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)104 ServerRequest (com.pokegoapi.main.ServerRequest)42 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)37 ByteString (com.google.protobuf.ByteString)21 IOException (java.io.IOException)13 ByteArrayInputStream (java.io.ByteArrayInputStream)5 CodedInputStream (com.google.protobuf.CodedInputStream)4 List (java.util.List)4 TypicalData (protos.TypicalData)4 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 Item (com.pokegoapi.api.inventory.Item)3 ItemBag (com.pokegoapi.api.inventory.ItemBag)3 TutorialListener (com.pokegoapi.api.listener.TutorialListener)3 ArrayList (java.util.ArrayList)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BytesWritable (org.apache.hadoop.io.BytesWritable)3 Text (org.apache.hadoop.io.Text)3 YamcsClient (org.yamcs.studio.core.client.YamcsClient)3 ArchiveCatalogue (org.yamcs.studio.core.model.ArchiveCatalogue)3 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2