use of com.pokegoapi.api.map.pokemon.CatchablePokemon in project Pokemap by omkarmoghe.
the class NianticManager method getLuredPokemon.
public void getLuredPokemon(final double lat, final double longitude, final double alt) {
final int myCurrentBatch = this.currentBatchCall;
mHandler.post(new Runnable() {
@Override
public void run() {
try {
if (mPokemonGo != null && NianticManager.this.currentBatchCall == myCurrentBatch) {
Thread.sleep(133);
mPokemonGo.setLocation(lat, longitude, alt);
Thread.sleep(133);
List<CatchablePokemon> pokemon = new ArrayList<>();
for (Pokestop pokestop : mPokemonGo.getMap().getMapObjects().getPokestops()) {
if (!pokestop.getFortData().getLureInfo().equals(FortLureInfoOuterClass.FortLureInfo.getDefaultInstance())) {
Log.d(TAG, "run: hasFortInfo = " + pokestop.getFortData().getLureInfo());
pokemon.add(new CatchablePokemon(mPokemonGo, pokestop.getFortData()));
}
}
if (NianticManager.this.currentBatchCall == myCurrentBatch)
EventBus.getDefault().post(new LurePokemonEvent(pokemon, lat, longitude));
}
} catch (LoginFailedException e) {
e.printStackTrace();
Log.e(TAG, "Failed to fetch map information via getPokeStops(). Login credentials wrong or user banned. Raised: " + e.getMessage());
EventBus.getDefault().post(new LoginEventResult(false, null, null));
} catch (RemoteServerException e) {
e.printStackTrace();
Log.e(TAG, "Failed to fetch map information via getPokeStops(). Remote server unreachable. Raised: " + e.getMessage());
EventBus.getDefault().post(new ServerUnreachableEvent(e));
} catch (InterruptedException | RuntimeException e) {
e.printStackTrace();
Log.e(TAG, "Failed to fetch map information via getPokeStops(). PoGoAPI crashed. Raised: " + e.getMessage());
EventBus.getDefault().post(new InternalExceptionEvent(e));
}
}
});
}
use of com.pokegoapi.api.map.pokemon.CatchablePokemon in project Pokemap by omkarmoghe.
the class PokemonNotificationService method onEvent.
@Subscribe
public void onEvent(CatchablePokemonEvent event) {
List<CatchablePokemon> catchablePokemon = event.getCatchablePokemon();
LatLng location = locationManager.getLocation();
Location myLoc = new Location("");
myLoc.setLatitude(location.latitude);
myLoc.setLongitude(location.longitude);
builder.setContentText(getString(R.string.notification_service_pokemon_near, catchablePokemon.size()));
builder.setStyle(null);
if (!catchablePokemon.isEmpty()) {
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(getString(R.string.notification_service_pokemon_in_area, catchablePokemon.size()));
Set<PokemonIdOuterClass.PokemonId> showablePokemonIDs = preffs.getShowablePokemonIDs();
for (CatchablePokemon cp : catchablePokemon) {
//Only show the notification if the Pokemon is in the preference list
if (showablePokemonIDs.contains(cp.getPokemonId())) {
Location pokeLocation = new Location("");
pokeLocation.setLatitude(cp.getLatitude());
pokeLocation.setLongitude(cp.getLongitude());
long remainingTime = cp.getExpirationTimestampMs() - System.currentTimeMillis();
String pokeName = PokemonIdUtils.getLocalePokemonName(getApplicationContext(), cp.getPokemonId().name());
long remTime = TimeUnit.MILLISECONDS.toMinutes(remainingTime);
int dist = (int) Math.ceil(pokeLocation.distanceTo(myLoc));
inboxStyle.addLine(getString(R.string.notification_service_inbox_line, pokeName, remTime, dist));
}
}
builder.setStyle(inboxStyle);
}
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(notificationId, builder.build());
}
use of com.pokegoapi.api.map.pokemon.CatchablePokemon in project Pokemap by omkarmoghe.
the class MapWrapperFragment method setPokemonMarkers.
private void setPokemonMarkers(final List<CatchablePokemon> pokeList) {
int markerSize = getResources().getDimensionPixelSize(R.dimen.pokemon_marker);
if (mGoogleMap != null) {
Set<String> markerKeys = markerList.keySet();
Set<String> futureKeys = futureMarkerList.keySet();
for (final CatchablePokemon poke : pokeList) {
if (futureKeys.contains(poke.getSpawnPointId())) {
if (poke.getExpirationTimestampMs() > 1) {
futureMarkerList.get(poke.getSpawnPointId()).getMarker().remove();
futureKeys.remove(poke.getSpawnPointId());
futureMarkerList.remove(poke.getSpawnPointId());
markerKeys.remove(poke.getSpawnPointId());
markerList.remove(poke.getSpawnPointId());
}
}
if (!markerKeys.contains(poke.getSpawnPointId())) {
// checking if we need to show this pokemon
PokemonIdOuterClass.PokemonId pokemonId = poke.getPokemonId();
if (showablePokemonIDs.contains(pokemonId)) {
RemoteImageLoader.loadMapIcon(getActivity(), "http://serebii.net/pokemongo/pokemon/" + PokemonIdUtils.getCorrectPokemonImageId(pokemonId.getNumber()) + ".png", markerSize, markerSize, new RemoteImageLoader.Callback() {
@Override
public void onFetch(Bitmap bitmap) {
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
//Setting marker since we got image
//int resourceID = getResources().getIdentifier("p" + poke.getPokemonId().getNumber(), "drawable", getActivity().getPackageName());
final Marker marker = mGoogleMap.addMarker(new MarkerOptions().position(new LatLng(poke.getLatitude(), poke.getLongitude())).title(PokemonIdUtils.getLocalePokemonName(getContext(), poke.getPokemonId().name())).icon(bitmapDescriptor).zIndex(MapHelper.LAYER_POKEMONS).anchor(0.5f, 0.5f));
//adding pokemons to list to be removed on next search
PokemonMarkerExtended markerExtended = new PokemonMarkerExtended(poke, marker);
markerList.put(poke.getSpawnPointId(), markerExtended);
MarkerRefreshController.getInstance().postMarker(markerExtended);
}
});
//Increase founded pokemon counter
nianticManager.setPokemonFound(nianticManager.getPokemonFound() + 1);
}
} else if (futureMarkerList.containsKey(poke.getSpawnPointId())) {
if (showablePokemonIDs.contains(poke.getPokemonId())) {
PokemonMarkerExtended futureMarker = futureMarkerList.get(poke.getSpawnPointId());
futureMarkerList.remove(futureMarker);
}
}
}
if (getView() != null) {
if (nianticManager.getCurrentScan() != nianticManager.getPendingSearch()) {
snackMe(getString(R.string.toast_still_searching, nianticManager.getPokemonFound()));
} else {
String text = nianticManager.getPokemonFound() > 0 ? getString(R.string.pokemon_found_new, nianticManager.getPokemonFound()) : getString(R.string.pokemon_found_none);
snackMe(text);
nianticManager.resetSearchCount();
}
}
updateMarkers();
} else {
showMapNotInitializedError();
}
}
use of com.pokegoapi.api.map.pokemon.CatchablePokemon in project Pokemap by omkarmoghe.
the class MapWrapperFragment method updateMarkers.
private void updateMarkers() {
if (mGoogleMap != null) {
if (markerList != null && !markerList.isEmpty()) {
for (Iterator<Map.Entry<String, PokemonMarkerExtended>> pokemonIterator = markerList.entrySet().iterator(); pokemonIterator.hasNext(); ) {
Map.Entry<String, PokemonMarkerExtended> pokemonEntry = pokemonIterator.next();
CatchablePokemon catchablePokemon = pokemonEntry.getValue().getCatchablePokemon();
Marker marker = pokemonEntry.getValue().getMarker();
if (!showablePokemonIDs.contains(catchablePokemon.getPokemonId())) {
marker.remove();
pokemonIterator.remove();
} else {
if (catchablePokemon.getExpirationTimestampMs() == -1) {
futureMarkerList.put(catchablePokemon.getSpawnPointId(), pokemonEntry.getValue());
marker.setAlpha(0.6f);
marker.setSnippet(getString(R.string.pokemon_will_spawn));
continue;
}
long millisLeft = catchablePokemon.getExpirationTimestampMs() - System.currentTimeMillis();
if (millisLeft < 0) {
marker.remove();
pokemonIterator.remove();
} else {
marker.setSnippet(getExpirationBreakdown(millisLeft));
if (marker.isInfoWindowShown()) {
marker.showInfoWindow();
}
}
}
}
}
if (pokestopsList != null && !pokestopsList.isEmpty() && mPref.getShowPokestops()) {
for (Iterator<Map.Entry<String, PokestopMarkerExtended>> pokestopIterator = pokestopsList.entrySet().iterator(); pokestopIterator.hasNext(); ) {
Map.Entry<String, PokestopMarkerExtended> pokestopEntry = pokestopIterator.next();
final Pokestop pokestop = pokestopEntry.getValue().getPokestop();
final Marker marker = pokestopEntry.getValue().getMarker();
int markerSize = getResources().getDimensionPixelSize(R.dimen.pokestop_marker);
RemoteImageLoader.loadMapIcon(getActivity(), pokestop.hasLurePokemon() ? lurePokeStopImageUrl : pokeStopImageUrl, markerSize, markerSize, new RemoteImageLoader.Callback() {
@Override
public void onFetch(Bitmap bitmap) {
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
marker.setIcon(bitmapDescriptor);
marker.setZIndex(pokestop.hasLurePokemon() ? 1.0f : 0.5f);
}
});
}
} else if (pokestopsList != null && !pokestopsList.isEmpty() && !mPref.getShowPokestops()) {
for (Iterator<Map.Entry<String, PokestopMarkerExtended>> pokestopIterator = pokestopsList.entrySet().iterator(); pokestopIterator.hasNext(); ) {
Map.Entry<String, PokestopMarkerExtended> pokestopEntry = pokestopIterator.next();
Marker marker = pokestopEntry.getValue().getMarker();
marker.remove();
pokestopIterator.remove();
}
}
if (gymsList != null && !gymsList.isEmpty() && mPref.getShowGyms()) {
for (Iterator<Map.Entry<String, GymMarkerExtended>> gymIterator = gymsList.entrySet().iterator(); gymIterator.hasNext(); ) {
Map.Entry<String, GymMarkerExtended> gymEntry = gymIterator.next();
final FortDataOuterClass.FortData gym = gymEntry.getValue().getGym();
final Marker marker = gymEntry.getValue().getMarker();
int markerSize = getResources().getDimensionPixelSize(R.dimen.gym_marker);
RemoteImageLoader.loadMapIcon(getActivity(), gymTeamImageUrls.get(gym.getOwnedByTeam().getNumber()), markerSize, markerSize, new RemoteImageLoader.Callback() {
@Override
public void onFetch(Bitmap bitmap) {
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
marker.setIcon(bitmapDescriptor);
}
});
}
} else if (gymsList != null && !gymsList.isEmpty() && !mPref.getShowGyms()) {
for (Iterator<Map.Entry<String, GymMarkerExtended>> gymIterator = gymsList.entrySet().iterator(); gymIterator.hasNext(); ) {
Map.Entry<String, GymMarkerExtended> gymEntry = gymIterator.next();
Marker marker = gymEntry.getValue().getMarker();
marker.remove();
gymIterator.remove();
}
}
if (!mPref.getShowScannedPlaces() && userSelectedPositionCircles != null && !userSelectedPositionCircles.isEmpty()) {
for (Circle circle : userSelectedPositionCircles) {
circle.remove();
}
userSelectedPositionCircles.clear();
}
}
}
use of com.pokegoapi.api.map.pokemon.CatchablePokemon in project PokeGOAPI-Java by Grover-c13.
the class CatchPokemonAtAreaExample method catchArea.
private static void catchArea(PokemonGo api) throws RequestFailedException, NoSuchItemException {
ItemBag bag = api.getInventories().getItemBag();
try {
//Wait until map is updated for the current location
api.getMap().awaitUpdate();
Set<CatchablePokemon> catchablePokemon = api.getMap().getMapObjects().getPokemon();
System.out.println("Pokemon in area: " + catchablePokemon.size());
Random random = new Random();
PokeBank pokebank = api.getInventories().getPokebank();
for (CatchablePokemon cp : catchablePokemon) {
// Encounter this pokemon
Encounter encounter = cp.encounter();
// If the encounter was successful, attempt to catch this pokemon
if (encounter.isSuccessful()) {
System.out.println("Encountered: " + cp.getPokemonId());
List<Pokeball> usablePokeballs = bag.getUsablePokeballs();
if (usablePokeballs.size() > 0) {
//Select pokeball with smart selector to print what pokeball is used
double probability = encounter.getCaptureProbability();
Pokeball pokeball = PokeballSelector.SMART.select(usablePokeballs, probability);
System.out.println("Attempting to catch: " + cp.getPokemonId() + " with " + pokeball + " (" + probability + ")");
// Throw pokeballs until capture or flee
while (encounter.isActive()) {
// Wait between Pokeball throws
Thread.sleep(500 + random.nextInt(1000));
// If no item is active, use a razzberry
int razzberryCount = bag.getItem(ItemId.ITEM_RAZZ_BERRY).getCount();
if (encounter.getActiveItem() == null && razzberryCount > 0) {
encounter.useItem(ItemId.ITEM_RAZZ_BERRY);
}
// Throw pokeball with random properties
encounter.throwPokeball(PokeballSelector.SMART, ThrowProperties.random());
if (encounter.getStatus() == CatchStatus.CATCH_SUCCESS) {
// Print pokemon stats
Pokemon pokemon = pokebank.getPokemonById(encounter.getCapturedPokemon());
if (pokemon != null) {
double iv = pokemon.getIvInPercentage();
int number = pokemon.getPokemonId().getNumber();
String name = PokeDictionary.getDisplayName(number, Locale.ENGLISH);
System.out.println("====" + name + "====");
System.out.println("CP: " + pokemon.getCp());
System.out.println("IV: " + iv + "%");
System.out.println("Height: " + pokemon.getHeightM() + "m");
System.out.println("Weight: " + pokemon.getWeightKg() + "kg");
System.out.println("Move 1: " + pokemon.getMove1());
System.out.println("Move 2: " + pokemon.getMove2());
//Rename the pokemon to <Name> IV%
pokemon.renamePokemon(name + " " + iv + "%");
//Set pokemon with IV above 90% as favorite
if (iv > 90) {
pokemon.setFavoritePokemon(true);
}
}
}
}
} else {
System.out.println("Skipping Pokemon, we have no Pokeballs!");
}
// Wait for animation before catching next pokemon
Thread.sleep(3000 + random.nextInt(1000));
} else {
System.out.println("Failed to encounter pokemon: " + encounter.getEncounterResult());
}
}
} catch (InterruptedException e) {
return;
}
}
Aggregations