diff --git a/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java b/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java index 66c712f6..1a179512 100644 --- a/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java +++ b/src/main/java/com/pokegoapi/api/inventory/EggIncubator.java @@ -31,8 +31,6 @@ public class EggIncubator { private final EggIncubatorOuterClass.EggIncubator proto; private final PokemonGo pgo; - @Getter - private boolean inUse = false; /** * Create new EggIncubator with given proto. @@ -43,7 +41,6 @@ public class EggIncubator { public EggIncubator(PokemonGo pgo, EggIncubatorOuterClass.EggIncubator proto) { this.pgo = pgo; this.proto = proto; - this.inUse = proto.getPokemonId() != 0; } /** @@ -83,8 +80,6 @@ public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg) pgo.getInventories().updateInventories(true); - this.inUse = true; - return response.getResult(); } @@ -123,4 +118,13 @@ public double getKmTarget() { public double getKmWalked() { return proto.getStartKmWalked(); } + + /** + * Is the incubator currently being used + * + * @return currently used or not + */ + public boolean isInUse() { + return getKmTarget() > pgo.getPlayerProfile().getStats().getKmWalked(); + } } diff --git a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java index 710f50ea..e621f885 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java +++ b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java @@ -49,6 +49,7 @@ public void reset(PokemonGo pgo) { } public void addEgg(EggPokemon egg) { + egg.setPgo(instance); eggs.add(egg); } diff --git a/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java index 4f611901..be16eb7d 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java @@ -18,6 +18,8 @@ import POGOProtos.Data.PokemonDataOuterClass.PokemonData; import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse; +import com.annimon.stream.Stream; +import com.annimon.stream.function.Predicate; import com.pokegoapi.api.PokemonGo; import com.pokegoapi.api.inventory.EggIncubator; import com.pokegoapi.exceptions.LoginFailedException; @@ -51,6 +53,28 @@ public UseItemEggIncubatorResponse.Result incubate(EggIncubator incubator) } return incubator.hatchEgg(this); } + + /** + * Get the current distance that has been done with this egg + * @return get distance already walked + */ + public double getEggKmWalked() { + if (!isIncubate()) + return 0; + EggIncubator incubator = Stream.of(pgo.getInventories().getIncubators()) + .filter(new Predicate() { + @Override + public boolean test(EggIncubator incub) { + return incub.getId().equals(proto.getEggIncubatorId()); + } + }).findFirst().orElse(null); + // incubator should not be null but why not eh + if (incubator == null) + return 0; + else + return proto.getEggKmWalkedTarget() + - (incubator.getKmTarget() - pgo.getPlayerProfile().getStats().getKmWalked()); + } // DELEGATE METHODS BELOW // /** @@ -73,10 +97,6 @@ public double getEggKmWalkedTarget() { return proto.getEggKmWalkedTarget(); } - public double getEggKmWalkedStart() { - return proto.getEggKmWalkedStart(); - } - public long getCapturedCellId() { return proto.getCapturedCellId(); }