Giter Club home page Giter Club logo

ant-forest-autoscript's Introduction

简介

基于 Autojs 的蚂蚁森林自动收能量脚本,采用 4.1.1 Alpha 版本开发。解锁模块参考自:https://github.com/e1399579/autojs

交流群:524611323

使用

下载安装 Autojs 之后把整个脚本项目放进 "/sdcard/脚本/" 文件夹下面。运行项目或者 main 即可。

功能

  • 自动匹配不同系统下自动化的方式,安卓7及以上通过无障碍服务模拟操作,以下版本通过 root 权限模拟操作;
  • 自动识别屏幕锁定方式并根据配置的密码解锁,支持图形解锁,PIN解锁,混合密码解锁;
  • 识别自己能量球的倒计时,和好友列表中的倒计时做对比,取最小值作为下次收取的等待时间;
  • 识别好友能量罩,下一次收取时跳过开启能量罩的好友;
  • 默认使用倒计时收取,可通过配置打开循环收取;
  • 根据设置选择是否帮助好友收取能量;
  • 根据白名单实现不收取特定好友能量;
  • 收取完毕后悬浮框显示收取的能量数量;
  • 可以直接更新最新脚本。

配置

运行 config.js 后可以看到如下图所示的配置:

配置图片

  • 执行模式:
    • 计时:由程序自动计算下次收取所需要的时间,通过设置最大等待时间来限制执行。
    • 循环:循环执行,选择循环模式时可以设置循环次数。
  • 帮好友收取:是否帮好友收取已经成熟的能量。
  • 颜色偏移量:如果识别失败可以尝试增加该值,默认为50,即80%的相似度。
  • 解锁密码:手机解锁密码,如果是图形解锁则为图形经过的点对应的数字。
  • 解锁操作时延:解锁模块的延时,解锁操作过快导致出错时可修改,默认为1000ms。
  • 控件搜索超时:控件搜索时最大搜索时间,找不到控件时可修改,默认为1000ms。
  • 白名单:将好友的昵称添加到白名单实现不收取特定好友的能量。
  • 清除本地储存:清除储存在本地的配置,相当于初始化。

添加解锁设备

在 Unlock.js 中,按照以下格式扩展:

var Devices = { 
  device_1: function(obj) {
    this.__proto__ = obj;

    this.unlock = function(password) {
      if (typeof password !== "string") throw new Error("密码应为字符串!");
      
      // 此处为解锁的代码

      return this.check_unlock();
    }
  },
  device_2: function(obj) {
    ...
  },
  device_3: function(obj) {
    ...
  }
}

上述所示为最简单的解锁模板,也可以参考 Unlocl.js 默认多解锁方式的代码进行修改。

然后在下方的 MyDevice 中设置解锁设备:

var MyDevice = Devices.device_1;

注意事项

解锁仅支持:

  • 具有ROOT权限的安卓5.0及以上版本
  • 没有ROOT权限的安卓7.0及以上版本

目前存在的问题

  • Autojs 在锁屏状态下由于软件优先度被降低导致 sleep() 函数时间不准确
  • 当好友列表数量超过大约 100 后,列表下拉会很慢

CHANGELOG

  • 2019/1/31

    • 发现识别能量罩时采用的函数不合适(使用了同步获取 toast 的方法,会卡住,已修正)
    • 帮助好友收取时,默认所有能量球都各点击一遍,效率太低(已修正)
    • 重构代码,添加注释
  • 2019/2/1

    • Toast 监听器超过10过导致报错(已修正)
    • 帮助好友收取时有时候会失败(因为控件下方文字闪烁导致,已修正)
    • 不限制监听器数量并且每次运行完成后清空监听器
  • 2019/2/2

    • 自己的倒计时减为0时会结束收取而不是立马收取下一次(已修正)
  • 2019/2/5

    • 实际运行中安卓7.0以下会报错(已修正)
  • 2019/2/24

    • 多语言问题,繁体或者英文环境下判断字符不同(取消)
    • 当收取次数设置为 0 次时,收取行为出错(已修正)
    • 初次进入蚂蚁森林弹窗提醒添加至首页和合种信息(已修正)
  • 2019/3/5

    • 重构了一下 Unlock 的内容,方便添加设备
    • 由于基本所有设备解锁都有滑动层,因此去掉了判断是否有滑动层的代码
    • 目前看来新版本效果不错,因此去掉了 old 版本的脚本
    • 增加循环收取的功能
  • 2019/3/7

    • 增加白名单功能
    • 计算颜色相似度,修改默认颜色偏移量为50
  • 2019/3/12

    • 增加设置UI界面
    • 解决春种活动导致的BUG
  • 2019/3/13

    • 增加脚本更新功能
  • 2019/3/14

    • 修复好友列表因网络加载慢出现“正在加载”时报错的问题
    • 修复循环执行时的各种问题
  • 2019/3/16

    • 实现真正的脚本更新功能
  • 2019/3/20

    • 重复运行脚本会报错,因此增加脚本重复运行检查功能

ant-forest-autoscript's People

Contributors

ihx-rainbow avatar nick-hopps avatar tonyjiangwj avatar ysinsane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ant-forest-autoscript's Issues

打开蚂蚁森林会卡住

原因在于如果支付宝没有退出,并且位于不在蚂蚁森林首页的其他页面,会卡着,因为在waitfor 背包。
不知是否可以加入超时检测,然后退出支付宝,重新进入

运行config 和main出错

08:14:28.424/E: TypeError: Cannot find function all in object [object Object]. (

#15)
at script(:15)

08:14:44.576/E: ReferenceError: "activity" is not defined. (ui.js#6)
at script(ui.js:6)
at script.draw_view(:32)
at script(:181)

收集完能量运行报错

手机:HTC U11
系统:HTC港版8.0
最新版脚本,4.0.1beta版本的auto.js
main.js运行的时候可以正常收1次能量。但是在以下2种情况会报错:
1、收完1次能量,如果所有好友的头像上都没有倒计时的话,会报错。
2、收完1次能量,如果好友倒计时比较长(据观察应该是大概超过30分钟的)的话,会报错。
报错时,画面停留在自己的小树上,不会返回桌面,脚本停止。

报错日志如下:
22:26:35.637/E: Wrapped android.view.InflateException: android.view.InflateException: java.lang.ClassNotFoundException: android.widget.card (floaty.js#9)
at script(floaty.js:9)
at script(file:/storage/emulated/0/脚本/Ant-Forest-3.20/core/Ant_forest.js:52)
at script(file:/storage/emulated/0/脚本/Ant-Forest-3.20/core/Ant_forest.js:202)
at script(file:/storage/emulated/0/脚本/Ant-Forest-3.20/core/Ant_forest.js:362)
at script(file:/storage/emulated/0/脚本/Ant-Forest-3.20/core/Ant_forest.js:376)
at script(

:51)

华为荣耀v10报错

新版本报错,旧版本好像没啥问题(如有再补充)
autojs 4.0.5Alpha 版本

_20190208141941

4.0.5版本的autojs运行,打开排行榜就报错

02:25:51.308/E: Wrapped java.lang.IllegalStateException: nodeInfo.viewIdResourceName must not be null (file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/core/Ant_forest.js#289)
Wrapped java.lang.IllegalStateException: nodeInfo.viewIdResourceName must not be null
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/core/Ant_forest.js:289:0
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/core/Ant_forest.js:323:0
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/core/Ant_forest.js:340:0
at /storage/emulated/0/脚本/Ant-Forest-autoscript-master/main.js:35:0

一加3t手机,magisk root,下载后未做任何设置,直接运行main.js便利到排名最后结束时程序会崩溃报错

Version: 256
Android: 26
java.lang.RuntimeException: android.view.InflateException: android.view.InflateException: java.lang.ClassNotFoundException: android.widget.card
at com.stardust.autojs.core.ui.ConvertLayoutInflater.inflate(ConvertLayoutInflater.java:32)
at com.stardust.autojs.runtime.api.Floaty.lambda$inflate$0$Floaty(Floaty.java:70)
at com.stardust.autojs.runtime.api.Floaty$$Lambda$0.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6798)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:108)
Caused by: android.view.InflateException: android.view.InflateException: java.lang.ClassNotFoundException: android.widget.card
at com.stardust.autojs.core.ui.inflater.DynamicLayoutInflater.inflate(DynamicLayoutInflater.java:142)
at com.stardust.autojs.core.ui.inflater.DynamicLayoutInflater.inflate(DynamicLayoutInflater.java:127)
at com.stardust.autojs.core.ui.ConvertLayoutInflater.inflate(ConvertLayoutInflater.java:29)
... 10 more
Caused by: android.view.InflateException: java.lang.ClassNotFoundException: android.widget.card
at com.stardust.autojs.core.ui.inflater.DynamicLayoutInflater.createViewForName(DynamicLayoutInflater.java:212)
at com.stardust.autojs.core.ui.inflater.DynamicLayoutInflater.inflate(DynamicLayoutInflater.java:155)
at com.stardust.autojs.core.ui.inflater.DynamicLayoutInflater.inflate(DynamicLayoutInflater.java:140)
... 12 more
Caused by: java.lang.ClassNotFoundException: android.widget.card
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at java.lang.Class.forName(Class.java:378)
at com.stardust.autojs.core.ui.inflater.DynamicLayoutInflater.createViewForName(DynamicLayoutInflater.java:202)
... 14 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.widget.card" on path: DexPathList[[zip file "/data/app/com.stardust.scriptdroid-XnwwJVYpMxC-liUHwRahBQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.stardust.scriptdroid-XnwwJVYpMxC-liUHwRahBQ==/lib/arm, /system/fake-libs, /data/app/com.stardust.scriptdroid-XnwwJVYpMxC-liUHwRahBQ==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 18 more

手机解锁画面不上滑,无法弹出密码页面

由于锁屏会根据手指的滑动速度决定是否弹出密码页面。建议用以下的方式上滑。

  var xyArr = [220]
  var x0=device.width/2
  var y0=device.height/4*3
  var angle = 0
  var x = 0
  var y = 0
  for (let i = 0; i < 30; i++) {
    y = x * tan(angle)
    log(y)
    if((y0-y)<0){
      break
    }
    var xy = [x0+x,y0-y]
    xyArr.push(xy)
    x += 5;
    angle += 3
  }
  gesture.apply(null,xyArr)
  function tan(angle) {
    return Math.tan(angle * Math.PI / 180);
  }

一加五解锁失败

报错,提示
01:52:59.846/E: Error: Can't resolve relative module ID "./lib/Automator.js" when require() is used outside of a module (file:///android_asset/modules/jvm-npm.js#89)
Error: Can't resolve relative module ID "./lib/Automator.js" when require() is used outside of a module
at Require (file:///android_asset/modules/jvm-npm.js:89:0)
at Tmp.js:40:0
autojs版本4.1.1,一加五,Android9

小米9解锁失败

Screenshot_2019-04-17-15-50-09-181_org autojs aut

见到亮起屏幕,然后看似上滑的动画,但是没有进入解锁界面。然后就熄灭了。等待了两分钟,手动打开手机,看到日志如图。

华为荣耀magic2问题汇总

/E: Wrapped android.view.InflateException: android.view.InflateException: java.lang.ClassNotFoundException: android.widget.card (floaty.js#9)
at script(floaty.js:9)
at script(file:/storage/emulated/0/脚本/Ant-Forest-autoscript/core/Ant_forest.js:52)
at script(file:/storage/emulated/0/脚本/Ant-Forest-autoscript/core/Ant_forest.js:202)
at script(file:/storage/emulated/0/脚本/Ant-Forest-autoscript/core/Ant_forest.js:362)
at script(file:/storage/emulated/0/脚本/Ant-Forest-autoscript/core/Ant_forest.js:376)
at script(

:51)

华为荣耀magic2报错~ 收集完一圈后(从“没有更多了”回到好友排行榜时)报错

收取自己的能量会被活动干扰

当蚂蚁森林页面,自己的能量球周围出现活动时会点击进入活动页面,导致无法运行到收取好友能量。
比如,今天是3月13日,蚂蚁森林有个春种活动,脚本会打开春种活动页面然后就一直在这里等待了。

image

bug反馈,多个支付宝包名时,无法智能打开,只能手动选择

15161952

如图,魅族手机可以设置支付宝的应用分身,分身与原软件属于同一个包名,会导致打开支付宝的时候卡主,手动选择后才会继续运行

// 进入蚂蚁森林主页
const _start_app = function() {
app.startActivity({
action: "VIEW",
data: "alipays://platformapi/startapp?appId=60000002",
});
}

请问下,这块能否进行优化

稳定全天运行的建议

autojs中的延时执行有两个问题:

  1. 时间不准确,无法准时执行
  2. 会被音量上键全局终止,停止执行

经测试使用tasker管理定时任务,调用autojs执行的方案更稳定,基本保证全天准时执行,关键在于autojs向tasker传递下次执行时间的参数,可参考Tasker 与 Autojs 之间如何传递数据的后半部分

一些BUG

设备:小米9

我认真观看运行,发现打开帮收朋友能量后,有时候点击进入,并不会帮忙收取,只是进入后就返回列表,速度非常快。有时候进入有能量可以偷取的朋友,也只是偷取了能量,并有没把帮忙收取的点击。

以及在早晨7点这种朋友能量多的时刻,计时似乎有点问题,具体表现在偷取能量列表上,有还剩1分钟的能量,结果当一次偷取完后,返回桌面,此时日志中显示下次偷取是4分钟。这导致错过很多能量偷取。

bug反馈

如果运行脚本之前支付宝在后台,并且已经进入好友排行的话,那么脚本将不能运行成功
运行日志:
23:56:46.506/D: 当前能量:159736
23:56:46.533/D: 无可收取能量
23:56:46.533/D: 开始收集好友能量
23:56:46.910/V:

[/storage/emulated/0/脚本/蚂蚁/main.js]运行结束,用时3.319000秒

bug

好友列表的最后是一些不玩蚂蚁森林的好友,他们的右边显示的是绿色的“邀请”按钮。
脚本运行,当好友列表自动滑动到这里,还没有到“没有更多了”前,脚本就会卡住。

希望能支持多语言

个人所有app都是用英语的,相信也有用繁体中文之类的同学,希望能加一个多语言的设置。
将几个字符串拿出来用变量替代应该不是很大工程,虽然能帮助的人不多,但还是有人能受益的。
希望采纳

BUG

运行的时候出现一个Bug,错误代码如下
**

Wrapped java.lang.IllegalStateException : nodelnfo. viewldResourceName must not be null

**
在开始收取好友能量的时候也出现了Bug。
刚去百度了下,这个Bug是因为 Auto.js 版本的问题. Auto.js版本 请下载 4.0.1 Bate。 新版本4.0.5Alpha会报错

每次在第2次运行的时候报错,使用的是4.1.1的autojs

10:03:35.449/D: 第 2 次运行
10:03:39.086/D: 开始收集自己能量
10:04:44.323/E: Wrapped java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.view.accessibility.AccessibilityNodeInfo.getPackageName()' on a null object reference (file:/storage/emulated/0/脚本/Ant-Forest-autoscript/core/Ant_forest.js#314)
Wrapped java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.view.accessibility.AccessibilityNodeInfo.getPackageName()' on a null object reference
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript/core/Ant_forest.js:314:0
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript/core/Ant_forest.js:342:0
at /storage/emulated/0/脚本/Ant-Forest-autoscript/main.js:35:0

定时任务解锁屏幕时报错

系统: MIUI 9 Android 7.0
Auto.js: 4.0.5 Alpha

07:00:01.645/E: Wrapped java.lang.IllegalStateException: nodeInfo.viewIdResourceName must not be null (file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/lib/Unlock.js#138)
Wrapped java.lang.IllegalStateException: nodeInfo.viewIdResourceName must not be null
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/lib/Unlock.js:138:0
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/lib/Unlock.js:121:0
at file:/storage/emulated/0/脚本/Ant-Forest-autoscript-master/lib/Ant_forest.js:222:0
at /storage/emulated/0/脚本/Ant-Forest-autoscript-master/main.js:35:0

荣耀畅玩6x不能解锁

大佬,脚本可以收取能量。如果锁频的话,亮屏后不能滑动进入解锁界面,也就无法输入密码解锁了,望大佬修复。感谢

魅族15plus无法运行

12:00:31.189/E: ReferenceError: "activity" is not defined. (file:///android_asset/modules/ui.js#14)
ReferenceError: "activity" is not defined.
at file:///android_asset/modules/ui.js:14:0
at draw_view (/storage/emulated/0/脚本/Ant-Forest-autoscript-master/config.js:32:0)
at /storage/emulated/0/脚本/Ant-Forest-autoscript-master/config.js:181:0

崩溃问题

1、运行一两遍会导致auto.js崩溃,并且日志也被清空了。
2、有没有什么方法,开始不用获取截屏授权,直接运行。
3、经常运行一遍结束后,卡在好友列表最低端不运行。

1,3两个问题比较急切。手机是小米8

运行报错

当好友的能量在倒计时时会报这个错误

错误: Wrapped java.lang.lllegalArgumentException: x must be < bitmap.width() (images.js#123)

建议增加每次收取完毕的日志

建议增加每次收取完毕的日志,在日志中打印一下本次收取了多少g能量
目前只有没能量收,运行结束的时候才会有悬浮窗提示,如果能每次打印一个log就更好了

运行config出错

手机:HTC U11
系统:HTC港版8.0
最新版脚本,4.0.1beta版本的auto.js
config.js运行报错如下:

22:05:32.702/E: ReferenceError: "activity" is not defined. (ui.js#15)
at script(ui.js:15)
at script.draw_view(:32)
at script(:181)

锤子坚果pro2s锁屏点亮没有打开支付宝

正常运行没问题。等待灭屏后,自动亮屏,没有设置密码,正常进入桌面,但是没有打开支付宝。
日志显示:已是最新版;正在偷取能量。
然后就没有了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.