优化自动每日指令与扫码退出秘境

This commit is contained in:
2026-08-30 00:40:18 +08:00
parent da8a82bfd5
commit 2d81615f78
10 changed files with 447 additions and 38 deletions
+77 -1
View File
@@ -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) {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"manifest_version": 1,
"name": "扫码上号",
"version": "1.0",
"version": "1.1",
"bgi_version": "0.48.0",
"description": "直播用扫码上号脚本:判断在大世界则退出到开门页面→点击扫码登录→等待扫码→检测验证码",
"authors": [
+5 -5
View File
@@ -44,7 +44,7 @@
{
"name": "useOcr",
"type": "checkbox",
"label": "使用OCR识别文本(否则用固定坐标)",
"label": "退出秘境确认按钮使用 OCR 定位(关闭后使用固定坐标",
"default": true
},
{
@@ -53,14 +53,14 @@
{
"name": "confirmExitX",
"type": "input-text",
"label": "确认退出按钮 X(固定坐标模式)",
"default": "830"
"label": "退出秘境确认按钮 X(1920×1080 固定坐标",
"default": "1164"
},
{
"name": "confirmExitY",
"type": "input-text",
"label": "确认退出按钮 Y(固定坐标模式)",
"default": "600"
"label": "退出秘境确认按钮 Y(1920×1080 固定坐标",
"default": "757"
},
{
"name": "qrLoginX",