use of POGOProtos.Networking.Responses.StartGymBattleResponseOuterClass.StartGymBattleResponse 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;
}
}
Aggregations