use of POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId in project PokeGOAPI-Java by Grover-c13.
the class TransferMultiplePokemon method main.
/**
* Transfers all bad pokemon from the player's inventory.
*/
public static void main(String[] args) {
OkHttpClient http = new OkHttpClient();
PokemonGo api = new PokemonGo(http);
try {
HashProvider hasher = ExampleConstants.getHashProvider();
api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
PokeBank pokebank = api.inventories.pokebank;
List<Pokemon> pokemons = pokebank.pokemons;
List<Pokemon> transferPokemons = new ArrayList<>();
// Find all pokemon of bad types or with IV less than 25%
for (Pokemon pokemon : pokemons) {
PokemonId id = pokemon.getPokemonId();
double iv = pokemon.getIvInPercentage();
if (iv < 90) {
if (id == PokemonId.RATTATA || id == PokemonId.PIDGEY || id == PokemonId.CATERPIE || id == PokemonId.WEEDLE || id == PokemonId.MAGIKARP || id == PokemonId.ZUBAT || iv < 25) {
transferPokemons.add(pokemon);
}
}
}
System.out.println("Releasing " + transferPokemons.size() + " pokemon.");
Pokemon[] transferArray = transferPokemons.toArray(new Pokemon[transferPokemons.size()]);
Map<PokemonFamilyId, Integer> responses = pokebank.releasePokemon(transferArray);
// Loop through all responses and find the total amount of candies earned for each family
Map<PokemonFamilyId, Integer> candies = new HashMap<>();
for (Map.Entry<PokemonFamilyId, Integer> entry : responses.entrySet()) {
int candyAwarded = entry.getValue();
PokemonFamilyId family = entry.getKey();
Integer candy = candies.get(family);
if (candy == null) {
// candies map does not yet contain the amount if null, so set it to 0
candy = 0;
}
// Add the awarded candies from this request
candy += candyAwarded;
candies.put(family, candy);
}
for (Map.Entry<PokemonFamilyId, Integer> entry : candies.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue() + " candies awarded");
}
} catch (RequestFailedException e) {
// failed to login, invalid credentials, auth issue or server issue.
Log.e("Main", "Failed to login. Invalid credentials, captcha or server issue: ", e);
}
}
use of POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId 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