-
Notifications
You must be signed in to change notification settings - Fork 2
/
tlopo_util.py
74 lines (57 loc) · 1.74 KB
/
tlopo_util.py
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
import win32gui, win32ui, win32con
from window_input import Window, Key
import time
from PIL import Image
import collections
Region = collections.namedtuple("Region", "top_left bot_right")
class Tlopo:
def __init__(self, win):
if win is None:
self.win = Window()
else:
self.win = win
class OnFoot(Tlopo):
def __init__(self, win=None):
super().__init__(win)
self.orientation = 0
def turn(self, desired):
duration = 3*(desired/360)
if duration < 0:
duration = abs(duration)
self.win.press(Key.VK_A, duration=duration)
else:
self.win.press(Key.VK_D, duration=duration)
def keep_jumping(self):
self.win.key_down(Key.VK_SPACE)
def sword_combo(self):
for _ in range(5):
self.win.press(Key.VK_CONTROL)
time.sleep(1)
def record_loot(self):
loot_area = Region((452, 338), (872, 516))
return self.win.capture(loot_area)
class Sailing(Tlopo):
def __init__(self, win=None):
super().__init__(win)
def circle(self, clockwise=True):
if clockwise:
button = Key.VK_D
else:
button = Key.VK_A
self.win.press(button, duration=.1)
time.sleep(.4)
self.fire()
@property
def should_fire(self):
for x in range(1790, 1850):
for y in range(90, 140):
if self.win.pixel(x, y).r > 200:
return True
return False
def fire(self, sides=None):
if sides is None:
sides = [True, True]
if sides[0]:
self.win.press(Key.VK_1, duration=.06)
if sides[1]:
self.win.press(Key.VK_2, duration=.06)