Skip to content

Commit 800e16f

Browse files
ramarro123Grover-c13
authored andcommitted
settings via DownloadSettings + protobuf update (#285)
* inizio pozioni pokemon * inizio pozioni pokemon * fixed space * checkstyle fixes * refresh pokemon stamina after heal/revive * add support for settings * add support for settings
1 parent 85d0304 commit 800e16f

File tree

8 files changed

+225
-5
lines changed

8 files changed

+225
-5
lines changed

src/main/java/com/pokegoapi/api/PokemonGo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.pokegoapi.api.inventory.Inventories;
2020
import com.pokegoapi.api.map.Map;
2121
import com.pokegoapi.api.player.PlayerProfile;
22+
import com.pokegoapi.api.settings.Settings;
2223
import com.pokegoapi.auth.CredentialProvider;
2324
import com.pokegoapi.exceptions.LoginFailedException;
2425
import com.pokegoapi.exceptions.RemoteServerException;
@@ -53,6 +54,8 @@ public class PokemonGo {
5354
@Setter
5455
private double altitude;
5556
private CredentialProvider credentialProvider;
57+
@Getter
58+
private Settings settings;
5659

5760
private RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo authInfo;
5861

@@ -81,6 +84,7 @@ public PokemonGo(CredentialProvider credentialProvider, OkHttpClient client, Tim
8184
requestHandler = new RequestHandler(this, client);
8285
playerProfile = new PlayerProfile(this);
8386
inventories = new Inventories(this);
87+
settings = new Settings(this);
8488

8589
playerProfile.updateProfile();
8690
inventories.updateInventories();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException,
136136
}
137137

138138
// candyjar
139-
if (itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED
140-
&& itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) {
139+
if (itemData.getCandy().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED
140+
&& itemData.getCandy().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) {
141141
candyjar.setCandy(
142-
itemData.getPokemonFamily().getFamilyId(),
143-
itemData.getPokemonFamily().getCandy()
142+
itemData.getCandy().getFamilyId(),
143+
itemData.getCandy().getCandy()
144144
);
145145
}
146146
// player stats
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.pokegoapi.api.settings;
2+
3+
import POGOProtos.Settings.FortSettingsOuterClass;
4+
5+
/**
6+
* Created by rama on 27/07/16.
7+
*/
8+
public class FortSettings {
9+
//TODO: parse & save data
10+
public void update(POGOProtos.Settings.FortSettingsOuterClass.FortSettings fortSettings) {
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.pokegoapi.api.settings;
2+
3+
import POGOProtos.Settings.InventorySettingsOuterClass;
4+
5+
/**
6+
* Created by rama on 27/07/16.
7+
*/
8+
public class InventorySettings {
9+
//TODO: parse & save data
10+
protected void update(POGOProtos.Settings.InventorySettingsOuterClass.InventorySettings inventorySettings) {
11+
12+
}
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.pokegoapi.api.settings;
2+
3+
import POGOProtos.Settings.InventorySettingsOuterClass;
4+
import POGOProtos.Settings.MapSettingsOuterClass;
5+
6+
/**
7+
* Created by rama on 27/07/16.
8+
*/
9+
public class LevelUpSettings {
10+
//TODO: parse & save data
11+
protected void update(InventorySettingsOuterClass.InventorySettings mapSettings) {
12+
13+
}
14+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.pokegoapi.api.settings;
2+
3+
import POGOProtos.Settings.MapSettingsOuterClass;
4+
import lombok.Getter;
5+
6+
/**
7+
* Created by rama on 27/07/16.
8+
*/
9+
public class MapSettings {
10+
11+
@Getter
12+
/**
13+
* Google api key used for display map
14+
*
15+
* @return String.
16+
*/
17+
private String googleApiKey;
18+
19+
@Getter
20+
/**
21+
* Minimum distance between getMapObjects requests
22+
*
23+
* @return distance in meters.
24+
*/
25+
private float minMapObjectDistance;
26+
27+
@Getter
28+
/**
29+
* Max refresh betweewn getMapObjecs requests
30+
*
31+
* @return value in milliseconds.
32+
*/
33+
private float maxRefresh;
34+
35+
@Getter
36+
/**
37+
* Min refresh betweewn getMapObjecs requests
38+
*
39+
* @return value in milliseconds.
40+
*/
41+
private float minRefresh;
42+
43+
@Getter
44+
/**
45+
* NOT SURE: the max distance for encounter pokemon?
46+
*
47+
* @return distance in meters.
48+
*/
49+
private double encoungerRange;
50+
51+
@Getter
52+
/**
53+
* NOT SURE: the max distance before show pokemon on map?
54+
*
55+
* @return distance in meters.
56+
*/
57+
private double pokemonVisibilityRange;
58+
59+
@Getter
60+
/**
61+
* NO IDEA
62+
*
63+
* @return distance in meters.
64+
*/
65+
private double pokeNavRange;
66+
67+
protected void update(MapSettingsOuterClass.MapSettings mapSettings) {
68+
googleApiKey = mapSettings.getGoogleMapsApiKey();
69+
minMapObjectDistance = mapSettings.getGetMapObjectsMinDistanceMeters();
70+
maxRefresh = mapSettings.getGetMapObjectsMaxRefreshSeconds() * 1000;
71+
minRefresh = mapSettings.getGetMapObjectsMinRefreshSeconds() * 1000;
72+
encoungerRange = mapSettings.getEncounterRangeMeters();
73+
pokemonVisibilityRange = mapSettings.getPokemonVisibleRange();
74+
pokeNavRange = mapSettings.getPokeNavRangeMeters();
75+
76+
}
77+
78+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.pokegoapi.api.settings;
2+
3+
import POGOProtos.Data.Player.CurrencyOuterClass;
4+
import POGOProtos.Networking.Requests.Messages.DownloadSettingsMessageOuterClass;
5+
import POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass;
6+
import POGOProtos.Networking.Requests.RequestTypeOuterClass;
7+
import POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass;
8+
import POGOProtos.Networking.Responses.GetPlayerResponseOuterClass;
9+
import com.google.protobuf.InvalidProtocolBufferException;
10+
import com.pokegoapi.api.PokemonGo;
11+
import com.pokegoapi.exceptions.InvalidCurrencyException;
12+
import com.pokegoapi.exceptions.LoginFailedException;
13+
import com.pokegoapi.exceptions.RemoteServerException;
14+
import com.pokegoapi.main.ServerRequest;
15+
import com.pokegoapi.util.Log;
16+
import lombok.Getter;
17+
18+
/**
19+
* Created by rama on 27/07/16.
20+
*/
21+
public class Settings {
22+
23+
private final PokemonGo api;
24+
25+
26+
@Getter
27+
/**
28+
* Settings for various parameters on map
29+
*
30+
* @return MapSettings instance.
31+
*/
32+
private final MapSettings mapSettings;
33+
34+
@Getter
35+
/**
36+
* Settings for various parameters during levelup
37+
*
38+
* @return LevelUpSettings instance.
39+
*/
40+
private final LevelUpSettings levelUpSettings;
41+
42+
@Getter
43+
/**
44+
* Settings for various parameters during levelup
45+
*
46+
* @return LevelUpSettings instance.
47+
*/
48+
private final FortSettings fortSettings;
49+
50+
51+
@Getter
52+
/**
53+
* Settings for various parameters during levelup
54+
*
55+
* @return LevelUpSettings instance.
56+
*/
57+
private final InventorySettings inventorySettings;
58+
59+
60+
/**
61+
* Settings object that hold different configuration aspect of the game.
62+
* Can be used to simulate the real app behaviour.
63+
*/
64+
public Settings(PokemonGo api) throws LoginFailedException, RemoteServerException {
65+
this.api = api;
66+
this.mapSettings = new MapSettings();
67+
this.levelUpSettings = new LevelUpSettings();
68+
this.fortSettings = new FortSettings();
69+
this.inventorySettings = new InventorySettings();
70+
updateSettings();
71+
}
72+
73+
/**
74+
* Updates settings latest data.
75+
*
76+
* @throws LoginFailedException the login failed exception
77+
* @throws RemoteServerException the remote server exception
78+
*/
79+
public void updateSettings() throws RemoteServerException, LoginFailedException {
80+
DownloadSettingsMessageOuterClass.DownloadSettingsMessage msg =
81+
DownloadSettingsMessageOuterClass.DownloadSettingsMessage.newBuilder().build();
82+
ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.DOWNLOAD_SETTINGS, msg);
83+
api.getRequestHandler().sendServerRequests(serverRequest); //here you marked everything as read
84+
DownloadSettingsResponseOuterClass.DownloadSettingsResponse response;
85+
try {
86+
response = DownloadSettingsResponseOuterClass.DownloadSettingsResponse.parseFrom(serverRequest.getData());
87+
} catch (InvalidProtocolBufferException e) {
88+
throw new RemoteServerException(e);
89+
}
90+
91+
mapSettings.update(response.getSettings().getMapSettings());
92+
levelUpSettings.update(response.getSettings().getInventorySettings());
93+
fortSettings.update(response.getSettings().getFortSettings());
94+
inventorySettings.update(response.getSettings().getInventorySettings());
95+
96+
}
97+
98+
99+
}

0 commit comments

Comments
 (0)