Skip to content

Commit

Permalink
added config to ignore item count for Spin and MoveToFort
Browse files Browse the repository at this point in the history
this works good with the `run_interval` configuration added to
TransferPokemon and RecycleItem
  • Loading branch information
douglascamata committed Aug 8, 2016
1 parent 4b16e9d commit 4e6138d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
23 changes: 19 additions & 4 deletions pokemongo_bot/cell_workers/catch_visible_pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ def work(self):
lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude'])
)
user_web_catchable = 'web/catchable-{}.json'.format(self.bot.config.username)


for pokemon in self.bot.cell['catchable_pokemons']:
with open(user_web_catchable, 'w') as outfile:
json.dump(pokemon, outfile)
self.emit_event(
'catchable_pokemon',
level='debug',
level='info',
data={
'pokemon_id': pokemon['pokemon_id'],
'spawn_point_id': pokemon['spawn_point_id'],
Expand All @@ -32,16 +34,29 @@ def work(self):
'expiration_timestamp_ms': pokemon['expiration_timestamp_ms'],
}
)

return self.catch_pokemon(self.bot.cell['catchable_pokemons'].pop(0))
self.catch_pokemon(pokemon)

if 'wild_pokemons' in self.bot.cell and len(self.bot.cell['wild_pokemons']) > 0:
# Sort all by distance from current pos- eventually this should
# build graph & A* it
self.bot.cell['wild_pokemons'].sort(
key=
lambda x: distance(self.bot.position[0], self.bot.position[1], x['latitude'], x['longitude']))
return self.catch_pokemon(self.bot.cell['wild_pokemons'].pop(0))

for pokemon in self.bot.cell['wild_pokemons']:
self.emit_event(
'catchable_pokemon',
level='info',
data={
'pokemon_id': pokemon['pokemon_data']['pokemon_id'],
'spawn_point_id': pokemon['spawn_point_id'],
'encounter_id': pokemon['encounter_id'],
'latitude': pokemon['latitude'],
'longitude': pokemon['longitude'],
'expiration_timestamp_ms': pokemon['time_till_hidden_ms'],
}
)
self.catch_pokemon(pokemon)

def catch_pokemon(self, pokemon):
worker = PokemonCatchWorker(pokemon, self.bot)
Expand Down
9 changes: 5 additions & 4 deletions pokemongo_bot/cell_workers/move_to_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ class MoveToFort(BaseTask):

def initialize(self):
self.lure_distance = 0
self.lure_attraction = True #self.config.get("lure_attraction", True)
self.lure_max_distance = 2000 #self.config.get("lure_max_distance", 2000)
self.lure_attraction = self.config.get("lure_attraction", True)
self.lure_max_distance = self.config.get("lure_max_distance", 2000)
self.ignore_item_count = self.config.get("ignore_item_count", False)

def should_run(self):
has_space_for_loot = self.bot.has_space_for_loot()
if not has_space_for_loot:
self.emit_event(
'inventory_full',
formatted="Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently."
formatted="Inventory is full. You might want to change your config to recycle more items if this message appears consistently."
)
return has_space_for_loot or self.bot.softban
return has_space_for_loot or self.ignore_item_count or self.bot.softban

def is_attracted(self):
return (self.lure_distance > 0)
Expand Down
8 changes: 5 additions & 3 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
class SpinFort(BaseTask):
SUPPORTED_TASK_API_VERSION = 1

def initialize(self):
self.ignore_item_count = self.config.get("ignore_item_count", False)

def should_run(self):
if not self.bot.has_space_for_loot():
self.emit_event(
'inventory_full',
formatted="Not moving to any forts as there aren't enough space. You might want to change your config to recycle more items if this message appears consistently."
formatted="Inventory is full. You might want to change your config to recycle more items if this message appears consistently."
)
return False
return True
return self.ignore_item_count or self.bot.has_space_for_loot()

def work(self):
fort = self.get_fort_in_range()
Expand Down

0 comments on commit 4e6138d

Please sign in to comment.