diff --git a/build.gradle b/build.gradle index 83c73d11..649a4407 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ sourceSets { main { proto { // Need to use custom dir cause Gradle doesn't like us otherwise :( - srcDir 'src/resources/protobuf/pogo' + srcDir 'src/resources/protobuf/src' include '**/*.proto' } } diff --git a/src/main/java/com/pokegoapi/api/map/Map.java b/src/main/java/com/pokegoapi/api/map/Map.java index 67100be9..ba2255b3 100644 --- a/src/main/java/com/pokegoapi/api/map/Map.java +++ b/src/main/java/com/pokegoapi/api/map/Map.java @@ -37,6 +37,7 @@ import com.google.protobuf.InvalidProtocolBufferException; import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.map.fort.FortDetails; +import com.pokegoapi.api.map.fort.Pokestop; import com.pokegoapi.api.map.pokemon.CatchablePokemon; import com.pokegoapi.api.map.pokemon.NearbyPokemon; import com.pokegoapi.exceptions.LoginFailedException; @@ -103,6 +104,12 @@ public List getCatchablePokemon() throws LoginFailedException, catchablePokemons.add(new CatchablePokemon(api, wildPokemon)); } + for (Pokestop pokestop : objects.getPokestops()) { + if (pokestop.inRange() && pokestop.hasLurePokemon()) { + catchablePokemons.add(new CatchablePokemon(api, pokestop.getFortData())); + } + } + return catchablePokemons; } @@ -408,7 +415,7 @@ public EncounterResponse encounterPokemon(MapPokemon catchablePokemon) .setEncounterId(catchablePokemon.getEncounterId()) .setPlayerLatitude(api.getLatitude()) .setPlayerLongitude(api.getLongitude()) - .setSpawnpointId(catchablePokemon.getSpawnpointId()) + .setSpawnPointId(catchablePokemon.getSpawnPointId()) .build(); ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.ENCOUNTER, reqMsg); api.getRequestHandler().sendServerRequests(serverRequest); @@ -448,7 +455,7 @@ public CatchPokemonResponse catchPokemon( .setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) .setNormalizedReticleSize(normalizedReticleSize) - .setSpawnPointGuid(catchablePokemon.getSpawnpointId()) + .setSpawnPointGuid(catchablePokemon.getSpawnPointId()) .setSpinModifier(spinModifier) .setPokeball(pokeball) .build(); diff --git a/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java b/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java index fabca72f..4b8b3e39 100644 --- a/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java +++ b/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java @@ -35,6 +35,7 @@ public class Pokestop { private final PokemonGo api; + @Getter private final FortDataOuterClass.FortData fortData; @Getter private long cooldownCompleteTimestampMs; @@ -52,6 +53,21 @@ public Pokestop(PokemonGo api, FortDataOuterClass.FortData fortData) { this.cooldownCompleteTimestampMs = fortData.getCooldownCompleteTimestampMs(); } + /** + * Returns whether or not a pokestop is in range. + * @return true when in range of player + */ + public boolean inRange() { + S2LatLng pokestop = S2LatLng.fromDegrees(getLatitude(), getLongitude()); + S2LatLng player = S2LatLng.fromDegrees(api.getLatitude(), api.getLongitude()); + double distance = pokestop.getEarthDistance(player); + return distance < 30; + } + + /** + * can user loot this from current position. + * @return true when lootable + */ public boolean canLoot() { return canLoot(false); } @@ -63,10 +79,11 @@ public boolean canLoot() { * @return the boolean */ public boolean canLoot(boolean ignoreDistance) { - S2LatLng pokestop = S2LatLng.fromDegrees(getLatitude(), getLongitude()); - S2LatLng player = S2LatLng.fromDegrees(api.getLatitude(), api.getLongitude()); - double distance = pokestop.getEarthDistance(player); - return (ignoreDistance || distance < 30) && cooldownCompleteTimestampMs < System.currentTimeMillis(); + boolean active = cooldownCompleteTimestampMs < System.currentTimeMillis(); + if (!ignoreDistance) { + return active && inRange(); + } + return active; } public String getId() { @@ -134,5 +151,11 @@ public FortDetails getDetails() throws LoginFailedException, RemoteServerExcepti return new FortDetails(response); } - + /** + * Returns whether this pokestop has an active lure. + * @return lure status + */ + public boolean hasLurePokemon() { + return fortData.hasLureInfo() && fortData.getLureInfo().getLureExpiresTimestampMs() < System.currentTimeMillis(); + } } 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 93ee3cb3..0b9e75a4 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -17,6 +17,10 @@ import POGOProtos.Enums.PokemonIdOuterClass; import POGOProtos.Inventory.ItemIdOuterClass; +import POGOProtos.Map.Fort.FortDataOuterClass; +import POGOProtos.Map.Fort.FortDataOuterClass.FortData; +import POGOProtos.Map.Fort.FortLureInfoOuterClass; +import POGOProtos.Map.Fort.FortLureInfoOuterClass.FortLureInfo; import POGOProtos.Map.Pokemon.MapPokemonOuterClass.MapPokemon; import POGOProtos.Map.Pokemon.WildPokemonOuterClass.WildPokemon; import POGOProtos.Networking.Requests.Messages.CatchPokemonMessageOuterClass.CatchPokemonMessage; @@ -29,9 +33,11 @@ import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.inventory.ItemBag; import com.pokegoapi.api.inventory.Pokeball; +import com.pokegoapi.api.map.fort.Pokestop; import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.exceptions.RemoteServerException; import com.pokegoapi.main.ServerRequest; +import com.pokegoapi.util.Log; import lombok.Getter; import lombok.ToString; @@ -44,7 +50,7 @@ public class CatchablePokemon { private final PokemonGo api; @Getter - private final String spawnpointId; + private final String spawnPointId; @Getter private final long encounterId; @Getter @@ -68,7 +74,7 @@ public class CatchablePokemon { public CatchablePokemon(PokemonGo api, MapPokemon proto) { this.api = api; - this.spawnpointId = proto.getSpawnpointId(); + this.spawnPointId = proto.getSpawnPointId(); this.encounterId = proto.getEncounterId(); this.pokemonId = proto.getPokemonId(); this.expirationTimestampMs = proto.getExpirationTimestampMs(); @@ -85,7 +91,7 @@ public CatchablePokemon(PokemonGo api, MapPokemon proto) { */ public CatchablePokemon(PokemonGo api, WildPokemon proto) { this.api = api; - this.spawnpointId = proto.getSpawnpointId(); + this.spawnPointId = proto.getSpawnPointId(); this.encounterId = proto.getEncounterId(); this.pokemonId = proto.getPokemonData().getPokemonId(); this.expirationTimestampMs = proto.getTimeTillHiddenMs(); @@ -93,6 +99,25 @@ public CatchablePokemon(PokemonGo api, WildPokemon proto) { this.longitude = proto.getLongitude(); } + /** + * Instantiates a new Catchable pokemon. + * + * @param api the api + * @param proto the proto + */ + public CatchablePokemon(PokemonGo api, FortData proto) { + if (!proto.hasLureInfo()) { + throw new IllegalArgumentException("Fort does not have lure"); + } + this.api = api; + // TODO: does this work? + this.spawnPointId = null; + this.encounterId = proto.getLureInfo().getEncounterId(); + this.pokemonId = proto.getLureInfo().getActivePokemonId(); + this.expirationTimestampMs = proto.getLureInfo().getLureExpiresTimestampMs(); + this.latitude = proto.getLatitude(); + this.longitude = proto.getLongitude(); + } /** * Encounter pokemon encounter result. @@ -106,7 +131,7 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer .setEncounterId(getEncounterId()) .setPlayerLatitude(api.getLatitude()) .setPlayerLongitude(api.getLongitude()) - .setSpawnpointId(getSpawnpointId()) + .setSpawnPointId(getSpawnPointId()) .build(); ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.ENCOUNTER, reqMsg); api.getRequestHandler().sendServerRequests(serverRequest); @@ -197,7 +222,7 @@ public CatchResult catchPokemon( .setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) .setNormalizedReticleSize(normalizedReticleSize) - .setSpawnPointGuid(getSpawnpointId()) + .setSpawnPointGuid(getSpawnPointId()) .setSpinModifier(spinModifier) .setPokeball(type.getBalltype()) .build(); @@ -223,5 +248,4 @@ public CatchResult catchPokemon( return new CatchResult(response); } - } diff --git a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java index dddc2313..8d45d41b 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java @@ -248,7 +248,7 @@ public int getBattlesDefended() { return proto.getBattlesDefended(); } - public int getEggIncubatorId() { + public String getEggIncubatorId() { return proto.getEggIncubatorId(); } diff --git a/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java b/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java index 9a9edef6..354150a8 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java +++ b/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java @@ -30,7 +30,7 @@ public class PokemonFamilyMap { familys.put(PokemonId.IVYSAUR, PokemonFamilyId.FAMILY_BULBASAUR); familys.put(PokemonId.VENUSAUR, PokemonFamilyId.FAMILY_BULBASAUR); highestForFamily.put(PokemonFamilyId.FAMILY_BULBASAUR, PokemonId.VENUSAUR); - familys.put(PokemonId.CHARMENDER, PokemonFamilyId.FAMILY_CHARMANDER); + familys.put(PokemonId.CHARMANDER, PokemonFamilyId.FAMILY_CHARMANDER); familys.put(PokemonId.CHARMELEON, PokemonFamilyId.FAMILY_CHARMANDER); familys.put(PokemonId.CHARIZARD, PokemonFamilyId.FAMILY_CHARMANDER); highestForFamily.put(PokemonFamilyId.FAMILY_CHARMANDER, PokemonId.CHARIZARD); @@ -63,17 +63,17 @@ public class PokemonFamilyMap { familys.put(PokemonId.RAICHU, PokemonFamilyId.FAMILY_PIKACHU); highestForFamily.put(PokemonFamilyId.FAMILY_PIKACHU, PokemonId.RAICHU); familys.put(PokemonId.SANDSHREW, PokemonFamilyId.FAMILY_SANDSHREW); - familys.put(PokemonId.SANDLASH, PokemonFamilyId.FAMILY_SANDSHREW); - highestForFamily.put(PokemonFamilyId.FAMILY_SANDSHREW, PokemonId.SANDLASH); - familys.put(PokemonId.NIDORAN_FEMALE, PokemonFamilyId.FAMILY_NIDORAN); - familys.put(PokemonId.NIDORINA, PokemonFamilyId.FAMILY_NIDORAN); - familys.put(PokemonId.NIDOQUEEN, PokemonFamilyId.FAMILY_NIDORAN); - highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN, PokemonId.NIDOQUEEN); - familys.put(PokemonId.NIDORAN_MALE, PokemonFamilyId.FAMILY_NIDORAN2); - familys.put(PokemonId.NIDORINO, PokemonFamilyId.FAMILY_NIDORAN2); - familys.put(PokemonId.NIDOKING, PokemonFamilyId.FAMILY_NIDORAN2); - highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN2, PokemonId.NIDOKING); - familys.put(PokemonId.CLEFARY, PokemonFamilyId.FAMILY_CLEFAIRY); + familys.put(PokemonId.SANDSLASH, PokemonFamilyId.FAMILY_SANDSHREW); + highestForFamily.put(PokemonFamilyId.FAMILY_SANDSHREW, PokemonId.SANDSLASH); + familys.put(PokemonId.NIDORAN_FEMALE, PokemonFamilyId.FAMILY_NIDORAN_FEMALE); + familys.put(PokemonId.NIDORINA, PokemonFamilyId.FAMILY_NIDORAN_FEMALE); + familys.put(PokemonId.NIDOQUEEN, PokemonFamilyId.FAMILY_NIDORAN_FEMALE); + highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN_FEMALE, PokemonId.NIDOQUEEN); + familys.put(PokemonId.NIDORAN_MALE, PokemonFamilyId.FAMILY_NIDORAN_MALE); + familys.put(PokemonId.NIDORINO, PokemonFamilyId.FAMILY_NIDORAN_MALE); + familys.put(PokemonId.NIDOKING, PokemonFamilyId.FAMILY_NIDORAN_MALE); + highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN_MALE, PokemonId.NIDOKING); + familys.put(PokemonId.CLEFAIRY, PokemonFamilyId.FAMILY_CLEFAIRY); familys.put(PokemonId.CLEFABLE, PokemonFamilyId.FAMILY_CLEFAIRY); highestForFamily.put(PokemonFamilyId.FAMILY_CLEFAIRY, PokemonId.CLEFABLE); familys.put(PokemonId.VULPIX, PokemonFamilyId.FAMILY_VULPIX); @@ -116,20 +116,20 @@ public class PokemonFamilyMap { highestForFamily.put(PokemonFamilyId.FAMILY_POLIWAG, PokemonId.POLIWRATH); familys.put(PokemonId.ABRA, PokemonFamilyId.FAMILY_ABRA); familys.put(PokemonId.KADABRA, PokemonFamilyId.FAMILY_ABRA); - familys.put(PokemonId.ALAKHAZAM, PokemonFamilyId.FAMILY_ABRA); - highestForFamily.put(PokemonFamilyId.FAMILY_ABRA, PokemonId.ALAKHAZAM); + familys.put(PokemonId.ALAKAZAM, PokemonFamilyId.FAMILY_ABRA); + highestForFamily.put(PokemonFamilyId.FAMILY_ABRA, PokemonId.ALAKAZAM); familys.put(PokemonId.MACHOP, PokemonFamilyId.FAMILY_MACHOP); familys.put(PokemonId.MACHOKE, PokemonFamilyId.FAMILY_MACHOP); familys.put(PokemonId.MACHAMP, PokemonFamilyId.FAMILY_MACHOP); highestForFamily.put(PokemonFamilyId.FAMILY_MACHOP, PokemonId.MACHAMP); familys.put(PokemonId.BELLSPROUT, PokemonFamilyId.FAMILY_BELLSPROUT); familys.put(PokemonId.WEEPINBELL, PokemonFamilyId.FAMILY_BELLSPROUT); - familys.put(PokemonId.VICTREEBELL, PokemonFamilyId.FAMILY_BELLSPROUT); - highestForFamily.put(PokemonFamilyId.FAMILY_BELLSPROUT, PokemonId.VICTREEBELL); + familys.put(PokemonId.VICTREEBEL, PokemonFamilyId.FAMILY_BELLSPROUT); + highestForFamily.put(PokemonFamilyId.FAMILY_BELLSPROUT, PokemonId.VICTREEBEL); familys.put(PokemonId.TENTACOOL, PokemonFamilyId.FAMILY_TENTACOOL); familys.put(PokemonId.TENTACRUEL, PokemonFamilyId.FAMILY_TENTACOOL); highestForFamily.put(PokemonFamilyId.FAMILY_TENTACOOL, PokemonId.TENTACRUEL); - familys.put(PokemonId.GEODUGE, PokemonFamilyId.FAMILY_GEODUDE); + familys.put(PokemonId.GEODUDE, PokemonFamilyId.FAMILY_GEODUDE); familys.put(PokemonId.GRAVELER, PokemonFamilyId.FAMILY_GEODUDE); familys.put(PokemonId.GOLEM, PokemonFamilyId.FAMILY_GEODUDE); highestForFamily.put(PokemonFamilyId.FAMILY_GEODUDE, PokemonId.GOLEM); diff --git a/src/main/java/com/pokegoapi/main/RequestHandler.java b/src/main/java/com/pokegoapi/main/RequestHandler.java index 1e9559cb..7520bf3a 100644 --- a/src/main/java/com/pokegoapi/main/RequestHandler.java +++ b/src/main/java/com/pokegoapi/main/RequestHandler.java @@ -246,8 +246,8 @@ private void resetBuilder() { private void resetBuilder(RequestEnvelopeOuterClass.RequestEnvelope.Builder builder) { builder.setStatusCode(2); builder.setRequestId(8145806132888207460L); - if (lastAuth != null - && lastAuth.getExpireTimestampMs() > 0 + if (lastAuth != null + && lastAuth.getExpireTimestampMs() > 0 && lastAuth.getExpireTimestampMs() > System.currentTimeMillis()) { builder.setAuthTicket(lastAuth); } else { diff --git a/src/resources/protobuf b/src/resources/protobuf index 1b124cdb..eeccbb12 160000 --- a/src/resources/protobuf +++ b/src/resources/protobuf @@ -1 +1 @@ -Subproject commit 1b124cdbdd271a9cd6953949a74db3865a5f42a8 +Subproject commit eeccbb121b126aa51fc4eebae8d2f23d013e1cb8