-
Notifications
You must be signed in to change notification settings - Fork 2
/
repair_mini_game.py
80 lines (66 loc) · 1.97 KB
/
repair_mini_game.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
72
73
74
75
76
77
78
79
80
import pyautogui
import collections
import win32gui
import win32api
import win32ui
import pyscreeze
import mouse
import time
Point = collections.namedtuple("Point", "x y")
Color = collections.namedtuple("Color", "r g b")
def rgbint2rgbtuple(rgb_int):
blue = rgb_int & 255
green = (rgb_int >> 8) & 255
red = (rgb_int >> 16) & 255
return red, green, blue
def pixel(x, y=None):
if y is None:
y = x[1]
x = x[0]
try:
window = win32gui.FindWindow(None, "The Legend of Pirates Online [BETA]")
dc = win32gui.GetWindowDC(window)
colorref = win32gui.GetPixel(dc, x+8, y+8)
except:
print("woops")
return 0, 0, 0
win32gui.DeleteDC(dc)
return rgbint2rgbtuple(colorref)
def points_to_region(p1, p2=None):
if p2 is None:
p2, p1 = p1
xi = min(p1[0], p2[0])
xf = max(p1[0], p2[0])
yi = min(p1[1], p2[1])
yf = max(p1[1], p2[1])
return [xi, yi, xf-xi, yf-yi]
class RepairMiniGame:
def __init__(self):
self.name = None
self.button = None
self.completed = False
self.snapshot = "./images/markers/temp.png"
@property
def active(self):
activity = pyscreeze.locateOnScreen("./images/markers/{name}/{name}.png".format(name=self.name), region=(754, 112, 1162-754, 306-112))
if activity:
return True
else:
return False
@property
def complete(self):
if pyscreeze.locateOnScreen("./images/markers/{name}/{name}_completion.png".format(name=self.name), region=(518, 856, 1406-518, 978-856)):
return True
else:
return False
@property
def time_stopped(self):
time_shot = pyscreeze.screenshot("./images/markers/timer_timestamp.png", region=(886, 760, 1034-886, 818-760))
time.sleep(1)
return True
def play(self):
pass
def repair(self):
if self.button:
pyautogui.click(self.button)
self.play()