From 8fe3285fef5abfe4516062129a6d2a7180fcbb0a Mon Sep 17 00:00:00 2001 From: Grover-c13 Date: Sat, 23 Jul 2016 17:27:44 +0800 Subject: [PATCH 1/7] Eggs --- .../com/pokegoapi/api/inventory/Hatchery.java | 22 ++++ .../pokegoapi/api/inventory/Inventories.java | 19 ++- .../com/pokegoapi/api/pokemon/EggPokemon.java | 112 ++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java diff --git a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java index 7b8990c6..22b3cd89 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java +++ b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java @@ -15,6 +15,28 @@ package com.pokegoapi.api.inventory; +import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.pokemon.EggPokemon; +import com.pokegoapi.api.pokemon.Pokemon; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + public class Hatchery { + @Getter + Set eggs = new HashSet(); + @Getter + PokemonGo instance; + + public Hatchery(PokemonGo instance) { + this.instance = instance; + } + + public void addEgg(EggPokemon egg) { + eggs.add(egg); + } } diff --git a/src/main/java/com/pokegoapi/api/inventory/Inventories.java b/src/main/java/com/pokegoapi/api/inventory/Inventories.java index b5926fd5..974d486e 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Inventories.java +++ b/src/main/java/com/pokegoapi/api/inventory/Inventories.java @@ -17,6 +17,7 @@ import POGOProtos.Enums.PokemonFamilyIdOuterClass; import POGOProtos.Enums.PokemonIdOuterClass; +import POGOProtos.Enums.PokemonIdOuterClass.PokemonId; import POGOProtos.Inventory.InventoryItemDataOuterClass; import POGOProtos.Inventory.InventoryItemOuterClass; import POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData; @@ -26,6 +27,7 @@ import POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse; import com.google.protobuf.InvalidProtocolBufferException; import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.pokemon.EggPokemon; import com.pokegoapi.api.pokemon.Pokemon; import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.exceptions.RemoteServerException; @@ -44,6 +46,8 @@ public class Inventories { private CandyJar candyjar; @Getter private Pokedex pokedex; + @Getter + private Hatchery hatchery; private long lastInventoryUpdate = 0; @@ -60,6 +64,7 @@ public Inventories(PokemonGo api) throws LoginFailedException, RemoteServerExcep pokebank = new PokeBank(api); candyjar = new CandyJar(api); pokedex = new Pokedex(api); + hatchery = new Hatchery(api); updateInventories(); } @@ -105,14 +110,24 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, : response.getInventoryDelta().getInventoryItemsList()) { InventoryItemDataOuterClass.InventoryItemData itemData = inventoryItem.getInventoryItemData(); - if (itemData.getPokemonData().getPokemonId() != PokemonIdOuterClass.PokemonId.MISSINGNO) { + // hatchery + if (itemData.getPokemonData().getPokemonId() == PokemonId.MISSINGNO && itemData.getPokemonData().getIsEgg()) { + hatchery.addEgg(new EggPokemon(itemData.getPokemonData())); + } + + // pokebank + if (itemData.getPokemonData().getPokemonId() != PokemonId.MISSINGNO) { pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); } + + // items if (itemData.getItem().getItemId() != ItemId.UNRECOGNIZED && itemData.getItem().getItemId() != ItemId.ITEM_UNKNOWN) { ItemData item = inventoryItem.getInventoryItemData().getItem(); itemBag.addItem(new Item(item)); } + + // candyjar if (itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED && itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) { candyjar.setCandy( @@ -120,10 +135,12 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, inventoryItem.getInventoryItemData().getPokemonFamily().getCandy() ); } + // player stats if (itemData.hasPlayerStats()) { api.getPlayerProfile().setStats(inventoryItem.getInventoryItemData().getPlayerStats()); } + // pokedex if (itemData.hasPokedexEntry()) { pokedex.add(itemData.getPokedexEntry()); } diff --git a/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java new file mode 100644 index 00000000..82c8e044 --- /dev/null +++ b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java @@ -0,0 +1,112 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.pokegoapi.api.pokemon; + +import POGOProtos.Data.PokemonDataOuterClass.PokemonData; +import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId; +import POGOProtos.Enums.PokemonIdOuterClass; +import POGOProtos.Enums.PokemonMoveOuterClass; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; +import POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage; +import POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage; +import POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage; +import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType; +import POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass.EvolvePokemonResponse; +import POGOProtos.Networking.Responses.NicknamePokemonResponseOuterClass.NicknamePokemonResponse; +import POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse; +import POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result; +import com.google.protobuf.InvalidProtocolBufferException; +import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.map.pokemon.EvolutionResult; +import com.pokegoapi.exceptions.LoginFailedException; +import com.pokegoapi.exceptions.RemoteServerException; +import com.pokegoapi.main.ServerRequest; +import com.pokegoapi.util.Log; +import lombok.Setter; + +/** + * The egg pokemon. + */ +public class EggPokemon { + + private static final String TAG = EggPokemon.class.getSimpleName(); + @Setter + PokemonGo pgo; + private PokemonData proto; + + // API METHODS // + + // DELEGATE METHODS BELOW // + public EggPokemon(PokemonData proto) { + this.proto = proto; + } + + public long getId() { + return proto.getId(); + } + + public boolean getIsEgg() { + return proto.getIsEgg(); + } + + public double getEggKmWalkedTarget() { + return proto.getEggKmWalkedTarget(); + } + + public double getEggKmWalkedStart() { + return proto.getEggKmWalkedStart(); + } + + public long getCapturedCellId() { + return proto.getCapturedCellId(); + } + + public long getCreationTimeMs() { + return proto.getCreationTimeMs(); + } + + + @Override + public int hashCode() { + return proto.getPokemonId().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof EggPokemon) { + EggPokemon other = (EggPokemon) obj; + return (this.getId() == other.getId()); + } + + return false; + } + // TODO: add wrapper objects for encubators and allow to be got. +} From 80627ff2bce1fc3629dfd7ef81b7b50ae40d039e Mon Sep 17 00:00:00 2001 From: Jasper Abbink Date: Sat, 23 Jul 2016 12:17:34 +0200 Subject: [PATCH 2/7] allow to hatch eggs; fully tested --- .../pokegoapi/api/inventory/EggIncubator.java | 72 +++++++++++++++++++ .../pokegoapi/api/inventory/Inventories.java | 33 +++++++-- .../com/pokegoapi/api/inventory/PokeBank.java | 2 - 3 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/pokegoapi/api/inventory/EggIncubator.java diff --git a/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java b/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java new file mode 100644 index 00000000..48f9aaad --- /dev/null +++ b/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java @@ -0,0 +1,72 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.pokegoapi.api.inventory; + +import POGOProtos.Inventory.EggIncubatorOuterClass; +import POGOProtos.Networking.Requests.Messages.UseItemEggIncubatorMessageOuterClass.UseItemEggIncubatorMessage; +import POGOProtos.Networking.Requests.RequestTypeOuterClass; +import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse; +import com.google.protobuf.InvalidProtocolBufferException; +import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.pokemon.Pokemon; +import com.pokegoapi.exceptions.LoginFailedException; +import com.pokegoapi.exceptions.RemoteServerException; +import com.pokegoapi.main.ServerRequest; +import lombok.Getter; + +public class EggIncubator { + private final EggIncubatorOuterClass.EggIncubator proto; + private final PokemonGo pgo; + @Getter + private boolean inUse = false; + + public EggIncubator(PokemonGo pgo, EggIncubatorOuterClass.EggIncubator proto) { + this.pgo = pgo; + this.proto = proto; + this.inUse = proto.getPokemonId() != 0; + } + + public int getUsesRemaining() { + return proto.getUsesRemaining(); + } + + public UseItemEggIncubatorResponse.Result hatchEgg(Pokemon pokemon) throws LoginFailedException, RemoteServerException { + if (!pokemon.getIsEgg()) { + return null; + } + UseItemEggIncubatorMessage reqMsg = UseItemEggIncubatorMessage.newBuilder() + .setItemId(proto.getId()) + .setPokemonId(pokemon.getId()) + .build(); + + ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.USE_ITEM_EGG_INCUBATOR, reqMsg); + pgo.getRequestHandler().sendServerRequests(serverRequest); + + UseItemEggIncubatorResponse response; + try { + response = UseItemEggIncubatorResponse.parseFrom(serverRequest.getData()); + } catch (InvalidProtocolBufferException e) { + throw new RemoteServerException(e); + } + + pgo.getInventories().getEggs().remove(pokemon); + pgo.getInventories().updateInventories(true); + + this.inUse = true; + + return response.getResult(); + } +} diff --git a/src/main/java/com/pokegoapi/api/inventory/Inventories.java b/src/main/java/com/pokegoapi/api/inventory/Inventories.java index b5926fd5..53c022fd 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Inventories.java +++ b/src/main/java/com/pokegoapi/api/inventory/Inventories.java @@ -17,6 +17,7 @@ import POGOProtos.Enums.PokemonFamilyIdOuterClass; import POGOProtos.Enums.PokemonIdOuterClass; +import POGOProtos.Inventory.EggIncubatorOuterClass; import POGOProtos.Inventory.InventoryItemDataOuterClass; import POGOProtos.Inventory.InventoryItemOuterClass; import POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData; @@ -32,6 +33,9 @@ import com.pokegoapi.main.ServerRequest; import lombok.Getter; +import java.util.ArrayList; +import java.util.List; + public class Inventories { @@ -44,6 +48,10 @@ public class Inventories { private CandyJar candyjar; @Getter private Pokedex pokedex; + @Getter + private List incubators; + @Getter + private List eggs; private long lastInventoryUpdate = 0; @@ -60,6 +68,8 @@ public Inventories(PokemonGo api) throws LoginFailedException, RemoteServerExcep pokebank = new PokeBank(api); candyjar = new CandyJar(api); pokedex = new Pokedex(api); + incubators = new ArrayList<>(); + eggs = new ArrayList<>(); updateInventories(); } @@ -87,6 +97,8 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, pokebank = new PokeBank(api); candyjar = new CandyJar(api); pokedex = new Pokedex(api); + incubators = new ArrayList<>(); + eggs = new ArrayList<>(); } GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder() .setLastTimestampMs(lastInventoryUpdate) @@ -98,7 +110,7 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, try { response = GetInventoryResponse.parseFrom(inventoryRequest.getData()); } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); + throw new RemoteServerException(e); } for (InventoryItemOuterClass.InventoryItem inventoryItem @@ -106,28 +118,37 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, InventoryItemDataOuterClass.InventoryItemData itemData = inventoryItem.getInventoryItemData(); if (itemData.getPokemonData().getPokemonId() != PokemonIdOuterClass.PokemonId.MISSINGNO) { - pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); + pokebank.addPokemon(new Pokemon(itemData.getPokemonData())); + } else if (itemData.getPokemonData().getIsEgg()) { + eggs.add(new Pokemon(itemData.getPokemonData())); } + if (itemData.getItem().getItemId() != ItemId.UNRECOGNIZED && itemData.getItem().getItemId() != ItemId.ITEM_UNKNOWN) { - ItemData item = inventoryItem.getInventoryItemData().getItem(); + ItemData item = itemData.getItem(); itemBag.addItem(new Item(item)); } if (itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED && itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) { candyjar.setCandy( - inventoryItem.getInventoryItemData().getPokemonFamily().getFamilyId(), - inventoryItem.getInventoryItemData().getPokemonFamily().getCandy() + itemData.getPokemonFamily().getFamilyId(), + itemData.getPokemonFamily().getCandy() ); } if (itemData.hasPlayerStats()) { - api.getPlayerProfile().setStats(inventoryItem.getInventoryItemData().getPlayerStats()); + api.getPlayerProfile().setStats(itemData.getPlayerStats()); } if (itemData.hasPokedexEntry()) { pokedex.add(itemData.getPokedexEntry()); } + if (itemData.hasEggIncubators()) { + for (EggIncubatorOuterClass.EggIncubator incubator : itemData.getEggIncubators().getEggIncubatorList()) { + incubators.add(new EggIncubator(api, incubator)); + } + } + lastInventoryUpdate = System.currentTimeMillis(); } } diff --git a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java index 4c87c08c..a0844655 100644 --- a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java +++ b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java @@ -54,8 +54,6 @@ public boolean test(Pokemon testPokemon) { } } - - /** * Gets pokemon by pokemon id. * From 8ef6562bc7bc0b89acaba916943e6fbb38b4305e Mon Sep 17 00:00:00 2001 From: Jari Date: Sat, 23 Jul 2016 15:52:16 +0200 Subject: [PATCH 3/7] Fix for issue 132 (pokemon double in list) --- src/main/java/com/pokegoapi/api/map/Map.java | 4 +- .../api/map/pokemon/CatchablePokemon.java | 164 +++++++++++------- 2 files changed, 108 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/map/Map.java b/src/main/java/com/pokegoapi/api/map/Map.java index 95318434..014bee04 100644 --- a/src/main/java/com/pokegoapi/api/map/Map.java +++ b/src/main/java/com/pokegoapi/api/map/Map.java @@ -93,7 +93,7 @@ public void clearCache() { * @return a List of CatchablePokemon at your current location */ public List getCatchablePokemon() throws LoginFailedException, RemoteServerException { - List catchablePokemons = new ArrayList<>(); + Set catchablePokemons = new HashSet<>(); MapObjects objects = getMapObjects(); for (MapPokemon mapPokemon : objects.getCatchablePokemons()) { @@ -111,7 +111,7 @@ public List getCatchablePokemon() throws LoginFailedException, } }*/ - return catchablePokemons; + return new ArrayList<>(catchablePokemons); } /** diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java index 3036984d..8d01bc30 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -62,9 +62,11 @@ public class CatchablePokemon { /** * Instantiates a new Catchable pokemon. - * - * @param api the api - * @param proto the proto + * + * @param api + * the api + * @param proto + * the proto */ public CatchablePokemon(PokemonGo api, MapPokemon proto) { this.api = api; @@ -77,12 +79,13 @@ public CatchablePokemon(PokemonGo api, MapPokemon proto) { this.longitude = proto.getLongitude(); } - /** * Instantiates a new Catchable pokemon. - * - * @param api the api - * @param proto the proto + * + * @param api + * the api + * @param proto + * the proto */ public CatchablePokemon(PokemonGo api, WildPokemon proto) { this.api = api; @@ -96,9 +99,11 @@ public CatchablePokemon(PokemonGo api, WildPokemon proto) { /** * Instantiates a new Catchable pokemon. - * - * @param api the api - * @param proto the proto + * + * @param api + * the api + * @param proto + * the proto */ public CatchablePokemon(PokemonGo api, FortData proto) { if (!proto.hasLureInfo()) { @@ -109,30 +114,35 @@ public CatchablePokemon(PokemonGo api, FortData proto) { this.spawnPointId = null; this.encounterId = proto.getLureInfo().getEncounterId(); this.pokemonId = proto.getLureInfo().getActivePokemonId(); - this.expirationTimestampMs = proto.getLureInfo().getLureExpiresTimestampMs(); + this.expirationTimestampMs = proto.getLureInfo() + .getLureExpiresTimestampMs(); this.latitude = proto.getLatitude(); this.longitude = proto.getLongitude(); } /** * Encounter pokemon encounter result. - * + * * @return the encounter result - * @throws LoginFailedException the login failed exception - * @throws RemoteServerException the remote server exception + * @throws LoginFailedException + * the login failed exception + * @throws RemoteServerException + * the remote server exception */ - public EncounterResult encounterPokemon() throws LoginFailedException, RemoteServerException { - EncounterMessageOuterClass.EncounterMessage reqMsg = EncounterMessageOuterClass.EncounterMessage.newBuilder() - .setEncounterId(getEncounterId()) + public EncounterResult encounterPokemon() throws LoginFailedException, + RemoteServerException { + EncounterMessageOuterClass.EncounterMessage reqMsg = EncounterMessageOuterClass.EncounterMessage + .newBuilder().setEncounterId(getEncounterId()) .setPlayerLatitude(api.getLatitude()) .setPlayerLongitude(api.getLongitude()) - .setSpawnPointId(getSpawnPointId()) - .build(); - ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.ENCOUNTER, reqMsg); + .setSpawnPointId(getSpawnPointId()).build(); + ServerRequest serverRequest = new ServerRequest( + RequestTypeOuterClass.RequestType.ENCOUNTER, reqMsg); api.getRequestHandler().sendServerRequests(serverRequest); EncounterResponseOuterClass.EncounterResponse response = null; try { - response = EncounterResponseOuterClass.EncounterResponse.parseFrom(serverRequest.getData()); + response = EncounterResponseOuterClass.EncounterResponse + .parseFrom(serverRequest.getData()); } catch (InvalidProtocolBufferException e) { throw new RemoteServerException(e); } @@ -141,13 +151,17 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer } /** - * Tries to catch a pokemon (will attempt to use a pokeball, if you have none will use greatball etc). - * + * Tries to catch a pokemon (will attempt to use a pokeball, if you have + * none will use greatball etc). + * * @return CatchResult - * @throws LoginFailedException if failed to login - * @throws RemoteServerException if the server failed to respond + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond */ - public CatchResult catchPokemon() throws LoginFailedException, RemoteServerException { + public CatchResult catchPokemon() throws LoginFailedException, + RemoteServerException { Pokeball pokeball; ItemBag bag = api.getInventories().getItemBag(); @@ -164,47 +178,64 @@ public CatchResult catchPokemon() throws LoginFailedException, RemoteServerExcep return catchPokemon(pokeball); } - /** * Tries to catch a pokeball with the given type. - * - * @param pokeball Type of pokeball + * + * @param pokeball + * Type of pokeball * @return CatchResult - * @throws LoginFailedException if failed to login - * @throws RemoteServerException if the server failed to respond + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond */ - public CatchResult catchPokemon(Pokeball pokeball) throws LoginFailedException, RemoteServerException { + public CatchResult catchPokemon(Pokeball pokeball) + throws LoginFailedException, RemoteServerException { return catchPokemon(pokeball, -1); } /** * Tried to catch a pokemon with given pokeball and max number of pokeballs. - * - * @param pokeball Type of pokeball - * @param amount Max number of pokeballs to use + * + * @param pokeball + * Type of pokeball + * @param amount + * Max number of pokeballs to use * @return CatchResult - * @throws LoginFailedException if failed to login - * @throws RemoteServerException if the server failed to respond + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond */ - public CatchResult catchPokemon(Pokeball pokeball, int amount) throws LoginFailedException, RemoteServerException { - return catchPokemon(1.0, 1.95 + Math.random() * 0.05, 0.85 + Math.random() * 0.15, pokeball, amount); + public CatchResult catchPokemon(Pokeball pokeball, int amount) + throws LoginFailedException, RemoteServerException { + return catchPokemon(1.0, 1.95 + Math.random() * 0.05, + 0.85 + Math.random() * 0.15, pokeball, amount); } /** * Tries to catch a pokemon. - * - * @param normalizedHitPosition the normalized hit position - * @param normalizedReticleSize the normalized hit reticle - * @param spinModifier the spin modifier - * @param type Type of pokeball to throw - * @param amount Max number of Pokeballs to throw, negative number for unlimited + * + * @param normalizedHitPosition + * the normalized hit position + * @param normalizedReticleSize + * the normalized hit reticle + * @param spinModifier + * the spin modifier + * @param type + * Type of pokeball to throw + * @param amount + * Max number of Pokeballs to throw, negative number for + * unlimited * @return CatchResult of resulted try to catch pokemon - * @throws LoginFailedException if failed to login - * @throws RemoteServerException if the server failed to respond + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond */ - public CatchResult catchPokemon( - double normalizedHitPosition, double normalizedReticleSize, double spinModifier, Pokeball type, int amount) - throws LoginFailedException, RemoteServerException { + public CatchResult catchPokemon(double normalizedHitPosition, + double normalizedReticleSize, double spinModifier, Pokeball type, + int amount) throws LoginFailedException, RemoteServerException { if (!isEncountered()) { return new CatchResult(); } @@ -213,19 +244,19 @@ public CatchResult catchPokemon( CatchPokemonResponse response = null; do { CatchPokemonMessage reqMsg = CatchPokemonMessage.newBuilder() - .setEncounterId(getEncounterId()) - .setHitPokemon(true) + .setEncounterId(getEncounterId()).setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) .setNormalizedReticleSize(normalizedReticleSize) .setSpawnPointGuid(getSpawnPointId()) .setSpinModifier(spinModifier) - .setPokeball(type.getBallType()) - .build(); - ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.CATCH_POKEMON, reqMsg); + .setPokeball(type.getBallType()).build(); + ServerRequest serverRequest = new ServerRequest( + RequestTypeOuterClass.RequestType.CATCH_POKEMON, reqMsg); api.getRequestHandler().sendServerRequests(serverRequest); try { - response = CatchPokemonResponse.parseFrom(serverRequest.getData()); + response = CatchPokemonResponse.parseFrom(serverRequest + .getData()); } catch (InvalidProtocolBufferException e) { throw new RemoteServerException(e); } @@ -235,12 +266,29 @@ public CatchResult catchPokemon( break; } numThrows++; - } - while (amount < 0 || numThrows < amount); + } while (amount < 0 || numThrows < amount); api.getInventories().updateInventories(); return new CatchResult(response); } + @Override + public boolean equals(Object o) { + if (!(o instanceof CatchablePokemon)) { + return false; + } + if (o == this) { + return true; + } else { + return this.getEncounterId() == ((CatchablePokemon) o) + .getEncounterId(); + } + } + + @Override + public int hashCode() { + return (int) this.getEncounterId(); + } + } From cbea83f16b45c683b4491ed04bc677126ad5fe89 Mon Sep 17 00:00:00 2001 From: Jari Date: Sat, 23 Jul 2016 15:59:35 +0200 Subject: [PATCH 4/7] Forgot imports, improvement in compareTo --- src/main/java/com/pokegoapi/api/map/Map.java | 6 +++++- .../com/pokegoapi/api/map/pokemon/CatchablePokemon.java | 8 +++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/map/Map.java b/src/main/java/com/pokegoapi/api/map/Map.java index 014bee04..18515dd7 100644 --- a/src/main/java/com/pokegoapi/api/map/Map.java +++ b/src/main/java/com/pokegoapi/api/map/Map.java @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -package com.pokegoapi.api.map; +package nl.sadye.bot; import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; import POGOProtos.Map.Fort.FortDataOuterClass.FortData; @@ -35,6 +35,7 @@ import POGOProtos.Networking.Responses.FortDetailsResponseOuterClass; import POGOProtos.Networking.Responses.FortSearchResponseOuterClass.FortSearchResponse; import POGOProtos.Networking.Responses.GetMapObjectsResponseOuterClass; + import com.annimon.stream.Collectors; import com.annimon.stream.Stream; import com.annimon.stream.function.Function; @@ -49,11 +50,14 @@ import com.pokegoapi.google.common.geometry.S2CellId; import com.pokegoapi.google.common.geometry.S2LatLng; import com.pokegoapi.main.ServerRequest; + import lombok.Getter; import lombok.Setter; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class Map { diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java index 8d01bc30..fcb64039 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -package com.pokegoapi.api.map.pokemon; +package nl.sadye.bot; import POGOProtos.Enums.PokemonIdOuterClass; import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; @@ -275,15 +275,13 @@ public CatchResult catchPokemon(double normalizedHitPosition, @Override public boolean equals(Object o) { - if (!(o instanceof CatchablePokemon)) { - return false; - } if (o == this) { return true; - } else { + } else if (o instanceof CatchablePokemon){ return this.getEncounterId() == ((CatchablePokemon) o) .getEncounterId(); } + return false; } @Override From 1e7e692a8723ee38b855e52757f9a05aaeaaa753 Mon Sep 17 00:00:00 2001 From: Jari Date: Sat, 23 Jul 2016 16:01:21 +0200 Subject: [PATCH 5/7] Fix packages --- src/main/java/com/pokegoapi/api/map/Map.java | 2 +- .../java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/map/Map.java b/src/main/java/com/pokegoapi/api/map/Map.java index 18515dd7..44aed570 100644 --- a/src/main/java/com/pokegoapi/api/map/Map.java +++ b/src/main/java/com/pokegoapi/api/map/Map.java @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -package nl.sadye.bot; +package com.pokegoapi.api.map; import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; import POGOProtos.Map.Fort.FortDataOuterClass.FortData; diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java index fcb64039..62eaa25d 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -package nl.sadye.bot; +package com.pokegoapi.api.map.pokemon; import POGOProtos.Enums.PokemonIdOuterClass; import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; From 478435ca8ab11d6c8c0e1c47c6f542794b86d307 Mon Sep 17 00:00:00 2001 From: Jari Date: Sat, 23 Jul 2016 16:03:53 +0200 Subject: [PATCH 6/7] Fix indentation --- .../java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java index 62eaa25d..16205d83 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -277,7 +277,7 @@ public CatchResult catchPokemon(double normalizedHitPosition, public boolean equals(Object o) { if (o == this) { return true; - } else if (o instanceof CatchablePokemon){ + } else if (o instanceof CatchablePokemon) { return this.getEncounterId() == ((CatchablePokemon) o) .getEncounterId(); } From 4e9042fa0812309ad3b242808a0a5933f3c70673 Mon Sep 17 00:00:00 2001 From: Jari Date: Sat, 23 Jul 2016 16:12:47 +0200 Subject: [PATCH 7/7] No single letter variables --- .../com/pokegoapi/api/map/pokemon/CatchablePokemon.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java index 16205d83..ad144cca 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -274,11 +274,11 @@ public CatchResult catchPokemon(double normalizedHitPosition, } @Override - public boolean equals(Object o) { - if (o == this) { + public boolean equals(Object obj) { + if (obj == this) { return true; - } else if (o instanceof CatchablePokemon) { - return this.getEncounterId() == ((CatchablePokemon) o) + } else if (obj instanceof CatchablePokemon) { + return this.getEncounterId() == ((CatchablePokemon) obj) .getEncounterId(); } return false;