15
15
16
16
package com .pokegoapi .api .gym ;
17
17
18
- import POGOProtos .Data .Gym .GymMembershipOuterClass . GymMembership ;
18
+ import POGOProtos .Data .Gym .GymDefenderOuterClass . GymDefender ;
19
19
import POGOProtos .Data .Gym .GymStateOuterClass .GymState ;
20
- import POGOProtos .Data .PokemonDataOuterClass .PokemonData ;
21
20
import POGOProtos .Enums .PokemonIdOuterClass ;
22
21
import POGOProtos .Enums .TeamColorOuterClass ;
23
22
import POGOProtos .Enums .TutorialStateOuterClass .TutorialState ;
24
23
import POGOProtos .Map .Fort .FortDataOuterClass .FortData ;
24
+ import POGOProtos .Map .Pokemon .MotivatedPokemonOuterClass .MotivatedPokemon ;
25
25
import POGOProtos .Networking .Requests .Messages .FortDeployPokemonMessageOuterClass .FortDeployPokemonMessage ;
26
- import POGOProtos .Networking .Requests .Messages .GetGymDetailsMessageOuterClass . GetGymDetailsMessage ;
26
+ import POGOProtos .Networking .Requests .Messages .GymGetInfoMessageOuterClass . GymGetInfoMessage ;
27
27
import POGOProtos .Networking .Requests .RequestTypeOuterClass .RequestType ;
28
28
import POGOProtos .Networking .Responses .FortDeployPokemonResponseOuterClass .FortDeployPokemonResponse ;
29
- import POGOProtos .Networking .Responses .GetGymDetailsResponseOuterClass .GetGymDetailsResponse ;
29
+ import POGOProtos .Networking .Responses .GymGetInfoResponseOuterClass .GymGetInfoResponse ;
30
+
30
31
import com .google .protobuf .ByteString ;
31
32
import com .google .protobuf .InvalidProtocolBufferException ;
32
- import com .google .protobuf .ProtocolStringList ;
33
33
import com .pokegoapi .api .PokemonGo ;
34
+ import com .pokegoapi .api .map .fort .Fort ;
34
35
import com .pokegoapi .api .pokemon .Pokemon ;
35
36
import com .pokegoapi .exceptions .InsufficientLevelException ;
36
37
import com .pokegoapi .exceptions .request .RequestFailedException ;
43
44
import java .util .ArrayList ;
44
45
import java .util .List ;
45
46
46
- public class Gym implements MapPoint {
47
- private FortData proto ;
48
- private GetGymDetailsResponse details ;
49
- private PokemonGo api ;
47
+ public class Gym extends Fort implements MapPoint {
48
+ private GymGetInfoResponse details ;
50
49
private long points ;
51
50
52
51
/**
@@ -56,47 +55,31 @@ public class Gym implements MapPoint {
56
55
* @param proto The FortData to populate the Gym with.
57
56
*/
58
57
public Gym (PokemonGo api , FortData proto ) {
59
- this .api = api ;
60
- this .proto = proto ;
61
- this .points = proto .getGymPoints ();
62
- }
63
-
64
- public String getId () {
65
- return proto .getId ();
66
- }
67
-
68
- @ Override
69
- public double getLatitude () {
70
- return proto .getLatitude ();
71
- }
72
-
73
- @ Override
74
- public double getLongitude () {
75
- return proto .getLongitude ();
76
- }
58
+ super (api , proto );
59
+ }
77
60
78
61
public boolean getEnabled () {
79
- return proto .getEnabled ();
62
+ return getFortData () .getEnabled ();
80
63
}
81
64
82
65
public TeamColorOuterClass .TeamColor getOwnedByTeam () {
83
- return proto .getOwnedByTeam ();
66
+ return getFortData () .getOwnedByTeam ();
84
67
}
85
68
86
69
public PokemonIdOuterClass .PokemonId getGuardPokemonId () {
87
- return proto .getGuardPokemonId ();
70
+ return getFortData () .getGuardPokemonId ();
88
71
}
89
72
90
73
public int getGuardPokemonCp () {
91
- return proto .getGuardPokemonCp ();
74
+ return getFortData () .getGuardPokemonCp ();
92
75
}
93
76
94
77
public long getPoints () {
95
78
return points ;
96
79
}
97
80
98
81
public boolean getIsInBattle () {
99
- return proto .getIsInBattle ();
82
+ return getFortData () .getIsInBattle ();
100
83
}
101
84
102
85
public boolean isAttackable () throws RequestFailedException {
@@ -109,11 +92,11 @@ public boolean isAttackable() throws RequestFailedException {
109
92
* @return the battle object
110
93
*/
111
94
public Battle battle () {
112
- int minimumPlayerLevel = api .getItemTemplates ().getBattleSettings ().getMinimumPlayerLevel ();
113
- if (api .getPlayerProfile ().getLevel () < minimumPlayerLevel ) {
95
+ int minimumPlayerLevel = getApi () .getItemTemplates ().getBattleSettings ().getMinimumPlayerLevel ();
96
+ if (getApi () .getPlayerProfile ().getLevel () < minimumPlayerLevel ) {
114
97
throw new InsufficientLevelException ("You must be at least " + minimumPlayerLevel + " to battle a gym!" );
115
98
}
116
- return new Battle (api , this );
99
+ return new Battle (getApi () , this );
117
100
}
118
101
119
102
/**
@@ -124,60 +107,42 @@ public void clearDetails() {
124
107
details = null ;
125
108
}
126
109
127
- private GetGymDetailsResponse details () throws RequestFailedException {
128
- List <TutorialState > tutorialStates = api .getPlayerProfile ().getTutorialState ().getTutorialStates ();
110
+ private GymGetInfoResponse details () throws RequestFailedException {
111
+ List <TutorialState > tutorialStates = getApi () .getPlayerProfile ().getTutorialState ().getTutorialStates ();
129
112
if (!tutorialStates .contains (TutorialState .GYM_TUTORIAL )) {
130
- api .getPlayerProfile ().visitGymComplete ();
113
+ getApi () .getPlayerProfile ().visitGymComplete ();
131
114
}
132
115
133
116
if (details == null ) {
134
- GetGymDetailsMessage reqMsg = GetGymDetailsMessage
117
+ GymGetInfoMessage reqMsg = GymGetInfoMessage
135
118
.newBuilder ()
136
119
.setGymId (this .getId ())
137
- .setGymLatitude (this .getLatitude ())
138
- .setGymLongitude (this .getLongitude ())
139
- .setPlayerLatitude ( api .getLatitude ())
140
- .setPlayerLongitude ( api .getLongitude ())
120
+ .setGymLatDegrees (this .getLatitude ())
121
+ .setGymLngDegrees (this .getLongitude ())
122
+ .setPlayerLatDegrees ( getApi () .getLatitude ())
123
+ .setPlayerLngDegrees ( getApi () .getLongitude ())
141
124
.build ();
142
125
143
- ServerRequest serverRequest = new ServerRequest (RequestType .GET_GYM_DETAILS , reqMsg );
144
- api .getRequestHandler ().sendServerRequests (serverRequest , true );
126
+ ServerRequest serverRequest = new ServerRequest (RequestType .GYM_GET_INFO , reqMsg );
127
+ getApi () .getRequestHandler ().sendServerRequests (serverRequest , true );
145
128
146
129
try {
147
- details = GetGymDetailsResponse .parseFrom (serverRequest .getData ());
130
+ details = GymGetInfoResponse .parseFrom (serverRequest .getData ());
148
131
} catch (InvalidProtocolBufferException e ) {
149
132
throw new RequestFailedException ();
150
133
}
151
134
}
152
135
153
136
return details ;
154
137
}
155
-
156
- public String getName () throws RequestFailedException {
157
- return details ().getName ();
158
- }
159
-
160
- public ProtocolStringList getUrlsList () throws RequestFailedException {
161
- return details ().getUrlsList ();
162
- }
163
-
164
- public GetGymDetailsResponse .Result getResult () throws RequestFailedException {
138
+
139
+ public GymGetInfoResponse .Result getResult () throws RequestFailedException {
165
140
return details ().getResult ();
166
141
}
167
-
168
- public boolean inRange () throws RequestFailedException {
169
- GetGymDetailsResponse .Result result = getResult ();
170
- return (result != GetGymDetailsResponse .Result .ERROR_NOT_IN_RANGE );
171
- }
172
-
173
- public String getDescription () throws RequestFailedException {
174
- return details ().getDescription ();
175
- }
176
-
177
-
178
- public List <GymMembership > getGymMembers ()
142
+
143
+ public List <GymDefender > getGymMembers ()
179
144
throws RequestFailedException {
180
- return details ().getGymState ().getMembershipsList ();
145
+ return details ().getGymStatusAndDefenders ().getGymDefenderList ();
181
146
}
182
147
183
148
/**
@@ -186,11 +151,11 @@ public List<GymMembership> getGymMembers()
186
151
* @return List of pokemon
187
152
* @throws RequestFailedException if an exception occurred while sending requests
188
153
*/
189
- public List <PokemonData > getDefendingPokemon () throws RequestFailedException {
190
- List <PokemonData > data = new ArrayList <PokemonData >();
154
+ public List <MotivatedPokemon > getDefendingPokemon () throws RequestFailedException {
155
+ List <MotivatedPokemon > data = new ArrayList <MotivatedPokemon >();
191
156
192
- for (GymMembership gymMember : getGymMembers ()) {
193
- data .add (gymMember .getPokemonData ());
157
+ for (GymDefender gymMember : getGymMembers ()) {
158
+ data .add (gymMember .getMotivatedPokemon ());
194
159
}
195
160
196
161
return data ;
@@ -206,13 +171,13 @@ public List<PokemonData> getDefendingPokemon() throws RequestFailedException {
206
171
public FortDeployPokemonResponse .Result deployPokemon (Pokemon pokemon ) throws RequestFailedException {
207
172
FortDeployPokemonMessage reqMsg = FortDeployPokemonMessage .newBuilder ()
208
173
.setFortId (getId ())
209
- .setPlayerLatitude (api .getLatitude ())
210
- .setPlayerLongitude (api .getLongitude ())
174
+ .setPlayerLatitude (getApi () .getLatitude ())
175
+ .setPlayerLongitude (getApi () .getLongitude ())
211
176
.setPokemonId (pokemon .getId ())
212
177
.build ();
213
178
214
179
ServerRequest serverRequest = new ServerRequest (RequestType .FORT_DEPLOY_POKEMON , reqMsg );
215
- api .getRequestHandler ().sendServerRequests (serverRequest , true );
180
+ getApi () .getRequestHandler ().sendServerRequests (serverRequest , true );
216
181
217
182
try {
218
183
return FortDeployPokemonResponse .parseFrom (serverRequest .getData ()).getResult ();
@@ -233,13 +198,13 @@ public Observable<FortDeployPokemonResponse.Result> deployPokemonAsync(Pokemon p
233
198
throws RequestFailedException {
234
199
FortDeployPokemonMessage reqMsg = FortDeployPokemonMessage .newBuilder ()
235
200
.setFortId (getId ())
236
- .setPlayerLatitude (api .getLatitude ())
237
- .setPlayerLongitude (api .getLongitude ())
201
+ .setPlayerLatitude (getApi () .getLatitude ())
202
+ .setPlayerLongitude (getApi () .getLongitude ())
238
203
.setPokemonId (pokemon .getId ())
239
204
.build ();
240
205
241
206
ServerRequest asyncServerRequest = new ServerRequest (RequestType .FORT_DEPLOY_POKEMON , reqMsg );
242
- return api .getRequestHandler ()
207
+ return getApi () .getRequestHandler ()
243
208
.sendAsyncServerRequests (asyncServerRequest )
244
209
.map (new Func1 <ByteString , FortDeployPokemonResponse .Result >() {
245
210
@@ -258,10 +223,6 @@ public FortDeployPokemonResponse.Result call(ByteString response) {
258
223
259
224
}
260
225
261
- protected PokemonGo getApi () {
262
- return api ;
263
- }
264
-
265
226
/**
266
227
* Updates this gym's point count by the given delta
267
228
*
@@ -277,7 +238,7 @@ public void updatePoints(int delta) {
277
238
* @param state the state to update from
278
239
*/
279
240
public void updateState (GymState state ) {
280
- proto = state .getFortData ();
241
+ setFortData ( state .getFortData () );
281
242
clearDetails ();
282
243
}
283
244
0 commit comments