Skip to content

Commit cf857fe

Browse files
committed
Merge branch 'catch_fix' of git://github.com/mjmfighter/PokeGOAPI-Java into mjmfighter-catch_fix
2 parents ba979f3 + f5f58f6 commit cf857fe

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse;
2828
import com.google.protobuf.InvalidProtocolBufferException;
2929
import com.pokegoapi.api.PokemonGo;
30+
import com.pokegoapi.api.inventory.ItemBag;
3031
import com.pokegoapi.api.inventory.Pokeball;
3132
import com.pokegoapi.exceptions.LoginFailedException;
3233
import com.pokegoapi.exceptions.RemoteServerException;
@@ -127,15 +128,20 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer
127128
* @throws RemoteServerException if the server failed to respond
128129
*/
129130
public CatchResult catchPokemon() throws LoginFailedException, RemoteServerException {
130-
Pokeball ball = Pokeball.POKEBALL;
131-
if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_POKE_BALL).getCount() == 0) {
132-
ball = Pokeball.GREATBALL;
133-
} else if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_GREAT_BALL).getCount() == 0) {
134-
ball = Pokeball.ULTRABALL;
135-
} else if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_ULTRA_BALL).getCount() == 0) {
136-
ball = Pokeball.MASTERBALL;
131+
Pokeball pokeball;
132+
133+
ItemBag bag = api.getInventories().getItemBag();
134+
if (bag.getItem(ItemIdOuterClass.ItemId.ITEM_POKE_BALL).getCount() > 0) {
135+
pokeball = Pokeball.POKEBALL;
136+
} else if (bag.getItem(ItemIdOuterClass.ItemId.ITEM_GREAT_BALL).getCount() > 0) {
137+
pokeball = Pokeball.GREATBALL;
138+
} else if (bag.getItem(ItemIdOuterClass.ItemId.ITEM_ULTRA_BALL).getCount() > 0) {
139+
pokeball = Pokeball.ULTRABALL;
140+
} else {
141+
pokeball = Pokeball.MASTERBALL;
137142
}
138-
return catchPokemon(ball);
143+
144+
return catchPokemon(pokeball);
139145
}
140146

141147

0 commit comments

Comments
 (0)