diff --git a/repo/js/AutoLeyLineOutcrop/main.js b/repo/js/AutoLeyLineOutcrop/main.js index e3c91db73..13eecc007 100644 --- a/repo/js/AutoLeyLineOutcrop/main.js +++ b/repo/js/AutoLeyLineOutcrop/main.js @@ -15,6 +15,8 @@ let isNotification = false; // 是否发送通知 let config = {}; // 全局配置对象 let recheckCount = 0; // 树脂重新检查次数(防止无限递归) const MAX_RECHECK_COUNT = 3; // 最大重新检查次数 +let consecutiveFailureCount = 0; // 连续战斗失败次数 +const MAX_CONSECUTIVE_FAILURES = 5; // 最大连续失败次数,超过后终止脚本 const ocrRegion1 = { x: 800, y: 200, width: 300, height: 100 }; // 中心区域 const ocrRegion2 = { x: 0, y: 200, width: 300, height: 300 }; // 追踪任务区域 const ocrRegion3 = { x: 1200, y: 520, width: 300, height: 300 }; // 拾取区域 @@ -592,6 +594,9 @@ async function executePath(path) { if (!rewardSuccess) { throw new Error("无法领取奖励,树脂不足或其他原因"); } + + // 成功完成地脉花挑战,重置连续失败计数器 + consecutiveFailureCount = 0; } /** diff --git a/repo/js/AutoLeyLineOutcrop/manifest.json b/repo/js/AutoLeyLineOutcrop/manifest.json index be6e7df8e..357d808b4 100644 --- a/repo/js/AutoLeyLineOutcrop/manifest.json +++ b/repo/js/AutoLeyLineOutcrop/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "全自动地脉花", - "version": "4.4", + "version": "4.4.1", "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如果遇到问题,请先参照手册中的方法进行解决。", diff --git a/repo/js/AutoLeyLineOutcrop/utils/executePathsUsingNodeData.js b/repo/js/AutoLeyLineOutcrop/utils/executePathsUsingNodeData.js index f7d05dd4e..f72820e2b 100644 --- a/repo/js/AutoLeyLineOutcrop/utils/executePathsUsingNodeData.js +++ b/repo/js/AutoLeyLineOutcrop/utils/executePathsUsingNodeData.js @@ -154,8 +154,19 @@ this.executePathsUsingNodeData = async function (position) { } catch (error) { if(error.message.includes("战斗失败")) { - log.error("战斗失败,重新寻找地脉花后重试"); + consecutiveFailureCount++; + log.error(`战斗失败,连续失败次数: ${consecutiveFailureCount}/${MAX_CONSECUTIVE_FAILURES}`); + + // 检查是否超过最大连续失败次数 + if (consecutiveFailureCount >= MAX_CONSECUTIVE_FAILURES) { + await ensureExitRewardPage(); + throw new Error(`连续战斗失败${MAX_CONSECUTIVE_FAILURES}次,可能是队伍配置不足以完成挑战,脚本终止`); + } + await ensureExitRewardPage(); + // processResurrect()已在processLeyLineOutcrop中调用,这里直接return + // return后会回到runLeyLineChallenges的while循环,重新寻找地脉花 + log.info("将重新寻找地脉花并重试"); return; } // 其他错误需要向上传播 diff --git a/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js b/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js index 81abc3e24..2ed3f8df0 100644 --- a/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js +++ b/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js @@ -53,6 +53,16 @@ async function (timeout, targetPath, retries = 0) { const fightResult = await autoFight(timeout); if (!fightResult) { await ensureExitRewardPage(); + + // 检查是否为全队阵亡(有复苏界面) + let isResurrect = await processResurrect(); + if(isResurrect) { + log.info("检测到全队阵亡,已点击复苏按钮,准备重试战斗"); + return await this.processLeyLineOutcrop(timeout, targetPath, retries + 1); + } + + // 没有复苏界面,说明是战斗超时,直接抛出错误 + log.warn("战斗失败(超时或其他原因),未检测到复苏界面"); throw new Error("战斗失败"); } @@ -77,3 +87,47 @@ async function (timeout, targetPath, retries = 0) { } } } + +async function processResurrect() { + let captureRegion = null; + try { + // OCR识别整个界面的文本 + captureRegion = captureGameRegion(); + let resList = captureRegion.findMulti(ocrRoThis); + + if (!resList || resList.count === 0) { + log.debug("未识别到任何文本,无法检查复苏按钮"); + return false; + } + + let resurrectButton = null; + for (let i = 0; i < resList.count; i++) { + let res = resList[i]; + if (res.text.includes("复苏")) { + resurrectButton = res; + break; + } + } + + if(resurrectButton) { + log.info("战斗失败,检测到复苏按钮,准备点击复苏"); + resurrectButton.click(); + await sleep(2000); // 等待复苏动画 + return true; + } + + log.debug("未检测到复苏按钮"); + return false; + } catch (error) { + log.error(`检查复苏按钮时出错: ${error.message}`); + return false; + } finally { + if (captureRegion) { + try { + captureRegion.dispose(); + } catch (disposeError) { + log.warn(`释放截图资源时出错: ${disposeError.message}`); + } + } + } +} \ No newline at end of file