Skip to content

Commit

Permalink
Moving MoveToFort to the top level (#1605)
Browse files Browse the repository at this point in the history
* Moving MoveToFort to the top level

* Fixing bad import
  • Loading branch information
elicwhite authored Jul 29, 2016
1 parent d391705 commit a14323c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 64 deletions.
8 changes: 7 additions & 1 deletion pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PokemonGoBot(object):
cell_workers.RecycleItemsWorker,
cell_workers.CatchVisiblePokemonWorker,
cell_workers.SeenFortWorker,
cell_workers.SpinNearestFortWorker
cell_workers.MoveToFortWorker
]

@property
Expand Down Expand Up @@ -565,6 +565,12 @@ def get_player_info(self):
'Pokemon Captured: {pokemons_captured}'.format(**playerdata) +
' | Pokestops Visited: {poke_stop_visits}'.format(**playerdata), 'cyan')

def has_space_for_loot(self):
number_of_things_gained_by_stop = 5
enough_space = self.get_inventory_count('item') < self._player['max_item_storage'] - number_of_things_gained_by_stop

return enough_space

def get_forts(self, order_by_distance=False):
forts = [fort
for fort in self.cell['forts']
Expand Down
1 change: 0 additions & 1 deletion pokemongo_bot/cell_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
from evolve_all_worker import EvolveAllWorker
from catch_visible_pokemon_worker import CatchVisiblePokemonWorker
from recycle_items_worker import RecycleItemsWorker
from spin_nearest_fort_worker import SpinNearestFortWorker
from incubate_eggs_worker import IncubateEggsWorker
47 changes: 40 additions & 7 deletions pokemongo_bot/cell_workers/move_to_fort_worker.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
from utils import distance, format_dist, i2f
from pokemongo_bot.constants import Constants
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot import logger
from pokemongo_bot.step_walker import StepWalker
from pokemongo_bot.worker_result import WorkerResult

class MoveToFortWorker(object):

def __init__(self, fort, bot):
def __init__(self, bot):
self.bot = bot
self.fort = fort
self.api = bot.api
self.config = bot.config
self.fort_timeouts = bot.fort_timeouts
self.recent_forts = bot.recent_forts
self.navigator = bot.navigator
self.position = bot.position

def should_run(self):
return self.config.spin_forts and self.bot.has_space_for_loot()

def work(self):
lat = self.fort['latitude']
lng = self.fort['longitude']
fortID = self.fort['id']
if not self.should_run():
return WorkerResult.SUCCESS

nearest_fort = self.get_nearest_fort()

if nearest_fort == None:
return WorkerResult.SUCCESS

lat = nearest_fort['latitude']
lng = nearest_fort['longitude']
fortID = nearest_fort['id']
unit = self.config.distance_unit # Unit to use when printing formatted distance

dist = distance(self.position[0], self.position[1], lat, lng)
dist = distance(
self.position[0],
self.position[1],
lat,
lng
)

if dist > 10:
if dist > Constants.MAX_DISTANCE_FORT_IS_REACHABLE:
logger.log('Moving towards fort {}, {} left'.format(fortID, format_dist(dist, unit)))

step_walker = StepWalker(
Expand All @@ -37,3 +55,18 @@ def work(self):

logger.log('Arrived at Pokestop')
return WorkerResult.SUCCESS

def get_nearest_fort(self):
forts = self.bot.get_forts()

# Remove stops that are still on timeout
forts = filter(lambda x: x["id"] not in self.fort_timeouts, forts)

# Remove all forts which were spun in the last ticks to avoid circles if set
if self.config.avoid_circles:
forts = filter(lambda x: x["id"] not in self.recent_forts, forts)

if len(forts) > 0:
return forts[0]
else:
return None
6 changes: 1 addition & 5 deletions pokemongo_bot/cell_workers/seen_fort_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ def __init__(self, bot):
self.item_list = bot.item_list

def should_run(self):
number_of_things_gained_by_stop = 5

enough_space = self.bot.get_inventory_count('item') < self.bot._player['max_item_storage'] - number_of_things_gained_by_stop

return self.config.spin_forts and enough_space
return self.config.spin_forts and self.bot.has_space_for_loot()

def work(self):
fort = self.get_fort_in_range()
Expand Down
50 changes: 0 additions & 50 deletions pokemongo_bot/cell_workers/spin_nearest_fort_worker.py

This file was deleted.

0 comments on commit a14323c

Please sign in to comment.