use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.
the class PokemonGo method verifyChallenge.
/**
* Verifies the current challenge with the given token.
*
* @param token the challenge response token
* @return if the token was valid or not
* @throws RequestFailedException if an exception occurred while sending requests
*/
public boolean verifyChallenge(String token) throws RequestFailedException {
hasChallenge = false;
VerifyChallengeMessage message = VerifyChallengeMessage.newBuilder().setToken(token).build();
ServerRequest request = new ServerRequest(RequestType.VERIFY_CHALLENGE, message);
ByteString responseData = getRequestHandler().sendServerRequests(request, true);
try {
VerifyChallengeResponse response = VerifyChallengeResponse.parseFrom(responseData);
hasChallenge = !response.getSuccess();
if (!hasChallenge) {
challengeURL = null;
synchronized (challengeLock) {
challengeLock.notifyAll();
}
}
return response.getSuccess();
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of com.google.protobuf.InvalidProtocolBufferException 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.getLatitude()).setPlayerLongitude(api.getLongitude()).setGymId(gym.getId()).setDefendingPokemonId(gym.getDefendingPokemon().get(defenderIndex).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.START_GYM_BATTLE, message);
api.getRequestHandler().sendServerRequests(request);
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.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.
the class Map method requestIncensePokemon.
/**
* Requests and returns incense pokemon from the server.
*
* @return the returned incense pokemon response
* @throws RequestFailedException if an exception occurred while sending requests
*/
protected GetIncensePokemonResponse requestIncensePokemon() throws RequestFailedException {
GetIncensePokemonMessage message = GetIncensePokemonMessage.newBuilder().setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
ServerRequest request = new ServerRequest(RequestType.GET_INCENSE_POKEMON, message);
api.getRequestHandler().sendServerRequests(request);
try {
return GetIncensePokemonResponse.parseFrom(request.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.
the class DiskEncounter method encounter.
@Override
public EncounterResult encounter() throws RequestFailedException {
DiskEncounterMessage message = DiskEncounterMessage.newBuilder().setEncounterId(pokemon.getEncounterId()).setFortId(pokemon.getSpawnPointId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
ServerRequest request = new ServerRequest(RequestType.DISK_ENCOUNTER, message);
ByteString responseData = api.getRequestHandler().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;
}
use of com.google.protobuf.InvalidProtocolBufferException in project PokeGOAPI-Java by Grover-c13.
the class Encounter method throwPokeball.
/**
* Throws a pokeball in this encounter
*
* @param pokeball the pokeball to throw
* @param throwProperties the throw properties for this throw
* @return the result from the pokeball throw
* @throws RequestFailedException if the throw request fails
* @throws NoSuchItemException if the requested pokeball does not exist
*/
public CatchPokemonResponse.CatchStatus throwPokeball(ItemId pokeball, ThrowProperties throwProperties) throws RequestFailedException, NoSuchItemException {
if (isActive()) {
ItemBag bag = api.getInventories().getItemBag();
Item item = bag.getItem(pokeball);
if (item.getCount() > 0) {
CatchPokemonMessage message = CatchPokemonMessage.newBuilder().setEncounterId(pokemon.getEncounterId()).setSpawnPointId(pokemon.getSpawnPointId()).setPokeball(pokeball).setNormalizedHitPosition(throwProperties.getNormalizedHitPosition()).setNormalizedReticleSize(throwProperties.getNormalizedReticleSize()).setSpinModifier(throwProperties.getSpinModifier()).setHitPokemon(throwProperties.shouldHitPokemon()).build();
ServerRequest request = new ServerRequest(RequestType.CATCH_POKEMON, message);
ByteString responseData = api.getRequestHandler().sendServerRequests(request, true);
try {
CatchPokemonResponse response = CatchPokemonResponse.parseFrom(responseData);
status = response.getStatus();
if (hasCaptured()) {
captureAward = response.getCaptureAward();
capturedPokemon = response.getCapturedPokemonId();
captureReason = response.getCaptureReason();
}
if (status == CatchStatus.CATCH_SUCCESS || status == CatchStatus.CATCH_FLEE) {
pokemon.setDespawned(true);
}
if (status == CatchStatus.CATCH_SUCCESS) {
api.getPlayerProfile().updateProfile();
}
if (status != CatchStatus.CATCH_ERROR) {
item.setCount(item.getCount() - 1);
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
} else {
throw new NoSuchItemException();
}
}
return status;
}
Aggregations