"""Бот для рыбалки WOW 3.3.5""" import time import os from PIL import ImageGrab import cv2 import numpy as np import pyautogui dev = False directory = 'floats' # В случае наличия другой папки с поплавками указать путь к ней floats = os.listdir(directory) # Получаем список шаблонов в папке # quantity_floats = len(floats) def use_skill(): pyautogui.press('1') time.sleep(2) # print('Удочка закинута!', time.strftime("%M:%S", time.gmtime())) def make_screenshot(): """Функция создания скриншотов, возвращает имя и путь сохраненного скриншота""" # Делаем и сохраняем скриншот screen_screenshot = ImageGrab.grab() screen_screenshot.save("screenshotsFS/screenshot.png") # FS(For Search), нужно создать папку return "screenshotsFS/screenshot.png" def find_float(screenshot): # print('Старт функции поиска', time.strftime("%M:%S", time.gmtime())) """Функция поиска поплавка по шаблонам. В нее подгружаются скриншоты постоянно. На основе шаблона ищется поплавок""" for float in floats: # Считываем шаблон, необходимо делать шаблон под локацию template = cv2.imread(f"floats/{float}", 0) w, h = template.shape[::-1] # Считываем скриншот img_rgb = cv2.imread(screenshot) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) # Поиск по шаблону с помощью OpenCV res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED) # Порог точности threshold = 0.6 # numpy фильтрует наши результаты по порогу loc = np.where(res >= threshold) # выводим результаты на картинку for pt in zip(*loc[::-1]): cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2) x = int(pt[0]) y = int(pt[1]) # и если результаты всё же есть, то возвращаем координаты и сохраняем картинку if loc[0].any(): # print(loc[0], x, y) # print(f'Поплавок {float} найден!', time.strftime("%M %S", time.gmtime())) cv2.imwrite(f'succesS/result{time.strftime("%M %S", time.gmtime())}.png', img_rgb) # print('Конец функции поиска', time.strftime("%M:%S", time.gmtime())) return (x + w / 2), (y + h / 2), x, y, w, h # возврат координат в случае успеха def move_mouse(coordinates): """Перемещение мыши к координатам из find_float""" pyautogui.moveTo(coordinates) time.sleep(1) def check_fish(coordinates): """Проверка поклёвки""" success = False average = [0] x, y, w, h = coordinates for _ in range(40): clean_screen = ImageGrab.grab(bbox=(x, y, x + w, y + h)) # получение скрина поплавка mean = np.mean(clean_screen) print(mean) diff = average[-1] - mean print(average[-1] - mean) if diff >= 3: return True break average.append(mean) average = [0] def snatch(): """Вытаскивание рыбы""" pyautogui.click(button='right') print('Рыба поймана') def main(): use_skill() screenshot = make_screenshot() coordinates = find_float(screenshot) if coordinates: coord4move = coordinates[0], coordinates[1] move_mouse(coord4move) coord4check = coordinates[2], coordinates[3], coordinates[4], coordinates[5] # print(coord4check) print(check_fish(coord4check)) if check_fish(coord4check): snatch() else: time.sleep(3) snatch() else: print('Поплавок не найден') for _ in range(50): time.sleep(3) main()