-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbotFunctions.py
More file actions
106 lines (85 loc) · 2.56 KB
/
botFunctions.py
File metadata and controls
106 lines (85 loc) · 2.56 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import cv2
import os
import numpy as np
from matplotlib import pyplot as plt
import win32api, win32con
import pyscreenshot as ImageGrab
import time
from PIL import ImageChops
def findCordinates(data):
img = cv2.imread('screenshots/screen.jpg',0)
img2 = img.copy()
template = cv2.imread('refrences/'+data,0)
w, h = template.shape[::-1]
# All the 6 methods for comparison in a list
meth = 'cv2.TM_CCOEFF_NORMED'
img = img2.copy()
method = eval(meth)
# Apply template Matching
res = cv2.matchTemplate(img,template,method)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = max_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
centerX = int((top_left[0] + bottom_right[0]) / 2)
centerY = int((top_left[1] + bottom_right[1]) / 2)
return (centerX,centerY)
def capture(data):
if data == 'add':
im = ImageGrab.grab()
im.save('screenshots/screen.jpg')
elif data == 'remove':
os.remove("screenshots/screen.jpg")
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
def clickElement(data):
capture('add')
cordinates = findCordinates(data+'.png')
click(cordinates[0], cordinates[1])
def findElement(data):
capture('add')
cordinates = findCordinates(data+'.png')
return cordinates
def champSelect():
clickElement('supporticon')
clickElement('soraka')
clickElement('lockin')
print("Done")
input()
def detectChangeOnScreen():
im = ImageGrab.grab(bbox=(50,50,100,100))
while True:
diff = ImageChops.difference(ImageGrab.grab(bbox=(50,50,500,500)), im)
bbox = diff.getbbox()
if bbox is not None: # exact comparison
break
return True
def cgangeScreen():
screenchanged = False
while screenchanged == False:
screenchanged = detectChangeOnScreen()
print("Screen Changed, Continue to next task")
return
def startGame():
matchfound = False
#Click play button
clickElement('play')
time.sleep(1)
clickElement('coop')
time.sleep(1)
clickElement('intermediate')
time.sleep(1)
clickElement('confirm')
time.sleep(3)
clickElement('findmatch')
cords = findElement('accept')
time.sleep(2)
while matchfound == False:
tmpcords = findElement('decline')
if tmpcords != cords:
click(tmpcords[0], tmpcords[1])
matchfound = True;
time.sleep(1)
print("Done")
input()