Skip to content

Commit 80c8052

Browse files
committed
Merge branch 'vmarchaud-Development' into Development
2 parents 797f45e + f544f80 commit 80c8052

File tree

10 files changed

+94
-17
lines changed

10 files changed

+94
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ___
3131
- `` gradle build bundle ``
3232
- you should have the api bundled in ``build/libs/PokeGOAPI-Java_bundle-0.0.1-SNAPSHOT.jar``
3333

34-
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
34+
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
3535

3636
# Usage
3737
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
6363
- Create your feature branch: `git checkout -b my-new-feature`
6464
- Commit your changes: `git commit -am 'Usefull information about your new features'`
6565
- Push to the branch: `git push origin my-new-feature`
66-
- Submit a pull request :D
66+
- Submit a pull request on the `Development` branch :D
6767

6868
## Contributors
6969
- Grover-c13

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public int getUsesRemaining() {
6464
*/
6565
public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg)
6666
throws LoginFailedException, RemoteServerException {
67-
if (!egg.getIsEgg()) {
68-
return null;
69-
}
67+
7068
UseItemEggIncubatorMessage reqMsg = UseItemEggIncubatorMessage.newBuilder()
7169
.setItemId(proto.getId())
7270
.setPokemonId(egg.getId())

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@
1515

1616
package com.pokegoapi.api.inventory;
1717

18+
import POGOProtos.Networking.Requests.Messages.GetHatchedEggsMessageOuterClass.GetHatchedEggsMessage;
19+
import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType;
20+
import POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse;
21+
import com.google.protobuf.InvalidProtocolBufferException;
1822
import com.pokegoapi.api.PokemonGo;
1923
import com.pokegoapi.api.pokemon.EggPokemon;
20-
import com.pokegoapi.api.pokemon.Pokemon;
24+
import com.pokegoapi.api.pokemon.HatchedEgg;
25+
import com.pokegoapi.exceptions.LoginFailedException;
26+
import com.pokegoapi.exceptions.RemoteServerException;
27+
import com.pokegoapi.main.ServerRequest;
28+
2129
import lombok.Getter;
2230

2331
import java.util.ArrayList;
@@ -38,5 +46,34 @@ public Hatchery(PokemonGo instance) {
3846
public void addEgg(EggPokemon egg) {
3947
eggs.add(egg);
4048
}
49+
50+
51+
/**
52+
* Get if eggs has hatched.
53+
*
54+
* @return list of hatched eggs
55+
* @throws RemoteServerException e
56+
* @throws LoginFailedException e
57+
*/
58+
public List<HatchedEgg> queryHatchedEggs() throws RemoteServerException, LoginFailedException {
59+
GetHatchedEggsMessage msg = GetHatchedEggsMessage.newBuilder().build();
60+
ServerRequest serverRequest = new ServerRequest(RequestType.GET_HATCHED_EGGS, msg);
61+
instance.getRequestHandler().sendServerRequests(serverRequest);
62+
63+
GetHatchedEggsResponse response = null;
64+
try {
65+
response = GetHatchedEggsResponse.parseFrom(serverRequest.getData());
66+
} catch (InvalidProtocolBufferException e) {
67+
throw new RemoteServerException(e);
68+
}
69+
List<HatchedEgg> eggs = new ArrayList<HatchedEgg>();
70+
for (int i = 0; i < response.getPokemonIdCount(); i++) {
71+
eggs.add(new HatchedEgg(response.getPokemonId(i),
72+
response.getExperienceAwarded(i),
73+
response.getCandyAwarded(i),
74+
response.getStardustAwarded(i)));
75+
}
76+
return eggs;
77+
}
4178

4279
}

src/main/java/com/pokegoapi/api/map/Map.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public CatchPokemonResponse catchPokemon(
462462
.setHitPokemon(true)
463463
.setNormalizedHitPosition(normalizedHitPosition)
464464
.setNormalizedReticleSize(normalizedReticleSize)
465-
.setSpawnPointGuid(catchablePokemon.getSpawnPointId())
465+
.setSpawnPointId(catchablePokemon.getSpawnPointId())
466466
.setSpinModifier(spinModifier)
467467
.setPokeball(pokeball)
468468
.build();

src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public CatchResult catchPokemon(double normalizedHitPosition,
340340
.setEncounterId(getEncounterId()).setHitPokemon(true)
341341
.setNormalizedHitPosition(normalizedHitPosition)
342342
.setNormalizedReticleSize(normalizedReticleSize)
343-
.setSpawnPointGuid(getSpawnPointId())
343+
.setSpawnPointId(getSpawnPointId())
344344
.setSpinModifier(spinModifier)
345345
.setPokeball(type.getBallType()).build();
346346
ServerRequest serverRequest = new ServerRequest(

src/main/java/com/pokegoapi/api/player/PlayerProfile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void updateProfile() throws LoginFailedException, RemoteServerException {
8989
creationTime = playerResponse.getPlayerData().getCreationTimestampMs();
9090
itemStorage = playerResponse.getPlayerData().getMaxItemStorage();
9191
pokemonStorage = playerResponse.getPlayerData().getMaxPokemonStorage();
92-
team = Team.values()[playerResponse.getPlayerData().getTeam()];
92+
team = Team.values()[playerResponse.getPlayerData().getTeamValue()];
9393
username = playerResponse.getPlayerData().getUsername();
9494

9595
final PlayerAvatar avatarApi = new PlayerAvatar();

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

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
package com.pokegoapi.api.pokemon;
1717

1818
import POGOProtos.Data.PokemonDataOuterClass.PokemonData;
19+
import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse;
20+
1921
import com.pokegoapi.api.PokemonGo;
22+
import com.pokegoapi.api.inventory.EggIncubator;
23+
import com.pokegoapi.exceptions.LoginFailedException;
24+
import com.pokegoapi.exceptions.RemoteServerException;
25+
2026
import lombok.Setter;
2127

2228
/**
@@ -30,20 +36,39 @@ public class EggPokemon {
3036
private PokemonData proto;
3137

3238
// API METHODS //
39+
/**
40+
* Incubate this egg.
41+
*
42+
* @param incubator : the incubator
43+
* @return status of putting egg in incubator
44+
* @throws LoginFailedException e
45+
* @throws RemoteServerException e
46+
*/
47+
public UseItemEggIncubatorResponse.Result incubate(EggIncubator incubator)
48+
throws LoginFailedException, RemoteServerException {
49+
if (incubator.isInUse()) {
50+
throw new IllegalArgumentException("Incubator already used");
51+
}
52+
return incubator.hatchEgg(this);
53+
}
3354

3455
// DELEGATE METHODS BELOW //
56+
/**
57+
* Build a EggPokemon wrapper from the proto.
58+
*
59+
* @param proto : the prototype
60+
*/
3561
public EggPokemon(PokemonData proto) {
62+
if (!proto.getIsEgg()) {
63+
throw new IllegalArgumentException("You cant build a EggPokemon without a valid PokemonData.");
64+
}
3665
this.proto = proto;
3766
}
3867

3968
public long getId() {
4069
return proto.getId();
4170
}
42-
43-
public boolean getIsEgg() {
44-
return proto.getIsEgg();
45-
}
46-
71+
4772
public double getEggKmWalkedTarget() {
4873
return proto.getEggKmWalkedTarget();
4974
}
@@ -63,6 +88,10 @@ public long getCreationTimeMs() {
6388
public String getEggIncubatorId() {
6489
return proto.getEggIncubatorId();
6590
}
91+
92+
public boolean isIncubate() {
93+
return proto.getEggIncubatorId().length() > 0;
94+
}
6695

6796
@Override
6897
public int hashCode() {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.pokegoapi.api.pokemon;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
6+
@Data
7+
@AllArgsConstructor
8+
public class HatchedEgg {
9+
10+
private Long id;
11+
private int experience;
12+
private int candy;
13+
private int stardust;
14+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId;
2020
import POGOProtos.Enums.PokemonIdOuterClass;
2121
import POGOProtos.Enums.PokemonMoveOuterClass;
22-
import POGOProtos.Inventory.Item.ItemIdOuterClass;
2322
import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId;
2423
import POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage;
2524
import POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage;
@@ -190,7 +189,7 @@ public PokemonMoveOuterClass.PokemonMove getMove2() {
190189
return proto.getMove2();
191190
}
192191

193-
public int getDeployedFortId() {
192+
public String getDeployedFortId() {
194193
return proto.getDeployedFortId();
195194
}
196195

0 commit comments

Comments
 (0)