-
Notifications
You must be signed in to change notification settings - Fork 71
/
微信跳一跳.js
95 lines (86 loc) · 2.96 KB
/
微信跳一跳.js
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
console.show();
// 设备信息
var WIDTH = device.width,
HEIGHT = device.height,
TYPE = device.brand + ' ' + device.model;
log('设备信息:', TYPE, '\n分辨率:', WIDTH, '*', HEIGHT);
// 获取截图权限
if (!requestScreenCapture()) {
toast('请求截图失败,程序结束');
exit();
}
// 启动微信
launchApp('微信');
// 提示用户进入跳一跳页面
new java.lang.Thread(function() {
packageName('com.stardust.scriptdroid').className('android.widget.EditText').setText('准备好后点击 确定');
}).start();
console.rawInput('进入微信跳一跳,点击 开始游戏\n点击 确定 开始自动游戏');
do {
// 获取截图
var img = captureScreen();
// 触按位置
var bx1 = parseInt(WIDTH / 2 + random(-10, 10)),
bx2 = parseInt(WIDTH / 2 + random(-10, 10)),
by1 = parseInt(HEIGHT * 0.785 + random(-4, 4)),
by2 = parseInt(HEIGHT * 0.785 + random(-4, 4));
// 棋子底部中心找色
var CHESS_X, CHESS_Y;
var linemax = 0;
for (let r = parseInt(HEIGHT * 0.7); r > parseInt(HEIGHT * 0.5);) {
var line = [];
for (let c = parseInt(WIDTH * 0.15); c < parseInt(WIDTH * 0.85); c++) {
var point = images.pixel(img, c, r);
var red = colors.red(point),
green = colors.green(point),
blue = colors.blue(point);
if (red >= 40 && red <= 70 && green >= 40 && green <= 60 && blue >= 70 && blue <= 105) {
line.push(c);
}
}
if (line.length > linemax) {
linemax = line.length;
CHESS_X = line[Math.floor(line.length / 2)];
CHESS_Y = r;
}
else if (line.length < linemax) {
break;
}
r -= 5;
}
log('棋子X坐标:', CHESS_X);
// 目标块顶部中心X坐标
var TARGET_X, TARGET_Y;
for (let r = parseInt(HEIGHT * 0.3); r <= parseInt(HEIGHT * 0.5);) {
var flag = false;
for (let c = parseInt(WIDTH * 0.15); c < parseInt(WIDTH * 0.85); c++) {
if (Math.abs(c - CHESS_X) <= linemax) {
continue
}
var c0 = images.pixel(img, c, r);
var c1 = images.pixel(img, c, r - 5);
if (Math.abs(colors.red(c0) - colors.red(c1)) + Math.abs(colors.green(c0) - colors.green(c1)) + Math.abs(colors.blue(c0) - colors.blue(c1)) >= 30) {
TARGET_X = c;
TARGET_Y = r;
flag = true;
break;
}
}
if (flag) {
break;
}
r += 5;
}
// 寻找白点
var whitepoint = images.findColor(img, '#f5f5f5', {
region: [TARGET_X - 20, TARGET_Y, 40, 250],
threshold: 2
});
if (whitepoint) {
TARGET_X = whitepoint.x;
}
log('目标块X坐标:', TARGET_X);
// 跳!
swipe(bx1, by1, bx2, by2, Math.abs(CHESS_X - TARGET_X) / WIDTH * 1900);
sleep(random(1500, 2000));
} while (true);