use of POGOProtos.Networking.Requests.Messages.AttackGymMessageOuterClass.AttackGymMessage in project PokeGOAPI-Java by Grover-c13.
the class Battle method sendActions.
/**
* Sends all currently queued actions to the server
*
* @param handler to handle this battle
* @return if this battle should switch to the next defender
* @throws RequestFailedException if an exception occurred while sending requests
*/
private boolean sendActions(BattleHandler handler) throws RequestFailedException {
AttackGymMessage.Builder builder = AttackGymMessage.newBuilder().setGymId(gym.getId()).setBattleId(battleId).setPlayerLatitude(api.latitude).setPlayerLongitude(api.longitude);
while (queuedActions.size() > 0) {
ClientAction action = queuedActions.element();
if (action.endTime < lastSendTime) {
queuedActions.remove();
long activePokemon = activeAttacker.pokemon.getId();
if (action.pokemon != null) {
activePokemon = action.pokemon.getId();
}
long start = action.startTime;
BattleAction.Builder actionBuilder = BattleAction.newBuilder().setActionStartMs(start).setDurationMs(action.duration).setTargetIndex(-1).setActivePokemonId(activePokemon).setType(action.type);
if (action.hasDamageWindow) {
long damageWindowsStart = start + action.damageWindowStart;
long damageWindowEnd = start + action.damageWindowEnd;
actionBuilder.setDamageWindowsStartTimestampMs(damageWindowsStart);
actionBuilder.setDamageWindowsEndTimestampMs(damageWindowEnd);
}
builder.addAttackActions(actionBuilder.build());
} else {
break;
}
}
if (lastRetrievedAction != null && sentActions) {
builder.setLastRetrievedAction(lastRetrievedAction);
}
if (builder.getAttackActionsCount() > 0) {
AttackGymMessage message = builder.build();
ServerRequest request = new ServerRequest(RequestType.GYM_BATTLE_ATTACK, message);
api.requestHandler.sendServerRequests(request, true);
boolean nextDefender;
try {
AttackGymResponse response = AttackGymResponse.parseFrom(request.getData());
nextDefender = handleAttackResponse(handler, response);
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
sentActions = true;
return nextDefender;
}
return false;
}
Aggregations