mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-16 03:33:25 +08:00
[自动地脉花]适配新的奖励领取界面及优化退出逻辑 (#2145)
* 适配新的奖励领取界面及优化退出逻辑 - 在各功能函数中添加奖励界面退出校验机制 - 增强奖励尝试及路径执行的错误处理与日志记录 - 适配新的奖励领取界面,基于当前状态优化树脂消耗决策 * Update version to 4.3 and add new contributor information in manifest.json * ”将检查是否关闭奖励界面“的逻辑从"未找到对应的地脉花策略"中移除
This commit is contained in:
@@ -48,6 +48,10 @@
|
||||
打开大地图,点击左下角设置,开启自定义标记。
|
||||
脚本非正常结束运行时会出现该问题。
|
||||
## 更新日志
|
||||
### 4.3
|
||||
- 适配新的奖励领取界面
|
||||
- 修复挪德卡莱识别错误及通过冒险之证寻找地脉花总会选择挪德卡莱的bug
|
||||
- 修复卡在奖励领取界面无法执行其他配置的bug
|
||||
### 4.2
|
||||
- 新增挪德卡莱区域
|
||||
### 4.1
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
BIN
repo/js/AutoLeyLineOutcrop/RecognitionObject/switch_button.png
Normal file
BIN
repo/js/AutoLeyLineOutcrop/RecognitionObject/switch_button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 696 B |
BIN
repo/js/AutoLeyLineOutcrop/RecognitionObject/use_button.png
Normal file
BIN
repo/js/AutoLeyLineOutcrop/RecognitionObject/use_button.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -42,6 +42,13 @@ const ocrRoThis = RecognitionObject.ocrThis;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
// 确保退出奖励界面(如果在奖励界面)
|
||||
try {
|
||||
await ensureExitRewardPage();
|
||||
} catch (exitError) {
|
||||
log.warn(`退出奖励界面时出错: ${exitError.message}`);
|
||||
}
|
||||
|
||||
if (!marksStatus) {
|
||||
// 任何时候都确保自定义标记处于打开状态
|
||||
await openCustomMarks();
|
||||
@@ -106,6 +113,12 @@ function initialize() {
|
||||
*/
|
||||
async function prepareForLeyLineRun() {
|
||||
// 0. 回到主界面
|
||||
// 确保退出奖励界面
|
||||
try {
|
||||
await ensureExitRewardPage();
|
||||
} catch (exitError) {
|
||||
log.warn(`退出奖励界面时出错: ${exitError.message}`);
|
||||
}
|
||||
await genshin.returnMainUi(); // 回到主界面
|
||||
setGameMetrics(1920, 1080, 1); // 看起来没什么用
|
||||
// 1. 开局传送到七天神像
|
||||
@@ -404,7 +417,12 @@ async function executePath(path) {
|
||||
const routePath = path.routes[path.routes.length - 1];
|
||||
const targetPath = routePath.replace('assets/pathing/', 'assets/pathing/target/').replace('-rerun', '');
|
||||
await processLeyLineOutcrop(settings.timeout, targetPath);
|
||||
await attemptReward();
|
||||
|
||||
// 尝试领取奖励,如果失败则抛出异常停止执行
|
||||
const rewardSuccess = await attemptReward();
|
||||
if (!rewardSuccess) {
|
||||
throw new Error("无法领取奖励,树脂不足或其他原因");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,6 +463,14 @@ async function handleNoStrategyFound() {
|
||||
log.error("未找到对应的地脉花策略,请再次运行脚本");
|
||||
log.error("如果仍然不行,请截图{1}游戏界面,并反馈给作者!", "*完整的*");
|
||||
log.error("完整的游戏界面!完整的游戏界面!完整的游戏界面!");
|
||||
|
||||
// 确保退出奖励界面 TODO: 可能会影响debug,先不执行ensureExitRewardPage
|
||||
// try {
|
||||
// await ensureExitRewardPage();
|
||||
// } catch (exitError) {
|
||||
// log.warn(`退出奖励界面时出错: ${exitError.message}`);
|
||||
// }
|
||||
|
||||
if (isNotification) {
|
||||
notification.error("未找到对应的地脉花策略");
|
||||
await genshin.returnMainUi();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "全自动地脉花",
|
||||
"version": "4.2",
|
||||
"version": "4.3",
|
||||
"tags": ["地脉花"],
|
||||
"bgi_version": "0.44.7",
|
||||
"description": "基于OCR图像识别的全自动刷取地脉花。\n💡更多信息请查看在线手册:https://hcnsvf0s8d0s.feishu.cn/wiki/Tb1twpThLi7UlykqcYOcuccTnjJ \n\n----------注意事项----------\n●仅支持BetterGI 0.44.7 及以上版本!\n●部分地脉花因特殊原因不支持全自动,具体的点位请在手册中查看。\n●树脂使用的优先级:2倍原粹树脂 > 浓缩树脂 > 原粹树脂。\n●运行时会传送到七天神像设置中设置的七天神像,需要关闭七天神像设置中的“是否就近七天神像恢复血量”,并指定七天神像。\n●战斗策略注意调度器设置中地图追踪行走配置里的“允许在JsSpript中使用”和“覆盖JS中的自动战斗配置”,只有在都打开的情况下脚本才会使用下面的战斗配置,否则会使用独立任务中的战斗策略。战斗超时时间不能大于脚本自定义配置中的时间。\n\n如果遇到问题,请先参照手册中的方法进行解决。",
|
||||
@@ -29,6 +29,10 @@
|
||||
{
|
||||
"name": "寒烟",
|
||||
"links": "https://github.com/214-hanyan"
|
||||
},
|
||||
{
|
||||
"name": "ColinXu",
|
||||
"links": "https://github.com/ColinXHL"
|
||||
}
|
||||
],
|
||||
"settings_ui": "settings.json",
|
||||
|
||||
@@ -38,9 +38,467 @@ this.clickWithVerification = async function(x, y, targetText, maxRetries = 20) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试领取地脉花奖励
|
||||
* 验证是否在奖励界面
|
||||
* 使用OCR识别"地脉之花"或"激活地脉之花"文字,不受分辨率影响
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
this.verifyRewardPage = async function() {
|
||||
try {
|
||||
let captureRegion = captureGameRegion();
|
||||
|
||||
// 使用OCR识别上半区域
|
||||
let ocrRo = RecognitionObject.Ocr(0, 0, captureRegion.width, captureRegion.height / 2);
|
||||
let textList = captureRegion.findMulti(ocrRo);
|
||||
captureRegion.dispose();
|
||||
|
||||
let isValid = false;
|
||||
if (textList && textList.count > 0) {
|
||||
for (let i = 0; i < textList.count; i++) {
|
||||
let text = textList[i].text;
|
||||
// 识别关键文字
|
||||
if (text.includes("激活地脉之花") ||
|
||||
text.includes("选择激活方式")) {
|
||||
isValid = true;
|
||||
log.info(`奖励界面验证: 成功(识别到文字: "${text}")`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 已注释:减少日志输出
|
||||
// if (!isValid) {
|
||||
// log.info(`奖励界面验证: 失败(未识别到关键文字)`);
|
||||
// }
|
||||
|
||||
return isValid;
|
||||
} catch (error) {
|
||||
log.error(`验证奖励界面失败: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查原粹树脂是否耗尽(通过OCR识别"补充"文字)
|
||||
* 如果原粹树脂耗尽,第一个按钮会变成"补充"按钮
|
||||
* @param {ImageRegion} captureRegion - 截图区域
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
async function checkOriginalResinEmpty(captureRegion) {
|
||||
try {
|
||||
// 使用OCR识别"补充"文字
|
||||
let ocrRo = RecognitionObject.Ocr(0, 0, captureRegion.width, captureRegion.height);
|
||||
let textList = captureRegion.findMulti(ocrRo);
|
||||
|
||||
if (textList && textList.count > 0) {
|
||||
for (let i = 0; i < textList.count; i++) {
|
||||
let text = textList[i].text;
|
||||
if (text.includes("补充")) {
|
||||
log.warn("检测到补充文字,原粹树脂已耗尽");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
log.error(`检查原粹树脂状态失败: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找并排序所有使用按钮(通过OCR识别"使用"文字)
|
||||
* 注意:如果原粹树脂耗尽,第一个位置是"补充"按钮,不会被识别为"使用"按钮
|
||||
* @param {ImageRegion} captureRegion - 截图区域
|
||||
* @returns {Promise<Array>}
|
||||
*/
|
||||
async function findAndSortUseButtons(captureRegion) {
|
||||
try {
|
||||
// 使用OCR识别所有"使用"文字
|
||||
let ocrRo = RecognitionObject.Ocr(0, 0, captureRegion.width, captureRegion.height);
|
||||
let textList = captureRegion.findMulti(ocrRo);
|
||||
|
||||
if (!textList || textList.count === 0) {
|
||||
log.warn("未找到任何文本");
|
||||
return [];
|
||||
}
|
||||
|
||||
// 查找只包含"使用"两个字的文本(真正的按钮)
|
||||
let buttons = [];
|
||||
for (let i = 0; i < textList.count; i++) {
|
||||
let textRegion = textList[i];
|
||||
let text = textRegion.text.trim(); // 去除首尾空格
|
||||
|
||||
// 只匹配恰好是"使用"的文本,排除描述性文字
|
||||
if (text === "使用") {
|
||||
// 按钮就在文本位置(OCR识别到的就是按钮本身)
|
||||
let buttonX = Math.round(textRegion.x + textRegion.width / 2);
|
||||
let buttonY = Math.round(textRegion.y + textRegion.height / 2);
|
||||
let textY = textRegion.y; // 提前保存Y坐标值
|
||||
let textContent = textRegion.text; // 提前保存文本内容
|
||||
|
||||
// 创建虚拟按钮Region对象(不保存textRegion引用,避免dispose后访问失败)
|
||||
let virtualButton = {
|
||||
index: buttons.length,
|
||||
region: {
|
||||
x: buttonX,
|
||||
y: buttonY,
|
||||
click: function() {
|
||||
click(buttonX, buttonY);
|
||||
}
|
||||
},
|
||||
x: buttonX,
|
||||
y: textY, // 用文本的Y坐标进行排序
|
||||
text: textContent // 保存文本内容而非引用
|
||||
};
|
||||
|
||||
buttons.push(virtualButton);
|
||||
}
|
||||
}
|
||||
|
||||
if (buttons.length === 0) {
|
||||
log.warn("未找到包含'使用'的文本");
|
||||
return [];
|
||||
}
|
||||
|
||||
// 按Y坐标排序
|
||||
buttons.sort((a, b) => a.y - b.y);
|
||||
|
||||
log.info(`找到 ${buttons.length} 个使用按钮`);
|
||||
|
||||
return buttons;
|
||||
} catch (error) {
|
||||
log.error(`查找使用按钮失败: ${error.message}`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分析树脂选项并决定使用哪个
|
||||
* @param {ImageRegion} captureRegion - 截图区域
|
||||
* @param {Array} sortedButtons - 排序后的使用按钮数组
|
||||
* @param {boolean} isOriginalResinEmpty - 原粹树脂是否耗尽
|
||||
* @returns {Promise<Object|null>}
|
||||
*/
|
||||
async function analyzeResinOptions(captureRegion, sortedButtons, isOriginalResinEmpty) {
|
||||
try {
|
||||
// OCR识别整个界面的文本
|
||||
let ocrRo = RecognitionObject.Ocr(0, 0, captureRegion.width, captureRegion.height);
|
||||
let textList = captureRegion.findMulti(ocrRo);
|
||||
|
||||
if (!textList || textList.count === 0) {
|
||||
log.warn("OCR未识别到任何文本");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 收集所有识别到的文本
|
||||
let allTexts = [];
|
||||
for (let i = 0; i < textList.count; i++) {
|
||||
allTexts.push({
|
||||
text: textList[i].text,
|
||||
y: textList[i].y
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 检测是否有双倍/多倍产出
|
||||
let hasDoubleReward = allTexts.some(t =>
|
||||
t.text.includes("双倍") ||
|
||||
t.text.includes("2倍产出") ||
|
||||
t.text.includes("2倍")
|
||||
);
|
||||
|
||||
// 只在有双倍产出时输出
|
||||
if (hasDoubleReward) {
|
||||
log.info("检测到双倍产出");
|
||||
}
|
||||
|
||||
// 识别树脂类型(注意:如果原粹树脂耗尽,应该忽略这些识别)
|
||||
let hasOriginalResin20 = !isOriginalResinEmpty && allTexts.some(t =>
|
||||
(t.text.includes("20") && t.text.includes("原粹树脂")) ||
|
||||
(t.text.includes("20个") && t.text.includes("原粹树脂"))
|
||||
);
|
||||
|
||||
let hasOriginalResin40 = !isOriginalResinEmpty && allTexts.some(t =>
|
||||
(t.text.includes("40") && t.text.includes("原粹树脂")) ||
|
||||
(t.text.includes("40个") && t.text.includes("原粹树脂"))
|
||||
);
|
||||
|
||||
let hasCondensedResin = allTexts.some(t =>
|
||||
t.text.includes("浓缩树脂") || t.text.includes("浓缩")
|
||||
);
|
||||
|
||||
let hasTransientResin = allTexts.some(t =>
|
||||
t.text.includes("须臾树脂") || t.text.includes("须臾")
|
||||
);
|
||||
|
||||
let hasFragileResin = allTexts.some(t =>
|
||||
t.text.includes("脆弱树脂") || t.text.includes("脆弱")
|
||||
);
|
||||
|
||||
let hasPrimogems = allTexts.some(t =>
|
||||
t.text.includes("原石") && t.text.includes("3次")
|
||||
);
|
||||
|
||||
// 输出识别到的树脂类型(调试用)
|
||||
log.info(`识别到的树脂类型 - 原粹20:${hasOriginalResin20}, 原粹40:${hasOriginalResin40}, 浓缩:${hasCondensedResin}, 须臾:${hasTransientResin}, 脆弱:${hasFragileResin}, 原石:${hasPrimogems}, 双倍:${hasDoubleReward}`);
|
||||
|
||||
// 决策逻辑(根据原粹树脂是否耗尽,决策不同)
|
||||
let choice = null;
|
||||
|
||||
if (isOriginalResinEmpty) {
|
||||
// ===== 原粹树脂耗尽的情况 =====
|
||||
// 此时第一个"使用"按钮对应的是浓缩/须臾/脆弱树脂
|
||||
log.warn("原粹树脂已耗尽,检测是否有其他可用树脂");
|
||||
|
||||
if (hasCondensedResin && sortedButtons.length >= 1) {
|
||||
choice = {
|
||||
type: "使用1个浓缩树脂(原粹耗尽)",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
} else if (hasTransientResin && sortedButtons.length >= 1) {
|
||||
choice = {
|
||||
type: "使用1个须臾树脂(原粹耗尽)",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
} else if (hasFragileResin && sortedButtons.length >= 1 && settings.useFragileResin) {
|
||||
choice = {
|
||||
type: "使用1个脆弱树脂(原粹耗尽)",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
} else {
|
||||
// 输出详细的调试信息
|
||||
if (hasFragileResin && !settings.useFragileResin) {
|
||||
log.warn(`原粹树脂耗尽,检测到脆弱树脂但配置禁止使用(settings.useFragileResin=${settings.useFragileResin})`);
|
||||
} else {
|
||||
log.warn(`原粹树脂耗尽且无其他可用树脂(浓缩:${hasCondensedResin}, 须臾:${hasTransientResin}, 脆弱:${hasFragileResin}, 原石:${hasPrimogems})`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
// ===== 原粹树脂充足的情况 =====
|
||||
// 第一个"使用"按钮对应原粹树脂
|
||||
// 第二个"使用"按钮对应浓缩/须臾/脆弱树脂
|
||||
|
||||
// 优先级1: 如果有双倍产出,优先使用原粹树脂
|
||||
if (hasDoubleReward && (hasOriginalResin20 || hasOriginalResin40)) {
|
||||
// 如果当前是20个原粹树脂,先尝试切换到40个
|
||||
if (hasOriginalResin20 && !hasOriginalResin40) {
|
||||
let switchSuccess = await trySwitch20To40Resin(captureRegion);
|
||||
if (switchSuccess) {
|
||||
choice = {
|
||||
type: "使用40个原粹树脂(从20切换,双倍产出)",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
} else {
|
||||
choice = {
|
||||
type: "使用20个原粹树脂(双倍产出)",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
}
|
||||
} else {
|
||||
choice = {
|
||||
type: hasOriginalResin40 ? "使用40个原粹树脂(双倍产出)" : "使用20个原粹树脂(双倍产出)",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
// 优先级2: 优先使用浓缩树脂
|
||||
else if (hasCondensedResin && sortedButtons.length >= 2) {
|
||||
choice = {
|
||||
type: "使用1个浓缩树脂",
|
||||
button: sortedButtons[1],
|
||||
buttonIndex: 1
|
||||
};
|
||||
}
|
||||
// 优先级3: 使用须臾树脂
|
||||
else if (hasTransientResin && sortedButtons.length >= 2) {
|
||||
choice = {
|
||||
type: "使用1个须臾树脂",
|
||||
button: sortedButtons[1],
|
||||
buttonIndex: 1
|
||||
};
|
||||
}
|
||||
// 优先级4: 使用原粹树脂
|
||||
else if (hasOriginalResin20 || hasOriginalResin40) {
|
||||
// 如果当前是20个原粹树脂,先尝试切换到40个
|
||||
if (hasOriginalResin20 && !hasOriginalResin40) {
|
||||
let switchSuccess = await trySwitch20To40Resin(captureRegion);
|
||||
if (switchSuccess) {
|
||||
choice = {
|
||||
type: "使用40个原粹树脂(从20切换)",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
} else {
|
||||
choice = {
|
||||
type: "使用20个原粹树脂",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
}
|
||||
} else {
|
||||
choice = {
|
||||
type: hasOriginalResin40 ? "使用40个原粹树脂" : "使用20个原粹树脂",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
// 优先级5: 如果配置允许,使用脆弱树脂
|
||||
else if (hasFragileResin && settings.useFragileResin && sortedButtons.length >= 2) {
|
||||
choice = {
|
||||
type: "使用1个脆弱树脂",
|
||||
button: sortedButtons[1],
|
||||
buttonIndex: 1
|
||||
};
|
||||
}
|
||||
// 默认: 点击第一个按钮(原粹树脂)
|
||||
else if (sortedButtons.length >= 1) {
|
||||
// 尝试切换到40个原粹树脂(如果当前是20个)
|
||||
if (hasOriginalResin20 && !hasOriginalResin40) {
|
||||
let switchSuccess = await trySwitch20To40Resin(captureRegion);
|
||||
choice = {
|
||||
type: switchSuccess ? "默认使用40个原粹树脂(从20切换)" : "默认使用20个原粹树脂",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
} else {
|
||||
choice = {
|
||||
type: "默认使用原粹树脂",
|
||||
button: sortedButtons[0],
|
||||
buttonIndex: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return choice;
|
||||
|
||||
} catch (error) {
|
||||
log.error(`分析树脂选项失败: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试将20个原粹树脂切换到40个原粹树脂
|
||||
* @param {ImageRegion} captureRegion - 截图区域
|
||||
* @returns {Promise<boolean>} 是否成功切换
|
||||
*/
|
||||
async function trySwitch20To40Resin(captureRegion) {
|
||||
try {
|
||||
log.info("检测到20个原粹树脂,尝试切换到40个");
|
||||
|
||||
// 检测切换按钮
|
||||
const switchButtonIcon = file.ReadImageMatSync("RecognitionObject/switch_button.png");
|
||||
const switchButtonRo = RecognitionObject.TemplateMatch(switchButtonIcon);
|
||||
switchButtonRo.threshold = 0.7; // 设置合适的阈值
|
||||
|
||||
// 查找切换按钮
|
||||
let switchButtonPos = captureRegion.find(switchButtonRo);
|
||||
|
||||
if (!switchButtonPos || switchButtonPos.isEmpty()) {
|
||||
log.info("未找到切换按钮(树脂不足40或按钮不可用),保持使用20个原粹树脂");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 找到可用的切换按钮,点击切换
|
||||
log.info(`找到切换按钮,点击切换到40个原粹树脂`);
|
||||
switchButtonPos.click();
|
||||
await sleep(800);
|
||||
|
||||
// 验证是否切换成功
|
||||
let newCaptureRegion = captureGameRegion();
|
||||
let ocrRo = RecognitionObject.Ocr(0, 0, newCaptureRegion.width, newCaptureRegion.height);
|
||||
let textList = newCaptureRegion.findMulti(ocrRo);
|
||||
newCaptureRegion.dispose();
|
||||
|
||||
if (textList && textList.count > 0) {
|
||||
for (let i = 0; i < textList.count; i++) {
|
||||
let text = textList[i].text;
|
||||
if ((text.includes("40") && text.includes("原粹")) ||
|
||||
(text.includes("40个") && text.includes("树脂"))) {
|
||||
log.info("成功切换到40个原粹树脂");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.warn("点击切换按钮后,未能确认切换到40个原粹树脂");
|
||||
return false;
|
||||
|
||||
} catch (error) {
|
||||
log.error(`切换树脂数量失败: ${error.message}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换回战斗队伍
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function switchBackToCombatTeam() {
|
||||
try {
|
||||
log.info("切换回战斗队伍");
|
||||
await sleep(500);
|
||||
const switchSuccess = await switchTeam(settings.team);
|
||||
if (!switchSuccess) {
|
||||
log.warn("切换队伍可能失败");
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(`切换队伍失败: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确保退出奖励界面
|
||||
* 循环检测并退出,直到确认不在奖励界面
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
this.ensureExitRewardPage = async function() {
|
||||
const MAX_ATTEMPTS = 5; // 最多尝试5次
|
||||
let attempts = 0;
|
||||
|
||||
try {
|
||||
log.info("检查是否需要退出奖励界面");
|
||||
|
||||
while (attempts < MAX_ATTEMPTS) {
|
||||
attempts++;
|
||||
|
||||
// 检测是否在奖励界面
|
||||
let isInRewardPage = await verifyRewardPage();
|
||||
|
||||
if (!isInRewardPage) {
|
||||
log.info("已确认不在奖励界面");
|
||||
return;
|
||||
}
|
||||
|
||||
// 还在奖励界面,按ESC退出
|
||||
log.info(`检测到仍在奖励界面,按ESC退出 (第${attempts}次)`);
|
||||
keyPress("VK_ESCAPE");
|
||||
await sleep(800); // 等待界面关闭动画
|
||||
}
|
||||
|
||||
// 超过最大尝试次数
|
||||
log.warn(`已尝试${MAX_ATTEMPTS}次退出奖励界面,可能仍在界面中`);
|
||||
|
||||
} catch (error) {
|
||||
log.error(`退出奖励界面时出错: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试领取地脉花奖励(图像识别+OCR混合版本)
|
||||
* @param {number} retryCount - 重试次数
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
this.attemptReward = async function (retryCount = 0) {
|
||||
const MAX_RETRY = 3;
|
||||
if (retryCount >= MAX_RETRY) {
|
||||
@@ -49,90 +507,63 @@ this.attemptReward = async function (retryCount = 0) {
|
||||
|
||||
log.info("开始领取地脉奖励");
|
||||
keyPress("F");
|
||||
await sleep(500);
|
||||
await sleep(800);
|
||||
|
||||
// 识别是否为地脉之花界面
|
||||
let captureRegion = captureGameRegion();
|
||||
let resList = captureRegion.findMulti(ocrRoThis); // 使用预定义的ocrRoThis对象
|
||||
captureRegion.dispose();
|
||||
let isValid = false;
|
||||
let condensedResin = null;
|
||||
let originalResin = null;
|
||||
let fragileResin = null;
|
||||
let isResinEmpty = false;
|
||||
let dobuleReward = false;
|
||||
let isOriginalResinEmpty = false;
|
||||
|
||||
if (resList && resList.count > 0) {
|
||||
// 分析识别到的文本
|
||||
for (let i = 0; i < resList.count; i++) {
|
||||
let res = resList[i];
|
||||
if (res.text.includes("浓缩树脂")) {
|
||||
isValid = true;
|
||||
condensedResin = res;
|
||||
} else if (res.text.includes("原粹树脂")) {
|
||||
isValid = true;
|
||||
originalResin = res;
|
||||
} else if (res.text.includes("脆弱树脂") && settings.fragileResin) {
|
||||
isValid = true;
|
||||
fragileResin = res;
|
||||
} else if (res.text.includes("双倍掉落")) {
|
||||
isValid = true;
|
||||
dobuleReward = true;
|
||||
} else if (res.text.includes("补充")){
|
||||
isValid = true;
|
||||
isOriginalResinEmpty = true;
|
||||
} else {
|
||||
isValid = true;
|
||||
isResinEmpty = true;
|
||||
}
|
||||
} // 处理不同的树脂情况
|
||||
if (originalResin && dobuleReward && !isOriginalResinEmpty) {
|
||||
log.info("选择使用原粹树脂,获得双倍产出");
|
||||
await clickWithVerification(
|
||||
Math.round(originalResin.x + originalResin.width / 2) + 400,
|
||||
Math.round(originalResin.y + originalResin.height / 2),
|
||||
"使用"
|
||||
);
|
||||
} else if (condensedResin) {
|
||||
log.info("选择使用浓缩树脂");
|
||||
await clickWithVerification(
|
||||
Math.round(condensedResin.x + condensedResin.width / 2) + 400,
|
||||
Math.round(condensedResin.y + condensedResin.height / 2),
|
||||
"使用"
|
||||
);
|
||||
} else if (originalResin && !isOriginalResinEmpty) {
|
||||
log.info("选择使用原粹树脂");
|
||||
await clickWithVerification(
|
||||
Math.round(originalResin.x + originalResin.width / 2) + 400,
|
||||
Math.round(originalResin.y + originalResin.height / 2),
|
||||
"使用"
|
||||
);
|
||||
} else if (fragileResin) {
|
||||
log.info("选择使用脆弱树脂");
|
||||
await clickWithVerification(
|
||||
Math.round(fragileResin.x + fragileResin.width / 2) + 400,
|
||||
Math.round(fragileResin.y + fragileResin.height / 2),
|
||||
"使用"
|
||||
);
|
||||
} else if (isResinEmpty && isOriginalResinEmpty) {
|
||||
log.error("树脂用完了呢");
|
||||
keyPress("VK_ESCAPE");
|
||||
throw new Error("原粹树脂不足20,无法领取奖励");
|
||||
}
|
||||
if (settings.friendshipTeam) {
|
||||
log.info("切换回战斗队伍");
|
||||
await sleep(500);
|
||||
const switchSuccess = await switchTeam(settings.team);
|
||||
}
|
||||
}
|
||||
|
||||
// 界面不正确,尝试重试
|
||||
if (!isValid) {
|
||||
log.info("当前界面不是地脉之花界面,重试");
|
||||
// 步骤1: 验证是否在奖励界面
|
||||
if (!await verifyRewardPage()) {
|
||||
log.warn("当前不在奖励界面,尝试重试");
|
||||
await genshin.returnMainUi();
|
||||
await sleep(1000);
|
||||
await autoNavigateToReward();
|
||||
await attemptReward(++retryCount);
|
||||
return await this.attemptReward(++retryCount);
|
||||
}
|
||||
|
||||
let captureRegion = captureGameRegion();
|
||||
|
||||
// 步骤2: 检查原粹树脂是否耗尽(通过"补充"按钮)
|
||||
let isOriginalResinEmpty = await checkOriginalResinEmpty(captureRegion);
|
||||
|
||||
// 步骤3: 识别所有使用按钮并排序
|
||||
let sortedButtons = await findAndSortUseButtons(captureRegion);
|
||||
|
||||
if (sortedButtons.length === 0) {
|
||||
log.error("未找到任何使用按钮");
|
||||
captureRegion.dispose();
|
||||
keyPress("VK_ESCAPE");
|
||||
await sleep(500);
|
||||
await ensureExitRewardPage();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 步骤4: 根据原粹树脂状态调整决策逻辑
|
||||
let resinChoice = await analyzeResinOptions(captureRegion, sortedButtons, isOriginalResinEmpty);
|
||||
|
||||
if (!resinChoice) {
|
||||
// 已在 analyzeResinOptions 中输出详细错误信息,这里不再重复
|
||||
captureRegion.dispose();
|
||||
keyPress("VK_ESCAPE");
|
||||
await sleep(500);
|
||||
await ensureExitRewardPage();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 步骤5: 点击对应的使用按钮
|
||||
log.info(`选择: ${resinChoice.type},点击按钮 (X=${resinChoice.button.x}, Y=${resinChoice.button.y})`);
|
||||
resinChoice.button.region.click();
|
||||
await sleep(1000);
|
||||
|
||||
// 步骤6: 如果需要切换回战斗队伍
|
||||
if (settings.friendshipTeam) {
|
||||
await switchBackToCombatTeam();
|
||||
}
|
||||
|
||||
captureRegion.dispose();
|
||||
|
||||
// 等待领奖动画/道具到账
|
||||
await sleep(1200);
|
||||
|
||||
// 确保完全退出奖励界面
|
||||
await ensureExitRewardPage();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ this.executePathsUsingNodeData = async function (position) {
|
||||
|
||||
if (!targetNode) {
|
||||
log.error(`未找到与坐标(${currentNodePosition.x}, ${currentNodePosition.y})匹配的目标节点`);
|
||||
await ensureExitRewardPage();
|
||||
return;
|
||||
}
|
||||
log.debug(`找到目标节点: ID ${targetNode.id}, 位置(${targetNode.position.x}, ${targetNode.position.y})`);
|
||||
@@ -18,6 +19,7 @@ this.executePathsUsingNodeData = async function (position) {
|
||||
|
||||
if (paths.length === 0) {
|
||||
log.error(`未找到通向目标节点(ID: ${targetNode.id})的路径`);
|
||||
await ensureExitRewardPage();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,6 +47,7 @@ this.executePathsUsingNodeData = async function (position) {
|
||||
const nextNode = nodeData.node.find(node => node.id === nextNodeId);
|
||||
|
||||
if (!nextNode) {
|
||||
await ensureExitRewardPage();
|
||||
return;
|
||||
}
|
||||
const pathObject = {
|
||||
@@ -81,6 +84,7 @@ this.executePathsUsingNodeData = async function (position) {
|
||||
|
||||
if (!found) {
|
||||
log.warn("无法在分支点找到下一个地脉花,退出本次循环");
|
||||
await ensureExitRewardPage();
|
||||
return;
|
||||
}
|
||||
log.info(`找到下一个地脉花,位置: (${leyLineX}, ${leyLineY})`);
|
||||
@@ -114,6 +118,7 @@ this.executePathsUsingNodeData = async function (position) {
|
||||
// 恢复原始坐标
|
||||
leyLineX = currentLeyLineX;
|
||||
leyLineY = currentLeyLineY;
|
||||
await ensureExitRewardPage();
|
||||
return;
|
||||
}
|
||||
const nextNode = nodeData.node.find(node => node.id === selectedNodeId);
|
||||
@@ -122,6 +127,7 @@ this.executePathsUsingNodeData = async function (position) {
|
||||
// 恢复原始坐标
|
||||
leyLineX = currentLeyLineX;
|
||||
leyLineY = currentLeyLineY;
|
||||
await ensureExitRewardPage();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -149,10 +155,12 @@ this.executePathsUsingNodeData = async function (position) {
|
||||
catch (error) {
|
||||
if(error.message.includes("战斗失败")) {
|
||||
log.error("战斗失败,重新寻找地脉花后重试");
|
||||
await ensureExitRewardPage();
|
||||
return;
|
||||
}
|
||||
// 其他错误需要向上传播
|
||||
log.error(`执行路径时出错: ${error.message}`);
|
||||
await ensureExitRewardPage();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ async function (country, type) {
|
||||
await sleep(1000);
|
||||
log.info("开始寻找地脉花");
|
||||
if (!config.mapPositions[country] || config.mapPositions[country].length === 0) {
|
||||
await ensureExitRewardPage();
|
||||
throw new Error(`未找到国家 ${country} 的位置信息`);
|
||||
}
|
||||
|
||||
@@ -29,6 +30,7 @@ async function (country, type) {
|
||||
}
|
||||
|
||||
// 如果到这里还没找到
|
||||
await ensureExitRewardPage();
|
||||
throw new Error("寻找地脉花失败,已达最大重试次数");
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
this.findLeyLineOutcropByBook = async function (country, type) {
|
||||
// 挪德卡莱会被识别成挪德卡菜,需要特殊处理
|
||||
if (country === "挪德卡莱") {
|
||||
country = "挪德卡";
|
||||
}
|
||||
|
||||
await genshin.returnMainUi();
|
||||
await sleep(1000);
|
||||
log.info("使用冒险之证寻找地脉花");
|
||||
@@ -30,7 +35,7 @@ this.findLeyLineOutcropByBook = async function (country, type) {
|
||||
captureRegion1.dispose();
|
||||
for (let i = 0; i < resList.count; i++) {
|
||||
let res = resList[i];
|
||||
if (res.text.includes(country) || res.text.includes("挪德")) {
|
||||
if (res.text.includes(country)) {
|
||||
res.click();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ async function (timeout, targetPath, retries = 0) {
|
||||
if (retries >= MAX_RETRIES) {
|
||||
const errorMsg = `开启地脉花失败,已重试${MAX_RETRIES}次,终止处理`;
|
||||
log.error("我辣么大一个地脉花哪去了?");
|
||||
await ensureExitRewardPage();
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
|
||||
@@ -51,6 +52,7 @@ async function (timeout, targetPath, retries = 0) {
|
||||
// 执行战斗
|
||||
const fightResult = await autoFight(timeout);
|
||||
if (!fightResult) {
|
||||
await ensureExitRewardPage();
|
||||
throw new Error("战斗失败");
|
||||
}
|
||||
|
||||
@@ -62,6 +64,7 @@ async function (timeout, targetPath, retries = 0) {
|
||||
// 保留原始错误信息
|
||||
const errorMsg = `地脉花处理失败 (重试${retries}/${MAX_RETRIES}): ${error.message}`;
|
||||
log.error(errorMsg);
|
||||
await ensureExitRewardPage();
|
||||
throw error;
|
||||
} finally {
|
||||
// 确保资源释放
|
||||
|
||||
Reference in New Issue
Block a user