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

Return RUNNING if there are more forts to spin #3412

Merged
merged 1 commit into from
Aug 11, 2016
Merged
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
33 changes: 15 additions & 18 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ def should_run(self):
return self.ignore_item_count or self.bot.has_space_for_loot()

def work(self):
fort = self.get_fort_in_range()
forts = self.get_forts_in_range()

if not self.should_run() or fort is None:
if not self.should_run() or len(forts) == 0:
return WorkerResult.SUCCESS

fort = forts[0]

lat = fort['latitude']
lng = fort['longitude']

Expand Down Expand Up @@ -134,33 +136,28 @@ def work(self):
)
else:
self.bot.fort_timeouts[fort["id"]] = (time.time() + 300) * 1000 # Don't spin for 5m
return 11
return WorkerResult.ERROR
sleep(2)
return 0

def get_fort_in_range(self):
if len(forts) > 1:
return WorkerResult.RUNNING

return WorkerResult.SUCCESS

def get_forts_in_range(self):
forts = self.bot.get_forts(order_by_distance=True)

for fort in forts:
if 'cooldown_complete_timestamp_ms' in fort:
self.bot.fort_timeouts[fort["id"]] = fort['cooldown_complete_timestamp_ms']
forts.remove(fort)

forts = filter(lambda x: x["id"] not in self.bot.fort_timeouts, forts)

if len(forts) == 0:
return None

fort = forts[0]

distance_to_fort = distance(
forts = filter(lambda fort: fort["id"] not in self.bot.fort_timeouts, forts)
forts = filter(lambda fort: distance(
self.bot.position[0],
self.bot.position[1],
fort['latitude'],
fort['longitude']
)

if distance_to_fort <= Constants.MAX_DISTANCE_FORT_IS_REACHABLE:
return fort
) <= Constants.MAX_DISTANCE_FORT_IS_REACHABLE, forts)

return None
return forts