forked from yuanninesuns/AutoHS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclick.py
More file actions
298 lines (213 loc) · 6.48 KB
/
click.py
File metadata and controls
298 lines (213 loc) · 6.48 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import win32gui
import win32api
import win32con
import pywintypes
import time
from pynput.mouse import Button, Controller
import random
# import get_screen
import sys
from constants.constants import *
from print_info import *
from get_screen import *
#测试不同分辨率的点击效果,因为屏幕截取未支持不同分辨率,失败了
#炉石传说坐标
# hwnd_left,hwnd_top, hwnd_right, hwnd_bottom = 0,0,0,0
# hwnd_width = 0
# hwnd_height = 0
#获取炉石传说的分辨率
#得到不同分辨率下的点击位置
# def hs_size():
# hwnd = get_HS_hwnd()
# global hwnd_left
# global hwnd_top
# global hwnd_right
# global hwnd_bottom
# hwnd_left,hwnd_top,hwnd_right,hwnd_bottom = win32gui.GetWindowRect(hwnd)
# # print(left)
# # print(top)
# # print(right)
# # print(bottom)
# global hwnd_width
# global hwnd_height
# hwnd_width = hwnd_right - hwnd_left -16
# hwnd_height = hwnd_bottom - hwnd_top -39
# print(hwnd_width)
# print(hwnd_height)
# # 1440 900 = 1456 939
# # 16 39
# # 1400 1050 = 1416 1089
# # 16 39
# def position_x(x):
# global hwnd_width
# global hwnd_left
# if hwnd_width == 0:
# return x
# return x * (hwnd_width / 1920) + 16 + hwnd_left
# def position_y(y):
# global hwnd_height
# global hwnd_top
# if hwnd_height == 0:
# return y
# return y * (hwnd_height / 1920) + 39 + hwnd_top
def rand_sleep(interval):
base_time = interval * 0.75
rand_time = interval * 0.5 * random.random() # avg = 0.25 * interval
time.sleep(base_time + rand_time)
def click_button(x, y, button):
# x = position_x(x)
# y = position_y(y)
mouse = Controller()
rand_sleep(0.1)
mouse.position = (x, y)
rand_sleep(0.1)
mouse.press(button)
rand_sleep(0.1)
mouse.release(button)
def left_click(x, y):
x += random.randint(-2, 3)
y += random.randint(-2, 3)
click_button(x, y, Button.left)
def right_click(x, y):
click_button(x, y, Button.right)
def choose_my_minion(mine_index, mine_num):
rand_sleep(OPERATE_INTERVAL)
x = 960 - (mine_num - 1) * 70 + mine_index * 140
y = 600
left_click(x, y)
def choose_my_hero():
rand_sleep(OPERATE_INTERVAL)
left_click(960, 850)
def choose_opponent_minion(oppo_index, oppo_num):
rand_sleep(OPERATE_INTERVAL)
x = 960 - (oppo_num - 1) * 70 + oppo_index * 140
y = 400
left_click(x, y)
def choose_oppo_hero():
rand_sleep(OPERATE_INTERVAL)
left_click(960, 200)
def cancel_click():
rand_sleep(TINY_OPERATE_INTERVAL)
right_click(50, 400)
def test_click():
rand_sleep(TINY_OPERATE_INTERVAL)
left_click(50, 400)
HAND_CARD_X = [
[], # 0
[885], # 1
[820, 980], # 2
[750, 890, 1040], # 3
[690, 820, 970, 1130], # 4
[680, 780, 890, 1010, 1130], # 5
[660, 750, 840, 930, 1020, 1110], # 6
[660, 733, 810, 885, 965, 1040, 1120], # 7
[650, 720, 785, 855, 925, 995, 1060, 1130], # 8
[650, 710, 765, 825, 880, 950, 1010, 1070, 1140], # 9
[647, 700, 750, 800, 860, 910, 970, 1020, 1070, 1120] # 10
]
def choose_card(card_index, card_num):
rand_sleep(OPERATE_INTERVAL)
assert 0 <= card_index < card_num <= 10
# x = START[card_num] + 65 + STEP[card_num] * card_index
x = HAND_CARD_X[card_num][card_index]
y = 1000
left_click(x, y)
STARTING_CARD_X = {
3: [600, 960, 1320],
5: [600, 850, 1100, 1350],
}
def replace_starting_card(card_index, hand_card_num):
assert hand_card_num in STARTING_CARD_X
assert card_index < len(STARTING_CARD_X[hand_card_num])
rand_sleep(OPERATE_INTERVAL)
left_click(STARTING_CARD_X[hand_card_num][card_index], 500)
def click_middle():
rand_sleep(OPERATE_INTERVAL)
left_click(960, 500)
def click_setting():
rand_sleep(OPERATE_INTERVAL)
left_click(1880, 1050)
def choose_and_use_spell(card_index, card_num):
choose_card(card_index, card_num)
click_middle()
# 第[i]个随从左边那个空隙记为第[i]个gap
def put_minion(gap_index, minion_num):
rand_sleep(OPERATE_INTERVAL)
if minion_num >= 7:
warn_print(f"Try to put a minion but there has already been {minion_num} minions")
x = 960 - (minion_num - 1) * 70 + 140 * gap_index - 70
y = 600
left_click(x, y)
def match_opponent():
# 一些奇怪的错误提示
commit_error_report()
rand_sleep(OPERATE_INTERVAL)
left_click(1400, 900)
def enter_battle_mode():
# 一些奇怪的错误提示
commit_error_report()
rand_sleep(OPERATE_INTERVAL)
left_click(950, 320)
def commit_choose_card():
rand_sleep(OPERATE_INTERVAL)
left_click(960, 850)
def end_turn():
rand_sleep(OPERATE_INTERVAL)
left_click(1550, 500)
def commit_error_report():
# 一些奇怪的错误提示
left_click(1100, 820)
# 如果已断线, 点这里时取消
left_click(960, 650)
def emoj(target=None):
emoj_list = [(800, 880), (800, 780), (800, 680), (1150, 680), (1150, 780)]
right_click(960, 830)
rand_sleep(OPERATE_INTERVAL)
if target is None:
x, y = emoj_list[random.randint(1, 4)]
else:
x, y = emoj_list[target]
left_click(x, y)
rand_sleep(OPERATE_INTERVAL)
def click_skill():
rand_sleep(OPERATE_INTERVAL)
left_click(1150, 850)
def use_skill_no_point():
click_skill()
cancel_click()
def use_skill_point_mine(my_index, my_num):
click_skill()
if my_index < 0:
choose_my_hero()
else:
choose_my_minion(my_index, my_num)
cancel_click()
def minion_beat_minion(mine_index, mine_number, oppo_index, oppo_num):
choose_my_minion(mine_index, mine_number)
choose_opponent_minion(oppo_index, oppo_num)
cancel_click()
def minion_beat_hero(mine_index, mine_number):
choose_my_minion(mine_index, mine_number)
choose_oppo_hero()
cancel_click()
def hero_beat_minion(oppo_index, oppo_num):
choose_my_hero()
choose_opponent_minion(oppo_index, oppo_num)
cancel_click()
def hero_beat_hero():
choose_my_hero()
choose_oppo_hero()
cancel_click()
def enter_HS():
rand_sleep(1)
if test_hs_available():
move_window_foreground(get_HS_hwnd(), "炉石传说")
return
battlenet_hwnd = get_battlenet_hwnd()
if battlenet_hwnd == 0:
error_print("未找到应用战网")
sys.exit()
move_window_foreground(battlenet_hwnd, "战网")
rand_sleep(1)
left, top, right, bottom = win32gui.GetWindowRect(battlenet_hwnd)
left_click(left + 180, bottom - 110)