Skip to content

Commit

Permalink
Added social hunter, currently break the map thing, need configuratio…
Browse files Browse the repository at this point in the history
…n to fix it.
  • Loading branch information
solderzzc committed Aug 24, 2016
1 parent 5d198c5 commit 36e66dd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
45 changes: 42 additions & 3 deletions pokemongo_bot/cell_workers/move_to_map_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,45 @@ def initialize(self):
open(data_file)
)
self.alt = uniform(self.bot.config.alt_min, self.bot.config.alt_max)
def get_pokemon_from_social(self):
if not self.bot.mqtt_pokemon_list or len(self.bot.mqtt_pokemon_list) <= 0:
return []

pokemon_list = []
now = int(time.time())

for pokemon in self.bot.mqtt_pokemon_list:
pokemon['encounter_id'] = pokemon['encounter_id']
pokemon['spawn_point_id'] = pokemon['spawn_point_id']
pokemon['disappear_time'] = int(pokemon['expiration_timestamp_ms'] / 1000)
pokemon['name'] = self.pokemon_data[pokemon['pokemon_id'] - 1]['Name']
pokemon['is_vip'] = pokemon['name'] in self.bot.config.vips

if pokemon['name'] not in self.config['catch']:
continue

if self.was_caught(pokemon):
continue

pokemon['priority'] = self.config['catch'].get(pokemon['name'], 0)

pokemon['dist'] = distance(
self.bot.position[0],
self.bot.position[1],
pokemon['latitude'],
pokemon['longitude'],
)

if pokemon['dist'] > self.config['max_distance'] and not self.config['snipe']:
continue

# pokemon not reachable with mean walking speed (by config)
mean_walk_speed = (self.bot.config.walk_max + self.bot.config.walk_min) / 2
if pokemon['dist'] > ((pokemon['disappear_time'] - now) * mean_walk_speed) and not self.config['snipe']:
continue
pokemon_list.append(pokemon)
self.bot.mqtt_pokemon_list = []
return pokemon_list
def get_pokemon_from_map(self):
try:
req = requests.get('{}/{}?gyms=false&scanned=false'.format(self.config['address'], self.map_path))
Expand Down Expand Up @@ -251,8 +289,9 @@ def work(self):

self.update_map_location()
self.dump_caught_pokemon()

pokemon_list = self.get_pokemon_from_map()
pokemon_list = self.get_pokemon_from_social()
#Temp works as it, need add more configuration
#pokemon_list = self.get_pokemon_from_map()
pokemon_list.sort(key=lambda x: x['dist'])
if self.config['mode'] == 'priority':
pokemon_list.sort(key=lambda x: x['priority'], reverse=True)
Expand Down Expand Up @@ -439,7 +478,7 @@ def _move_to_pokemon_througt_fort(self, fort, pokemon):
self.emit_event(
'arrived_at_fort',
formatted='Arrived at fort.'
)
)

return walker_factory(self.walker,
self.bot,
Expand Down
11 changes: 4 additions & 7 deletions pokemongo_bot/event_handlers/social_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ def __init__(self, bot, clientid=None):
def mqtt_on_message(self, mqttc, obj, msg):
#msg.topic+" "+str(msg.qos)+" "+str(msg.payload)
pokemon = json.loads(msg.payload)
print pokemon
#if pokemon and 'encounter_id' in pokemon:
# matches = (x for x in self.bot.mqtt_pokemon_list if x.encounter_id is pokemon['encounter_id'])
# if matches and len(matches) > 0:
# print 'Match es'
# else:
# self.bot.mqtt_pokemon_list.append(pokemon)
if pokemon and 'encounter_id' in pokemon:
new_list = [x for x in self.bot.mqtt_pokemon_list if x['encounter_id'] is pokemon['encounter_id']]
if not (new_list and len(new_list) > 0):
self.bot.mqtt_pokemon_list.append(pokemon)
#def mqtt_on_publish(self, mqttc, obj, mid):
#print "mid: "+str(mid)
#def mqtt_on_subscribe(self, mqttc, obj, mid, granted_qos):
Expand Down

0 comments on commit 36e66dd

Please sign in to comment.