12
12
import com .pokegoapi .exceptions .RemoteServerException ;
13
13
import com .pokegoapi .google .common .geometry .S2LatLng ;
14
14
import com .pokegoapi .main .ServerRequest ;
15
+ import lombok .Getter ;
15
16
16
17
/**
17
18
* Created by mjmfighter on 7/20/2016.
@@ -20,17 +21,25 @@ public class Pokestop {
20
21
21
22
private final PokemonGo api ;
22
23
private final FortDataOuterClass .FortData fortData ;
24
+ @ Getter
25
+ private long cooldownCompleteTimestampMs ;
26
+
23
27
24
28
public Pokestop (PokemonGo api , FortDataOuterClass .FortData fortData ) {
25
29
this .api = api ;
26
30
this .fortData = fortData ;
31
+ this .cooldownCompleteTimestampMs = fortData .getCooldownCompleteTimestampMs ();
27
32
}
28
33
29
34
public boolean canLoot () {
35
+ return canLoot (false );
36
+ }
37
+
38
+ public boolean canLoot (boolean ignoreDistance ) {
30
39
S2LatLng pokestop = S2LatLng .fromDegrees (getLatitude (), getLongitude ());
31
40
S2LatLng player = S2LatLng .fromDegrees (api .getLatitude (), api .getLongitude ());
32
41
double distance = pokestop .getEarthDistance (player );
33
- return distance < 30 && fortData . getCooldownCompleteTimestampMs () < System .currentTimeMillis ();
42
+ return ( ignoreDistance || distance < 30 ) && cooldownCompleteTimestampMs < System .currentTimeMillis ();
34
43
}
35
44
36
45
public String getId () {
@@ -64,12 +73,13 @@ public PokestopLootResult loot() throws LoginFailedException, RemoteServerExcept
64
73
ServerRequest serverRequest = new ServerRequest (RequestTypeOuterClass .RequestType .FORT_SEARCH , searchMessage );
65
74
api .getRequestHandler ().request (serverRequest );
66
75
api .getRequestHandler ().sendServerRequests ();
67
- FortSearchResponseOuterClass .FortSearchResponse response = null ;
76
+ FortSearchResponseOuterClass .FortSearchResponse response ;
68
77
try {
69
78
response = FortSearchResponseOuterClass .FortSearchResponse .parseFrom (serverRequest .getData ());
70
79
} catch (InvalidProtocolBufferException e ) {
71
- e . printStackTrace ( );
80
+ throw new RemoteServerException ( e );
72
81
}
82
+ cooldownCompleteTimestampMs = response .getCooldownCompleteTimestampMs ();
73
83
return new PokestopLootResult (response );
74
84
}
75
85
0 commit comments