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

Making the navigators workers #1933

Merged
merged 1 commit into from
Jul 31, 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
5 changes: 2 additions & 3 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import cell_workers
import logger
import navigators
from api_wrapper import ApiWrapper
from cell_workers.utils import distance
from event_manager import EventManager
Expand Down Expand Up @@ -55,9 +54,9 @@ def start(self):
self._setup_workers()

if self.config.navigator_type == 'spiral':
self.navigator=navigators.SpiralNavigator(self)
self.navigator=cell_workers.FollowSpiral(self)
elif self.config.navigator_type == 'path':
self.navigator=navigators.PathNavigator(self)
self.navigator=cell_workers.FollowPath(self)

random.seed()

Expand Down
2 changes: 2 additions & 0 deletions pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
from recycle_items import RecycleItems
from spin_fort import SpinFort
from handle_soft_ban import HandleSoftBan
from follow_path import FollowPath
from follow_spiral import FollowSpiral
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@
from pgoapi.utilities import f2i


class PathNavigator(object):
class FollowPath(object):

def __init__(self, bot):
self.bot = bot
self.api = bot.api
self.config = bot.config
self.ptr = 0
self.points = self.load_path()

def load_path(self):
if self.config.navigator_path_file == None:
if self.bot.config.navigator_path_file == None:
raise RuntimeError('You need to specify a path file (json or gpx)')

if self.config.navigator_path_file.endswith('.json'):
return self.load_json(self.config.navigator_path_file)
elif self.config.navigator_path_file.endswith('.gpx'):
return self.load_gpx(self.config.navigator_path_file)
if self.bot.config.navigator_path_file.endswith('.json'):
return self.load_json(self.bot.config.navigator_path_file)
elif self.bot.config.navigator_path_file.endswith('.gpx'):
return self.load_gpx(self.bot.config.navigator_path_file)

def load_json(self, file):
with open(file) as data_file:
Expand Down Expand Up @@ -63,10 +61,10 @@ def take_step(self):
lat = float(point['lat'])
lng = float(point['lng'])

if self.config.walk > 0:
if self.bot.config.walk > 0:
step_walker = StepWalker(
self.bot,
self.config.walk,
self.bot.config.walk,
lat,
lng
)
Expand All @@ -76,19 +74,19 @@ def take_step(self):
is_at_destination = True

else:
self.api.set_position(lat, lng)
self.bot.api.set_position(lat, lng)

dist = distance(
self.api._position_lat,
self.api._position_lng,
self.bot.api._position_lat,
self.bot.api._position_lng,
lat,
lng
)

if dist <= 1 or (self.config.walk > 0 and is_at_destination):
if dist <= 1 or (self.bot.config.walk > 0 and is_at_destination):
if (self.ptr + 1) == len(self.points):
self.ptr = 0
if self.config.navigator_path_mode == 'linear':
if self.bot.config.navigator_path_mode == 'linear':
self.points = list(reversed(self.points))
else:
self.ptr += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
from pokemongo_bot.step_walker import StepWalker


class SpiralNavigator(object):
class FollowSpiral(object):
def __init__(self, bot):
self.bot = bot
self.api = bot.api
self.config = bot.config

self.steplimit = self.config.max_steps
self.steplimit = self.bot.config.max_steps
self.origin_lat = self.bot.position[0]
self.origin_lon = self.bot.position[1]

Expand Down Expand Up @@ -59,38 +57,38 @@ def take_step(self):
point = self.points[self.ptr]
self.cnt += 1

if self.config.walk > 0:
if self.bot.config.walk > 0:
step_walker = StepWalker(
self.bot,
self.config.walk,
self.bot.config.walk,
point['lat'],
point['lng']
)

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

if self.cnt == 1:
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))
'Walking from ' + str((self.bot.api._position_lat,
self.bot.api._position_lng)) + " to " + str([point['lat'], point['lng']]) + " " + format_dist(dist,
self.bot.config.distance_unit))

if step_walker.step():
step_walker = None
else:
self.api.set_position(point['lat'], point['lng'])
self.bot.api.set_position(point['lat'], point['lng'])

if distance(
self.api._position_lat,
self.api._position_lng,
self.bot.api._position_lat,
self.bot.api._position_lng,
point['lat'],
point['lng']
) <= 1 or (self.config.walk > 0 and step_walker == None):
) <= 1 or (self.bot.config.walk > 0 and step_walker == None):
if self.ptr + self.direction == len(self.points) or self.ptr + self.direction == -1:
self.direction *= -1
self.ptr += self.direction
Expand Down
2 changes: 0 additions & 2 deletions pokemongo_bot/navigators/__init__.py

This file was deleted.