300 lines
9.6 KiB
JavaScript
300 lines
9.6 KiB
JavaScript
/**
|
|
* 專案名稱: AutoCatAndSoup
|
|
* Copyright (C) 2026 Sthkm3
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
"auto";
|
|
|
|
const STORAGE = storages.create("AutoCatAndSoupConfig");
|
|
const T = require("./i18n.js");
|
|
const Tasks = require("./tasks.js");
|
|
|
|
const SCREEN_W = 720;
|
|
const SCREEN_H = 1280;
|
|
|
|
// 讀取
|
|
let config = {
|
|
sellProduct: STORAGE.get("sellProduct", false),
|
|
upgradeFacility: STORAGE.get("upgradeFacility", false),
|
|
upgradeRecipe: STORAGE.get("upgradeRecipe", false),
|
|
Photo: STORAGE.get("Photo", false),
|
|
Gift: STORAGE.get("Gift", false),
|
|
Play: STORAGE.get("Play", false),
|
|
receiveAFK: STORAGE.get("receiveAFK", false),
|
|
receiveJar: STORAGE.get("receiveJar", false),
|
|
receiveMerchant: STORAGE.get("receiveMerchant", false),
|
|
receiveButterfly: STORAGE.get("receiveButterfly", false),
|
|
receiveFrog: STORAGE.get("receiveFrog", false),
|
|
receiveMail: STORAGE.get("receiveMail", false),
|
|
receiveAchievement: STORAGE.get("receiveAchievement", false)
|
|
};
|
|
|
|
// 小視窗
|
|
let isPaused = false;
|
|
|
|
let win = floaty.rawWindow(
|
|
<vertical bg="#AA000000" padding="6">
|
|
<text text="Auto CatAndSoup" textColor="#FFFFFF" textSize="12sp"/>
|
|
<button id="btnPause" text="{{T('pause')}}"/>
|
|
</vertical>
|
|
);
|
|
|
|
win.setPosition(0, (SCREEN_H / 2) - 80);
|
|
win.setSize(160, -2);
|
|
|
|
win.btnPause.click(() => {
|
|
isPaused = !isPaused;
|
|
ui.run(() => {
|
|
win.btnPause.setText(isPaused ? T('start') : T('pause'));
|
|
});
|
|
toast(isPaused ? T('pause') : T('start'));
|
|
});
|
|
|
|
// 主循環
|
|
while (true) {
|
|
|
|
//暫停等待
|
|
if (isPaused) {
|
|
sleep(1000);
|
|
continue;
|
|
}
|
|
|
|
// 判斷應用
|
|
if (currentPackage() != "com.hidea.cat" && !isPaused) {
|
|
home();
|
|
sleep(1000);
|
|
|
|
app.launchPackage("com.hidea.cat");
|
|
toast(T('launching'));
|
|
var img = captureScreen();
|
|
var launch_time = 0;
|
|
while(!images.detectsColor(img, "#F4ECD3", 685, 1095) && launch_time <= 600){ //啟動五分鐘無果 再次啟動
|
|
launch_time += 1;
|
|
sleep(5000);
|
|
var img = captureScreen();
|
|
}
|
|
continue;
|
|
}
|
|
|
|
var img = captureScreen();
|
|
|
|
// 販賣商品
|
|
if (config.sellProduct && !isPaused) {
|
|
let l = (
|
|
!images.detectsColor(img, "#B38282", 35, 1267) &&
|
|
!images.detectsColor(img, "#DCAB82", 35, 1267)
|
|
)
|
|
let r = (
|
|
!images.detectsColor(img, "#B38282", 45, 1267) &&
|
|
!images.detectsColor(img, "#DCAB82", 45, 1267)
|
|
)
|
|
if (l || r) {
|
|
click(60, 1222);
|
|
}
|
|
}
|
|
|
|
// 設施升級
|
|
if (config.upgradeFacility && !isPaused) {
|
|
if (images.detectsColor(img, "#FFFFFF", 87, 1032)) {
|
|
click(31, 1044);
|
|
}
|
|
}
|
|
|
|
// 食譜升級
|
|
if (config.upgradeRecipe && !isPaused) {
|
|
if (images.detectsColor(img, "#FD7171", 581, 1081)) {
|
|
click(550, 1101); sleep(500);
|
|
var img = captureScreen();
|
|
while (images.detectsColor(img, "#8EE3D3", 458, 1037)){
|
|
click(535, 1053);
|
|
var img = captureScreen();
|
|
} sleep(100);
|
|
back(); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 拍照
|
|
if (config.Photo && !isPaused) {
|
|
if (images.detectsColor(img, "#B5B5C6", 648, 813) && images.detectsColor(img, "#FD7171", 682, 795)){
|
|
click(660, 815);
|
|
var img = captureScreen();
|
|
while(!images.detectsColor(img, "#FFFFFF", 360, 950)){
|
|
sleep(100);
|
|
var img = captureScreen();
|
|
}
|
|
click(360, 1025);
|
|
var img = captureScreen();
|
|
while(!images.detectsColor(img, "#F4ECD3", 360, 1150)){
|
|
sleep(100);
|
|
var img = captureScreen();
|
|
}
|
|
back(); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 禮物
|
|
if (config.Gift && !isPaused) {
|
|
if (images.detectsColor(img, "#FFFFFF", 680, 725) && images.detectsColor(img, "#FFFFFF", 680, 715)) {
|
|
click(662, 745);
|
|
var img = captureScreen();
|
|
while (!images.detectsColor(img, "#FFFFFF", 250, 825)){
|
|
sleep(100);
|
|
var img = captureScreen();
|
|
} sleep(500);
|
|
click(360, 760); sleep(500);
|
|
back(); sleep(2000);
|
|
var img = captureScreen();
|
|
if (images.detectsColor(img, "#FFFFFF", 250, 830)){
|
|
click(360, 735); sleep(3000);
|
|
back();
|
|
}
|
|
sleep(500);
|
|
}
|
|
}
|
|
|
|
// 玩耍
|
|
if (config.Play && !isPaused) {
|
|
if (images.detectsColor(img, "#F9DBDC", 673, 737)) {
|
|
click(645, 739); sleep(3000);
|
|
click(360, 800); sleep(500);
|
|
var playing_screen = (images.detectsColor(img, "#FDEFEF", 575, 400) && !images.detectsColor(img, "#F2B1B1", 501, 858));
|
|
var img = captureScreen();
|
|
while(images.detectsColor(img, "#F2B1B1", 527, 846) && !isPaused){
|
|
swipe(360, 800, 360, 200, 500); sleep(50);// up
|
|
swipe(360, 300, 360, 900, 500); sleep(50);// down
|
|
|
|
img = captureScreen();
|
|
var firstY = -1;
|
|
var lastY = -1;
|
|
|
|
// 從上往下
|
|
for (var y = 300; y <= 800; y += 5) {
|
|
if (images.detectsColor(img, "#F9DBDC", 360, y)) {
|
|
firstY = y;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 從下往上
|
|
for (var y = 800; y >= 300; y -= 5) {
|
|
if (images.detectsColor(img, "#F9DBDC", 360, y)) {
|
|
lastY = y;
|
|
break;
|
|
}
|
|
}
|
|
if (firstY !== -1 && lastY !== -1) {
|
|
var avgY = (firstY + lastY) / 2;
|
|
swipe(360, avgY, 360, 900, 500); sleep(50);
|
|
}
|
|
|
|
var img = captureScreen();
|
|
}
|
|
click(415, 923); sleep(1000);
|
|
}
|
|
}
|
|
|
|
// 掛機獎勵
|
|
if (config.receiveAFK && !isPaused) {
|
|
if (images.detectsColor(img, "#E3C5AE", 371, 1092)) {
|
|
click(360, 1130); sleep(500);
|
|
click(420, 809); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 罐子精靈獎勵
|
|
if (config.receiveJar && !isPaused) {
|
|
if (images.detectsColor(img, "#AAAAAA", 433, 1132)) {
|
|
click(360, 1130); sleep(500);
|
|
click(420, 844); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 商人獎勵
|
|
if (config.receiveMerchant && !isPaused) {
|
|
if (images.detectsColor(img, "#DB937D", 351, 1152)) {
|
|
click(360, 1130); sleep(500);
|
|
click(420, 755); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 黃金蝴蝶獎勵
|
|
if (config.receiveButterfly && !isPaused) {
|
|
if (images.detectsColor(img, "#FBE771", 71, 280)) {
|
|
click(71, 280); sleep(2000);
|
|
click(360, 650); sleep(300);
|
|
click(423, 724); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 青蛙王子獎勵
|
|
if (config.receiveFrog && !isPaused) {
|
|
if (images.detectsColor(img, "#D8E0B7", 55, 291) && images.detectsColor(img, "#D8E0B7", 49, 291)) {
|
|
click(71, 280); sleep(2000);
|
|
click(360, 650); sleep(300);
|
|
click(423, 724); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 信箱
|
|
if (config.receiveMail && !isPaused) {
|
|
if (images.detectsColor(img, "#FFFFFF", 376, 199) && images.detectsColor(img, "#F2DFC7", 356, 234)) {
|
|
click(360, 208); sleep(1000);
|
|
var img = captureScreen();
|
|
while (images.detectsColor(img, "#8EE3D3", 570, 380) && !isPaused) {
|
|
click(484, 398);
|
|
sleep(500);
|
|
var img = captureScreen();
|
|
if (images.detectsColor(img, "#E5D8CA", 489, 632)) {
|
|
click(400, 720);
|
|
var img = captureScreen();
|
|
} sleep(500);
|
|
var img = captureScreen();
|
|
}
|
|
back(); sleep(500);
|
|
}
|
|
}
|
|
|
|
// 成就與任務
|
|
if (config.receiveAchievement && !isPaused) {
|
|
if (images.detectsColor(img, "#FF6F6E", 680, 243)) {
|
|
click(662, 263); sleep(1000);
|
|
var img = captureScreen();
|
|
if (images.detectsColor(img, "#FF6F6E", 307, 234)) {
|
|
click(225, 250); sleep(500);
|
|
var img = captureScreen();
|
|
while (images.detectsColor(img, "#8EE3D3", 520, 460) && !isPaused) {
|
|
click(520, 470); sleep(100);
|
|
var img = captureScreen();
|
|
}
|
|
sleep(500);
|
|
if (images.detectsColor(img, "#F3E5D3", 370, 380) && !isPaused) {
|
|
click(370, 380);
|
|
}
|
|
}
|
|
else {
|
|
click(495, 250); sleep(500);
|
|
var img = captureScreen();
|
|
while (images.detectsColor(img, "#8EE3D3", 520, 344) && !isPaused) {
|
|
click(520, 344); sleep(100);
|
|
var img = captureScreen();
|
|
}
|
|
}
|
|
back(); sleep(500);
|
|
}
|
|
}
|
|
img.recycle();
|
|
}
|