-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathleague.py
134 lines (114 loc) · 3.87 KB
/
league.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import pyautogui
import pyperclip
import window
import os
from random import seed
from random import randint
import time
# client window size
# 1024 x 576
# 1280 x 720 -- currently used
# 1600 x 900
class Reporter:
def __init__(self, logger, images, cwd):
self.logger = logger
self.images = images
with open(os.path.join(cwd, 'reportText.txt'), encoding='utf8') as file:
self.reportText = file.read()
self.cancel_1280_720 = pyautogui.Point(865, 75)
self.team_1280_720 = [
pyautogui.Point(280, 150),
pyautogui.Point(280, 190),
pyautogui.Point(280, 230),
pyautogui.Point(280, 270),
pyautogui.Point(280, 310),
]
self.enemy_1280_720 = [
pyautogui.Point(280, 395),
pyautogui.Point(280, 435),
pyautogui.Point(280, 475),
pyautogui.Point(280, 515),
pyautogui.Point(280, 555),
]
def reportTeam(self):
self.logger.info("report teammates")
client = window.LeagueClient()
clientSize = client.getSize()
client.bringFront()
if clientSize == (1280, 720):
self.report(client, self.team_1280_720)
else:
self.logger.warning("not supported window size: %s", clientSize)
def reportEnemy(self):
self.logger.info("report enemies")
client = window.LeagueClient()
clientSize = client.getSize()
client.bringFront()
if clientSize == (1280, 720):
self.report(client, self.enemy_1280_720)
else:
self.logger.warning("not supported window size: %s", clientSize)
def reportAll(self):
self.logger.info("report all other players")
self.reportTeam()
self.reportEnemy()
def report(self, client, targets):
self.logger.info('report() >>>')
self.logger.info("client: %s", client.rect)
for point in targets:
self.reportAPlayer(client.rect, point)
self.logger.info('report() <<<')
def reportAPlayer(self, leagueRegion, point):
# move directly to the report button
reportPoint = pyautogui.Point(leagueRegion[0] + point.x, leagueRegion[1] + point.y + 20)
self.logger.info("move mouse to report button: %s", reportPoint)
pyautogui.moveTo(reportPoint)
pyautogui.mouseDown(reportPoint, button='left', duration=1.0)
pyautogui.mouseUp(reportPoint, button='left')
time.sleep(0.3)
self.logger.info("locate check boxes")
# locate report check boxes
checkboxes = list(pyautogui.locateAllOnScreen(self.images.checkbox, region=leagueRegion, confidence=0.7))
if checkboxes:
# now we can check them all
for cb in checkboxes:
pyautogui.click(cb)
# paste report text to comment text field
commentTextField = pyautogui.locateCenterOnScreen(self.images.commentText, region=leagueRegion)
if commentTextField:
pyautogui.click(commentTextField)
pyperclip.copy(self.reportText)
pyautogui.hotkey('ctrl','v')
# cancel report for testing
# cancel = pyautogui.Point(self.cancel_1280_720.x + leagueRegion[0], self.cancel_1280_720.y + leagueRegion[1])
# self.logger.info(cancel)
# if cancel:
# pyautogui.click(cancel)
# return
#press report confirm button
reportConfirmRetry = 3
while reportConfirmRetry > 0:
reportConfirm = pyautogui.locateCenterOnScreen(self.images.reportConfirm, region=leagueRegion)
if reportConfirm:
pyautogui.moveTo(reportConfirm)
pyautogui.click(reportConfirm)
break
else:
self.logger.debug("report confirm button not found, wait for 1 second to retry. %d left" % reportConfirmRetry)
reportConfirmRetry = reportConfirmRetry - 1
time.sleep(1)
pass
else:
self.logger.info('checkbox is not detected')
# cancel report and go on.
cancel = pyautogui.Point(self.cancel_1280_720.x + leagueRegion[0], self.cancel_1280_720.y + leagueRegion[1])
pyautogui.click(cancel)
def myRandom():
seed(time.time())
randomNumbers = []
for i in range(0,3):
rn = randint(0,6)
while rn in randomNumbers:
rn = randint(0,6)
randomNumbers.append(rn)
return randomNumbers