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

Wander #5695

Merged
merged 2 commits into from
Sep 26, 2016
Merged

Wander #5695

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
10 changes: 5 additions & 5 deletions docs/configuration_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,8 @@ This task is an upgrade version of the MoveToMapPokemon task. It will fetch poke

Walk to the specified locations loaded from .gpx or .json file. It is highly recommended to use website such as [GPSies](http://www.gpsies.com) which allow you to export your created track in JSON file. Note that you'll have to first convert its JSON file into the format that the bot can understand. See [Example of pier39.json] below for the content. I had created a simple python script to do the conversion.

The json file can contain for each point an optional `loiter` field. This
indicated the number of seconds the bot should loiter after reaching the point.
The json file can contain for each point an optional `wander` field. This
indicated the number of seconds the bot should wander after reaching the point.
During this time, the next Task in the configuration file is executed, e.g. a
MoveToFort task. This allows the bot to walk around the waypoint looking for
forts for a limited time.
Expand All @@ -902,9 +902,9 @@ forts for a limited time.
### Notice
If you use the `single` `path_mode` without e.g. a `MoveToFort` task, your bot
with /not move at all/ when the path is finished. Similarly, if you use the
`loiter` option in your json path file without a following `MoveToFort` or
similar task, your bot will not move during the loitering period. Please
make sure, when you use `single` mode or the `loiter` option, that another
`wander` option in your json path file without a following `MoveToFort` or
similar task, your bot will not move during the wandering period. Please
make sure, when you use `single` mode or the `wander` option, that another
move-type task follows the `FollowPath` task in your `config.json`.

### Sample Configuration
Expand Down
24 changes: 13 additions & 11 deletions pokemongo_bot/cell_workers/follow_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from datetime import datetime as dt, timedelta

STATUS_MOVING = 0
STATUS_LOITERING = 1
STATUS_WANDERING = 1
STATUS_FINISHED = 2

class FollowPath(BaseTask):
Expand All @@ -28,7 +28,7 @@ def initialize(self):
self._process_config()
self.points = self.load_path()
self.status = STATUS_MOVING
self.loiter_end_time = 0
self.wander_end_time = 0
self.distance_unit = self.bot.config.distance_unit
self.append_unit = False

Expand Down Expand Up @@ -139,12 +139,12 @@ def endLaps(self):
self.bot.login()

def work(self):
# If done or loitering allow the next task to run
# If done or wandering allow the next task to run
if self.status == STATUS_FINISHED:
return WorkerResult.SUCCESS

if self.status == STATUS_LOITERING and time.time() < self.loiter_end_time:
return WorkerResult.RUNNING
if self.status == STATUS_WANDERING and time.time() < self.wander_end_time:
return WorkerResult.SUCCESS

last_lat, last_lng, last_alt = self.bot.position

Expand Down Expand Up @@ -190,12 +190,14 @@ def work(self):
}
)

if (self.bot.config.walk_min > 0 and is_at_destination) or (self.status == STATUS_LOITERING and time.time() >= self.loiter_end_time):
if "loiter" in point and self.status != STATUS_LOITERING:
self.logger.info("Loitering for {} seconds...".format(point["loiter"]))
self.status = STATUS_LOITERING
self.loiter_end_time = time.time() + point["loiter"]
return WorkerResult.RUNNING
if (self.bot.config.walk_min > 0 and is_at_destination) or (self.status == STATUS_WANDERING and time.time() >= self.wander_end_time):
if "loiter" in point:
self.logger.warning("'loiter' is obsolete, please change to 'wander' in {}".format(self.path_file))
if "wander" in point and self.status != STATUS_WANDERING:
self.logger.info("Wandering for {} seconds...".format(point["wander"]))
self.status = STATUS_WANDERING
self.wander_end_time = time.time() + point["wander"]
return WorkerResult.SUCCESS
if (self.ptr + 1) == len(self.points):
if self.path_mode == 'single':
self.status = STATUS_FINISHED
Expand Down