蚂蚁庄园 php源码,求一个基于Auto.js的蚂蚁庄园脚本

[JavaScript] 纯文本查看 复制代码/*

* @Description: “蚂蚁庄园”辅助脚本 - 自动“喂养/赶鸡/收蛋/使用加速卡”

* @Author: 清雨 [[url]https://blog.gazer.win/[/url]]

* @Updated: 2019-01-06 08:55

* @Created: 2018-12-31 19:07

* @Device: Xiaomi Mi 5

* @System: LineageOS 15.1 (Based on Android 8.1.0)

* [url=home.php?mod=space&uid=1433904]@Auto.js[/url] Version: 4.0.1 Beta

* @Permission: Root Access / Screen Capture / Suspension Window

*/

/************************

* 初始化

***********************/

sleep(1000);

// 启用分辨率自动缩放,不确保能正常工作

setScreenMetrics(1080, 1920);

// 尝试请求截图权限,如果无截图权限则退出脚本

// 屏幕截图是判断蚂蚁庄园各种状态,以便进一步进行各项操作的重要依据

if (! requestScreenCapture()) {

log("无屏幕截图权限,脚本将退出...");

exit();

}

// 启动“支付宝”App,以便在待会更快的进入蚂蚁庄园

launch("com.eg.android.AlipayGphone");

// 延时10秒,等待支付宝启动

sleep(10000);

//waitForPackage("com.eg.android.AlipayGphone", period=200);

/********************************

* 定义 蚂蚁庄园 状态常量/状态变量

*******************************/

// 如脚本无法正常工作,请根据自己的设备,对对应的分辨率坐标进行适当的调整

var manor = {

Colors: { Eggs: "#FFEC3817", Msgs: "#FFEC4646", Trough: "#FFFFCF00", Thief: "#FF000000" },

Point: {

Props: [{x: 960, y: 660}, {x: 520, y: 1690}, {x: 750, y: 1280}],

Eggs: {x: 205, y: 1445, w: 45, h: 30},

Foods: {x: 930, y: 1735},

Msgs: {x: 912, y: 445},

Thief_1: [{x: 400, y: 1280}, {x: 575, y: 1175}, {x: 540, y: 1660}],

Thief_2: [{x: 850, y: 1280}, {x: 1010, y: 1175}, {x: 540, y: 1660}],

Trough: {x: 856, y: 1460}

},

Status: { Accelerator: true, Msgs: false, Trough: false, Thief_1: false, Thief_2: false },

};

var manorImg = new Object();

/************************

* 主程序

***********************/

// 使用 su shell 调用支付宝APi接口进入蚂蚁庄园

shell("am start -a android.intent.action.VIEW -d alipays://platformapi/startapp?appId=66666674", true);

// 延时 25秒 确保完全进入蚂蚁庄园界面后,脚本才继续运行(请根据设备性能及网络状况适当调整延时)

sleep(25000);

waitForActivity("com.alipay.mobile.nebulacore.ui.H5Activity", period=200);

// 获取屏幕截图备用(判断蚂蚁庄园各种状态的依据)

manorImg = captureScreen();

sleep(2500);

// 显示控制台 - 用于提示各种操作信息和调试脚本

console.show();

// 已阅

manorRead();

// 赶鸡

manorShoo();

// 收蛋

manorCollect();

// 喂食

manorFeed();

// 脚本执行完毕,强制结束支付宝并退出

shell("am force-stop com.eg.android.AlipayGphone", true);

// 退出

exit();

/************************

* 函数模块

***********************/

// 关闭“最新活动提醒”遮盖

function manorRead(){

manor.Status.Msgs = images.detectsColor(manorImg, manor.Colors.Msgs, manor.Point.Msgs.x, manor.Point.Msgs.y);

if(manor.Status.Msgs){

log("正在关闭活动提醒...");

Tap(manor.Point.Msgs.x, manor.Point.Msgs.y);

sleep(800);

}

}

// 驱赶小鸡

function manorShoo(){

if(manor.Status.Msgs){

sleep(500);

manorImg = captureScreen();

sleep(2500);

}

// 如有左边小鸡正在偷食,则驱赶,否则不执行任何操作

manor.Status.Thief_1 = images.detectsColor(manorImg, manor.Colors.Thief, manor.Point.Thief_1[0].x, manor.Point.Thief_1[0].y);

if(manor.Status.Thief_1){

log("追打胖揍小鸡甲中...");

for(i=0;i<3;i++){

Tap(manor.Point.Thief_1[i].x, manor.Point.Thief_1[i].y);

sleep(1000);

if(i==1){ sleep(3500); };

}

sleep(1000);

}

// 如有右边小鸡正在偷食,则驱赶,否则不执行任何操作

manor.Status.Thief_2 = images.detectsColor(manorImg, manor.Colors.Thief, manor.Point.Thief_2[0].x, manor.Point.Thief_2[0].y);

if(manor.Status.Thief_2){

log("追打胖揍小鸡乙中...");

for(i=0;i<3;i++){

Tap(manor.Point.Thief_2[i].x, manor.Point.Thief_2[i].y);

sleep(1000);

if(i==1){ sleep(3500); };

}

sleep(1000);

}

//小鸡驱赶结束

}

// 喂食小鸡

function manorFeed() {

// 分析蚂蚁庄园状态

if(!manor.Status.Thief_1 && !manor.Status.Thief_2){

log("没有其它小鸡在偷食...");

// 判断食槽状态,如果食槽为空,则喂食

manor.Status.Trough = images.detectsColor(manorImg, manor.Colors.Trough, manor.Point.Trough.x, manor.Point.Trough.y);

if(!manor.Status.Trough){

log("正在喂食小鸡...");

Tap(manor.Point.Foods.x, manor.Point.Foods.y);

sleep(1000);

manorHasten();

}else{ log("不要着急,还没吃完呢..."); }

}else{

log("已胖揍完其它小鸡...");

sleep(3600);

let feedImg = captureScreen();

sleep(2500);

// 判断食槽状态,如果食槽为空,则喂食

manor.Status.Trough = images.detectsColor(feedImg, manor.Colors.Trough, manor.Point.Trough.x, manor.Point.Trough.y);

if(!manor.Status.Trough){

log("正在喂食小鸡...");

Tap(manor.Point.Foods.x, manor.Point.Foods.y);

sleep(1000);

manorHasten();

}else{ log("不要着急,还没吃完呢..."); }

}

}

// 使用道具 - 加速卡

function manorHasten(){

if(manor.Status.Accelerator){

log("使用加速卡...");

for(i=0;i<3;i++){

Tap(manor.Point.Props[i].x, manor.Point.Props[i].y);

sleep(1800);

if(i==2){ sleep(2600); };

}

}

}

// 收取鸡蛋

function manorCollect(){

var egg = findColor(manorImg, manor.Colors.Eggs, {

region: [manor.Point.Eggs.x, manor.Point.Eggs.y, manor.Point.Eggs.w, manor.Point.Eggs.h],

threads: 8,

});

if(egg){

log("正在收取鸡蛋...");

Tap(manor.Point.Eggs.x, manor.Point.Eggs.y);

sleep(1000);

}else{ log("没有鸡蛋可以收取..."); }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值