Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API update fixes (i2f etc) and lured pokemon catching #1163

Merged
merged 23 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PokemonGoBot(object):

@property
def position(self):
return (i2f(self.api._position_lat), i2f(self.api._position_lng), 0)
return self.api._position_lat, self.api._position_lng, 0

def __init__(self, config):
self.config = config
Expand Down Expand Up @@ -69,9 +69,9 @@ def process_cells(self, work_on_forts=True):
def update_web_location(self, cells=[], lat=None, lng=None, alt=None):
# we can call the function with no arguments and still get the position and map_cells
if lat == None:
lat = i2f(self.api._position_lat)
lat = self.api._position_lat
if lng == None:
lng = i2f(self.api._position_lng)
lng = self.api._position_lng
if alt == None:
alt = 0

Expand Down Expand Up @@ -272,7 +272,12 @@ def _print_character_info(self):
currency_1 = "0"
currency_2 = "0"

player = response_dict['responses']['GET_PLAYER']['player_data']
if response_dict:
player = response_dict['responses']['GET_PLAYER']['player_data']
else:
logger.log("The API didn't return player info, servers are unstable - retrying.", 'red')
sleep(5)
self._print_character_info()

# @@@ TODO: Convert this to d/m/Y H:M:S
creation_date = datetime.datetime.fromtimestamp(
Expand Down Expand Up @@ -426,7 +431,7 @@ def _set_starting_position(self):
has_position = True
return
except:
logger.log('[x] The location given using -l could not be parsed. Checking for a cached location.')
logger.log('[x] The location given in the config could not be parsed. Checking for a cached location.')
pass

if self.config.location_cache and not has_position:
Expand Down Expand Up @@ -460,20 +465,17 @@ def _set_starting_position(self):
def _get_pos_by_name(self, location_name):
# Check if the given location is already a coordinate.
if ',' in location_name:
possibleCoordinates = re.findall("[-]?\d{1,3}[.]\d{6,7}", location_name)
if len(possibleCoordinates) == 2:
possible_coordinates = re.findall("[-]?\d{1,3}[.]\d{6,7}", location_name)
if len(possible_coordinates) == 2:
# 2 matches, this must be a coordinate. We'll bypass the Google geocode so we keep the exact location.
logger.log(
'[x] Coordinates found in passed in location, not geocoding.')
return (float(possibleCoordinates[0]), float(possibleCoordinates[1]), float("0.0"))
return float(possible_coordinates[0]), float(possible_coordinates[1]), float("0.0")

geolocator = GoogleV3(api_key=self.config.gmapkey)
loc = geolocator.geocode(location_name, timeout=10)

#self.log.info('Your given location: %s', loc.address.encode('utf-8'))
#self.log.info('lat/long/alt: %s %s %s', loc.latitude, loc.longitude, loc.altitude)

return (loc.latitude, loc.longitude, loc.altitude)
return float(loc.latitude), float(loc.longitude), float(loc.altitude)

def heartbeat(self):
# Remove forts that we can now spin again.
Expand Down
60 changes: 44 additions & 16 deletions pokemongo_bot/cell_workers/pokemon_catch_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,38 @@ def __init__(self, pokemon, bot):
self.pokemon_list = bot.pokemon_list
self.item_list = bot.item_list
self.inventory = bot.inventory
self.spawn_point_guid = ''
self.response_key = ''
self.response_status_key = ''

def work(self):

encounter_id = self.pokemon['encounter_id']
spawnpoint_id = self.pokemon['spawnpoint_id']
player_latitude = self.pokemon['latitude']
player_longitude = self.pokemon['longitude']
self.api.encounter(encounter_id=encounter_id, spawnpoint_id=spawnpoint_id,
player_latitude=player_latitude, player_longitude=player_longitude)
response_dict = self.api.call()

response_dict = self.create_encounter_api_call()

if response_dict and 'responses' in response_dict:
if 'ENCOUNTER' in response_dict['responses']:
if 'status' in response_dict['responses']['ENCOUNTER']:
if response_dict['responses']['ENCOUNTER']['status'] is 7:
if self.response_key in response_dict['responses']:
if self.response_status_key in response_dict['responses'][self.response_key]:
if response_dict['responses'][self.response_key][self.response_status_key] is 7:
if self.config.initial_transfer:
logger.log('Pokemon Bag is full!', 'red')
return PokemonCatchWorker.BAG_FULL
else:
raise RuntimeError('Pokemon Bag is full!')

if response_dict['responses']['ENCOUNTER']['status'] is 1:
if response_dict['responses'][self.response_key][self.response_status_key] is 1:
cp = 0
total_IV = 0
if 'wild_pokemon' in response_dict['responses']['ENCOUNTER']:
pokemon = response_dict['responses']['ENCOUNTER']['wild_pokemon']
catch_rate = response_dict['responses']['ENCOUNTER']['capture_probability']['capture_probability'] # 0 = pokeballs, 1 great balls, 3 ultra balls

if 'wild_pokemon' in response_dict['responses'][self.response_key] or 'pokemon_data' in \
response_dict['responses'][self.response_key]:
if self.response_key == 'ENCOUNTER':
pokemon = response_dict['responses'][self.response_key]['wild_pokemon']
else:
pokemon = response_dict['responses'][self.response_key]

catch_rate = response_dict['responses'][self.response_key]['capture_probability'][
'capture_probability'] # 0 = pokeballs, 1 great balls, 3 ultra balls
if 'pokemon_data' in pokemon and 'cp' in pokemon['pokemon_data']:
cp = pokemon['pokemon_data']['cp']

Expand Down Expand Up @@ -126,7 +131,7 @@ def work(self):
self.api.use_item_capture(
item_id=berry_id,
encounter_id = encounter_id,
spawn_point_guid = spawnpoint_id
spawn_point_id = self.spawn_point_guid
)
response_dict = self.api.call()
if response_dict and response_dict['status_code'] is 1 and 'item_capture_mult' in response_dict['responses']['USE_ITEM_CAPTURE']:
Expand Down Expand Up @@ -164,7 +169,7 @@ def work(self):
self.api.catch_pokemon(encounter_id=encounter_id,
pokeball=pokeball,
normalized_reticle_size=1.950,
spawn_point_guid=spawnpoint_id,
spawn_point_id=self.spawn_point_guid,
hit_pokemon=1,
spin_modifier=1,
NormalizedHitPosition=1)
Expand Down Expand Up @@ -377,3 +382,26 @@ def _get_release_config_for(self, pokemon):
if not release_config:
release_config = {}
return release_config

def create_encounter_api_call(self):

encounter_id = self.pokemon['encounter_id']
player_latitude = self.pokemon['latitude']
player_longitude = self.pokemon['longitude']

if 'spawn_point_id' in self.pokemon:
spawn_point_id = self.pokemon['spawn_point_id']
self.spawn_point_guid = spawn_point_id
self.response_key = 'ENCOUNTER'
self.response_status_key = 'status'
self.api.encounter(encounter_id=encounter_id, spawn_point_id=spawn_point_id,
player_latitude=player_latitude, player_longitude=player_longitude)
else:
fort_id = self.pokemon['fort_id']
self.spawn_point_guid = fort_id
self.response_key = 'DISK_ENCOUNTER'
self.response_status_key = 'result'
self.api.disk_encounter(encounter_id=encounter_id, fort_id=fort_id,
player_latitude=player_latitude, player_longitude=player_longitude)

return self.api.call()
40 changes: 38 additions & 2 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from pokemongo_bot import logger
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot.cell_workers import PokemonCatchWorker
from utils import format_time


Expand All @@ -17,6 +18,11 @@ def __init__(self, fort, bot):
self.position = bot.position
self.config = bot.config
self.item_list = bot.item_list
self.pokemon_list = bot.pokemon_list
self.inventory = bot.inventory
self.current_inventory = bot.current_inventory
self.item_inventory_count = bot.item_inventory_count
self.metrics = bot.metrics
self.rest_time = 50

def work(self):
Expand All @@ -34,9 +40,28 @@ def work(self):
fort_name = fort_details['name'].encode('utf8', 'replace')
else:
fort_name = 'Unknown'
logger.log('Now at Pokestop: ' + fort_name + ' - Spinning...',
logger.log('Now at Pokestop: ' + fort_name,
'cyan')
sleep(2)
if self.config.mode != 'farm' and 'lure_info' in self.fort:
# Check if the lure has a pokemon active
if 'encounter_id' in self.fort['lure_info']:
logger.log("Found a lure on this pokestop! Catching pokemon...", 'cyan')

pokemon = {
'encounter_id': self.fort['lure_info']['encounter_id'],
'fort_id': self.fort['id'],
'latitude': self.fort['latitude'],
'longitude': self.fort['longitude']
}

self.catch_pokemon(pokemon)

else:
logger.log('Found a lure, but there is no pokemon present.', 'yellow')
sleep(2)

logger.log('Spinning ...', 'cyan')

self.api.fort_search(fort_id=self.fort['id'],
fort_latitude=lat,
fort_longitude=lng,
Expand Down Expand Up @@ -120,6 +145,17 @@ def work(self):
sleep(2)
return 0

def catch_pokemon(self, pokemon):
worker = PokemonCatchWorker(pokemon, self.bot)
return_value = worker.work()

# Disabled for now, importing InitialTransferWorker fails.
# if return_value == PokemonCatchWorker.BAG_FULL:
# worker = InitialTransferWorker(self)
# worker.work()

return return_value

@staticmethod
def closest_fort(current_lat, current_long, forts):
print x
5 changes: 2 additions & 3 deletions pokemongo_bot/polyline_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from math import ceil

import logger
from cell_workers.utils import i2f
from human_behaviour import sleep
from polyline_walker import PolylineWalker


class PolylineStepper(Stepper):

def _walk_to(self, speed, lat, lng, alt):
origin = ','.join([str(i2f(self.api._position_lat)), str(i2f(self.api._position_lng))])
origin = ','.join([str(self.api._position_lat), str(self.api._position_lng)])
destination = ','.join([str(lat), str(lng)])
polyline_walker = PolylineWalker(origin, destination, speed)
proposed_origin = polyline_walker.points[0]
Expand All @@ -29,7 +28,7 @@ def _walk_to(self, speed, lat, lng, alt):
cLat, cLng = polyline_walker.get_pos()[0]
self.api.set_position(cLat, cLng, alt)
self.bot.heartbeat()
self._work_at_position(i2f(self.api._position_lat), i2f(self.api._position_lng), alt, False)
self._work_at_position(self.api._position_lat, self.api._position_lng, alt, False)
sleep(1) # sleep one second plus a random delta
if proposed_lat != self.api._position_lat and proposed_lng != self.api._position_lng:
logger.log('[#] Using _old_walk_to to go from the proposed destination : {} to {}'
Expand Down
12 changes: 6 additions & 6 deletions pokemongo_bot/spiral_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ def take_step(self):
)

dist = distance(
i2f(self.api._position_lat),
i2f(self.api._position_lng),
self.api._position_lat,
self.api._position_lng,
point['lat'],
point['lng']
)

if self.cnt == 1:
logger.log('Walking from ' + str((i2f(self.api._position_lat), i2f(
self.api._position_lng))) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist,
logger.log('Walking from ' + str((self.api._position_lat,
self.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist,
self.config.distance_unit))

if step_walker.step():
Expand All @@ -79,8 +79,8 @@ def take_step(self):
self.api.set_position(point['lat'], point['lng'])

if distance(
i2f(self.api._position_lat),
i2f(self.api._position_lng),
self.api._position_lat,
self.api._position_lng,
point['lat'],
point['lng']
) <= 1 or (self.config.walk > 0 and step_walker == None):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-e git+https://github.com/tejado/pgoapi.git@v1.1.0#egg=pgoapi
-e git+https://github.com/tejado/pgoapi.git@81e786cabf027a1c8fbd1e9a07e1c11aa3d8ee8b#egg=pgoapi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it should be 1.1.0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nihisil this PR is about updating pgoapi to latest version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a commit later than 1.1.0 for these features to work, Locking it to a specific commit makes sure things won't break in the future.

geopy==1.11.0
protobuf==3.0.0b4
requests==2.10.0
Expand Down