forked from PokemonGoF/PokemonGo-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstepper.py
More file actions
110 lines (90 loc) · 4.46 KB
/
stepper.py
File metadata and controls
110 lines (90 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import json
import time
from s2sphere import CellId, LatLng
from google.protobuf.internal import encoder
from human_behaviour import sleep, random_lat_long_delta
from cell_workers.utils import distance, i2f
from pgoapi.utilities import f2i, h2f
class Stepper(object):
def __init__(self, bot):
self.bot = bot
self.api = bot.api
self.config = bot.config
self.pos = 1
self.x = 0
self.y = 0
self.dx = 0
self.dy = -1
self.steplimit=self.config.maxsteps
self.steplimit2 = self.steplimit**2
self.origin_lat = self.bot.position[0]
self.origin_lon = self.bot.position[1]
def take_step(self):
position=(self.origin_lat,self.origin_lon,0.0)
self.api.set_position(*position)
for step in range(self.steplimit2):
#starting at 0 index
print('[#] Scanning area for objects ({} / {})'.format((step+1), self.steplimit**2))
if self.config.debug:
print('steplimit: {} x: {} y: {} pos: {} dx: {} dy {}'.format(self.steplimit2, self.x, self.y, self.pos, self.dx, self.dy))
# Scan location math
if -self.steplimit2 / 2 < self.x <= self.steplimit2 / 2 and -self.steplimit2 / 2 < self.y <= self.steplimit2 / 2:
position = (self.x * 0.0025 + self.origin_lat, self.y * 0.0025 + self.origin_lon, 0)
if self.config.walk > 0:
self._walk_to(self.config.walk, *position)
else:
self.api.set_position(*position)
print(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:
(self.dx, self.dy) = (-self.dy, self.dx)
(self.x, self.y) = (self.x + self.dx, self.y + self.dy)
# get map objects call
# ----------------------
timestamp = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
cellid = self._get_cellid(position[0], position[1])
self.api.get_map_objects(latitude=f2i(position[0]), longitude=f2i(position[1]), since_timestamp_ms=timestamp, cell_id=cellid)
with open('location.json', 'w') as outfile:
json.dump({'lat': position[0], 'lng': position[1]}, outfile)
response_dict = self.api.call()
#print('Response dictionary: \n\r{}'.format(json.dumps(response_dict, indent=2)))
if response_dict and 'responses' in response_dict and \
'GET_MAP_OBJECTS' in response_dict['responses'] and \
'status' in response_dict['responses']['GET_MAP_OBJECTS'] and \
response_dict['responses']['GET_MAP_OBJECTS']['status'] is 1:
#print('got the maps')
map_cells=response_dict['responses']['GET_MAP_OBJECTS']['map_cells']
#print('map_cells are {}'.format(len(map_cells)))
for cell in map_cells:
self.bot.work_on_cell(cell,position)
sleep(10)
def _walk_to(self, speed, lat, lng, alt):
dist = distance(float(self.api._position_lat), float(self.api._position_lng), lat, lng)
steps = (dist+0.0)/(speed+0.0) # may be rational number
intSteps = int(steps)
residuum = steps - intSteps
if steps != 0:
dLat = (lat - i2f(self.api._position_lat)) / steps
dLng = (lng - i2f(self.api._position_lng)) / steps
for i in range(intSteps):
self.api.set_position(i2f(self.api._position_lat) + dLat + random_lat_long_delta(), i2f(self.api._position_lng) + dLng + random_lat_long_delta(), alt)
self.api.heartbeat()
self.catchThem()
time.sleep(1 + self.random_sleep()) # sleep one second plus a random delta
self.api.heartbeat()
print "[#] Finished walking"
def _get_cellid(self, lat, long):
origin = CellId.from_lat_lng(LatLng.from_degrees(lat, long)).parent(15)
walk = [origin.id()]
# 10 before and 10 after
next = origin.next()
prev = origin.prev()
for i in range(10):
walk.append(prev.id())
walk.append(next.id())
next = next.next()
prev = prev.prev()
return ''.join(map(self._encode, sorted(walk)))
def _encode(self, cellid):
output = []
encoder._VarintEncoder()(output.append, cellid)
return ''.join(output)