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

Fixing teleporting to poke stops #775

Merged
merged 1 commit into from
Jul 25, 2016
Merged
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
14 changes: 6 additions & 8 deletions pokemongo_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from pgoapi.utilities import f2i, h2f
from cell_workers import PokemonCatchWorker, SeenFortWorker, MoveToFortWorker, InitialTransferWorker, EvolveAllWorker
from cell_workers.utils import distance, get_cellid, encode
from step_walker import StepWalker
from human_behaviour import sleep
from spiral_navigator import SpiralNavigator
from geopy.geocoders import GoogleV3
Expand All @@ -31,7 +30,6 @@ def __init__(self, config):
def start(self):
self._setup_logging()
self._setup_api()
self.step_walker = StepWalker(self)
self.navigator = SpiralNavigator(self)
random.seed()

Expand Down Expand Up @@ -73,7 +71,7 @@ def work_on_cell(self, cell, position):
if self.config.evolve_all:
# Will skip evolving if user wants to use an egg and there is none
skip_evolves = False

# Pop lucky egg before evolving to maximize xp gain
use_lucky_egg = self.config.use_lucky_egg
lucky_egg_count = self.item_inventory_count(Item.ITEM_LUCKY_EGG.value)
Expand Down Expand Up @@ -102,7 +100,7 @@ def work_on_cell(self, cell, position):
print('[#] Attempting to evolve all pokemons ...')
worker = EvolveAllWorker(self)
worker.work()

# Flip the bit.
self.config.evolve_all = []

Expand Down Expand Up @@ -267,7 +265,7 @@ def drop_item(self, item_id, count):
# Example of good request response
#{'responses': {'RECYCLE_INVENTORY_ITEM': {'result': 1, 'new_count': 46}}, 'status_code': 1, 'auth_ticket': {'expire_timestamp_ms': 1469306228058L, 'start': '/HycFyfrT4t2yB2Ij+yoi+on778aymMgxY6RQgvrGAfQlNzRuIjpcnDd5dAxmfoTqDQrbz1m2dGqAIhJ+eFapg==', 'end': 'f5NOZ95a843tgzprJo4W7Q=='}, 'request_id': 8145806132888207460L}
return inventory_req

def use_lucky_egg(self):
self.api.use_item_xp_boost(item_id=301)
inventory_req = self.api.call()
Expand Down Expand Up @@ -352,9 +350,9 @@ def item_inventory_count(self, id):
return item_count

def _set_starting_position(self):

has_position = False

if self.config.test:
# TODO: Add unit tests
return
Expand Down Expand Up @@ -398,7 +396,7 @@ def _set_starting_position(self):
'[x] Last in-game location was set as: {}'.format(
self.position))
logger.log('')

has_position = True
return
except:
Expand Down
17 changes: 15 additions & 2 deletions pokemongo_bot/cell_workers/move_to_fort_worker.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from utils import distance, format_dist
from pokemongo_bot.human_behaviour import sleep
from pokemongo_bot import logger
from pokemongo_bot.step_walker import StepWalker

class MoveToFortWorker(object):
def __init__(self, fort, bot):
self.bot = bot
self.fort = fort
self.api = bot.api
self.config = bot.config
self.navigator = bot.navigator
self.step_walker = bot.step_walker
self.position = bot.position

def work(self):
Expand All @@ -28,7 +29,19 @@ def work(self):
position = (lat, lng, 0.0)

if self.config.walk > 0:
self.step_walker.step(self.config.walk, *position[0:2])
step_walker = StepWalker(
self.bot,
self.config.walk,
self.api._position_lat,
self.api._position_lng,
position[0],
position[1]
)

while True:
if step_walker.step(self.config.walk, *position[0:2]):
break

else:
self.api.set_position(*position)

Expand Down
15 changes: 14 additions & 1 deletion pokemongo_bot/spiral_navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from human_behaviour import sleep, random_lat_long_delta
from cell_workers.utils import distance, i2f, format_time, format_dist
from step_walker import StepWalker

from pgoapi.utilities import f2i, h2f
import logger
Expand All @@ -31,6 +32,7 @@ def __init__(self, bot):
self.steplimit2 = self.steplimit**2
self.origin_lat = self.bot.position[0]
self.origin_lon = self.bot.position[1]
self._step_walker = None

def take_step(self):
position = (self.origin_lat, self.origin_lon, 0.0)
Expand All @@ -49,6 +51,15 @@ def take_step(self):
position = (self.x * 0.0025 + self.origin_lat,
self.y * 0.0025 + self.origin_lon, 0)
if self.config.walk > 0:
if not self._step_walker:
self._step_walker = StepWalker(
self.bot,
self.config.walk,
self.api._position_lat,
self.api._position_lng,
position[0],
position[1]
)

dist = distance(
i2f(self.api._position_lat),
Expand All @@ -59,7 +70,9 @@ def take_step(self):

logger.log('[#] Walking from ' + str((i2f(self.api._position_lat), i2f(
self.api._position_lng))) + " to " + str((str(position[0:2]))) + " " + format_dist(dist, self.config.distance_unit))
self.bot.step_walker.step(self.config.walk, *position[0:2])

if self._step_walker.step():
self._step_walker = None
else:
self.api.set_position(*position)
if self.x == self.y or self.x < 0 and self.x == -self.y or self.x > 0 and self.x == 1 - self.y:
Expand Down
59 changes: 50 additions & 9 deletions pokemongo_bot/step_walker.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,70 @@
import logger

from cell_workers.utils import distance, i2f, format_time
from cell_workers.utils import distance, i2f, format_time, format_dist
from human_behaviour import random_lat_long_delta, sleep
from math import ceil
from math import ceil, sqrt


class StepWalker(object):

def __init__(self, bot):
def __init__(self, bot, speed, initLat, initLng, destLat, destLng):
self.bot = bot
self.api = bot.api

def step(self, speed, lat, lng):
if self.api._position_lat == lat and self.api._position_lng == lng:
dist = distance(
i2f(initLat),
i2f(initLng),
destLat,
destLng
)

self.speed = speed

self.destLat = destLat
self.destLng = destLng

self.steps = (dist + 0.0) / (speed + 0.0)

if dist < 0.01 or self.steps < 1:
self.dLat = 0
self.dLng = 0
self.magnitude = 0;
else:
self.dLat = (destLat - i2f(initLat)) / self.steps
self.dLng = (destLng - i2f(initLng)) / self.steps
self.magnitude = self._pythagorean(self.dLat, self.dLng)

def step(self):
dist = distance(
i2f(self.api._position_lat),
i2f(self.api._position_lng),
self.destLat,
self.destLng
)
# print 'distance'
# print dist

if (self.dLat == 0 and self.dLng == 0) or dist < 15:
return True

dLat = (lat - i2f(self.api._position_lat)) / speed
dLng = (lng - i2f(self.api._position_lng)) / speed
totalDLat = (self.destLat - i2f(self.api._position_lat))
totalDLng = (self.destLng - i2f(self.api._position_lng))
magnitude = self._pythagorean(totalDLat, totalDLng)
unitLat = totalDLat / magnitude
unitLng = totalDLng / magnitude

cLat = i2f(self.api._position_lat) + dLat + random_lat_long_delta()
cLng = i2f(self.api._position_lng) + dLng + random_lat_long_delta()
scaledDLat = unitLat * self.magnitude
scaledDLng = unitLng * self.magnitude

cLat = i2f(self.api._position_lat) + scaledDLat + random_lat_long_delta()
cLng = i2f(self.api._position_lng) + scaledDLng + random_lat_long_delta()

self.api.set_position(cLat, cLng, 0)
self.bot.heartbeat()
sleep(1) # sleep one second plus a random delta
# self._work_at_position(
# i2f(self.api._position_lat), i2f(self.api._position_lng),
# alt, False)

def _pythagorean(self, lat, lng):
return sqrt((lat ** 2) + (lng ** 2))