-
Notifications
You must be signed in to change notification settings - Fork 0
/
yys_v3_test.py
225 lines (210 loc) · 5.75 KB
/
yys_v3_test.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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*
from ctypes import *
import random
import time
import win32gui
import win32con
import win32api
import gc
# 全局变量
NAME = u"阴阳师-网易游戏"
HWND = win32gui.FindWindow(None, NAME)
GDI32 = windll.gdi32
USER32 = windll.user32
HDC = USER32.GetDC(HWND) # 获取颜色值
win32gui.SetWindowPos(HWND, win32con.HWND_NOTOPMOST, 0, 0, 1076, 636, win32con.SWP_NOMOVE) # 设置阴阳师窗口大小,需要权限比阴阳师进程高
# 用于设置各种场景的检测点
POINTS = {
'task': {
'x': 698,
'y': 422,
'color': 5597145
},
'hunTuStart': {
'x': 1014,
'y': 531,
'color': 8311532
},
'hunTuEndingA': {
'x': 68,
'y': 52,
'color': 2108221
},
'hunTuEndingB': {
'x': 60,
'y': 546,
'color': 5735338
},
'teamUp': {
'x': 364,
'y': 340,
'color': 4663948
},
'beTeam': {
'x': 114,
'y': 216,
'color': 6402902
},
'beFixedTeam': {
'x': 202,
'y': 227,
'color': 6665306
}
}
# 用于设置各种场景点击区域
MATRIX = {
'rejectTask': {
'x1': 702,
'y1': 425,
'x2': 702,
'y2': 425
},
'hunTuStart': {
'x1': 968,
'y1': 492,
'x2': 1050,
'y2': 572
},
'hunTuExit': {
'x1': 768,
'y1': 402,
'x2': 1048,
'y2': 586
},
'defaultInviteCheck': {
'x1': 466,
'y1': 300,
'x2': 466,
'y2': 300
},
'defaultInvite': {
'x1': 630,
'y1': 358,
'x2': 630,
'y2': 358
}
}
# 鼠标点击
def globalClick(cx, cy):
long_position = win32api.MAKELONG(cx, cy) # 模拟鼠标指针 传送到指定坐标
win32api.SendMessage(HWND, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, long_position) # 模拟鼠标按下
win32api.SendMessage(HWND, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, long_position) # 模拟鼠标弹起
# 获取坐标点的颜色值,返回十进制
def globalGetColor(x, y):
pixel = GDI32.GetPixel(HDC, x, y) # 提取RGB值
return pixel
# 判断2个颜色是否相近,返回布尔值
def globalCompareColors(pixel1, pixel2):
status = False
r1 = pixel1 & 0x0000ff
g1 = (pixel1 & 0x00ff00) >> 8
b1 = pixel1 >> 16
r2 = pixel2 & 0x0000ff
g2 = (pixel2 & 0x00ff00) >> 8
b2 = pixel2 >> 16
return abs(r1 - r2) < 10 and abs(g1 - g2) < 10 and abs(b1 - b2) < 10
class Onmyoji:
def __init__(self):
pass
def position(self):
pass
def teamUp(self):
pass
def taskInvitation(self):
pointTask = POINTS['task']
matrixRejectTask = MATRIX['rejectTask']
color = globalGetColor(pointTask['x'], pointTask['y'])
if globalCompareColors(pointTask['color'], color):
globalClick(matrixRejectTask['x1'], matrixRejectTask['y1'])
class Leader(Onmyoji):
def teamUp(self):
point = POINTS['teamUp']
matrixDefaultInviteCheck = MATRIX['defaultInviteCheck']
matrixDefaultInvite = MATRIX['defaultInvite']
color = globalGetColor(point['x'], point['y'])
if globalCompareColors(point['color'], color):
globalClick(matrixDefaultInviteCheck['x1'], matrixDefaultInviteCheck['y1'])
time.sleep(0.5)
globalClick(matrixDefaultInvite['x1'], matrixDefaultInvite['y1'])
class Member(Onmyoji):
def teamUp(self):
pointBeTeam = POINTS['beTeam']
pointBeFixedTeam = POINTS['beFixedTeam']
colorBeTeam = globalGetColor(pointBeTeam['x'], pointBeTeam['y'])
colorBeFixedTeam = globalGetColor(pointBeFixedTeam['x'], pointBeFixedTeam['y'])
if globalCompareColors(pointBeFixedTeam['color'], colorBeFixedTeam):
globalClick(pointBeFixedTeam['x'], pointBeFixedTeam['y'])
elif globalCompareColors(pointBeTeam['color'], colorBeTeam):
globalClick(pointBeTeam['x'], pointBeTeam['y'])
class Game:
def __init__(self, player):
self.player = player
def ready(self):
pass
def start(self):
pass
def ending(self):
pass
def teammateInvitation(self):
pass
class HunTu(Game):
def ready(self):
self.player.taskInvitation()
pointStart = POINTS['hunTuStart']
matrixStart = MATRIX['hunTuStart']
color = globalGetColor(pointStart['x'], pointStart['y'])
if globalCompareColors(pointStart['color'], color):
# print('game ready') # test handle
globalClick(
random.randint(matrixStart['x1'], matrixStart['x2']),
random.randint(matrixStart['y1'], matrixStart['y2'])
)
else:
# print('game not ready') # test handle
time.sleep(0.5)
self.ready()
# print('game start') # test handle
def ending(self, isEnding = False):
self.player.taskInvitation()
self.player.teamUp()
pointEndingA = POINTS['hunTuEndingA']
pointEndingB = POINTS['hunTuEndingB']
matrixExit = MATRIX['hunTuExit']
colorA = globalGetColor(pointEndingA['x'], pointEndingA['y'])
colorB = globalGetColor(pointEndingB['x'], pointEndingB['y'])
testA = globalCompareColors(pointEndingA['color'], colorA)
testB = globalCompareColors(pointEndingB['color'], colorB)
if bool(1 - isEnding):
time.sleep(0.5)
if testA or testB:
# print('game ending') # test handle
self.ending(True)
else:
# print('game not ending') # test handle
self.ending()
if testA or testB:
# print('game will ending') # test handle
globalClick(
random.randint(matrixExit['x1'], matrixExit['x2']),
random.randint(matrixExit['y1'], matrixExit['y2'])
)
time.sleep(0.5)
self.ending(True)
# print('game over') # test handle
# 主流程
print(u"由于开发时间有限, 目前仅支持魂土")
print(u"1: 队长")
print(u"2: 队员")
mode = int(input("请输入序号: "))
count = 1
player = Leader() if mode == 1 else Member()
game = HunTu(player)
while True:
print('number of runs: ', count)
count += 1
if mode == 1:
game.ready()
game.ending()
time.sleep(0.5)
gc.collect()