From d3c87dd627c60f6b01058e33cc70d7f93b8a33d5 Mon Sep 17 00:00:00 2001 From: mjmfighter Date: Fri, 22 Jul 2016 21:21:10 -0500 Subject: [PATCH 01/15] null pointer fix --- src/main/java/com/pokegoapi/api/inventory/Inventories.java | 2 +- src/main/java/com/pokegoapi/api/pokemon/Pokemon.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/inventory/Inventories.java b/src/main/java/com/pokegoapi/api/inventory/Inventories.java index b5926fd5..75792b7a 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Inventories.java +++ b/src/main/java/com/pokegoapi/api/inventory/Inventories.java @@ -106,7 +106,7 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, InventoryItemDataOuterClass.InventoryItemData itemData = inventoryItem.getInventoryItemData(); if (itemData.getPokemonData().getPokemonId() != PokemonIdOuterClass.PokemonId.MISSINGNO) { - pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); + pokebank.addPokemon(new Pokemon(api, inventoryItem.getInventoryItemData().getPokemonData())); } if (itemData.getItem().getItemId() != ItemId.UNRECOGNIZED && itemData.getItem().getItemId() != ItemId.ITEM_UNKNOWN) { diff --git a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java index b9591eef..fcc4f457 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java @@ -44,14 +44,14 @@ public class Pokemon { private static final String TAG = Pokemon.class.getSimpleName(); - @Setter - PokemonGo pgo; + private final PokemonGo pgo; private PokemonData proto; // API METHODS // // DELEGATE METHODS BELOW // - public Pokemon(PokemonData proto) { + public Pokemon(PokemonGo api, PokemonData proto) { + this.pgo = api; this.proto = proto; } From 4de377b41ef19d48c91c865e7f2cff553caea5ae Mon Sep 17 00:00:00 2001 From: mjmfighter Date: Fri, 22 Jul 2016 21:29:13 -0500 Subject: [PATCH 02/15] Adjusted some other functions --- src/main/java/com/pokegoapi/api/inventory/PokeBank.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java index 4c87c08c..ef83cd02 100644 --- a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java +++ b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java @@ -42,7 +42,6 @@ public PokeBank(PokemonGo instance) { * @param pokemon Pokemon to add to the inventory */ public void addPokemon(final Pokemon pokemon) { - pokemon.setPgo(instance); List alreadyAdded = StreamSupport.stream(pokemons).filter(new Predicate() { @Override public boolean test(Pokemon testPokemon) { From 1929a14f3d2ae12ff4420840dc3bfb71486e902f Mon Sep 17 00:00:00 2001 From: mjmfighter Date: Fri, 22 Jul 2016 21:31:22 -0500 Subject: [PATCH 03/15] Didn't commit all the files... --- .../java/com/pokegoapi/api/map/pokemon/EvolutionResult.java | 5 +++-- src/main/java/com/pokegoapi/api/pokemon/Pokemon.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java b/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java index a8863267..a27bc2a8 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java @@ -16,6 +16,7 @@ package com.pokegoapi.api.map.pokemon; import POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass; +import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.pokemon.Pokemon; public class EvolutionResult { @@ -23,9 +24,9 @@ public class EvolutionResult { private EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto; private Pokemon pokemon; - public EvolutionResult(EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) { + public EvolutionResult(PokemonGo api, EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) { this.proto = proto; - this.pokemon = new Pokemon(proto.getEvolvedPokemonData()); + this.pokemon = new Pokemon(api, proto.getEvolvedPokemonData()); } public EvolvePokemonResponseOuterClass.EvolvePokemonResponse.Result getResult() { diff --git a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java index fcc4f457..b9d4c0d4 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java @@ -137,7 +137,7 @@ public EvolutionResult evolve() throws LoginFailedException, RemoteServerExcepti return null; } - EvolutionResult result = new EvolutionResult(response); + EvolutionResult result = new EvolutionResult(pgo, response); pgo.getInventories().getPokebank().removePokemon(this); From 5f32f7a18a5f3cd4e607f6544b9833f41de6507d Mon Sep 17 00:00:00 2001 From: fabianterhorst Date: Sat, 23 Jul 2016 16:56:29 +0200 Subject: [PATCH 04/15] replace gson with moshi to improve performance and reduce library size, because moshi is depending on okio as well as okhttp --- build.gradle | 2 +- src/main/java/com/pokegoapi/auth/GoogleAuthJson.java | 12 ++++++------ .../java/com/pokegoapi/auth/GoogleAuthTokenJson.java | 12 ++++++------ src/main/java/com/pokegoapi/auth/GoogleLogin.java | 11 +++++------ src/main/java/com/pokegoapi/auth/PtcLogin.java | 9 ++++----- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 6e3b3e15..e34006ef 100644 --- a/build.gradle +++ b/build.gradle @@ -94,7 +94,7 @@ checkstyleMain.doLast { } dependencies { - compile 'com.google.code.gson:gson:2.7' + compile 'com.squareup.moshi:moshi:1.2.0' compile 'com.annimon:stream:1.1.1' compile 'com.squareup.okhttp3:okhttp:3.4.0-RC1' compile 'com.google.protobuf:protobuf-java:3.0.0-beta-3' diff --git a/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java b/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java index 9d6427f7..be71193b 100644 --- a/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java +++ b/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java @@ -15,18 +15,18 @@ package com.pokegoapi.auth; -import com.google.gson.annotations.SerializedName; +import com.squareup.moshi.Json; public class GoogleAuthJson { - @SerializedName("device_code") + @Json(name = "device_code") String deviceCode; - @SerializedName("user_code") + @Json(name = "user_code") String userCode; - @SerializedName("verification_url") + @Json(name = "verification_url") String verificationUrl; - @SerializedName("expires_in") + @Json(name = "expires_in") int expiresIn; - @SerializedName("interval") + @Json(name = "interval") int interval; public String getDeviceCode() { diff --git a/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java b/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java index eba7fbea..4d0b58e7 100644 --- a/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java +++ b/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java @@ -15,19 +15,19 @@ package com.pokegoapi.auth; -import com.google.gson.annotations.SerializedName; +import com.squareup.moshi.Json; public class GoogleAuthTokenJson { private String error; - @SerializedName("access_token") + @Json(name = "access_token") private String accessToken; - @SerializedName("token_type") + @Json(name = "token_type") private String tokenType; - @SerializedName("expires_in") + @Json(name = "expires_in") private int expiresIn; - @SerializedName("refresh_token") + @Json(name = "refresh_token") private String refreshToken; - @SerializedName("id_token") + @Json(name = "id_token") private String idToken; public String getError() { diff --git a/src/main/java/com/pokegoapi/auth/GoogleLogin.java b/src/main/java/com/pokegoapi/auth/GoogleLogin.java index 9924bb3a..ad80f8c5 100644 --- a/src/main/java/com/pokegoapi/auth/GoogleLogin.java +++ b/src/main/java/com/pokegoapi/auth/GoogleLogin.java @@ -16,10 +16,9 @@ package com.pokegoapi.auth; import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.util.Log; +import com.squareup.moshi.Moshi; import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -80,9 +79,9 @@ public AuthInfo login(String username, String password) throws LoginFailedExcept Response response = client.newCall(request).execute(); - Gson gson = new GsonBuilder().create(); + Moshi moshi = new Moshi.Builder().build(); - GoogleAuthJson googleAuth = gson.fromJson(response.body().string(), GoogleAuthJson.class); + GoogleAuthJson googleAuth = moshi.adapter(GoogleAuthJson.class).fromJson(response.body().string()); Log.d(TAG, "Get user to go to:" + googleAuth.getVerificationUrl() + " and enter code:" + googleAuth.getUserCode()); @@ -125,8 +124,8 @@ private GoogleAuthTokenJson poll(GoogleAuthJson json) throws URISyntaxException, Response response = client.newCall(request).execute(); - Gson gson = new GsonBuilder().create(); - GoogleAuthTokenJson token = gson.fromJson(response.body().string(), GoogleAuthTokenJson.class); + Moshi moshi = new Moshi.Builder().build(); + GoogleAuthTokenJson token = moshi.adapter(GoogleAuthTokenJson.class).fromJson(response.body().string()); if (token.getError() == null) { return token; diff --git a/src/main/java/com/pokegoapi/auth/PtcLogin.java b/src/main/java/com/pokegoapi/auth/PtcLogin.java index db5fbae9..fe124245 100644 --- a/src/main/java/com/pokegoapi/auth/PtcLogin.java +++ b/src/main/java/com/pokegoapi/auth/PtcLogin.java @@ -16,9 +16,8 @@ package com.pokegoapi.auth; import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.pokegoapi.exceptions.LoginFailedException; +import com.squareup.moshi.Moshi; import lombok.Getter; import okhttp3.Cookie; import okhttp3.CookieJar; @@ -122,9 +121,9 @@ public AuthInfo login(String username, String password) throws LoginFailedExcept Response getResponse = client.newCall(get).execute(); - Gson gson = new GsonBuilder().create(); + Moshi moshi = new Moshi.Builder().build(); - PtcAuthJson ptcAuth = gson.fromJson(getResponse.body().string(), PtcAuthJson.class); + PtcAuthJson ptcAuth = moshi.adapter(PtcAuthJson.class).fromJson(getResponse.body().string()); HttpUrl url = HttpUrl.parse(LOGIN_URL).newBuilder() .addQueryParameter("lt", ptcAuth.getLt()) @@ -152,7 +151,7 @@ public AuthInfo login(String username, String password) throws LoginFailedExcept String body = response.body().string(); if (body.length() > 0) { - PtcError ptcError = gson.fromJson(body, PtcError.class); + PtcError ptcError = moshi.adapter(PtcError.class).fromJson(body); if (ptcError.getError() != null && ptcError.getError().length() > 0) { throw new LoginFailedException(); } From 7579c3cc54d103302f6c74c77a85db30e9b48025 Mon Sep 17 00:00:00 2001 From: fabianterhorst Date: Sat, 23 Jul 2016 17:06:58 +0200 Subject: [PATCH 05/15] add okio dependence to keep it up to date --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index e34006ef..4306a6c5 100644 --- a/build.gradle +++ b/build.gradle @@ -94,6 +94,7 @@ checkstyleMain.doLast { } dependencies { + compile 'com.squareup.okio:okio:1.9.0' compile 'com.squareup.moshi:moshi:1.2.0' compile 'com.annimon:stream:1.1.1' compile 'com.squareup.okhttp3:okhttp:3.4.0-RC1' From 85adb75254798e4ff2598e30e86dc39aaa3045b2 Mon Sep 17 00:00:00 2001 From: Grover-c13 Date: Sat, 23 Jul 2016 23:07:03 +0800 Subject: [PATCH 06/15] Add getItems() to ItemBag --- src/main/java/com/pokegoapi/api/inventory/ItemBag.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/pokegoapi/api/inventory/ItemBag.java b/src/main/java/com/pokegoapi/api/inventory/ItemBag.java index f2dad7dc..e36e3a25 100644 --- a/src/main/java/com/pokegoapi/api/inventory/ItemBag.java +++ b/src/main/java/com/pokegoapi/api/inventory/ItemBag.java @@ -29,6 +29,7 @@ import com.pokegoapi.exceptions.RemoteServerException; import com.pokegoapi.main.ServerRequest; +import java.util.Collection; import java.util.HashMap; /** @@ -102,4 +103,9 @@ public Item getItem(ItemId type) { return items.get(type); } + + + public Collection getItems() { + return items.values(); + } } From 01bf715cb820e543d679480c4f24524ce01b0114 Mon Sep 17 00:00:00 2001 From: Grover-c13 Date: Sat, 23 Jul 2016 23:17:04 +0800 Subject: [PATCH 07/15] Modified travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2011a38f..3665fe94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ jdk: branches: only: - master + - Development before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock From e415b06cce9480d5439201e93d475d91847d4033 Mon Sep 17 00:00:00 2001 From: fabianterhorst Date: Sat, 23 Jul 2016 17:20:54 +0200 Subject: [PATCH 08/15] dummy commit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4306a6c5..89d55f1c 100644 --- a/build.gradle +++ b/build.gradle @@ -94,7 +94,7 @@ checkstyleMain.doLast { } dependencies { - compile 'com.squareup.okio:okio:1.9.0' + compile 'com.squareup.okio:okio:1.8.0' compile 'com.squareup.moshi:moshi:1.2.0' compile 'com.annimon:stream:1.1.1' compile 'com.squareup.okhttp3:okhttp:3.4.0-RC1' From 4ceb6279ad57fe61f839bc8b36270bf3849e2016 Mon Sep 17 00:00:00 2001 From: fabianterhorst Date: Sat, 23 Jul 2016 17:21:12 +0200 Subject: [PATCH 09/15] revert dummy commit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 89d55f1c..4306a6c5 100644 --- a/build.gradle +++ b/build.gradle @@ -94,7 +94,7 @@ checkstyleMain.doLast { } dependencies { - compile 'com.squareup.okio:okio:1.8.0' + compile 'com.squareup.okio:okio:1.9.0' compile 'com.squareup.moshi:moshi:1.2.0' compile 'com.annimon:stream:1.1.1' compile 'com.squareup.okhttp3:okhttp:3.4.0-RC1' From 27392b7f0d08429449d6333d0d159c5732dd1aa0 Mon Sep 17 00:00:00 2001 From: Grover-c13 Date: Sun, 24 Jul 2016 00:14:58 +0800 Subject: [PATCH 10/15] Added using capture items on CatchablePokemon, added overloaded methods for using razzberrys. --- .../api/map/pokemon/CatchItemResult.java | 55 ++++++++ .../api/map/pokemon/CatchablePokemon.java | 127 +++++++++++++++++- .../examples/CatchPokemonAtAreaExample.java | 3 +- 3 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/pokegoapi/api/map/pokemon/CatchItemResult.java diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchItemResult.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchItemResult.java new file mode 100644 index 00000000..c4061af5 --- /dev/null +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchItemResult.java @@ -0,0 +1,55 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.pokegoapi.api.map.pokemon; + +import POGOProtos.Networking.Responses.UseItemCaptureResponseOuterClass; +import POGOProtos.Networking.Responses.UseItemCaptureResponseOuterClass.UseItemCaptureResponse; + +public class CatchItemResult { + private UseItemCaptureResponse proto; + + public CatchItemResult(UseItemCaptureResponse proto) { + this.proto = proto; + } + + public boolean getSuccess() { + return proto.getSuccess(); + } + + public double getItemCaptureMult() { + return proto.getItemCaptureMult(); + } + + public double getItemFleeMult() { + return proto.getItemFleeMult(); + } + + public boolean getStopMovement() { + return proto.getStopMovement(); + } + + public boolean getStopAttack() { + return proto.getStopAttack(); + } + + public boolean getTargetMax() { + return proto.getTargetMax(); + } + + public boolean getTargetSlow() { + return proto.getTargetSlow(); + } +} diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java index 32ecd439..3f794d1f 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -22,10 +22,14 @@ import POGOProtos.Map.Pokemon.WildPokemonOuterClass.WildPokemon; import POGOProtos.Networking.Requests.Messages.CatchPokemonMessageOuterClass.CatchPokemonMessage; import POGOProtos.Networking.Requests.Messages.EncounterMessageOuterClass; +import POGOProtos.Networking.Requests.Messages.UseItemCaptureMessageOuterClass; +import POGOProtos.Networking.Requests.Messages.UseItemCaptureMessageOuterClass.UseItemCaptureMessage; import POGOProtos.Networking.Requests.RequestTypeOuterClass; import POGOProtos.Networking.Responses.CatchPokemonResponseOuterClass.CatchPokemonResponse; import POGOProtos.Networking.Responses.EncounterResponseOuterClass; import POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse; +import POGOProtos.Networking.Responses.UseItemCaptureResponseOuterClass; +import POGOProtos.Networking.Responses.UseItemCaptureResponseOuterClass.UseItemCaptureResponse; import com.google.protobuf.InvalidProtocolBufferException; import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.inventory.ItemBag; @@ -150,6 +154,36 @@ public EncounterResult encounterPokemon() throws LoginFailedException, return new EncounterResult(response); } + /** + * Tries to catch a pokemon (will attempt to use a pokeball, if you have + * none will use greatball etc) and uwill use a single razz berry if available. + * + * @return CatchResult + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond + */ + public CatchResult catchPokemonWithRazzBerry() throws LoginFailedException, + RemoteServerException { + Pokeball pokeball; + + ItemBag bag = api.getInventories().getItemBag(); + if (bag.getItem(ItemId.ITEM_POKE_BALL).getCount() > 0) { + pokeball = Pokeball.POKEBALL; + } else if (bag.getItem(ItemId.ITEM_GREAT_BALL).getCount() > 0) { + pokeball = Pokeball.GREATBALL; + } else if (bag.getItem(ItemId.ITEM_ULTRA_BALL).getCount() > 0) { + pokeball = Pokeball.ULTRABALL; + } else { + pokeball = Pokeball.MASTERBALL; + } + + useItem(ItemId.ITEM_RAZZ_BERRY); + return catchPokemon(pokeball, -1, -1); + } + + /** * Tries to catch a pokemon (will attempt to use a pokeball, if you have * none will use greatball etc). @@ -178,6 +212,8 @@ public CatchResult catchPokemon() throws LoginFailedException, return catchPokemon(pokeball); } + + /** * Tries to catch a pokeball with the given type. * @@ -213,6 +249,54 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount) 0.85 + Math.random() * 0.15, pokeball, amount); } + /** + * Tried to catch a pokemon with given pokeball and max number of pokeballs. + * + * @param pokeball + * Type of pokeball + * @param amount + * Max number of pokeballs to use + * @param razberryLimit + * Max number of razberrys to use + * @return CatchResult + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond + */ + public CatchResult catchPokemon(Pokeball pokeball, int amount, int razberryLimit) + throws LoginFailedException, RemoteServerException { + return catchPokemon(1.0, 1.95 + Math.random() * 0.05, + 0.85 + Math.random() * 0.15, pokeball, razberryLimit); + } + + /** + * Tries to catch a pokemon. + * + * @param normalizedHitPosition + * the normalized hit position + * @param normalizedReticleSize + * the normalized hit reticle + * @param spinModifier + * the spin modifier + * @param type + * Type of pokeball to throw + * @param amount + * Max number of Pokeballs to throw, negative number for + * unlimited + * @return CatchResult of resulted try to catch pokemon + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond + */ + public CatchResult catchPokemon(double normalizedHitPosition, + double normalizedReticleSize, double spinModifier, Pokeball type, + int amount) throws LoginFailedException, RemoteServerException { + + return catchPokemon(normalizedHitPosition, normalizedReticleSize, spinModifier, type, amount, -1); + } + /** * Tries to catch a pokemon. * @@ -227,6 +311,8 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount) * @param amount * Max number of Pokeballs to throw, negative number for * unlimited + * @param razberriesLimit + * The maximum amount of razberries to use, -1 for unlimited * @return CatchResult of resulted try to catch pokemon * @throws LoginFailedException * if failed to login @@ -235,14 +321,21 @@ public CatchResult catchPokemon(Pokeball pokeball, int amount) */ public CatchResult catchPokemon(double normalizedHitPosition, double normalizedReticleSize, double spinModifier, Pokeball type, - int amount) throws LoginFailedException, RemoteServerException { + int amount, int razberriesLimit) throws LoginFailedException, RemoteServerException { if (!isEncountered()) { return new CatchResult(); } + int razberries = 0; int numThrows = 0; CatchPokemonResponse response = null; do { + + if (razberries < razberriesLimit || razberriesLimit == -1) { + useItem(ItemId.ITEM_RAZZ_BERRY); + razberries++; + } + CatchPokemonMessage reqMsg = CatchPokemonMessage.newBuilder() .setEncounterId(getEncounterId()).setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) @@ -274,6 +367,38 @@ public CatchResult catchPokemon(double normalizedHitPosition, return new CatchResult(response); } + /** + * Tries to use an item on a catchable pokemon (ie razzberry). + * + * @param item + * the item ID + * @return CatchItemResult info about the new modifiers about the pokemon (can move, item capture multi) eg + * @throws LoginFailedException + * if failed to login + * @throws RemoteServerException + * if the server failed to respond + */ + public CatchItemResult useItem(ItemId item) throws LoginFailedException, RemoteServerException { + + UseItemCaptureMessage reqMsg = UseItemCaptureMessage + .newBuilder() + .setEncounterId(this.getEncounterId()) + .setSpawnPointGuid(this.getSpawnPointId()) + .setItemId(item) + .build(); + + ServerRequest serverRequest = new ServerRequest( + RequestTypeOuterClass.RequestType.USE_ITEM_CAPTURE, reqMsg); + api.getRequestHandler().sendServerRequests(serverRequest); + UseItemCaptureResponse response = null; + try { + response = UseItemCaptureResponse.parseFrom(serverRequest.getData()); + } catch (InvalidProtocolBufferException e) { + throw new RemoteServerException(e); + } + return new CatchItemResult(response); + } + @Override public boolean equals(Object obj) { if (obj == this) { diff --git a/src/main/java/com/pokegoapi/examples/CatchPokemonAtAreaExample.java b/src/main/java/com/pokegoapi/examples/CatchPokemonAtAreaExample.java index fedd05d9..3ea40914 100644 --- a/src/main/java/com/pokegoapi/examples/CatchPokemonAtAreaExample.java +++ b/src/main/java/com/pokegoapi/examples/CatchPokemonAtAreaExample.java @@ -36,6 +36,7 @@ import com.pokegoapi.api.map.pokemon.CatchResult; import com.pokegoapi.api.map.pokemon.CatchablePokemon; import com.pokegoapi.api.map.pokemon.EncounterResult; +import com.pokegoapi.auth.GoogleLogin; import com.pokegoapi.auth.PtcLogin; import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.exceptions.RemoteServerException; @@ -69,7 +70,7 @@ public static void main(String[] args) { // if encounter was succesful, catch if (encResult.wasSuccessful()) { System.out.println("Encounted:" + cp.getPokemonId()); - CatchResult result = cp.catchPokemon(); + CatchResult result = cp.catchPokemonWithRazzBerry(); System.out.println("Attempt to catch:" + cp.getPokemonId() + " " + result.getStatus()); } From 1aa2458db4ae252da84fc6e7e315b28d3b7ee82e Mon Sep 17 00:00:00 2001 From: langerhans Date: Sat, 23 Jul 2016 18:56:09 +0200 Subject: [PATCH 11/15] Add contribution guidelines, issue template and PR template --- .github/CONTRIBUTING.md | 18 ++++++++++++++++++ .github/ISSUE_TEMPLATE.md | 19 +++++++++++++++++++ .github/PULL_REQUEST_TEMPLATE.md | 13 +++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 00000000..33fc433c --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,18 @@ +# Contributing +Thank you for wanting to help with this project! Pull requests and bug reports are always welcome, there are just some small things you should review before submitting. + +## Issues +If you find any issue with the library, feel free to open an issue report. If it's just a small issue you might want to consider just asking on Slack (see below). + +## Feature Requests +You may open an issue also to request new features. Make sure you describe what you are missing in the library and add any pointers someone might need to implement it. + +## Pull Requests +If you consider submitting a pull request, please note the following: + +1. All pull requests **must** be submitted to the `Development` branch. The `master` branch is exclusively mutable by release. PRs against `master` will not be merged. +2. Pleae make sure you follow the projects code style. To make sure you did, you can use `./gradlew checkstyleMain`. +3. The project is licensed under [GNU GPLv3](../LICENSE.txt) thus all code you submit will be subject to this license. + +## Contact +If you have any questions regarding the library you can ask those on the `#javaapi` channel on the [Pokemon GO Reverse Engineering Slack](https://pkre.slack.com/). You can [get your invite here](https://shielded-earth-81203.herokuapp.com/). \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..2496eccf --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,19 @@ +**Description:** +[Short description of the issue observed. If this ia feature request you can modify the template as required.] + +**Steps to reproduce:** + +1. [Step 1] +2. [Step 2] + +**Expected behavior:** +[What should happen?] + +**Actual behavior:** +[What actually happens] + +**Stacktrace (If it's a crash):** +[Please use pastebin if it's too long] + +**Version:** +[The version of the lib you used] \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..57ef51de --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,13 @@ +### Prerequisites (Remove this section if you want) +Make sure you... + +* Follow the [contribution guidelines](CONTRIBUTING.md) +* Follow the code style (run `./gradlew checkstyleMain`) +* Submit this PR against the `Development` branch. + +**Fixed issue:** [Reference the issue number here, or remove if not a fix] + +**Changes made:** + +* List your changes here +* Change 2... \ No newline at end of file From 991620175fbeee38b0bcb29a62b7f316ea8e986e Mon Sep 17 00:00:00 2001 From: mjmfighter Date: Fri, 22 Jul 2016 21:21:10 -0500 Subject: [PATCH 12/15] null pointer fix --- src/main/java/com/pokegoapi/api/inventory/Inventories.java | 2 +- src/main/java/com/pokegoapi/api/pokemon/Pokemon.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/inventory/Inventories.java b/src/main/java/com/pokegoapi/api/inventory/Inventories.java index ab41960f..2918dee2 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Inventories.java +++ b/src/main/java/com/pokegoapi/api/inventory/Inventories.java @@ -125,7 +125,7 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, // pokebank if (itemData.getPokemonData().getPokemonId() != PokemonId.MISSINGNO) { - pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); + pokebank.addPokemon(new Pokemon(api, inventoryItem.getInventoryItemData().getPokemonData())); } // items diff --git a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java index b9591eef..fcc4f457 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java @@ -44,14 +44,14 @@ public class Pokemon { private static final String TAG = Pokemon.class.getSimpleName(); - @Setter - PokemonGo pgo; + private final PokemonGo pgo; private PokemonData proto; // API METHODS // // DELEGATE METHODS BELOW // - public Pokemon(PokemonData proto) { + public Pokemon(PokemonGo api, PokemonData proto) { + this.pgo = api; this.proto = proto; } From 5e30454c87232447969f4b0ecd7006437cd838ee Mon Sep 17 00:00:00 2001 From: mjmfighter Date: Fri, 22 Jul 2016 21:29:13 -0500 Subject: [PATCH 13/15] Adjusted some other functions --- src/main/java/com/pokegoapi/api/inventory/PokeBank.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java index fe40c054..9f6989cb 100644 --- a/src/main/java/com/pokegoapi/api/inventory/PokeBank.java +++ b/src/main/java/com/pokegoapi/api/inventory/PokeBank.java @@ -42,7 +42,6 @@ public PokeBank(PokemonGo instance) { * @param pokemon Pokemon to add to the inventory */ public void addPokemon(final Pokemon pokemon) { - pokemon.setPgo(instance); List alreadyAdded = Stream.of(pokemons).filter(new Predicate() { @Override public boolean test(Pokemon testPokemon) { From 8615fa62a9c23ec9aaad53d6a0e0f807cd942e3b Mon Sep 17 00:00:00 2001 From: mjmfighter Date: Fri, 22 Jul 2016 21:31:22 -0500 Subject: [PATCH 14/15] Didn't commit all the files... --- .../java/com/pokegoapi/api/map/pokemon/EvolutionResult.java | 5 +++-- src/main/java/com/pokegoapi/api/pokemon/Pokemon.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java b/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java index a8863267..a27bc2a8 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java @@ -16,6 +16,7 @@ package com.pokegoapi.api.map.pokemon; import POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass; +import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.pokemon.Pokemon; public class EvolutionResult { @@ -23,9 +24,9 @@ public class EvolutionResult { private EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto; private Pokemon pokemon; - public EvolutionResult(EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) { + public EvolutionResult(PokemonGo api, EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) { this.proto = proto; - this.pokemon = new Pokemon(proto.getEvolvedPokemonData()); + this.pokemon = new Pokemon(api, proto.getEvolvedPokemonData()); } public EvolvePokemonResponseOuterClass.EvolvePokemonResponse.Result getResult() { diff --git a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java index fcc4f457..b9d4c0d4 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java @@ -137,7 +137,7 @@ public EvolutionResult evolve() throws LoginFailedException, RemoteServerExcepti return null; } - EvolutionResult result = new EvolutionResult(response); + EvolutionResult result = new EvolutionResult(pgo, response); pgo.getInventories().getPokebank().removePokemon(this); From ac3c15fe82b221e1abda0326cd5f5c1696d02166 Mon Sep 17 00:00:00 2001 From: mjmfighter Date: Sat, 23 Jul 2016 14:39:24 -0500 Subject: [PATCH 15/15] Added Javadoc to a file so checkstyle would not complain --- .../java/com/pokegoapi/api/map/pokemon/EvolutionResult.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java b/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java index a27bc2a8..afedddf0 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java @@ -24,6 +24,11 @@ public class EvolutionResult { private EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto; private Pokemon pokemon; + /** + * The evolution result. + * @param api PokemonGo api + * @param proto Pokemon proto + */ public EvolutionResult(PokemonGo api, EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) { this.proto = proto; this.pokemon = new Pokemon(api, proto.getEvolvedPokemonData());