Search in sources :

Example 1 with UpgradePokemonMessage

use of POGOProtos.Networking.Requests.Messages.UpgradePokemonMessageOuterClass.UpgradePokemonMessage in project PokeGOAPI-Java by Grover-c13.

the class Pokemon method powerUpAsync.

/**
	 * Powers up a pokemon with candy and stardust.
	 * After powering up this pokemon object will reflect the new changes.
	 *
	 * @return The result
	 */
public Observable<UpgradePokemonResponse.Result> powerUpAsync() {
    UpgradePokemonMessage reqMsg = UpgradePokemonMessage.newBuilder().setPokemonId(getId()).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.UPGRADE_POKEMON, reqMsg);
    return api.getRequestHandler().sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, UpgradePokemonResponse.Result>() {

        @Override
        public UpgradePokemonResponse.Result call(ByteString result) {
            UpgradePokemonResponse response;
            try {
                response = UpgradePokemonResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            //set new pokemon details
            applyProto(response.getUpgradedPokemon());
            return response.getResult();
        }
    });
}
Also used : UpgradePokemonMessage(POGOProtos.Networking.Requests.Messages.UpgradePokemonMessageOuterClass.UpgradePokemonMessage) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) UpgradePokemonResponse(POGOProtos.Networking.Responses.UpgradePokemonResponseOuterClass.UpgradePokemonResponse) EvolutionResult(com.pokegoapi.api.map.pokemon.EvolutionResult) Result(POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result)

Aggregations

UpgradePokemonMessage (POGOProtos.Networking.Requests.Messages.UpgradePokemonMessageOuterClass.UpgradePokemonMessage)1 Result (POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result)1 UpgradePokemonResponse (POGOProtos.Networking.Responses.UpgradePokemonResponseOuterClass.UpgradePokemonResponse)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 EvolutionResult (com.pokegoapi.api.map.pokemon.EvolutionResult)1 ServerRequest (com.pokegoapi.main.ServerRequest)1