walterdis / lunarush-bot

Luna Rush Bot Auto Clicker
GNU General Public License v3.0
32 stars 20 forks source link

Resolvendo o "Tips" #63

Closed Daltsop closed 2 years ago

Daltsop commented 2 years ago

from random import random, uniform import sys import cv2 import mss import time import numpy as np import pyautogui

try: from pyclick import HumanClicker except ImportError or ModuleNotFoundError: print('pyclick not found! Run pip install -r requirements.txt again.') time.sleep(5) sys.exit(1)

clicker = HumanClicker()

hc = HumanClicker() pyautogui.MINIMUM_DURATION = 0.1 pyautogui.MINIMUM_SLEEP = 0.1 pyautogui.PAUSE = 1

def moveDestination(x, y, time=2): hc.move((int(x), int(y)), time)

def clickDestination(x, y, duration=2): moveDestination(x, y, duration) time.sleep(1) pyautogui.click()

def clickDestinationImage(img, name=None, timeout=2, threshold=0.7): if not name is None: pass

start = time.time()
while(True):
    matches = getImagePositions(img, threshold)
    if(len(matches) == 0):
        has_timed_out = time.time()-start > timeout
        if(has_timed_out):
            return False

        continue

    x, y, w, h = matches[0]

    pos_click_x = round(x+w/2+uniform(2, 10))
    pos_click_y = round(y+h/2+uniform(-2, -10))

    clickDestination(pos_click_x, pos_click_y, 2)

    #pyautogui.moveTo(pos_click_x, pos_click_y, 1 + random()/2)
    # pyautogui.click()

    return True

def hasImage(name, threshold=0.7, img=None): image = getImagePositions(name, threshold, img)

return len(image) > 0

def getImage(filename): path = 'target_images/' + filename

return cv2.imread(path)

def getImagePositions(imageName, threshold=0.7, img=None): if img is None: img = printSreen()

target = getImage(imageName)

result = cv2.matchTemplate(img, target, cv2.TM_CCOEFF_NORMED)
w = target.shape[1]
h = target.shape[0]

yloc, xloc = np.where(result >= threshold)

rectangles = []
for (x, y) in zip(xloc, yloc):
    rectangles.append([int(x), int(y), int(w), int(h)])
    rectangles.append([int(x), int(y), int(w), int(h)])

rectangles, weights = cv2.groupRectangles(rectangles, 1, 0.2)

return rectangles

def printSreen(): with mss.mss() as sct: monitor = sct.monitors[0] sct_img = np.array(sct.grab(monitor))

    return sct_img[:, :, :3]

def handlePopup(screen=None): time.sleep(1) if screen is None: screen = printSreen()

if(hasImage('button-ok.png', 0.8, screen)):
    clickDestinationImage('button-ok.png', None, 2, 0.8)

if(hasImage('button-ok2.png', 0.8, screen)):
    clickDestinationImage('button-ok2.png', None, 2, 0.8)

if(hasImage('button-seta-dupla.png', 0.8, screen)):
    clickDestinationImage('button-seta-dupla.png', None, 2, 0.8)

if(hasImage('button-x.png', 0.8, screen)):
    clickDestinationImage('button-x.png', None, 2, 0.8)

if(hasImage('button-x2.png', 0.8, screen)):
    clickDestinationImage('button-x2.png', None, 2, 0.8)

button-ok2 button-seta-dupla button-x2

walterdis commented 2 years ago

Opa cara, não posso dar merge nesse seu pull request.

Tens que baixar o projeto via git, fazer as modificações no código, fazer um commit com as mudanças e ai sim fazer o envio do PR.

Colar o código dessa forma vai dar problema no sistema, fora os arquivos não modificados que ele está querendo substituir ;)

Daltsop commented 2 years ago

Peço desculpas.

Vou refazer seguindo suas orientações e reenvio