class Display: def __init__(self): self.vision = Vision( { "top": 850, "left": 1920, "width": 500, "height": 200 }, ratio=0.25) def show_grid(self): # loop_time = time() while True: self.vision.capture_window() self.vision.draw_grid(text=True) cv2.imshow("screen", self.vision.sct_img) # print("FPS {}".format(round(1 / (time() - loop_time), 2))) # loop_time = time() if (cv2.waitKey(1) & 0xFF) == ord("q"): cv2.destroyAllWindows() break
class Bot: def __init__(self, ratio=1): self.RUN = True self.TOGGLE = False self.vision = Vision(ratio=ratio) self.keyboard = Keyboard(sleep=1) self.KEYCODES = {1: 18, 2: 19, 3: 20, 4: 21, 5: 23} self.potions_box = {"top": 850, "left": 1920, "width": 500, "height": 200} self.menu_box = {"top": 300, "left": 1920 + 680, "width": 320, "height": 260} self.mouse = Mouse() def drink_defense_potion(self, x, y, xb, yb, channel, slot): print("Starting drink_defense_potion") while self.RUN: if not self.TOGGLE: sleep(0.1) continue self.vision.capture_window(self.potions_box) dp = self.vision.pcat(x=x, y=y, channel=channel, threshold=60) dp_bar = self.vision.pcat(x=xb, y=yb, channel="green", threshold=200) if dp and not dp_bar: self.keyboard.key(KeyCode.from_vk(self.KEYCODES[slot])) print(f"Drinking from Defense Potion {slot}") sleep(1) def run_fast(self): print("Starting run_fast") while self.RUN: if not self.TOGGLE: sleep(0.1) continue self.vision.capture_window(self.potions_box) qs4 = self.vision.pcat(x=425, y=175, channel="green", threshold=70) qs4_bar = self.vision.pcat(x=418, y=194, channel="green", threshold=200) qs5 = self.vision.pcat(x=465, y=175, channel="green", threshold=60) qs5_bar = self.vision.pcat(x=459, y=194, channel="green", threshold=200) if not qs5_bar and not qs4_bar: if qs4: self.keyboard.key(KeyCode.from_vk(self.KEYCODES[4])) print("Drinking from QS4") sleep(0.5) elif qs5: self.keyboard.key(KeyCode.from_vk(self.KEYCODES[5])) print("Drinking from QS5") sleep(0.5) def drink_life_potions(self): print("Starting drink_life_potions") while self.RUN: if not self.TOGGLE: sleep(0.1) continue self.vision.capture_window(self.potions_box) life_10 = self.vision.pcat(x=105, y=15, channel="red", threshold=70) life_20 = self.vision.pcat(x=105, y=25, channel="red", threshold=80) life_30 = self.vision.pcat(x=105, y=35, channel="red", threshold=80) life_40 = self.vision.pcat(x=105, y=45, channel="red", threshold=80) life_50 = self.vision.pcat(x=102, y=55, channel="red", threshold=80) life_60 = self.vision.pcat(x=102, y=65, channel="red", threshold=80) life_70 = self.vision.pcat(x=105, y=75, channel="red", threshold=80) life_80 = self.vision.pcat(x=105, y=85, channel="red", threshold=80) life_90 = self.vision.pcat(x=105, y=95, channel="red", threshold=80) life_100 = self.vision.pcat(x=105, y=105, channel="red", threshold=80) life_110 = self.vision.pcat(x=105, y=115, channel="red", threshold=80) life_120 = self.vision.pcat(x=105, y=125, channel="red", threshold=80) life_130 = self.vision.pcat(x=105, y=135, channel="red", threshold=80) life_140 = self.vision.pcat(x=105, y=145, channel="red", threshold=70) life_150 = self.vision.pcat(x=105, y=155, channel="red", threshold=70) life_160 = self.vision.pcat(x=105, y=165, channel="red", threshold=60) life_170 = self.vision.pcat(x=105, y=175, channel="red", threshold=60) life_1 = self.vision.pcat(x=298, y=175, channel="red", threshold=60) life_2 = self.vision.pcat(x=338, y=175, channel="red", threshold=60) in_game = self.vision.pcat(238, 126, channel="green", threshold=70) if not life_120 and in_game: self.keyboard.quit() print("Emergency exit (life too low)") if not life_30: if life_1: self.keyboard.key(KeyCode.from_vk(self.KEYCODES[1])) print("Drinking from LP1") sleep(0.1) elif life_2: self.keyboard.key(KeyCode.from_vk(self.KEYCODES[2])) print("Drinking from LP2") sleep(0.1) elif in_game: self.keyboard.quit() print("Emergency exit (No more potions)") def listen(self): print("Starting listen") while self.RUN: listener = Listener() listener.listen() if listener.last_key == "home": if self.TOGGLE: print("Toggling OFF") self.TOGGLE = False else: print("Toggling ON") self.TOGGLE = True if listener.last_key == "end": print("Quitting") self.RUN = False def logout(self): while self.RUN: self.vision.capture_window(self.menu_box) found = self.vision.template_match("exit.png") if found: self.mouse.set_position( x=int(1920 + 680 + 256 / 2 + found[0][0]), y=int(300 + 24 / 2 + found[0][1]), ) self.mouse.double_click()