Skip to content

Commit 27f976c

Browse files
committed
添加爱心图片,可以帮TA收取了
1 parent 75c3233 commit 27f976c

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

help.png

4.57 KB
Loading

help2160.png

4.4 KB
Loading

蚂蚁森林.js

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ function TaskManager() {
8989
var task_list = this.getTaskList();
9090
this.task_no = task_list.indexOf(engines.myEngine());
9191
log(Object.keys(task_list));
92-
}.bind(this);
92+
};
9393

9494
this.getTaskList = function () {
9595
return engines.all().sort(function(e1, e2) {
9696
return e1.getTag(this.time_tag) - e2.getTag(this.time_tag);
9797
}.bind(this));
98-
}.bind(this);
98+
};
9999

100100
this.listen = function() {
101101
// 子线程
@@ -107,7 +107,7 @@ function TaskManager() {
107107
exit();
108108
});
109109
});
110-
}.bind(this);
110+
};
111111

112112
this.waitFor = function () {
113113
while (1) {
@@ -122,7 +122,7 @@ function TaskManager() {
122122
break;
123123
}
124124
}
125-
}.bind(this);
125+
};
126126
}
127127

128128
/**
@@ -141,13 +141,15 @@ function AntForest(robot, options) {
141141
max_swipe_times: 100, // 好友列表最多滑动次数
142142
min_time: "7:14:00", // 检测时段
143143
max_time: "7:15:50",
144-
check_within_time: 5
144+
check_within_time: 5,
145+
help_img: ""
145146
};
146147
this.options = Object.assign(settings, options);
147148
this.package = "com.eg.android.AlipayGphone"; // 支付宝包名
148149
this.state = {};
149150
this.capture = null;
150151
this.bounds = [0, 0, WIDTH, 1100];
152+
this.icon_num = 1;
151153

152154
toastLog("即将收取能量,按音量上键停止");
153155

@@ -276,10 +278,18 @@ function AntForest(robot, options) {
276278
var power = this.getPower() - startPower;
277279
if (power > 0) toastLog("收取了" + power + "g自己的能量");
278280

281+
var icon_list = [];
279282
var icon = images.read(this.options.takeImg);
280283
if (null === icon) {
281284
throw new Error("缺少图片文件,请仔细查看使用方法的第一条!!!");
282285
}
286+
icon_list = [icon];
287+
var icon2;
288+
if (this.options.help_img && (icon2 = images.read(this.options.help_img))) {
289+
icon_list[1] = icon2;
290+
}
291+
this.icon_num = icon_list.length;
292+
283293
// 截图权限申请
284294
threads.start(function () {
285295
var remember;
@@ -301,9 +311,8 @@ function AntForest(robot, options) {
301311
sleep(500);
302312
log("开始收取好友能量");
303313

304-
var total = 0;
305314
var bottom = 0;
306-
total += this.takeOthers(icon, 500, function () {
315+
var total_list = this.takeOthers(icon_list, 500, function () {
307316
var rect = desc("合种").findOnce().bounds();
308317

309318
if (rect.bottom === bottom) {
@@ -329,11 +338,11 @@ function AntForest(robot, options) {
329338
this.robot.swipe(WIDTH / 2, y, WIDTH / 2, 0);
330339
sleep(500);
331340

332-
var page, min_minute, swipe_sleep = 500;
341+
var page, min_minute, add_total_list, swipe_sleep = 500;
333342
for (;;) {
334343
log("往下翻页");
335344
page = 0;
336-
total += this.takeOthers(icon, swipe_sleep, function () {
345+
add_total_list = this.takeOthers(icon_list, swipe_sleep, function () {
337346
/*var selector = desc("没有更多了");
338347
if (!selector.exists()) return false;
339348
@@ -342,6 +351,7 @@ function AntForest(robot, options) {
342351
return (page > this.options.max_swipe_times)
343352
|| (findColorEquals(this.capture, "#30BF6C", WIDTH - 300, 0, 200, HEIGHT) !== null);
344353
}.bind(this));
354+
this.addTotal(total_list, add_total_list);
345355

346356
minuteList = this.statisticsNextTime();
347357
this.filterMinuteList(minuteList);
@@ -362,11 +372,12 @@ function AntForest(robot, options) {
362372

363373
log("往上翻页");
364374
page = 0;
365-
total += this.takeOthers(icon, swipe_sleep, function () {
375+
add_total_list = this.takeOthers(icon_list, swipe_sleep, function () {
366376
page++;
367377
return (page > this.options.max_swipe_times)
368378
|| (findColorEquals(this.capture, "#EFAE44", 0, 0, 110, HEIGHT / 2) !== null);
369379
}.bind(this), "prev");
380+
this.addTotal(total_list, add_total_list);
370381
}
371382

372383
this.back();
@@ -389,7 +400,11 @@ function AntForest(robot, options) {
389400
added = Math.max(0, added);
390401

391402
this.back();
392-
toastLog("收取完毕,共" + total + "个好友," + added + "g能量");
403+
var message = "收取完毕,共" + total_list[0] + "个好友," + added + "g能量";
404+
if (this.icon_num > 1) {
405+
message += ",帮了" + total_list[1] + "个好友收取";
406+
}
407+
toastLog(message);
393408
sleep(1500);
394409

395410
// 统计部分,可以删除
@@ -407,6 +422,12 @@ function AntForest(robot, options) {
407422
}
408423
};
409424

425+
this.addTotal = function (total_list, add_total_list) {
426+
for (var i = 0; i < this.icon_num; i++) {
427+
total_list[i] += add_total_list[i];
428+
}
429+
};
430+
410431
this.statisticsNextTime = function () {
411432
var minuteList = [];
412433
descMatches(/\d+/).find().forEach(function (o) {
@@ -535,15 +556,16 @@ function AntForest(robot, options) {
535556

536557
/**
537558
* 收取好友能量
538-
* @param icon
559+
* @param icon_list
539560
* @param isEndFunc
540561
* @param swipe_sleep
541562
* @param scroll
542-
* @returns {number}
563+
* @returns {Array}
543564
*/
544-
this.takeOthers = function (icon, swipe_sleep, isEndFunc, scroll) {
565+
this.takeOthers = function (icon_list, swipe_sleep, isEndFunc, scroll) {
545566
var row = (192 * (HEIGHT / 1920)) | 0;
546-
var total = 0;
567+
var total_list = [];
568+
var take_num = icon_list.length;
547569
var x1, y1, x2, y2;
548570
x2 = x1 = WIDTH / 2;
549571
switch (scroll) {
@@ -557,8 +579,14 @@ function AntForest(robot, options) {
557579
y2 = HEIGHT - row;
558580
break;
559581
}
582+
for (var i = 0; i < take_num; i++) {
583+
total_list[i] = 0;
584+
}
560585
while (1) {
561-
total += this.takeFromImage(icon);
586+
for (var i = 0; i < take_num; i++) {
587+
var icon = icon_list[i];
588+
total_list[i] += this.takeFromImage(icon);
589+
}
562590

563591
if (isEndFunc()) {
564592
break;
@@ -568,7 +596,7 @@ function AntForest(robot, options) {
568596
sleep(swipe_sleep); // 等待滑动动画
569597
}
570598

571-
return total;
599+
return total_list;
572600
};
573601

574602
/**

蚂蚁森林设置向导.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ var default_config = {
99
min_time: "7:14:00", // 检测时段
1010
max_time: "7:15:50",
1111
max_swipe_times: 100, // 好友列表最多滑动次数
12-
check_within_time: 5 // 排行反复检测5分钟以内
12+
check_within_time: 5, // 排行反复检测5分钟以内
13+
help_img: "" // 帮TA收取用到的图片
1314
};
1415
if (typeof config !== "object") {
1516
config = {};
@@ -23,9 +24,13 @@ function showSettings(options) {
2324
<frame>
2425
<vertical h="auto" align="center" w="auto">
2526
<linear>
26-
<text w="96" h="*" gravity="right|center" size="16">图片路径</text>
27+
<text w="96" h="*" gravity="right|center" size="16">收取图片路径</text>
2728
<input id="takeImg" w="150" h="40" />
2829
</linear>
30+
<linear>
31+
<text w="96" h="*" gravity="right|center" size="16">爱心图片路径</text>
32+
<input id="help_img" w="150" h="40" />
33+
</linear>
2934
<linear>
3035
<text w="96" h="*" gravity="right|center" size="16">锁屏密码</text>
3136
<input id="password" w="150" h="40" />

0 commit comments

Comments
 (0)