Skip to content

Commit

Permalink
fixes Polyline class to handle a case in which google is returning on…
Browse files Browse the repository at this point in the history
…ly one point (#1674)

* Fixes:

https://github.com/th3w4y/PokemonGo-Bot/issues/27

* Fixes:
PolylineStepWalker walks for only one seconds #28
https://github.com/th3w4y/PokemonGo-Bot/issues/28

by adding a while destination nat reached loop

* fixes typo
  • Loading branch information
th3w4y authored and douglascamata committed Jul 29, 2016
1 parent a177b7f commit 9a29c0f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
30 changes: 18 additions & 12 deletions pokemongo_bot/walkers/polyline_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def walk_steps(self):
walk_steps = zip(chain([self.points[0]], self.points),
chain(self.points, [self.points[-1]]))
walk_steps = filter(None, [(o, d) if o != d else None for o, d in walk_steps])
return walk_steps
# consume the filter as list https://github.com/th3w4y/PokemonGo-Bot/issues/27
return list(walk_steps)
else:
return []

Expand All @@ -73,19 +74,24 @@ def get_pos(self):
else:
time_passed = self._last_paused_timestamp
time_passed_distance = self.speed * abs(time_passed - self._timestamp - self._paused_total)
steps_dict = {}
for step in self.walk_steps():
walked_distance += haversine.haversine(*step)*1000
steps_dict[walked_distance] = step
for walked_end_step in sorted(steps_dict.keys()):
# check if there are any steps to take https://github.com/th3w4y/PokemonGo-Bot/issues/27
if self.walk_steps():
steps_dict = {}
for step in self.walk_steps():
walked_distance += haversine.haversine(*step)*1000
steps_dict[walked_distance] = step
for walked_end_step in sorted(steps_dict.keys()):
if walked_end_step >= time_passed_distance:
break
step_distance = haversine.haversine(*steps_dict[walked_end_step])*1000
if walked_end_step >= time_passed_distance:
break
step_distance = haversine.haversine(*steps_dict[walked_end_step])*1000
if walked_end_step >= time_passed_distance:
percentage_walked = (time_passed_distance - (walked_end_step - step_distance)) / step_distance
percentage_walked = (time_passed_distance - (walked_end_step - step_distance)) / step_distance
else:
percentage_walked = 1.0
return self.calculate_coord(percentage_walked, *steps_dict[walked_end_step])
else:
percentage_walked = 1.0
return self.calculate_coord(percentage_walked, *steps_dict[walked_end_step])
# otherwise return the destination https://github.com/th3w4y/PokemonGo-Bot/issues/27
return [self.points[-1]]

def calculate_coord(self, percentage, o, d):
# If this is the destination then returning as such
Expand Down
17 changes: 9 additions & 8 deletions pokemongo_bot/walkers/polyline_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def __init__(self, bot, speed, destLat, destLng):
logger.log('[#] {}'.format(self.polyline_walker.URL))

def step(self):
self.polyline_walker.unpause()
sleep(1)
self.polyline_walker.pause()
cLat, cLng = self.polyline_walker.get_pos()[0]
self.api.set_position(round(cLat, 5), round(cLng, 5), 0)
self.bot.heartbeat()
if self.destLat == cLat and self.destLng == cLng:
return True
cLat, cLng = self.api._position_lat, self.api._position_lng
while (cLat, cLng) != self.polyline_walker.get_pos()[0]:
self.polyline_walker.unpause()
sleep(1)
self.polyline_walker.pause()
cLat, cLng = self.polyline_walker.get_pos()[0]
self.api.set_position(round(cLat, 5), round(cLng, 5), 0)
self.bot.heartbeat()
return True

0 comments on commit 9a29c0f

Please sign in to comment.