use of com.pokegoapi.exceptions.request.RequestFailedException 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
* @deprecated Inventory is updated as a common request
*/
@Deprecated
public GetHoloInventoryResponse updateInventories(boolean forceUpdate) throws RequestFailedException {
if (forceUpdate) {
lastInventoryUpdate = 0;
itemBag.reset();
pokebank.reset();
candyjar.reset();
pokedex.reset();
synchronized (this.lock) {
incubators.clear();
}
hatchery.reset();
}
GetHoloInventoryMessage invReqMsg = GetHoloInventoryMessage.newBuilder().setLastTimestampMs(lastInventoryUpdate).build();
ServerRequest inventoryRequest = new ServerRequest(RequestType.GET_HOLOHOLO_INVENTORY, invReqMsg);
api.requestHandler.sendServerRequests(inventoryRequest, false);
GetHoloInventoryResponse response;
try {
response = GetHoloInventoryResponse.parseFrom(inventoryRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
return response;
}
use of com.pokegoapi.exceptions.request.RequestFailedException 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.requestHandler.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.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.
the class Battle method beginDefenderBattle.
/**
* Starts this battle with an individual defender
*
* @param handler to handle this battle
* @throws RequestFailedException if an exception occurred while sending requests
*/
private void beginDefenderBattle(final BattleHandler handler) throws RequestFailedException {
lastRetrievedAction = null;
queuedActions.clear();
battleState = BattleState.STATE_UNSET;
lastServerTime = api.currentTimeMillis();
lastSendTime = lastServerTime;
sentActions = false;
List<Pokemon> attackers = new ArrayList<>();
for (Pokemon pokemon : team) {
if (!faintedPokemon.contains(pokemon.getId())) {
attackers.add(pokemon);
}
}
if (attackers.size() > 0 && defenderIndex < defenderCount) {
StartGymBattleMessage.Builder builder = StartGymBattleMessage.newBuilder().setPlayerLatitude(api.latitude).setPlayerLongitude(api.longitude).setGymId(gym.getId()).setDefendingPokemonId(gym.getDefendingPokemon().get(defenderIndex).getPokemon().getId());
for (Pokemon pokemon : attackers) {
builder.addAttackingPokemonIds(pokemon.getId());
if (pokemon.getStamina() < pokemon.getMaxStamina()) {
throw new IllegalArgumentException("Pokemon must have full stamina to battle in a gym!");
} else {
String deployedFortId = pokemon.getDeployedFortId();
if (pokemon.getFromFort() && deployedFortId != null && deployedFortId.length() > 0) {
throw new IllegalArgumentException("Cannot deploy Pokemon that is already in a gym!");
}
}
}
try {
StartGymBattleMessage message = builder.build();
ServerRequest request = new ServerRequest(RequestType.GYM_START_SESSION, message);
api.requestHandler.sendServerRequests(request, true);
StartGymBattleResponse response = StartGymBattleResponse.parseFrom(request.getData());
if (response.getResult() == StartGymBattleResponse.Result.SUCCESS) {
battleId = response.getBattleId();
attacker = response.getAttacker();
defender = response.getDefender();
activeDefender = new BattlePokemon(defender.getActivePokemon());
activeAttacker = new BattlePokemon(attacker.getActivePokemon());
updateLog(handler, response.getBattleLog());
}
sendActions(handler);
handler.onStart(api, this, response.getResult());
} catch (InvalidProtocolBufferException e) {
battleId = "";
throw new RequestFailedException(e);
}
} else {
active = false;
}
}
use of com.pokegoapi.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.
the class Hatchery method queryHatchedEggs.
/**
* Get if eggs has hatched.
*
* @return list of hatched eggs
* @throws RequestFailedException if an exception occurred while sending requests
* @deprecated Use getHatchedEggs()
*/
@Deprecated
public List<HatchedEgg> queryHatchedEggs() throws RequestFailedException {
GetHatchedEggsMessage msg = GetHatchedEggsMessage.newBuilder().build();
ServerRequest serverRequest = new ServerRequest(RequestType.GET_HATCHED_EGGS, msg);
api.requestHandler.sendServerRequests(serverRequest, false);
GetHatchedEggsResponse response;
try {
response = GetHatchedEggsResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
api.inventories.updateInventories();
return updateHatchedEggs(response);
}
use of com.pokegoapi.exceptions.request.RequestFailedException in project PokeGOAPI-Java by Grover-c13.
the class DiskEncounter method encounter.
@Override
public EncounterResult encounter() throws RequestFailedException {
DiskEncounterMessage message = DiskEncounterMessage.newBuilder().setEncounterId(pokemon.encounterId).setFortId(pokemon.spawnPointId).setPlayerLatitude(api.latitude).setPlayerLongitude(api.longitude).build();
ServerRequest request = new ServerRequest(RequestType.DISK_ENCOUNTER, message);
ByteString responseData = api.requestHandler.sendServerRequests(request, true);
try {
DiskEncounterResponse response = DiskEncounterResponse.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;
}
Aggregations