forked from e1399579/autojs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path蚂蚁庄园.js
86 lines (73 loc) · 2.25 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
auto();
const WIDTH = Math.min(device.width, device.height);
const HEIGHT = Math.max(device.width, device.height);
start();
function start() {
var timeout = 10000;
// 截图权限申请
threads.start(function () {
var remember;
var beginBtn;
if (remember = id("com.android.systemui:id/remember").checkable(true).findOne(timeout)) {
remember.click();
}
if (beginBtn = classNameContains("Button").textContains("立即开始").findOne(timeout)) {
beginBtn.click();
}
});
if (!requestScreenCapture(false)) {
toastLog("请求截图失败");
exit();
}
toast("打开星星球界面");
app.startActivity({
action: "VIEW",
data: "alipays://platformapi/startapp?appId=66666782"
});
waitForActivity("com.alipay.mobile.nebulacore.ui.H5Activity");
toast("进入星星球成功");
sleep(5000);
var antManor = new AntManor();
antManor.play();
exit();
}
function AntManor() {
this.colors = ["#FF4C4C", "#4E86FF"];
this.find_time = 5000;
this.play = function () {
var len = this.colors.length;
var wait_time = 100;
var baseline = device.height * 0.412 | 0;
var min_height = baseline * 0.55 | 0;
// 发球
var point = this.findColorPoint(len);
var x = point.x;
var y = point.y;
click(x, y);
while (1) {
var point = this.findColorPoint(len);
var x = point.x;
var y = point.y;
if (min_height <= y && y <= baseline)
click(x, baseline);
}
};
this.findColorPoint = function (len) {
var wait_time = 100;
for (var time = 0;time < this.find_time;time += wait_time) {
for (var i = 0;i < len;i++) {
var capture = captureScreen();
if (!capture) {
sleep(50);
continue;
}
var color = this.colors[i];
var point = findColorEquals(capture, color, 0, 0, WIDTH, HEIGHT);
if (point !== null) {
return point;
}
}
}
return null;
};
}