use of POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse in project PokeGOAPI-Java by Grover-c13.
the class Pokemon method transferPokemon.
/**
* Transfers the pokemon.
*
* @return the result
* @throws RequestFailedException if an exception occurred while sending requests
*/
public Result transferPokemon() throws RequestFailedException {
if (this.isFavorite() || this.isDeployed()) {
return Result.FAILED;
}
ReleasePokemonMessage reqMsg = ReleasePokemonMessage.newBuilder().setPokemonId(getId()).build();
ServerRequest serverRequest = new ServerRequest(RequestType.RELEASE_POKEMON, reqMsg);
api.requestHandler.sendServerRequests(serverRequest, true);
ReleasePokemonResponse response;
try {
response = ReleasePokemonResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
return ReleasePokemonResponse.Result.FAILED;
}
if (response.getResult() == Result.SUCCESS) {
api.inventories.pokebank.removePokemon(this);
}
return response.getResult();
}
use of POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse in project PokeGOAPI-Java by Grover-c13.
the class PokeBank method releasePokemon.
/**
* Releases multiple pokemon in a single request
*
* @param releasePokemon the pokemon to release
* @return the amount of candies for each pokemon family
* @throws RequestFailedException if an exception occurred while sending requests
*/
public Map<PokemonFamilyId, Integer> releasePokemon(Pokemon... releasePokemon) throws RequestFailedException {
ReleasePokemonMessage.Builder releaseBuilder = ReleasePokemonMessage.newBuilder();
for (Pokemon pokemon : releasePokemon) {
if (!pokemon.isDeployed() && !pokemon.isFavorite()) {
releaseBuilder.addPokemonIds(pokemon.getId());
}
}
ServerRequest releaseRequest = new ServerRequest(RequestType.RELEASE_POKEMON, releaseBuilder.build());
ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons(releaseRequest, api);
Map<PokemonFamilyId, Integer> lastCandies = new HashMap<>(api.inventories.candyjar.getCandies());
ServerResponse response = api.requestHandler.sendServerRequests(envelope);
try {
ByteString inventoryData = response.get(RequestType.GET_HOLOHOLO_INVENTORY);
GetHoloInventoryResponse inventoryResponse = GetHoloInventoryResponse.parseFrom(inventoryData);
ReleasePokemonResponse releaseResponse = ReleasePokemonResponse.parseFrom(releaseRequest.getData());
Map<PokemonFamilyId, Integer> candyCount = new HashMap<>();
if (releaseResponse.getResult() == Result.SUCCESS && inventoryResponse.getSuccess()) {
synchronized (this.lock) {
this.pokemons.removeAll(Arrays.asList(releasePokemon));
}
for (Pokemon pokemon : releasePokemon) {
api.inventories.pokebank.removePokemon(pokemon);
}
List<InventoryItem> items = inventoryResponse.getInventoryDelta().getInventoryItemsList();
for (InventoryItem item : items) {
InventoryItemData data = item.getInventoryItemData();
if (data != null && data.hasCandy()) {
Candy candy = data.getCandy();
PokemonFamilyId family = candy.getFamilyId();
Integer lastCandy = lastCandies.get(family);
if (lastCandy == null) {
lastCandy = 0;
}
candyCount.put(family, candy.getCandy() - lastCandy);
}
}
api.inventories.updateInventories(inventoryResponse);
}
return candyCount;
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
Aggregations