注册时间
最后登录
新帖
发布在 bug、问题、建议 阅读更多
//点击屏幕内容
function ClickTheScreenContent(TargetImage, AssociationKeyImage) {
    //循环查找
    while (true) {
        //截屏
        console.log("CaptureScreenImageDDDD");
        let CaptureScreenImage = images.captureScreen();
        console.log("CaptureScreenImage");
        if (CaptureScreenImage == null) {
            toastLog("截屏失败!脚本已退出");
            exit();
        }
        //判断是否存在关联键
        let HaveAssociationKey = false;
        if (AssociationKeyImage != null) {
            if (images.findImage(CaptureScreenImage, AssociationKeyImage) != null) {
                HaveAssociationKey = true;
            }
        } else {
            HaveAssociationKey = true;
        }
        //查找目标位置
        let TargetPosition = images.findImage(CaptureScreenImage, TargetImage);
        if (HaveAssociationKey && TargetPosition != null) {
            click(TargetPosition.x, TargetPosition.y);
            break;
        }
        console.log("debug");
    }
}
//主函数
function main() {
    //如果安卓版本高于Android 9则开启自动点击接受截图申请线程
    if (device.sdkInt > 28) {
        threads.start(function () {
            packageName('com.android.systemui').text('立即开始').waitFor();
            text('立即开始').click();
        });
    }
    //申请截屏权限
    if (!requestScreenCapture()) {
        toastLog("申请截屏权限失败");
        exit();
    }

    //提醒用户脚本运行
    toastLog("脚本开始运行,打开需要挂机的关卡信息界面即可自动化挂机")

    //加载图像
    let GoNowImage = images.read("./Texture/Button/GoNow.png");
    if (GoNowImage == null) {
        toastLog("GoNowImage图像加载失败");
        exit();
    }
    let AutomaticImage = images.read("./Texture/Button/Automatic.png");
    if (AutomaticImage == null) {
        toastLog("AutomaticImage图像加载失败");
        exit();
    }
    let DoubleIncomeImage = images.read("./Texture/Button/DoubleIncome.png");
    if (DoubleIncomeImage == null) {
        toastLog("DoubleIncomeImage图像加载失败");
        exit();
    }
    //点击关卡信息界面的立刻前往
    ClickTheScreenContent(GoNowImage, AutomaticImage);
    console.log("点击关卡信息界面的立刻前往");
    //点击编队界面的立刻前往
    ClickTheScreenContent(GoNowImage, DoubleIncomeImage);
    console.log("点击编队界面的立刻前往");
    //释放图像
    GoNowImage.recycle();
    AutomaticImage.recycle();
    DoubleIncomeImage.recycle();

    //加载图像
    let DoubleIncomeAImage = images.read("./Texture/Button/DoubleIncomeA.png");
    if (DoubleIncomeAImage == null) {
        toastLog("DoubleIncomeAImage图像加载失败");
        exit();
    }
    let GoAgainImage = images.read("./Texture/Button/GoAgain.png");
    if (GoAgainImage == null) {
        toastLog("GoAgainImage图像加载失败");
        exit();
    }
    //循环挂机
    for (let index = 0; index < 5; index++) {
        //点击结算界面的双倍资源
        ClickTheScreenContent(DoubleIncomeAImage, GoAgainImage);
        console.log("点击结算界面的双倍资源");
        //点击结算界面的再次前往
        ClickTheScreenContent(GoAgainImage, DoubleIncomeAImage);
        console.log("点击结算界面的再次前往");
    }
    //释放图像
    DoubleIncomeAImage.recycle();
    GoAgainImage.recycle();

    //提醒用户脚本运行结束
    toastLog("挂机结束,脚本结束运行");
}
main();

具体表现就是偶尔只打印"CaptureScreenImageDDDD",不打印"CaptureScreenImage",一直卡在这。