1515
1616package com .pokegoapi .api .map .pokemon ;
1717
18- import POGOProtos .Enums .PokemonIdOuterClass ;
18+
19+ import POGOProtos .Enums .PokemonIdOuterClass .PokemonId ;
1920import POGOProtos .Inventory .Item .ItemIdOuterClass .ItemId ;
2021import POGOProtos .Map .Fort .FortDataOuterClass .FortData ;
2122import POGOProtos .Map .Pokemon .MapPokemonOuterClass .MapPokemon ;
2223import POGOProtos .Map .Pokemon .WildPokemonOuterClass .WildPokemon ;
2324import POGOProtos .Networking .Requests .Messages .CatchPokemonMessageOuterClass .CatchPokemonMessage ;
24- import POGOProtos .Networking .Requests .Messages .EncounterMessageOuterClass ;
25+ import POGOProtos .Networking .Requests .Messages .DiskEncounterMessageOuterClass ;
26+ import POGOProtos .Networking .Requests .Messages .DiskEncounterMessageOuterClass .DiskEncounterMessage ;
27+ import POGOProtos .Networking .Requests .Messages .EncounterMessageOuterClass .EncounterMessage ;
2528import POGOProtos .Networking .Requests .Messages .UseItemCaptureMessageOuterClass .UseItemCaptureMessage ;
26- import POGOProtos .Networking .Requests .RequestTypeOuterClass ;
29+ import POGOProtos .Networking .Requests .RequestTypeOuterClass . RequestType ;
2730import POGOProtos .Networking .Responses .CatchPokemonResponseOuterClass .CatchPokemonResponse ;
2831import POGOProtos .Networking .Responses .CatchPokemonResponseOuterClass .CatchPokemonResponse .CatchStatus ;
29- import POGOProtos .Networking .Responses .EncounterResponseOuterClass ;
32+ import POGOProtos .Networking .Responses .DiskEncounterResponseOuterClass . DiskEncounterResponse ;
3033import POGOProtos .Networking .Responses .EncounterResponseOuterClass .EncounterResponse ;
3134import POGOProtos .Networking .Responses .UseItemCaptureResponseOuterClass .UseItemCaptureResponse ;
3235import com .google .protobuf .ByteString ;
3336import com .google .protobuf .InvalidProtocolBufferException ;
3437import com .pokegoapi .api .PokemonGo ;
3538import com .pokegoapi .api .inventory .ItemBag ;
3639import com .pokegoapi .api .inventory .Pokeball ;
40+ import com .pokegoapi .api .map .pokemon .encounter .DiskEncounterResult ;
41+ import com .pokegoapi .api .map .pokemon .encounter .EncounterResult ;
42+ import com .pokegoapi .api .map .pokemon .encounter .NormalEncounterResult ;
3743import com .pokegoapi .exceptions .LoginFailedException ;
3844import com .pokegoapi .exceptions .NoSuchItemException ;
3945import com .pokegoapi .exceptions .RemoteServerException ;
4854
4955import java .util .concurrent .Future ;
5056
57+
5158/**
5259 * The type Catchable pokemon.
5360 */
5461@ ToString
55- public class CatchablePokemon implements MapPoint {
62+ public class CatchablePokemon implements MapPoint {
63+
64+ private enum EncounterKind {
65+ NORMAL ,
66+ DISK ;
67+ }
68+
69+
5670 private static final String TAG = CatchablePokemon .class .getSimpleName ();
5771 private final PokemonGo api ;
5872
@@ -61,16 +75,19 @@ public class CatchablePokemon implements MapPoint{
6175 @ Getter
6276 private final long encounterId ;
6377 @ Getter
64- private final PokemonIdOuterClass . PokemonId pokemonId ;
78+ private final PokemonId pokemonId ;
6579 @ Getter
6680 private final long expirationTimestampMs ;
6781 @ Getter
6882 private final double latitude ;
6983 @ Getter
7084 private final double longitude ;
85+ private final EncounterKind encounterKind ;
7186
7287 private Boolean encountered = null ;
7388
89+
90+
7491 /**
7592 * Instantiates a new Catchable pokemon.
7693 *
@@ -79,7 +96,7 @@ public class CatchablePokemon implements MapPoint{
7996 */
8097 public CatchablePokemon (PokemonGo api , MapPokemon proto ) {
8198 this .api = api ;
82-
99+ this . encounterKind = EncounterKind . NORMAL ;
83100 this .spawnPointId = proto .getSpawnPointId ();
84101 this .encounterId = proto .getEncounterId ();
85102 this .pokemonId = proto .getPokemonId ();
@@ -96,6 +113,7 @@ public CatchablePokemon(PokemonGo api, MapPokemon proto) {
96113 */
97114 public CatchablePokemon (PokemonGo api , WildPokemon proto ) {
98115 this .api = api ;
116+ this .encounterKind = EncounterKind .NORMAL ;
99117 this .spawnPointId = proto .getSpawnPointId ();
100118 this .encounterId = proto .getEncounterId ();
101119 this .pokemonId = proto .getPokemonData ().getPokemonId ();
@@ -116,13 +134,24 @@ public CatchablePokemon(PokemonGo api, FortData proto) {
116134 }
117135 this .api = api ;
118136 // TODO: does this work?
119- this .spawnPointId = null ;
137+ // seems that spawnPoint it's fortId in catchAPI so it should be safe to just set it in that way
138+ this .spawnPointId = proto .getLureInfo ().getFortId ();
120139 this .encounterId = proto .getLureInfo ().getEncounterId ();
121140 this .pokemonId = proto .getLureInfo ().getActivePokemonId ();
122141 this .expirationTimestampMs = proto .getLureInfo ()
123142 .getLureExpiresTimestampMs ();
124143 this .latitude = proto .getLatitude ();
125144 this .longitude = proto .getLongitude ();
145+ this .encounterKind = EncounterKind .DISK ;
146+ }
147+
148+ /**
149+ * Encounter pokemon
150+ *
151+ * @return the encounter result
152+ */
153+ public EncounterResult encounterPokemon () throws LoginFailedException , RemoteServerException {
154+ return encounterPokemonAsync ().toBlocking ();
126155 }
127156
128157 /**
@@ -131,26 +160,41 @@ public CatchablePokemon(PokemonGo api, FortData proto) {
131160 * @return the encounter result
132161 */
133162 public PokemonFuture <EncounterResult > encounterPokemonAsync () {
134- EncounterMessageOuterClass .EncounterMessage reqMsg = EncounterMessageOuterClass .EncounterMessage
163+ if (encounterKind == EncounterKind .NORMAL ) {
164+ return encounterNormalPokemonAsync ();
165+ } else if (encounterKind == EncounterKind .DISK ) {
166+ return encounterDiskPokemonAsync ();
167+ }
168+
169+ throw new IllegalStateException ("Catchable pokemon missing encounter type" );
170+ }
171+
172+ /**
173+ * Encounter pokemon encounter result.
174+ *
175+ * @return the encounter result
176+ */
177+ public PokemonFuture <EncounterResult > encounterNormalPokemonAsync () {
178+ EncounterMessage reqMsg = EncounterMessage
135179 .newBuilder ().setEncounterId (getEncounterId ())
136180 .setPlayerLatitude (api .getLatitude ())
137181 .setPlayerLongitude (api .getLongitude ())
138182 .setSpawnPointId (getSpawnPointId ()).build ();
139183 AsyncServerRequest serverRequest = new AsyncServerRequest (
140- RequestTypeOuterClass . RequestType .ENCOUNTER , reqMsg );
184+ RequestType .ENCOUNTER , reqMsg );
141185 return new FutureWrapper <ByteString , EncounterResult >(api .getRequestHandler ()
142186 .sendAsyncServerRequests (serverRequest )) {
143187 @ Override
144188 protected EncounterResult handle (ByteString result ) throws RemoteServerException {
145- EncounterResponseOuterClass . EncounterResponse response ;
189+ EncounterResponse response ;
146190 try {
147- response = EncounterResponseOuterClass . EncounterResponse
191+ response = EncounterResponse
148192 .parseFrom (result );
149193 } catch (InvalidProtocolBufferException e ) {
150194 throw new RemoteServerException (e );
151195 }
152196 encountered = response .getStatus () == EncounterResponse .Status .ENCOUNTER_SUCCESS ;
153- return new EncounterResult (response );
197+ return new NormalEncounterResult (response );
154198 }
155199 };
156200 }
@@ -162,11 +206,42 @@ protected EncounterResult handle(ByteString result) throws RemoteServerException
162206 * @throws LoginFailedException the login failed exception
163207 * @throws RemoteServerException the remote server exception
164208 */
165- public EncounterResult encounterPokemon () throws LoginFailedException ,
209+ public EncounterResult encounterNormalPokemon () throws LoginFailedException ,
166210 RemoteServerException {
167- return encounterPokemonAsync ().toBlocking ();
211+ return encounterNormalPokemonAsync ().toBlocking ();
212+ }
213+
214+
215+
216+ /**
217+ * Encounter pokemon
218+ *
219+ * @return the encounter result
220+ */
221+ public PokemonFuture <EncounterResult > encounterDiskPokemonAsync () {
222+ DiskEncounterMessage reqMsg = DiskEncounterMessage
223+ .newBuilder ().setEncounterId (getEncounterId ())
224+ .setPlayerLatitude (api .getLatitude ())
225+ .setPlayerLongitude (api .getLongitude ())
226+ .setFortId (getSpawnPointId ()).build ();
227+ AsyncServerRequest serverRequest = new AsyncServerRequest (RequestType .DISK_ENCOUNTER , reqMsg );
228+ return new FutureWrapper <ByteString , EncounterResult >(api .getRequestHandler ()
229+ .sendAsyncServerRequests (serverRequest )) {
230+ @ Override
231+ protected EncounterResult handle (ByteString result ) throws RemoteServerException {
232+ DiskEncounterResponse response ;
233+ try {
234+ response = DiskEncounterResponse .parseFrom (result );
235+ } catch (InvalidProtocolBufferException e ) {
236+ throw new RemoteServerException (e );
237+ }
238+ encountered = response .getResult () == DiskEncounterResponse .Result .SUCCESS ;
239+ return new DiskEncounterResult (response );
240+ }
241+ };
168242 }
169243
244+
170245 /**
171246 * Tries to catch a pokemon (will attempt to use a pokeball, if you have
172247 * none will use greatball etc) and uwill use a single razz berry if available.
@@ -389,11 +464,12 @@ public PokemonFuture<CatchResult> catchPokemonAsync(double normalizedHitPosition
389464 .setSpinModifier (spinModifier )
390465 .setPokeball (type .getBallType ()).build ();
391466 AsyncServerRequest serverRequest = new AsyncServerRequest (
392- RequestTypeOuterClass . RequestType .CATCH_POKEMON , reqMsg );
467+ RequestType .CATCH_POKEMON , reqMsg );
393468 return new FutureWrapper <ByteString , CatchResult >(api .getRequestHandler ()
394469 .sendAsyncServerRequests (serverRequest )) {
395470 @ Override
396471 protected CatchResult handle (ByteString result ) throws RemoteServerException , LoginFailedException {
472+ System .out .println ("ASYNC CATCH CALL" );
397473 CatchPokemonResponse response ;
398474
399475 try {
@@ -439,7 +515,7 @@ public PokemonFuture<CatchItemResult> useItemAsync(ItemId item) {
439515 .build ();
440516
441517 AsyncServerRequest serverRequest = new AsyncServerRequest (
442- RequestTypeOuterClass . RequestType .USE_ITEM_CAPTURE , reqMsg );
518+ RequestType .USE_ITEM_CAPTURE , reqMsg );
443519 return new FutureWrapper <ByteString , CatchItemResult >(api .getRequestHandler ()
444520 .sendAsyncServerRequests (serverRequest )) {
445521 @ Override
0 commit comments