Skip to content

Commit 974a27a

Browse files
vmarchaudGrover-c13
authored andcommitted
fix #237 + #227 (#240)
1 parent a64020a commit 974a27a

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/main/java/com/pokegoapi/api/inventory/EggIncubator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
public class EggIncubator {
3232
private final EggIncubatorOuterClass.EggIncubator proto;
3333
private final PokemonGo pgo;
34-
@Getter
35-
private boolean inUse = false;
3634

3735
/**
3836
* Create new EggIncubator with given proto.
@@ -43,7 +41,6 @@ public class EggIncubator {
4341
public EggIncubator(PokemonGo pgo, EggIncubatorOuterClass.EggIncubator proto) {
4442
this.pgo = pgo;
4543
this.proto = proto;
46-
this.inUse = proto.getPokemonId() != 0;
4744
}
4845

4946
/**
@@ -83,8 +80,6 @@ public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg)
8380

8481
pgo.getInventories().updateInventories(true);
8582

86-
this.inUse = true;
87-
8883
return response.getResult();
8984
}
9085

@@ -123,4 +118,13 @@ public double getKmTarget() {
123118
public double getKmWalked() {
124119
return proto.getStartKmWalked();
125120
}
121+
122+
/**
123+
* Is the incubator currently being used
124+
*
125+
* @return currently used or not
126+
*/
127+
public boolean isInUse() {
128+
return getKmTarget() > pgo.getPlayerProfile().getStats().getKmWalked();
129+
}
126130
}

src/main/java/com/pokegoapi/api/inventory/Hatchery.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void reset(PokemonGo pgo) {
4949
}
5050

5151
public void addEgg(EggPokemon egg) {
52+
egg.setPgo(instance);
5253
eggs.add(egg);
5354
}
5455

src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import POGOProtos.Data.PokemonDataOuterClass.PokemonData;
1919
import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse;
2020

21+
import com.annimon.stream.Stream;
22+
import com.annimon.stream.function.Predicate;
2123
import com.pokegoapi.api.PokemonGo;
2224
import com.pokegoapi.api.inventory.EggIncubator;
2325
import com.pokegoapi.exceptions.LoginFailedException;
@@ -51,6 +53,28 @@ public UseItemEggIncubatorResponse.Result incubate(EggIncubator incubator)
5153
}
5254
return incubator.hatchEgg(this);
5355
}
56+
57+
/**
58+
* Get the current distance that has been done with this egg
59+
* @return get distance already walked
60+
*/
61+
public double getEggKmWalked() {
62+
if (!isIncubate())
63+
return 0;
64+
EggIncubator incubator = Stream.of(pgo.getInventories().getIncubators())
65+
.filter(new Predicate<EggIncubator>() {
66+
@Override
67+
public boolean test(EggIncubator incub) {
68+
return incub.getId().equals(proto.getEggIncubatorId());
69+
}
70+
}).findFirst().orElse(null);
71+
// incubator should not be null but why not eh
72+
if (incubator == null)
73+
return 0;
74+
else
75+
return proto.getEggKmWalkedTarget()
76+
- (incubator.getKmTarget() - pgo.getPlayerProfile().getStats().getKmWalked());
77+
}
5478

5579
// DELEGATE METHODS BELOW //
5680
/**
@@ -73,10 +97,6 @@ public double getEggKmWalkedTarget() {
7397
return proto.getEggKmWalkedTarget();
7498
}
7599

76-
public double getEggKmWalkedStart() {
77-
return proto.getEggKmWalkedStart();
78-
}
79-
80100
public long getCapturedCellId() {
81101
return proto.getCapturedCellId();
82102
}

0 commit comments

Comments
 (0)