Skip to content

Commit

Permalink
Merge branch 'vmarchaud-Development' into Development
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbink committed Jul 24, 2016
2 parents 797f45e + f544f80 commit 80c8052
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 17 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ___
- `` gradle build bundle ``
- you should have the api bundled in ``build/libs/PokeGOAPI-Java_bundle-0.0.1-SNAPSHOT.jar``

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
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

# Usage
Include the API as jar from your own build, or use Maven/Gradle/SBT/Leiningen: https://jitpack.io/#Grover-c13/PokeGOAPI-Java/master-SNAPSHOT
Expand Down Expand Up @@ -63,7 +63,7 @@ This library is meant to be a Java implementation of the API. Google Volley is s
- Create your feature branch: `git checkout -b my-new-feature`
- Commit your changes: `git commit -am 'Usefull information about your new features'`
- Push to the branch: `git push origin my-new-feature`
- Submit a pull request :D
- Submit a pull request on the `Development` branch :D

## Contributors
- Grover-c13
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/pokegoapi/api/inventory/EggIncubator.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public int getUsesRemaining() {
*/
public UseItemEggIncubatorResponse.Result hatchEgg(EggPokemon egg)
throws LoginFailedException, RemoteServerException {
if (!egg.getIsEgg()) {
return null;
}

UseItemEggIncubatorMessage reqMsg = UseItemEggIncubatorMessage.newBuilder()
.setItemId(proto.getId())
.setPokemonId(egg.getId())
Expand Down
39 changes: 38 additions & 1 deletion src/main/java/com/pokegoapi/api/inventory/Hatchery.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@

package com.pokegoapi.api.inventory;

import POGOProtos.Networking.Requests.Messages.GetHatchedEggsMessageOuterClass.GetHatchedEggsMessage;
import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType;
import POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse;
import com.google.protobuf.InvalidProtocolBufferException;
import com.pokegoapi.api.PokemonGo;
import com.pokegoapi.api.pokemon.EggPokemon;
import com.pokegoapi.api.pokemon.Pokemon;
import com.pokegoapi.api.pokemon.HatchedEgg;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;
import com.pokegoapi.main.ServerRequest;

import lombok.Getter;

import java.util.ArrayList;
Expand All @@ -38,5 +46,34 @@ public Hatchery(PokemonGo instance) {
public void addEgg(EggPokemon egg) {
eggs.add(egg);
}


/**
* Get if eggs has hatched.
*
* @return list of hatched eggs
* @throws RemoteServerException e
* @throws LoginFailedException e
*/
public List<HatchedEgg> queryHatchedEggs() throws RemoteServerException, LoginFailedException {
GetHatchedEggsMessage msg = GetHatchedEggsMessage.newBuilder().build();
ServerRequest serverRequest = new ServerRequest(RequestType.GET_HATCHED_EGGS, msg);
instance.getRequestHandler().sendServerRequests(serverRequest);

GetHatchedEggsResponse response = null;
try {
response = GetHatchedEggsResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RemoteServerException(e);
}
List<HatchedEgg> eggs = new ArrayList<HatchedEgg>();
for (int i = 0; i < response.getPokemonIdCount(); i++) {
eggs.add(new HatchedEgg(response.getPokemonId(i),
response.getExperienceAwarded(i),
response.getCandyAwarded(i),
response.getStardustAwarded(i)));
}
return eggs;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/pokegoapi/api/map/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public CatchPokemonResponse catchPokemon(
.setHitPokemon(true)
.setNormalizedHitPosition(normalizedHitPosition)
.setNormalizedReticleSize(normalizedReticleSize)
.setSpawnPointGuid(catchablePokemon.getSpawnPointId())
.setSpawnPointId(catchablePokemon.getSpawnPointId())
.setSpinModifier(spinModifier)
.setPokeball(pokeball)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public CatchResult catchPokemon(double normalizedHitPosition,
.setEncounterId(getEncounterId()).setHitPokemon(true)
.setNormalizedHitPosition(normalizedHitPosition)
.setNormalizedReticleSize(normalizedReticleSize)
.setSpawnPointGuid(getSpawnPointId())
.setSpawnPointId(getSpawnPointId())
.setSpinModifier(spinModifier)
.setPokeball(type.getBallType()).build();
ServerRequest serverRequest = new ServerRequest(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pokegoapi/api/player/PlayerProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void updateProfile() throws LoginFailedException, RemoteServerException {
creationTime = playerResponse.getPlayerData().getCreationTimestampMs();
itemStorage = playerResponse.getPlayerData().getMaxItemStorage();
pokemonStorage = playerResponse.getPlayerData().getMaxPokemonStorage();
team = Team.values()[playerResponse.getPlayerData().getTeam()];
team = Team.values()[playerResponse.getPlayerData().getTeamValue()];
username = playerResponse.getPlayerData().getUsername();

final PlayerAvatar avatarApi = new PlayerAvatar();
Expand Down
39 changes: 34 additions & 5 deletions src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
package com.pokegoapi.api.pokemon;

import POGOProtos.Data.PokemonDataOuterClass.PokemonData;
import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse;

import com.pokegoapi.api.PokemonGo;
import com.pokegoapi.api.inventory.EggIncubator;
import com.pokegoapi.exceptions.LoginFailedException;
import com.pokegoapi.exceptions.RemoteServerException;

import lombok.Setter;

/**
Expand All @@ -30,20 +36,39 @@ public class EggPokemon {
private PokemonData proto;

// API METHODS //
/**
* Incubate this egg.
*
* @param incubator : the incubator
* @return status of putting egg in incubator
* @throws LoginFailedException e
* @throws RemoteServerException e
*/
public UseItemEggIncubatorResponse.Result incubate(EggIncubator incubator)
throws LoginFailedException, RemoteServerException {
if (incubator.isInUse()) {
throw new IllegalArgumentException("Incubator already used");
}
return incubator.hatchEgg(this);
}

// DELEGATE METHODS BELOW //
/**
* Build a EggPokemon wrapper from the proto.
*
* @param proto : the prototype
*/
public EggPokemon(PokemonData proto) {
if (!proto.getIsEgg()) {
throw new IllegalArgumentException("You cant build a EggPokemon without a valid PokemonData.");
}
this.proto = proto;
}

public long getId() {
return proto.getId();
}

public boolean getIsEgg() {
return proto.getIsEgg();
}


public double getEggKmWalkedTarget() {
return proto.getEggKmWalkedTarget();
}
Expand All @@ -63,6 +88,10 @@ public long getCreationTimeMs() {
public String getEggIncubatorId() {
return proto.getEggIncubatorId();
}

public boolean isIncubate() {
return proto.getEggIncubatorId().length() > 0;
}

@Override
public int hashCode() {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/pokegoapi/api/pokemon/HatchedEgg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.pokegoapi.api.pokemon;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class HatchedEgg {

private Long id;
private int experience;
private int candy;
private int stardust;
}
3 changes: 1 addition & 2 deletions src/main/java/com/pokegoapi/api/pokemon/Pokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId;
import POGOProtos.Enums.PokemonIdOuterClass;
import POGOProtos.Enums.PokemonMoveOuterClass;
import POGOProtos.Inventory.Item.ItemIdOuterClass;
import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId;
import POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage;
import POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage;
Expand Down Expand Up @@ -190,7 +189,7 @@ public PokemonMoveOuterClass.PokemonMove getMove2() {
return proto.getMove2();
}

public int getDeployedFortId() {
public String getDeployedFortId() {
return proto.getDeployedFortId();
}

Expand Down

0 comments on commit 80c8052

Please sign in to comment.