Search in sources :

Example 1 with EncounterMessage

use of POGOProtos.Networking.Requests.Messages.EncounterMessageOuterClass.EncounterMessage 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.encounterId).setSpawnPointId(pokemon.spawnPointId).setPlayerLatitude(api.latitude).setPlayerLongitude(api.longitude).build();
    ServerRequest request = new ServerRequest(RequestType.ENCOUNTER, message);
    ByteString responseData = api.requestHandler.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)

Aggregations

EncounterMessage (POGOProtos.Networking.Requests.Messages.EncounterMessageOuterClass.EncounterMessage)1 UseItemEncounterMessage (POGOProtos.Networking.Requests.Messages.UseItemEncounterMessageOuterClass.UseItemEncounterMessage)1 EncounterResponse (POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse)1 UseItemEncounterResponse (POGOProtos.Networking.Responses.UseItemEncounterResponseOuterClass.UseItemEncounterResponse)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1