From f5f58f6e25c605b381f7928718df6d1bf2597060 Mon Sep 17 00:00:00 2001 From: "Matthew J. Mjelde" Date: Fri, 22 Jul 2016 11:42:02 -0500 Subject: [PATCH] Another fix for catching pokemon --- .../api/map/pokemon/CatchablePokemon.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 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 e47c6997..93ee3cb3 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -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; @@ -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); }