This commit is contained in:
JerryXiao 2021-10-06 21:14:43 +08:00
parent e5e5cabf29
commit e8973545d2
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5

View file

@ -1,23 +1,28 @@
import pyautogui import pyautogui
import time import time
from PIL import ImageGrab from PIL import ImageGrab
import threading
# monkey patch # monkey patch
pyautogui.pyscreeze.ImageGrab = ImageGrab pyautogui.pyscreeze.ImageGrab = ImageGrab
pyautogui.pyscreeze.screenshot = pyautogui.pyscreeze._screenshot_win32 pyautogui.pyscreeze.screenshot = pyautogui.pyscreeze._screenshot_win32
def pyautogui_typewrite(btn, sleepintv=0.050*2, typeintv=0.030):
threading.Thread(target=pyautogui.typewrite, args=[btn, typeintv]).start()
time.sleep(sleepintv)
class lumberjackBot(): class lumberjackBot():
__author__ = "EnriqueMoran" __author__ = "EnriqueMoran"
def __init__(self, x, y): def __init__(self, x, y):
self.branch_width = 60 self.branch_width = 60
self.vertical_branch_distance = 70 self.vertical_branch_distance = 120
self.to_match = (169, 113, 65) self.to_match = (169, 113, 65)
self.speed = 0.08 self.speed = 0.078
self.sleep = 0.083 self.sleep = 0.083
self.sleep_min = 0.078 self.sleep_min = 0.045*2
self.sleep_max = 0.090 self.sleep_max = 0.050*2
self.xl = x - self.branch_width self.xl = x - self.branch_width
self.xr = x + self.branch_width self.xr = x + self.branch_width
@ -32,18 +37,18 @@ class lumberjackBot():
def play(self): def play(self):
last = [True]*5 last = [True]*5
pyautogui.typewrite(['right', 'right'], self.speed) pyautogui_typewrite(['right', 'right'], self.speed)
while True: while True:
match_l, match_r = self.get_pixel() match_l, match_r = self.get_pixel()
if match_l: if match_l:
print('left match') print('left match')
pyautogui.typewrite(['right', 'right'], self.speed) pyautogui_typewrite(['right', 'right'], self.speed)
elif match_r: elif match_r:
print('right match') print('right match')
pyautogui.typewrite(['left', 'left'], self.speed) pyautogui_typewrite(['left', 'left'], self.speed)
else: else:
if not last[-1]: if not last[-1]:
pyautogui.typewrite(['right', 'right'], self.speed) pyautogui_typewrite(['right', 'right'], self.speed)
print('!! no match') print('!! no match')
last.append(match_l or match_r) last.append(match_l or match_r)
while len(last) > 5: while len(last) > 5: