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;
}
});
}
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;
}
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);
}
}
Aggregations