|
27 | 27 | import POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse; |
28 | 28 | import com.google.protobuf.InvalidProtocolBufferException; |
29 | 29 | import com.pokegoapi.api.PokemonGo; |
| 30 | +import com.pokegoapi.api.inventory.ItemBag; |
30 | 31 | import com.pokegoapi.api.inventory.Pokeball; |
31 | 32 | import com.pokegoapi.exceptions.LoginFailedException; |
32 | 33 | import com.pokegoapi.exceptions.RemoteServerException; |
@@ -127,15 +128,20 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer |
127 | 128 | * @throws RemoteServerException if the server failed to respond |
128 | 129 | */ |
129 | 130 | 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; |
137 | 142 | } |
138 | | - return catchPokemon(ball); |
| 143 | + |
| 144 | + return catchPokemon(pokeball); |
139 | 145 | } |
140 | 146 |
|
141 | 147 |
|
|
0 commit comments