Search in sources :

Example 46 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Fort 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.latitude).setPlayerLongitude(api.longitude).build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_SEARCH, searchMessage);
    return api.requestHandler.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, Fort.this);
            }
            return lootResult;
        }
    });
}
Also used : PokestopListener(com.pokegoapi.api.listener.PokestopListener) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ProtocolStringList(com.google.protobuf.ProtocolStringList) List(java.util.List) FortSearchMessage(POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 47 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class IncenseEncounter method encounter.

@Override
public EncounterResult encounter() throws RequestFailedException {
    IncenseEncounterMessage message = IncenseEncounterMessage.newBuilder().setEncounterId(pokemon.encounterId).setEncounterLocation(pokemon.spawnPointId).build();
    ServerRequest request = new ServerRequest(RequestType.INCENSE_ENCOUNTER, message);
    ByteString responseData = api.requestHandler.sendServerRequests(request, true);
    try {
        IncenseEncounterResponse response = IncenseEncounterResponse.parseFrom(responseData);
        encounterResult = EncounterResult.from(response.getResult());
        activeItem = response.getActiveItem();
        captureProbabilities = response.getCaptureProbability();
        encounteredPokemon = response.getPokemonData();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return encounterResult;
}
Also used : IncenseEncounterResponse(POGOProtos.Networking.Responses.IncenseEncounterResponseOuterClass.IncenseEncounterResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IncenseEncounterMessage(POGOProtos.Networking.Requests.Messages.IncenseEncounterMessageOuterClass.IncenseEncounterMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 48 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Map method requestMapObjects.

/**
 * Requests and returns MapObjects from the server.
 *
 * @return the returned MapObjects
 * @throws RequestFailedException if an exception occurred while sending requests
 */
protected MapObjects requestMapObjects() throws RequestFailedException {
    List<Long> cells = getDefaultCells();
    GetMapObjectsMessage.Builder builder = GetMapObjectsMessage.newBuilder();
    builder.setLatitude(api.latitude);
    builder.setLongitude(api.longitude);
    for (Long cell : cells) {
        builder.addCellId(cell);
        builder.addSinceTimestampMs(0);
    }
    ServerRequest request = new ServerRequest(RequestType.GET_MAP_OBJECTS, builder.build());
    api.requestHandler.sendServerRequests(request, true);
    try {
        long updateTime = mapUpdateTime;
        GetMapObjectsResponse response = GetMapObjectsResponse.parseFrom(request.getData());
        MapObjects mapObjects = new MapObjects(api);
        for (MapCell cell : response.getMapCellsList()) {
            mapObjects.addCell(cell);
            updateTime = Math.max(updateTime, cell.getCurrentTimestampMs());
        }
        mapUpdateTime = updateTime;
        return mapObjects;
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) GetMapObjectsResponse(POGOProtos.Networking.Responses.GetMapObjectsResponseOuterClass.GetMapObjectsResponse) ServerRequest(com.pokegoapi.main.ServerRequest) GetMapObjectsMessage(POGOProtos.Networking.Requests.Messages.GetMapObjectsMessageOuterClass.GetMapObjectsMessage) MapCell(POGOProtos.Map.MapCellOuterClass.MapCell)

Aggregations

ServerRequest (com.pokegoapi.main.ServerRequest)48 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)46 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)37 ByteString (com.google.protobuf.ByteString)17 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 TutorialState (POGOProtos.Enums.TutorialStateOuterClass.TutorialState)2 AddFortModifierMessage (POGOProtos.Networking.Requests.Messages.AddFortModifierMessageOuterClass.AddFortModifierMessage)2 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2 FortDetailsMessage (POGOProtos.Networking.Requests.Messages.FortDetailsMessageOuterClass.FortDetailsMessage)2 FortSearchMessage (POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage)2 LevelUpRewardsMessage (POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage)2 ReleasePokemonMessage (POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage)2 UseItemEncounterMessage (POGOProtos.Networking.Requests.Messages.UseItemEncounterMessageOuterClass.UseItemEncounterMessage)2 LevelUpRewardsResponse (POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse)2 UseItemEncounterResponse (POGOProtos.Networking.Responses.UseItemEncounterResponseOuterClass.UseItemEncounterResponse)2 PokestopListener (com.pokegoapi.api.listener.PokestopListener)2 EvolutionResult (com.pokegoapi.api.map.pokemon.EvolutionResult)2