2020螞蟻森林自動收能量-保持更新

最近一直在研究Auto.js 就順手寫了個腳本,就是各種幫你玩日常小遊戲,能薅一點是一點!

來個最直接的方式,百度雲下載地址 鏈接:https://pan.baidu.com/s/1jradOvFF9-z53ycNaUd8MQ 密碼:r8rh
說下APP使用方法,螞蟻森林,主要在支付寶首頁有螞蟻森林入口,如果沒有,點擊更多去添加
代碼完全開元,需要參考請拿走!
Github地址:https://github.com/MasterSumCloud/YangmaoHelper
提BUG羣:567679111
最新版請到羣裏下載,最新支持螞蟻莊園的一些小遊戲,努力更新中!
下面就直接附上代碼啦:代碼已經更新:更新日期12月22日(暫時不會有什麼大更新了,基本穩定了)
如果不是最新請移至Github獲取最新完整代碼

let deviceWidth = device.width;
let deviceHeight = device.height;

function startAntForest(playFarm, getAliScore) {
    //進入支付寶
    launch("com.eg.android.AlipayGphone");
    sleep(1000);
    let witeInHome = 5;
    while (witeInHome > 0) {
        let inHome = id("tab_description").text("首頁").findOnce();
        if (inHome == null) {
            sleep(1000);
            witeInHome--;
        } else {
            witeInHome = -10;
        }
    }
    //是否需要領取積分
    getNeedGetAliScore(getAliScore);
    //判斷是否已經在遊戲界面
    let gamePartHome = id("J_af_home").findOnce();

    if (witeInHome != -10 && gamePartHome == null) {
        toastLog("不在支付寶首頁,也不在遊戲界面!退出");
        exit();
    }
    //在首頁尋找 螞蟻深林和螞蟻莊園的入口
    let antForest = id("app_text").textContains("螞蟻森林").findOnce();
    if (antForest != null || gamePartHome != null) {
        //在螞蟻森林
        if (gamePartHome == null) {
            //進入螞蟻深林
            toastLog("進入螞蟻深林");
            click(antForest.bounds().centerX(), antForest.bounds().centerY());
            sleep(5000);
        }
        toastLog("查詢是否有能量可以收集");
        collectEnergy();
        //滑動半個屏幕
        swipe(deviceWidth / 2, deviceHeight * 0.8, deviceWidth / 2, deviceHeight * 0.2, 1000);
        //尋找定位點
        let weekTop = className("android.view.View").textContains("周排行榜").findOnce();
        if (weekTop != null) {
            weekTop.click();
            swipe(deviceWidth / 2, weekTop.bounds().top, deviceWidth / 2, 0, 1000);
        }
        toastLog("開始尋找偷能量");
        // seekToSteal(true);
        //去全部頁面
        let seekMore = className("android.view.View").textContains("查看更多好友").findOnce();
        if (seekMore != null) {
            seekMore.click();
            sleep(3000);
            //判斷是否還有更多
            let screen = getScreenImg();
            let noMore = images.read("./res/no_more.png");
            let hasMore = images.matchTemplate(screen, noMore, { threshold: 0.8, region: [deviceWidth / 3, deviceHeight - 150], max: 1 }).matches.length == 0;
            console.log("是否有更多", hasMore);
            let maxSearchTime = 32;//最大限制次數
            let handImg = images.read("./res/ghand.png");
            while (hasMore && maxSearchTime > 0) {
                let finded = getCanStealfriend(handImg);
                if (finded != null && finded.length > 0) {
                    finded.forEach(item => {
                        console.log("找到的點", item);
                        stealAndBack(item);
                    });
                }

                sleep(1000);
                swipe(deviceWidth / 2, deviceHeight * 0.8, deviceWidth / 2, deviceHeight * 0.1, 1000);
                if (maxSearchTime < 27) {//前5次不判斷是否到底部
                    let screen2 = getScreenImg();
                    hasMore = images.matchTemplate(screen2, noMore, { threshold: 0.8, region: [deviceWidth / 3, deviceHeight - 150], max: 1 }).matches.length == 0;
                    if (!hasMore) {
                        toastLog("已經沒有更多了")
                        break;
                    }
                }
                maxSearchTime--;
            }
            //回收資源
            handImg.recycle();
            noMore.recycle();
        }

        if (playFarm) {
            //返回一級
            back();
            sleep(1000);
            //滑動到頂部
            swipe(deviceWidth / 2, deviceHeight * 0.1, deviceWidth / 2, deviceHeight * 0.8, 1000);
            swipe(deviceWidth / 2, deviceHeight * 0.1, deviceWidth / 2, deviceHeight * 0.8, 1000);
            let antFf = id("J_antfarm_container").text("螞蟻莊園").findOnce();
            if (antFf) {
                antFf.click();
                let antFramGame = require("./antFarm.js")
                antFramGame();
            }
        }
        back();
        sleep(500);
        back();
        sleep(500);
        back();
        sleep(500);
        toastLog("完成了");
    } else {
        toastLog("不在遊戲界面,也不再主界面,結束");
        exit();
    }

}

function seekToSteal(simple) {
    if (simple) {
        let canSteal = className("android.widget.Button").textContains("可收取").findOnce() != null;
        while (canSteal) {
            stealAndBack(canSteal);
            //繼續尋找
            let canStealItem = className("android.widget.Button").textContains("可收取").findOnce();
            if (canStealItem != null) {
                canStealItem.click();
            } else {
                canSteal = false;
                break;
            }
        }
    } else {
        let finded = getCanStealfriend();
        if (finded != null && finded.length > 0) {
            finded.forEach(item => {
                stealAndBack(item);
            });
        }
    }
}



function stealAndBack(item) {
    click(deviceWidth / 2, item.point.y + 10);
    sleep(3000);
    //判斷進入了遊戲佈局 否則不返回
    let gameV = id("J_app_outter").findOnce();
    if (gameV != null) {
        //開始偷
        collectEnergy();
        back();
        sleep(1000);
    }
}

function collectEnergy() {
    let hasSelfPower = className("android.widget.Button").textContains("收集能量").findOnce() != null;
    while (hasSelfPower) {
        toastLog("開始收集");
        let collectSelf = className("android.widget.Button").textContains("收集能量").findOnce();
        if (collectSelf != null) {
            click(collectSelf.bounds().centerX(), collectSelf.bounds().centerY());
            sleep(300);
        } else {
            toastLog("採集完畢");
            hasSelfPower = false;
            break;
        }
    }
}

/**
 * 從排行榜 找到可以收取能量的
 */
function getCanStealfriend(handImg) {
    let img = getScreenImg();
    let pList = images.matchTemplate(img, handImg, { threshold: 0.8, region: [deviceWidth * 0.9, deviceHeight * 0.16], max: 9 });
    if (pList != null) {
        console.log("找到的做標記", pList.matches);
        return pList.matches;
    }
}

/**
 * 獲取屏幕圖片
 */
function getScreenImg() {
    let screenPic = captureScreen();
    console.log(screenPic);
    sleep(100);
    if (screenPic == null || typeof (screenPic) == "undifined") {
        toastLog("截圖失敗,退出腳本");
        exit();
    } else {
        return screenPic;
    }
}

function getNeedGetAliScore(need) {
    //如果需要領取積分
    if (need) {
        let inMine = id("tab_description").text("我的").findOnce();
        click(inMine.bounds().centerX(), inMine.bounds().centerY());
        sleep(1000);
        //判斷當前有沒有積分可以領取
        let hasScore = textContains("個積分待領取").findOnce();
        if (hasScore != null) {
            let backCount = 0;
            let memeberAli = id("item_left_text").text("支付寶會員").findOnce();
            if (memeberAli != null) {
                click(memeberAli.bounds().centerX(), memeberAli.bounds().centerY());
                backCount++;
                sleep(2000);
                let getScoreV = className("android.view.View").text("領積分").findOnce();
                if (getScoreV != null) {
                    click(getScoreV.bounds().centerX(), getScoreV.bounds().centerY());
                    sleep(2000);
                    backCount++;
                    let clickGetScore = className("android.view.View").text("點擊領取").findOnce();
                    while (clickGetScore != null) {
                        click(clickGetScore.bounds().centerX(), clickGetScore.bounds().centerY());
                        sleep(300);
                        clickGetScore = className("android.view.View").text("點擊領取").findOnce();
                    }
                }
            }

            for (let i = 0; i < backCount; i++) {
                back();
                sleep(500);
            }
        } else {
            toastLog("沒有積分可領取")
        }
        let inHome = id("tab_description").text("首頁").findOnce();
        click(inHome.bounds().centerX(), inHome.bounds().centerY());
        sleep(500);
    }
}
// collectEnergy();
module.exports = startAntForest;

最新請到Github下載;
還有其他功能正在完善中,有什麼好的需要薅的,可以留言,人多妥妥的!!!

發佈了31 篇原創文章 · 獲贊 21 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章