Search in sources :

Example 1 with EvolutionResult

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

the class Pokemon method evolve.

/**
 * Evolves pokemon with evolution item
 *
 * @param evolutionItem the evolution item to evolve with
 * @return the evolution result
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public EvolutionResult evolve(ItemId evolutionItem) throws RequestFailedException {
    EvolvePokemonMessage.Builder messageBuilder = EvolvePokemonMessage.newBuilder().setPokemonId(getId());
    if (evolutionItem != null) {
        messageBuilder.setEvolutionItemRequirement(evolutionItem);
    }
    ServerRequest serverRequest = new ServerRequest(RequestType.EVOLVE_POKEMON, messageBuilder.build());
    api.requestHandler.sendServerRequests(serverRequest, true);
    EvolvePokemonResponse response;
    try {
        response = EvolvePokemonResponse.parseFrom(serverRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        return null;
    }
    return new EvolutionResult(api, response);
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) EvolvePokemonResponse(POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass.EvolvePokemonResponse) EvolutionResult(com.pokegoapi.api.map.pokemon.EvolutionResult) ServerRequest(com.pokegoapi.main.ServerRequest) EvolvePokemonMessage(POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage)

Aggregations

EvolvePokemonMessage (POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage)1 EvolvePokemonResponse (POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass.EvolvePokemonResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 EvolutionResult (com.pokegoapi.api.map.pokemon.EvolutionResult)1 ServerRequest (com.pokegoapi.main.ServerRequest)1