优化自动每日指令与扫码退出秘境
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
(async function () {
|
||||
// ========================================
|
||||
// 扫码上号 v3
|
||||
// 扫码上号 v3.1
|
||||
// 流程: 状态判定 → (已登录则先退出) → A0检测tap → A1选号 → A2等登录+点中心 → A3完成
|
||||
// 状态文件: status.txt (登录中 / 已登录)
|
||||
// ========================================
|
||||
@@ -20,6 +20,25 @@
|
||||
// 脚本启动 → 写入"登录中"
|
||||
writeStatus("登录中");
|
||||
|
||||
function settingNumber(name, fallback) {
|
||||
const value = typeof settings !== "undefined" && settings ? Number(settings[name]) : NaN;
|
||||
return Number.isFinite(value) ? value : fallback;
|
||||
}
|
||||
|
||||
function settingBoolean(name, fallback) {
|
||||
if (typeof settings === "undefined" || !settings || settings[name] === undefined) return fallback;
|
||||
return settings[name] !== false && String(settings[name]).toLowerCase() !== "false";
|
||||
}
|
||||
|
||||
const useExitDomainOcr = settingBoolean("useOcr", true);
|
||||
let confirmExitX = settingNumber("confirmExitX", 1164);
|
||||
let confirmExitY = settingNumber("confirmExitY", 757);
|
||||
if (confirmExitX === 830 && confirmExitY === 600) {
|
||||
confirmExitX = 1164;
|
||||
confirmExitY = 757;
|
||||
log.info("检测到旧版退出秘境坐标,已自动修正为 (1164, 757)");
|
||||
}
|
||||
|
||||
// ---------- 加载图像资源 ----------
|
||||
const tapMat = file.readImageMatSync("assets/tap.png");
|
||||
const a0PhoneMat = file.readImageMatSync("assets/a0_phone.png");
|
||||
@@ -115,6 +134,54 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
function normalizeOcrText(text) {
|
||||
return String(text || "").replace(/\s+/g, "");
|
||||
}
|
||||
|
||||
function readOcrResults(x, y, w, h) {
|
||||
const cap = captureGameRegion();
|
||||
try {
|
||||
const results = cap.findMulti(RecognitionObject.ocr(x, y, w, h));
|
||||
return Array.from(results).map((result) => ({
|
||||
text: normalizeOcrText(result.text),
|
||||
x: Number(result.x || 0),
|
||||
y: Number(result.y || 0),
|
||||
w: Number(result.width || result.Width || 0),
|
||||
h: Number(result.height || result.Height || 0)
|
||||
}));
|
||||
} catch (e) {
|
||||
log.warn("退出秘境弹窗 OCR 失败: " + e);
|
||||
return [];
|
||||
} finally {
|
||||
cap.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
async function handleExitDomainDialog() {
|
||||
const results = readOcrResults(480, 220, 960, 620);
|
||||
const combinedText = results.map((result) => result.text).join("");
|
||||
if (!combinedText.includes("退出秘境")) return false;
|
||||
|
||||
log.info("检测到退出秘境确认弹窗");
|
||||
const confirmResult = results
|
||||
.filter((result) => result.text.includes("确认") && result.x >= 900)
|
||||
.sort((left, right) => right.x - left.x)[0];
|
||||
if (useExitDomainOcr && confirmResult) {
|
||||
const x = Math.round(confirmResult.x + confirmResult.w / 2);
|
||||
const y = Math.round(confirmResult.y + confirmResult.h / 2);
|
||||
log.info(`OCR 定位确认按钮,点击 (${x}, ${y})`);
|
||||
click(x, y);
|
||||
} else {
|
||||
const reason = useExitDomainOcr ? "OCR 未定位到确认按钮" : "已关闭 OCR 按钮定位";
|
||||
log.warn(`${reason},使用固定坐标 (${confirmExitX}, ${confirmExitY})`);
|
||||
click(confirmExitX, confirmExitY);
|
||||
}
|
||||
|
||||
log.info("已点击退出秘境确认,等待返回主界面...");
|
||||
await sleep(6000);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
// 前置处理:检测登录前的提示图标
|
||||
// 检测到则点击 (1830, 985),1秒后点击 (1100, 675),再1秒后进入初始判定;
|
||||
@@ -155,11 +222,20 @@
|
||||
log.info("未同时检测到 tap 图标和手机图标 → 开始检测派蒙头像");
|
||||
let paimonFound = findImageMatchRobust(paimonMat);
|
||||
|
||||
if (!paimonFound && await handleExitDomainDialog()) {
|
||||
paimonFound = findImageMatchRobust(paimonMat);
|
||||
if (paimonFound) log.info("退出秘境后已检测到派蒙头像");
|
||||
}
|
||||
|
||||
for (let i = 0; !paimonFound && i < 8; i++) {
|
||||
log.info(`第 ${i + 1}/8 次未检测到派蒙头像,按 ESC 后重试...`);
|
||||
keyPress("Escape");
|
||||
await sleep(1000);
|
||||
if (await handleExitDomainDialog()) {
|
||||
log.info("退出秘境弹窗已处理,重新检测主界面");
|
||||
}
|
||||
paimonFound = findImageMatchRobust(paimonMat);
|
||||
if (paimonFound) log.info("已检测到派蒙头像,继续退出账号流程");
|
||||
}
|
||||
|
||||
if (!paimonFound) {
|
||||
|
||||
Reference in New Issue
Block a user