2222import POGOProtos .Map .Pokemon .WildPokemonOuterClass .WildPokemon ;
2323import POGOProtos .Networking .Requests .Messages .CatchPokemonMessageOuterClass .CatchPokemonMessage ;
2424import POGOProtos .Networking .Requests .Messages .EncounterMessageOuterClass ;
25+ import POGOProtos .Networking .Requests .Messages .UseItemCaptureMessageOuterClass ;
26+ import POGOProtos .Networking .Requests .Messages .UseItemCaptureMessageOuterClass .UseItemCaptureMessage ;
2527import POGOProtos .Networking .Requests .RequestTypeOuterClass ;
2628import POGOProtos .Networking .Responses .CatchPokemonResponseOuterClass .CatchPokemonResponse ;
2729import POGOProtos .Networking .Responses .EncounterResponseOuterClass ;
2830import POGOProtos .Networking .Responses .EncounterResponseOuterClass .EncounterResponse ;
31+ import POGOProtos .Networking .Responses .UseItemCaptureResponseOuterClass ;
32+ import POGOProtos .Networking .Responses .UseItemCaptureResponseOuterClass .UseItemCaptureResponse ;
2933import com .google .protobuf .InvalidProtocolBufferException ;
3034import com .pokegoapi .api .PokemonGo ;
3135import com .pokegoapi .api .inventory .ItemBag ;
@@ -150,6 +154,36 @@ public EncounterResult encounterPokemon() throws LoginFailedException,
150154 return new EncounterResult (response );
151155 }
152156
157+ /**
158+ * Tries to catch a pokemon (will attempt to use a pokeball, if you have
159+ * none will use greatball etc) and uwill use a single razz berry if available.
160+ *
161+ * @return CatchResult
162+ * @throws LoginFailedException
163+ * if failed to login
164+ * @throws RemoteServerException
165+ * if the server failed to respond
166+ */
167+ public CatchResult catchPokemonWithRazzBerry () throws LoginFailedException ,
168+ RemoteServerException {
169+ Pokeball pokeball ;
170+
171+ ItemBag bag = api .getInventories ().getItemBag ();
172+ if (bag .getItem (ItemId .ITEM_POKE_BALL ).getCount () > 0 ) {
173+ pokeball = Pokeball .POKEBALL ;
174+ } else if (bag .getItem (ItemId .ITEM_GREAT_BALL ).getCount () > 0 ) {
175+ pokeball = Pokeball .GREATBALL ;
176+ } else if (bag .getItem (ItemId .ITEM_ULTRA_BALL ).getCount () > 0 ) {
177+ pokeball = Pokeball .ULTRABALL ;
178+ } else {
179+ pokeball = Pokeball .MASTERBALL ;
180+ }
181+
182+ useItem (ItemId .ITEM_RAZZ_BERRY );
183+ return catchPokemon (pokeball , -1 , -1 );
184+ }
185+
186+
153187 /**
154188 * Tries to catch a pokemon (will attempt to use a pokeball, if you have
155189 * none will use greatball etc).
@@ -178,6 +212,8 @@ public CatchResult catchPokemon() throws LoginFailedException,
178212 return catchPokemon (pokeball );
179213 }
180214
215+
216+
181217 /**
182218 * Tries to catch a pokeball with the given type.
183219 *
@@ -213,6 +249,54 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount)
213249 0.85 + Math .random () * 0.15 , pokeball , amount );
214250 }
215251
252+ /**
253+ * Tried to catch a pokemon with given pokeball and max number of pokeballs.
254+ *
255+ * @param pokeball
256+ * Type of pokeball
257+ * @param amount
258+ * Max number of pokeballs to use
259+ * @param razberryLimit
260+ * Max number of razberrys to use
261+ * @return CatchResult
262+ * @throws LoginFailedException
263+ * if failed to login
264+ * @throws RemoteServerException
265+ * if the server failed to respond
266+ */
267+ public CatchResult catchPokemon (Pokeball pokeball , int amount , int razberryLimit )
268+ throws LoginFailedException , RemoteServerException {
269+ return catchPokemon (1.0 , 1.95 + Math .random () * 0.05 ,
270+ 0.85 + Math .random () * 0.15 , pokeball , razberryLimit );
271+ }
272+
273+ /**
274+ * Tries to catch a pokemon.
275+ *
276+ * @param normalizedHitPosition
277+ * the normalized hit position
278+ * @param normalizedReticleSize
279+ * the normalized hit reticle
280+ * @param spinModifier
281+ * the spin modifier
282+ * @param type
283+ * Type of pokeball to throw
284+ * @param amount
285+ * Max number of Pokeballs to throw, negative number for
286+ * unlimited
287+ * @return CatchResult of resulted try to catch pokemon
288+ * @throws LoginFailedException
289+ * if failed to login
290+ * @throws RemoteServerException
291+ * if the server failed to respond
292+ */
293+ public CatchResult catchPokemon (double normalizedHitPosition ,
294+ double normalizedReticleSize , double spinModifier , Pokeball type ,
295+ int amount ) throws LoginFailedException , RemoteServerException {
296+
297+ return catchPokemon (normalizedHitPosition , normalizedReticleSize , spinModifier , type , amount , -1 );
298+ }
299+
216300 /**
217301 * Tries to catch a pokemon.
218302 *
@@ -227,6 +311,8 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount)
227311 * @param amount
228312 * Max number of Pokeballs to throw, negative number for
229313 * unlimited
314+ * @param razberriesLimit
315+ * The maximum amount of razberries to use, -1 for unlimited
230316 * @return CatchResult of resulted try to catch pokemon
231317 * @throws LoginFailedException
232318 * if failed to login
@@ -235,14 +321,21 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount)
235321 */
236322 public CatchResult catchPokemon (double normalizedHitPosition ,
237323 double normalizedReticleSize , double spinModifier , Pokeball type ,
238- int amount ) throws LoginFailedException , RemoteServerException {
324+ int amount , int razberriesLimit ) throws LoginFailedException , RemoteServerException {
239325 if (!isEncountered ()) {
240326 return new CatchResult ();
241327 }
242328
329+ int razberries = 0 ;
243330 int numThrows = 0 ;
244331 CatchPokemonResponse response = null ;
245332 do {
333+
334+ if (razberries < razberriesLimit || razberriesLimit == -1 ) {
335+ useItem (ItemId .ITEM_RAZZ_BERRY );
336+ razberries ++;
337+ }
338+
246339 CatchPokemonMessage reqMsg = CatchPokemonMessage .newBuilder ()
247340 .setEncounterId (getEncounterId ()).setHitPokemon (true )
248341 .setNormalizedHitPosition (normalizedHitPosition )
@@ -274,6 +367,38 @@ public CatchResult catchPokemon(double normalizedHitPosition,
274367 return new CatchResult (response );
275368 }
276369
370+ /**
371+ * Tries to use an item on a catchable pokemon (ie razzberry).
372+ *
373+ * @param item
374+ * the item ID
375+ * @return CatchItemResult info about the new modifiers about the pokemon (can move, item capture multi) eg
376+ * @throws LoginFailedException
377+ * if failed to login
378+ * @throws RemoteServerException
379+ * if the server failed to respond
380+ */
381+ public CatchItemResult useItem (ItemId item ) throws LoginFailedException , RemoteServerException {
382+
383+ UseItemCaptureMessage reqMsg = UseItemCaptureMessage
384+ .newBuilder ()
385+ .setEncounterId (this .getEncounterId ())
386+ .setSpawnPointGuid (this .getSpawnPointId ())
387+ .setItemId (item )
388+ .build ();
389+
390+ ServerRequest serverRequest = new ServerRequest (
391+ RequestTypeOuterClass .RequestType .USE_ITEM_CAPTURE , reqMsg );
392+ api .getRequestHandler ().sendServerRequests (serverRequest );
393+ UseItemCaptureResponse response = null ;
394+ try {
395+ response = UseItemCaptureResponse .parseFrom (serverRequest .getData ());
396+ } catch (InvalidProtocolBufferException e ) {
397+ throw new RemoteServerException (e );
398+ }
399+ return new CatchItemResult (response );
400+ }
401+
277402 @ Override
278403 public boolean equals (Object obj ) {
279404 if (obj == this ) {
0 commit comments