Search in sources :

Example 1 with FortSearchMessage

use of POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage in project PokeGOAPI-Java by Grover-c13.

the class Pokestop method lootAsync.

/**
	 * Loots a pokestop for pokeballs and other items.
	 *
	 * @return PokestopLootResult
	 */
public Observable<PokestopLootResult> lootAsync() {
    FortSearchMessage searchMessage = FortSearchMessage.newBuilder().setFortId(getId()).setFortLatitude(getLatitude()).setFortLongitude(getLongitude()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_SEARCH, searchMessage);
    return api.getRequestHandler().sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, PokestopLootResult>() {

        @Override
        public PokestopLootResult call(ByteString result) {
            FortSearchResponseOuterClass.FortSearchResponse response;
            try {
                response = FortSearchResponseOuterClass.FortSearchResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            cooldownCompleteTimestampMs = response.getCooldownCompleteTimestampMs();
            PokestopLootResult lootResult = new PokestopLootResult(response);
            List<PokestopListener> listeners = api.getListeners(PokestopListener.class);
            for (PokestopListener listener : listeners) {
                // listener.onLoot(lootResult);
                // return the pokestop, also change in listener
                listener.onLoot(lootResult, Pokestop.this);
            }
            return lootResult;
        }
    });
}
Also used : PokestopListener(com.pokegoapi.api.listener.PokestopListener) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) List(java.util.List) FortSearchMessage(POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

FortSearchMessage (POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage)1 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 PokestopListener (com.pokegoapi.api.listener.PokestopListener)1 ServerRequest (com.pokegoapi.main.ServerRequest)1 List (java.util.List)1