Skip to content

Commit

Permalink
Do not spin fort on timeout when restarting the bot (#3931)
Browse files Browse the repository at this point in the history
Fix bot stuck between forts when inventory is full
  • Loading branch information
julienlavergne authored and elicwhite committed Aug 16, 2016
1 parent dc9f172 commit c1743c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
9 changes: 9 additions & 0 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,15 @@ def _register_events(self):
def tick(self):
self.health_record.heartbeat()
self.cell = self.get_meta_cell()

now = time.time() * 1000

for fort in self.cell["forts"]:
timeout = fort.get("cooldown_complete_timestamp_ms", 0)

if timeout >= now:
self.fort_timeouts[fort["id"]] = timeout

self.tick_count += 1

# Check if session token has expired
Expand Down
20 changes: 3 additions & 17 deletions pokemongo_bot/cell_workers/spin_fort.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ def work(self):
player_latitude=f2i(self.bot.position[0]),
player_longitude=f2i(self.bot.position[1])
)
if 'responses' in response_dict and 'FORT_SEARCH' in response_dict['responses']:

if ('responses' in response_dict) and ('FORT_SEARCH' in response_dict['responses']):
spin_details = response_dict['responses']['FORT_SEARCH']
spin_result = spin_details.get('result', -1)
if spin_result == SPIN_REQUEST_RESULT_SUCCESS:

if (spin_result == SPIN_REQUEST_RESULT_SUCCESS) or (spin_result == SPIN_REQUEST_RESULT_INVENTORY_FULL):
self.bot.softban = False
experience_awarded = spin_details.get('experience_awarded', 0)


items_awarded = self.get_items_awarded_from_fort_spinned(response_dict)

if experience_awarded or items_awarded:
Expand Down Expand Up @@ -108,12 +107,6 @@ def work(self):
formatted="Pokestop {pokestop} on cooldown. Time left: {minutes_left}.",
data={'pokestop': fort_name, 'minutes_left': minutes_left}
)
elif spin_result == SPIN_REQUEST_RESULT_INVENTORY_FULL:
if not self.ignore_item_count:
self.emit_event(
'inventory_full',
formatted="Inventory is full!"
)
else:
self.emit_event(
'unknown_spin_result',
Expand Down Expand Up @@ -148,12 +141,6 @@ def work(self):

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

for fort in reversed(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 fort: fort["id"] not in self.bot.fort_timeouts, forts)
forts = filter(lambda fort: distance(
self.bot.position[0],
Expand Down Expand Up @@ -186,4 +173,3 @@ def get_items_awarded_from_fort_spinned(self, response_dict):
# TODO : Refactor this class, hide the inventory update right after the api call
def _update_inventory(self, item_awarded):
inventory.items().get(item_awarded['item_id']).add(item_awarded['item_count'])

0 comments on commit c1743c9

Please sign in to comment.