Skip to content

Commit 09e66f6

Browse files
authored
Merge pull request #112 from Grover-c13/PokemonCatch
made catchPokemon() use the next tier pokeball if out of the tier below (ie 0 pokeballs = use greatball, 0 greatballs use ultraball)
2 parents 9bcc995 + 855ad07 commit 09e66f6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.pokegoapi.api.map.pokemon;
1717

1818
import POGOProtos.Enums.PokemonIdOuterClass;
19+
import POGOProtos.Inventory.ItemIdOuterClass;
1920
import POGOProtos.Map.Pokemon.MapPokemonOuterClass.MapPokemon;
2021
import POGOProtos.Map.Pokemon.WildPokemonOuterClass.WildPokemon;
2122
import POGOProtos.Networking.Requests.Messages.CatchPokemonMessageOuterClass.CatchPokemonMessage;
@@ -120,14 +121,18 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer
120121
}
121122

122123
/**
123-
* Tries to catch a pokemon with a pokeball.
124+
* Tries to catch a pokemon (will attempt to use a pokeball, if you have none will use greatball etc)
124125
*
125126
* @return CatchResult
126127
* @throws LoginFailedException if failed to login
127128
* @throws RemoteServerException if the server failed to respond
128129
*/
129130
public CatchResult catchPokemon() throws LoginFailedException, RemoteServerException {
130-
return catchPokemon(Pokeball.POKEBALL);
131+
Pokeball ball = Pokeball.POKEBALL;
132+
if (api.getBag().getItem(ItemIdOuterClass.ItemId.ITEM_POKE_BALL).getCount() == 0) ball = Pokeball.GREATBALL;
133+
if (api.getBag().getItem(ItemIdOuterClass.ItemId.ITEM_GREAT_BALL).getCount() == 0) ball = Pokeball.ULTRABALL;
134+
if (api.getBag().getItem(ItemIdOuterClass.ItemId.ITEM_ULTRA_BALL).getCount() == 0) ball = Pokeball.MASTERBALL;
135+
return catchPokemon(ball);
131136
}
132137

133138

0 commit comments

Comments
 (0)