Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add Fort Search and Catch Pokemon functionality #46

Merged
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
2 changes: 1 addition & 1 deletion src/main/java/com/pokegoapi/api/PokemonGo.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public PlayerProfile getPlayerProfile() {
return playerProfile;
}

playerProfile = new PlayerProfile();

LocalPlayerOuterClass.LocalPlayer localPlayer = getLocalPlayer();

if (localPlayer == null) {
return null;
}
playerProfile = new PlayerProfile();

playerProfile.setBadge(localPlayer.getEquippedBadge());
playerProfile.setCreationTime(localPlayer.getCreationTimestampMs());
Expand Down
50 changes: 49 additions & 1 deletion src/main/java/com/pokegoapi/api/map/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
import POGOProtos.Map.Fort.FortDataOuterClass;
import POGOProtos.Map.Fort.FortTypeOuterClass;
import POGOProtos.Map.MapCellOuterClass;
import POGOProtos.Map.Pokemon.MapPokemonOuterClass;
import POGOProtos.Networking.Requests.Messages.CatchPokemonMessageOuterClass;
import POGOProtos.Networking.Requests.Messages.FortDetailsMessageOuterClass;
import POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass;
import POGOProtos.Networking.Requests.Messages.GetMapObjectsMessageOuterClass;
import POGOProtos.Networking.Requests.RequestTypeOuterClass;
import POGOProtos.Networking.Responses.CatchPokemonResponseOuterClass;
import POGOProtos.Networking.Responses.FortDetailsResponseOuterClass;
import POGOProtos.Networking.Responses.FortSearchResponseOuterClass;
import POGOProtos.Networking.Responses.GetMapObjectsResponseOuterClass;
import com.google.protobuf.InvalidProtocolBufferException;
import com.pokegoapi.api.PokemonGo;
import com.pokegoapi.api.player.FortDetails;
import com.pokegoapi.api.map.fort.FortDetails;
import com.pokegoapi.google.common.geometry.MutableInteger;
import com.pokegoapi.google.common.geometry.S2CellId;
import com.pokegoapi.google.common.geometry.S2LatLng;
Expand Down Expand Up @@ -163,4 +169,46 @@ public FortDetails getFortDetails(String id, long lon, long lat) {
return null;
}
}

public FortSearchResponseOuterClass.FortSearchResponse searchFort(FortDataOuterClass.FortData fortData) {
FortSearchMessageOuterClass.FortSearchMessage reqMsg = FortSearchMessageOuterClass.FortSearchMessage.newBuilder()
.setFortId(fortData.getId())
.setFortLatitude(fortData.getLatitude())
.setFortLongitude(fortData.getLongitude())
.setPlayerLatitude(api.getLatitude())
.setPlayerLongitude(api.getLongitude())
.build();
ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_SEARCH, reqMsg);
api.getRequestHandler().request(serverRequest);
api.getRequestHandler().sendServerRequests();
FortSearchResponseOuterClass.FortSearchResponse response = null;
try {
response = FortSearchResponseOuterClass.FortSearchResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
return response;
}

public CatchPokemonResponseOuterClass.CatchPokemonResponse catchPokemon(MapPokemonOuterClass.MapPokemon catchablePokemon, double normalizedHitPosition, double normalizedReticleSize, double spinModifier, int pokeball) {
CatchPokemonMessageOuterClass.CatchPokemonMessage reqMsg = CatchPokemonMessageOuterClass.CatchPokemonMessage.newBuilder()
.setEncounterId(catchablePokemon.getEncounterId())
.setHitPokemon(true)
.setNormalizedHitPosition(normalizedHitPosition)
.setNormalizedReticleSize(normalizedReticleSize)
.setSpawnPointGuid(catchablePokemon.getSpawnpointId())
.setSpinModifier(spinModifier)
.setPokeball(pokeball)
.build();
ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.CATCH_POKEMON, reqMsg);
api.getRequestHandler().request(serverRequest);
api.getRequestHandler().sendServerRequests();
CatchPokemonResponseOuterClass.CatchPokemonResponse response = null;
try {
response = CatchPokemonResponseOuterClass.CatchPokemonResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
return response;
}
}
14 changes: 7 additions & 7 deletions src/main/java/com/pokegoapi/api/map/MapObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,55 +27,55 @@ public void addNearbyPokemons(Collection<NearbyPokemonOuterClass.NearbyPokemon>
return;
}
complete = true;
nearbyPokemons.addAll(nearbyPokemons);
this.nearbyPokemons.addAll(nearbyPokemons);
}

public void addCatchablePokemons(Collection<MapPokemonOuterClass.MapPokemon> catchablePokemons) {
if (catchablePokemons == null || catchablePokemons.isEmpty()) {
return;
}
complete = true;
catchablePokemons.addAll(catchablePokemons);
this.catchablePokemons.addAll(catchablePokemons);
}

public void addWildPokemons(Collection<WildPokemonOuterClass.WildPokemon> wildPokemons) {
if (wildPokemons == null || wildPokemons.isEmpty()) {
return;
}
complete = true;
wildPokemons.addAll(wildPokemons);
this.wildPokemons.addAll(wildPokemons);
}

public void addDecimatedSpawnPoints(Collection<SpawnPointOuterClass.SpawnPoint> decimatedSpawnPoints) {
if (decimatedSpawnPoints == null || decimatedSpawnPoints.isEmpty()) {
return;
}
complete = true;
decimatedSpawnPoints.addAll(decimatedSpawnPoints);
this.decimatedSpawnPoints.addAll(decimatedSpawnPoints);
}

public void addSpawnPoints(Collection<SpawnPointOuterClass.SpawnPoint> spawnPoints) {
if (spawnPoints == null || spawnPoints.isEmpty()) {
return;
}
complete = true;
spawnPoints.addAll(spawnPoints);
this.spawnPoints.addAll(spawnPoints);
}

public void addGyms(Collection<FortDataOuterClass.FortData> gyms) {
if (gyms == null || gyms.isEmpty()) {
return;
}
complete = true;
gyms.addAll(gyms);
this.gyms.addAll(gyms);
}

public void addPokestops(Collection<FortDataOuterClass.FortData> pokestops) {
if (pokestops == null || pokestops.isEmpty()) {
return;
}
complete = true;
pokestops.addAll(pokestops);
this.pokestops.addAll(pokestops);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pokegoapi.api.player;
package com.pokegoapi.api.map.fort;

import POGOProtos.Enums.TeamColorOuterClass;
import POGOProtos.Map.Fort.FortModifierOuterClass;
Expand Down