22
22
import POGOProtos .Map .Pokemon .WildPokemonOuterClass .WildPokemon ;
23
23
import POGOProtos .Networking .Requests .Messages .CatchPokemonMessageOuterClass .CatchPokemonMessage ;
24
24
import POGOProtos .Networking .Requests .Messages .EncounterMessageOuterClass ;
25
+ import POGOProtos .Networking .Requests .Messages .UseItemCaptureMessageOuterClass ;
26
+ import POGOProtos .Networking .Requests .Messages .UseItemCaptureMessageOuterClass .UseItemCaptureMessage ;
25
27
import POGOProtos .Networking .Requests .RequestTypeOuterClass ;
26
28
import POGOProtos .Networking .Responses .CatchPokemonResponseOuterClass .CatchPokemonResponse ;
27
29
import POGOProtos .Networking .Responses .EncounterResponseOuterClass ;
28
30
import POGOProtos .Networking .Responses .EncounterResponseOuterClass .EncounterResponse ;
31
+ import POGOProtos .Networking .Responses .UseItemCaptureResponseOuterClass ;
32
+ import POGOProtos .Networking .Responses .UseItemCaptureResponseOuterClass .UseItemCaptureResponse ;
29
33
import com .google .protobuf .InvalidProtocolBufferException ;
30
34
import com .pokegoapi .api .PokemonGo ;
31
35
import com .pokegoapi .api .inventory .ItemBag ;
@@ -150,6 +154,36 @@ public EncounterResult encounterPokemon() throws LoginFailedException,
150
154
return new EncounterResult (response );
151
155
}
152
156
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
+
153
187
/**
154
188
* Tries to catch a pokemon (will attempt to use a pokeball, if you have
155
189
* none will use greatball etc).
@@ -178,6 +212,8 @@ public CatchResult catchPokemon() throws LoginFailedException,
178
212
return catchPokemon (pokeball );
179
213
}
180
214
215
+
216
+
181
217
/**
182
218
* Tries to catch a pokeball with the given type.
183
219
*
@@ -213,6 +249,54 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount)
213
249
0.85 + Math .random () * 0.15 , pokeball , amount );
214
250
}
215
251
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
+
216
300
/**
217
301
* Tries to catch a pokemon.
218
302
*
@@ -227,6 +311,8 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount)
227
311
* @param amount
228
312
* Max number of Pokeballs to throw, negative number for
229
313
* unlimited
314
+ * @param razberriesLimit
315
+ * The maximum amount of razberries to use, -1 for unlimited
230
316
* @return CatchResult of resulted try to catch pokemon
231
317
* @throws LoginFailedException
232
318
* if failed to login
@@ -235,14 +321,21 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount)
235
321
*/
236
322
public CatchResult catchPokemon (double normalizedHitPosition ,
237
323
double normalizedReticleSize , double spinModifier , Pokeball type ,
238
- int amount ) throws LoginFailedException , RemoteServerException {
324
+ int amount , int razberriesLimit ) throws LoginFailedException , RemoteServerException {
239
325
if (!isEncountered ()) {
240
326
return new CatchResult ();
241
327
}
242
328
329
+ int razberries = 0 ;
243
330
int numThrows = 0 ;
244
331
CatchPokemonResponse response = null ;
245
332
do {
333
+
334
+ if (razberries < razberriesLimit || razberriesLimit == -1 ) {
335
+ useItem (ItemId .ITEM_RAZZ_BERRY );
336
+ razberries ++;
337
+ }
338
+
246
339
CatchPokemonMessage reqMsg = CatchPokemonMessage .newBuilder ()
247
340
.setEncounterId (getEncounterId ()).setHitPokemon (true )
248
341
.setNormalizedHitPosition (normalizedHitPosition )
@@ -274,6 +367,38 @@ public CatchResult catchPokemon(double normalizedHitPosition,
274
367
return new CatchResult (response );
275
368
}
276
369
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
+
277
402
@ Override
278
403
public boolean equals (Object obj ) {
279
404
if (obj == this ) {
0 commit comments