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 #1082

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 9 additions & 14 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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 All @@ -51,9 +51,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 @@ -131,7 +131,6 @@ def find_close_cells(self, lat, lng):
x['forts'][0]['latitude'],
x['forts'][0]['longitude']) if x.get('forts', []) else 1e6
)
self.update_web_location(map_cells)
return map_cells

def work_on_cell(self, cell, position, work_on_forts=1):
Expand Down Expand Up @@ -386,8 +385,7 @@ def pokeball_inventory(self):
self.api.get_player().get_inventory()

inventory_req = self.api.call()
inventory_dict = inventory_req['responses']['GET_INVENTORY'][
'inventory_delta']['inventory_items']
inventory_dict = inventory_req['responses']['GET_INVENTORY']['inventory_delta']['inventory_items']

user_web_inventory = 'web/inventory-%s.json' % (self.config.username)
with open(user_web_inventory, 'w') as outfile:
Expand Down Expand Up @@ -454,7 +452,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 @@ -489,20 +487,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):
self.api.get_player()
Expand Down
2 changes: 1 addition & 1 deletion pokemongo_bot/cell_workers/move_to_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def work(self):
position[1]
)

while distance(i2f(self.api._position_lat), i2f(self.api._position_lng), lat, lng) > 10:
while distance(self.api._position_lat, self.api._position_lng, lat, lng) > 10:
if step_walker.step():
break
else:
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()
38 changes: 36 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,10 @@ 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.pokeball_inventory = bot.pokeball_inventory
self.item_inventory_count = bot.item_inventory_count
self.rest_time = 50

def work(self):
Expand All @@ -34,9 +39,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 @@ -141,6 +165,16 @@ def work(self):
sleep(8)
return 0

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

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
11 changes: 7 additions & 4 deletions pokemongo_bot/logger.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import time

try:
import lcd

lcd = lcd.lcd()
# Change this to your i2c address
lcd.set_addr(0x23)
except:
lcd = False

def log(string, color = 'white'):

def log(string, color='white'):
colorHex = {
'red': '91m',
'green': '92m',
Expand All @@ -16,9 +19,9 @@ def log(string, color = 'white'):
'cyan': '96m'
}
if color not in colorHex:
print('[' + time.strftime("%H:%M:%S") + '] '+ string)
print('[' + time.strftime("%H:%M:%S") + '] ' + string)
else:
print('[' + time.strftime("%H:%M:%S") + '] ' + u'\033['+ colorHex[color] + string.decode('utf-8') + '\033[0m')
print('[' + time.strftime("%H:%M:%S") + '] ' + u'\033[' + colorHex[color] + string.decode('utf-8') + '\033[0m')
if lcd:
if(string):
if (string):
lcd.message(string)
4 changes: 2 additions & 2 deletions pokemongo_bot/polyline_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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 @@ -31,7 +31,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 @@ -66,15 +66,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 self._step_walker.step():
Expand All @@ -83,8 +83,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 self._step_walker == None):
Expand Down
20 changes: 10 additions & 10 deletions pokemongo_bot/step_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(self, bot, speed, initLat, initLng, destLat, destLng):
self.api = bot.api

dist = distance(
i2f(initLat),
i2f(initLng),
initLat,
initLng,
destLat,
destLng
)
Expand All @@ -42,14 +42,14 @@ def __init__(self, bot, speed, initLat, initLng, destLat, destLng):
self.dLng = 0
self.magnitude = 0;
else:
self.dLat = (destLat - i2f(initLat)) / self.steps
self.dLng = (destLng - i2f(initLng)) / self.steps
self.dLat = (destLat - initLat) / self.steps
self.dLng = (destLng - initLng) / self.steps
self.magnitude = self._pythagorean(self.dLat, self.dLng)

def step(self):
dist = distance(
i2f(self.api._position_lat),
i2f(self.api._position_lng),
self.api._position_lat,
self.api._position_lng,
self.destLat,
self.destLng
)
Expand All @@ -62,17 +62,17 @@ def step(self):
self.api.set_position(self.destLat, self.destLng, 0)
return True

totalDLat = (self.destLat - i2f(self.api._position_lat))
totalDLng = (self.destLng - i2f(self.api._position_lng))
totalDLat = (self.destLat - self.api._position_lat)
totalDLng = (self.destLng - self.api._position_lng)
magnitude = self._pythagorean(totalDLat, totalDLng)
unitLat = totalDLat / magnitude
unitLng = totalDLng / magnitude

scaledDLat = unitLat * self.magnitude
scaledDLng = unitLng * self.magnitude

cLat = i2f(self.api._position_lat) + scaledDLat + random_lat_long_delta()
cLng = i2f(self.api._position_lng) + scaledDLng + random_lat_long_delta()
cLat = self.api._position_lat + scaledDLat + random_lat_long_delta()
cLng = self.api._position_lng + scaledDLng + random_lat_long_delta()

self.api.set_position(cLat, cLng, 0)
self.bot.heartbeat()
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#egg=pgoapi
geopy==1.11.0
protobuf==3.0.0b4
requests==2.10.0
Expand Down