diff --git a/README.md b/README.md index e025388a..d25a2b20 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ ___ - `` gradle build bundle `` - you should have the api bundled in ``build/libs/PokeGOAPI-Java_bundle-0.0.1-SNAPSHOT.jar`` - PS : To eclipse user, you may build one time and add the generated java class for proto into eclipse path : Right click on the project > Build path > New Source Folder > Type 'build/generated/source/proto/main/java' > Finish + PS : To Eclipse user, you must build once : `` gradle build `` and add the generated java class for proto into eclipse source path : Right click on the project > Build path > Configure Build Path > Source > Add Folder > Select `build/generated/source/proto/main/java` > Finish # Usage Include the API as jar from your own build, or use Maven/Gradle/SBT/Leiningen: https://jitpack.io/#Grover-c13/PokeGOAPI-Java/master-SNAPSHOT @@ -63,7 +63,7 @@ This library is meant to be a Java implementation of the API. Google Volley is s - Create your feature branch: `git checkout -b my-new-feature` - Commit your changes: `git commit -am 'Usefull information about your new features'` - Push to the branch: `git push origin my-new-feature` - - Submit a pull request :D + - Submit a pull request on the `Development` branch :D ## Contributors - Grover-c13 diff --git a/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java b/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java index 1521fa89..3b8c4acc 100644 --- a/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java +++ b/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java @@ -64,9 +64,7 @@ public int getUsesRemaining() { */ public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg) throws LoginFailedException, RemoteServerException { - if (!egg.getIsEgg()) { - return null; - } + UseItemEggIncubatorMessage reqMsg = UseItemEggIncubatorMessage.newBuilder() .setItemId(proto.getId()) .setPokemonId(egg.getId()) diff --git a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java index 22b3cd89..19236139 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java +++ b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java @@ -15,9 +15,17 @@ package com.pokegoapi.api.inventory; +import POGOProtos.Networking.Requests.Messages.GetHatchedEggsMessageOuterClass.GetHatchedEggsMessage; +import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType; +import POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse; +import com.google.protobuf.InvalidProtocolBufferException; import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.pokemon.EggPokemon; -import com.pokegoapi.api.pokemon.Pokemon; +import com.pokegoapi.api.pokemon.HatchedEgg; +import com.pokegoapi.exceptions.LoginFailedException; +import com.pokegoapi.exceptions.RemoteServerException; +import com.pokegoapi.main.ServerRequest; + import lombok.Getter; import java.util.ArrayList; @@ -38,5 +46,34 @@ public Hatchery(PokemonGo instance) { public void addEgg(EggPokemon egg) { eggs.add(egg); } + + + /** + * Get if eggs has hatched. + * + * @return list of hatched eggs + * @throws RemoteServerException e + * @throws LoginFailedException e + */ + public List queryHatchedEggs() throws RemoteServerException, LoginFailedException { + GetHatchedEggsMessage msg = GetHatchedEggsMessage.newBuilder().build(); + ServerRequest serverRequest = new ServerRequest(RequestType.GET_HATCHED_EGGS, msg); + instance.getRequestHandler().sendServerRequests(serverRequest); + + GetHatchedEggsResponse response = null; + try { + response = GetHatchedEggsResponse.parseFrom(serverRequest.getData()); + } catch (InvalidProtocolBufferException e) { + throw new RemoteServerException(e); + } + List eggs = new ArrayList(); + for (int i = 0; i < response.getPokemonIdCount(); i++) { + eggs.add(new HatchedEgg(response.getPokemonId(i), + response.getExperienceAwarded(i), + response.getCandyAwarded(i), + response.getStardustAwarded(i))); + } + return eggs; + } } diff --git a/src/main/java/com/pokegoapi/api/map/Map.java b/src/main/java/com/pokegoapi/api/map/Map.java index 44aed570..6145a287 100644 --- a/src/main/java/com/pokegoapi/api/map/Map.java +++ b/src/main/java/com/pokegoapi/api/map/Map.java @@ -462,7 +462,7 @@ public CatchPokemonResponse catchPokemon( .setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) .setNormalizedReticleSize(normalizedReticleSize) - .setSpawnPointGuid(catchablePokemon.getSpawnPointId()) + .setSpawnPointId(catchablePokemon.getSpawnPointId()) .setSpinModifier(spinModifier) .setPokeball(pokeball) .build(); 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 3f794d1f..b1a5f5fd 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -340,7 +340,7 @@ public CatchResult catchPokemon(double normalizedHitPosition, .setEncounterId(getEncounterId()).setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) .setNormalizedReticleSize(normalizedReticleSize) - .setSpawnPointGuid(getSpawnPointId()) + .setSpawnPointId(getSpawnPointId()) .setSpinModifier(spinModifier) .setPokeball(type.getBallType()).build(); ServerRequest serverRequest = new ServerRequest( diff --git a/src/main/java/com/pokegoapi/api/player/PlayerProfile.java b/src/main/java/com/pokegoapi/api/player/PlayerProfile.java index 6d36d4d7..78cd2bf8 100644 --- a/src/main/java/com/pokegoapi/api/player/PlayerProfile.java +++ b/src/main/java/com/pokegoapi/api/player/PlayerProfile.java @@ -89,7 +89,7 @@ public void updateProfile() throws LoginFailedException, RemoteServerException { creationTime = playerResponse.getPlayerData().getCreationTimestampMs(); itemStorage = playerResponse.getPlayerData().getMaxItemStorage(); pokemonStorage = playerResponse.getPlayerData().getMaxPokemonStorage(); - team = Team.values()[playerResponse.getPlayerData().getTeam()]; + team = Team.values()[playerResponse.getPlayerData().getTeamValue()]; username = playerResponse.getPlayerData().getUsername(); final PlayerAvatar avatarApi = new PlayerAvatar(); diff --git a/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java index 120744b6..4f611901 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java @@ -16,7 +16,13 @@ package com.pokegoapi.api.pokemon; import POGOProtos.Data.PokemonDataOuterClass.PokemonData; +import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse; + import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.inventory.EggIncubator; +import com.pokegoapi.exceptions.LoginFailedException; +import com.pokegoapi.exceptions.RemoteServerException; + import lombok.Setter; /** @@ -30,20 +36,39 @@ public class EggPokemon { private PokemonData proto; // API METHODS // + /** + * Incubate this egg. + * + * @param incubator : the incubator + * @return status of putting egg in incubator + * @throws LoginFailedException e + * @throws RemoteServerException e + */ + public UseItemEggIncubatorResponse.Result incubate(EggIncubator incubator) + throws LoginFailedException, RemoteServerException { + if (incubator.isInUse()) { + throw new IllegalArgumentException("Incubator already used"); + } + return incubator.hatchEgg(this); + } // DELEGATE METHODS BELOW // + /** + * Build a EggPokemon wrapper from the proto. + * + * @param proto : the prototype + */ public EggPokemon(PokemonData proto) { + if (!proto.getIsEgg()) { + throw new IllegalArgumentException("You cant build a EggPokemon without a valid PokemonData."); + } this.proto = proto; } public long getId() { return proto.getId(); } - - public boolean getIsEgg() { - return proto.getIsEgg(); - } - + public double getEggKmWalkedTarget() { return proto.getEggKmWalkedTarget(); } @@ -63,6 +88,10 @@ public long getCreationTimeMs() { public String getEggIncubatorId() { return proto.getEggIncubatorId(); } + + public boolean isIncubate() { + return proto.getEggIncubatorId().length() > 0; + } @Override public int hashCode() { diff --git a/src/main/java/com/pokegoapi/api/pokemon/HatchedEgg.java b/src/main/java/com/pokegoapi/api/pokemon/HatchedEgg.java new file mode 100644 index 00000000..396a4033 --- /dev/null +++ b/src/main/java/com/pokegoapi/api/pokemon/HatchedEgg.java @@ -0,0 +1,14 @@ +package com.pokegoapi.api.pokemon; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class HatchedEgg { + + private Long id; + private int experience; + private int candy; + private int stardust; +} diff --git a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java index b9591eef..7e4692cf 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java @@ -19,7 +19,6 @@ import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId; import POGOProtos.Enums.PokemonIdOuterClass; import POGOProtos.Enums.PokemonMoveOuterClass; -import POGOProtos.Inventory.Item.ItemIdOuterClass; import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; import POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage; import POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage; @@ -190,7 +189,7 @@ public PokemonMoveOuterClass.PokemonMove getMove2() { return proto.getMove2(); } - public int getDeployedFortId() { + public String getDeployedFortId() { return proto.getDeployedFortId(); } diff --git a/src/resources/protobuf b/src/resources/protobuf index eeccbb12..ff99b436 160000 --- a/src/resources/protobuf +++ b/src/resources/protobuf @@ -1 +1 @@ -Subproject commit eeccbb121b126aa51fc4eebae8d2f23d013e1cb8 +Subproject commit ff99b436a34f0db79e3f1db805811f083405aecd