use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Inventories method updateInventories.
/**
* Updates the inventories with the latest data.
*
* @param forceUpdate For a full update if true
* @return the response to the update message
* @throws RequestFailedException if an exception occurred while sending requests
*/
public GetInventoryResponse updateInventories(boolean forceUpdate) throws RequestFailedException {
if (forceUpdate) {
lastInventoryUpdate = 0;
itemBag.reset();
pokebank.reset();
candyjar.reset();
pokedex.reset();
synchronized (this.lock) {
incubators.clear();
}
hatchery.reset();
}
GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder().setLastTimestampMs(lastInventoryUpdate).build();
ServerRequest inventoryRequest = new ServerRequest(RequestTypeOuterClass.RequestType.GET_INVENTORY, invReqMsg);
api.getRequestHandler().sendServerRequests(inventoryRequest);
GetInventoryResponse response;
try {
response = GetInventoryResponse.parseFrom(inventoryRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
return response;
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class ItemBag method useLuckyEgg.
/**
* use a lucky egg
*
* @return the xp boost response
* @throws RequestFailedException if an exception occurred while sending requests
*/
public UseItemXpBoostResponse useLuckyEgg() throws RequestFailedException {
UseItemXpBoostMessage xpMsg = UseItemXpBoostMessage.newBuilder().setItemId(ItemId.ITEM_LUCKY_EGG).build();
ServerRequest req = new ServerRequest(RequestType.USE_ITEM_XP_BOOST, xpMsg);
api.getRequestHandler().sendServerRequests(req, true);
try {
UseItemXpBoostResponse response = UseItemXpBoostResponse.parseFrom(req.getData());
Log.i("Main", "Use incense result: " + response.getResult());
return response;
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of com.pokegoapi.main.ServerRequest 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.getRequestHandler().sendServerRequests(serverRequest, true);
EvolvePokemonResponse response;
try {
response = EvolvePokemonResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
return null;
}
return new EvolutionResult(api, response);
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Gym method details.
private GetGymDetailsResponse details() throws RequestFailedException {
if (details == null) {
GetGymDetailsMessage reqMsg = GetGymDetailsMessage.newBuilder().setGymId(this.getId()).setGymLatitude(this.getLatitude()).setGymLongitude(this.getLongitude()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
ServerRequest serverRequest = new ServerRequest(RequestType.GET_GYM_DETAILS, reqMsg);
api.getRequestHandler().sendServerRequests(serverRequest, true);
try {
details = GetGymDetailsResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException();
}
}
return details;
}
use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.
the class Gym method deployPokemonAsync.
/**
* Deploy pokemon
*
* @param pokemon The pokemon to deploy
* @return Result of attempt to deploy pokemon
* @throws RequestFailedException if an exception occurred while sending requests
*/
public Observable<FortDeployPokemonResponse.Result> deployPokemonAsync(Pokemon pokemon) throws RequestFailedException {
FortDeployPokemonMessage reqMsg = FortDeployPokemonMessage.newBuilder().setFortId(getId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).setPokemonId(pokemon.getId()).build();
ServerRequest asyncServerRequest = new ServerRequest(RequestType.FORT_DEPLOY_POKEMON, reqMsg);
return api.getRequestHandler().sendAsyncServerRequests(asyncServerRequest).map(new Func1<ByteString, FortDeployPokemonResponse.Result>() {
@Override
public FortDeployPokemonResponse.Result call(ByteString response) {
try {
return FortDeployPokemonResponse.parseFrom(response).getResult();
} catch (InvalidProtocolBufferException e) {
throw Exceptions.propagate(e);
}
}
});
}
Aggregations