Skip to content

Commit

Permalink
Merge branch 'catch_fix' of git://github.com/mjmfighter/PokeGOAPI-Jav…
Browse files Browse the repository at this point in the history
…a into mjmfighter-catch_fix
  • Loading branch information
jabbink committed Jul 22, 2016
2 parents ba979f3 + f5f58f6 commit cf857fe
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse;
import com.google.protobuf.InvalidProtocolBufferException;
import com.pokegoapi.api.PokemonGo;
import com.pokegoapi.api.inventory.ItemBag;
import com.pokegoapi.api.inventory.Pokeball;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;
Expand Down Expand Up @@ -127,15 +128,20 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer
* @throws RemoteServerException if the server failed to respond
*/
public CatchResult catchPokemon() throws LoginFailedException, RemoteServerException {
Pokeball ball = Pokeball.POKEBALL;
if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_POKE_BALL).getCount() == 0) {
ball = Pokeball.GREATBALL;
} else if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_GREAT_BALL).getCount() == 0) {
ball = Pokeball.ULTRABALL;
} else if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_ULTRA_BALL).getCount() == 0) {
ball = Pokeball.MASTERBALL;
Pokeball pokeball;

ItemBag bag = api.getInventories().getItemBag();
if (bag.getItem(ItemIdOuterClass.ItemId.ITEM_POKE_BALL).getCount() > 0) {
pokeball = Pokeball.POKEBALL;
} else if (bag.getItem(ItemIdOuterClass.ItemId.ITEM_GREAT_BALL).getCount() > 0) {
pokeball = Pokeball.GREATBALL;
} else if (bag.getItem(ItemIdOuterClass.ItemId.ITEM_ULTRA_BALL).getCount() > 0) {
pokeball = Pokeball.ULTRABALL;
} else {
pokeball = Pokeball.MASTERBALL;
}
return catchPokemon(ball);

return catchPokemon(pokeball);
}


Expand Down

0 comments on commit cf857fe

Please sign in to comment.