Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/main/java/com/pokegoapi/api/inventory/EggIncubator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -83,8 +80,6 @@ public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg)

pgo.getInventories().updateInventories(true);

this.inUse = true;

return response.getResult();
}

Expand Down Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions src/main/java/com/pokegoapi/api/inventory/Hatchery.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void reset(PokemonGo pgo) {
}

public void addEgg(EggPokemon egg) {
egg.setPgo(instance);
eggs.add(egg);
}

Expand Down
28 changes: 24 additions & 4 deletions src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<EggIncubator>() {
@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 //
/**
Expand All @@ -73,10 +97,6 @@ public double getEggKmWalkedTarget() {
return proto.getEggKmWalkedTarget();
}

public double getEggKmWalkedStart() {
return proto.getEggKmWalkedStart();
}

public long getCapturedCellId() {
return proto.getCapturedCellId();
}
Expand Down