diff --git a/repo/js/AutoLeyLineOutcrop/README.md b/repo/js/AutoLeyLineOutcrop/README.md index b363cd2ce..6d24e6b12 100644 --- a/repo/js/AutoLeyLineOutcrop/README.md +++ b/repo/js/AutoLeyLineOutcrop/README.md @@ -47,6 +47,11 @@ wgc的bug,请使用bitblt截图方式,脚本只支持这个 打开大地图,点击左下角设置,开启自定义标记。 脚本非正常结束运行时会出现该问题。 ## 更新日志 +### 4.1.4 +修复取消自动任务报错 +### 4.1.3 +修复v8报错 + ### 4.1 通过冒险之证找花 - 测试 ### 4.0 diff --git a/repo/js/AutoLeyLineOutcrop/main.js b/repo/js/AutoLeyLineOutcrop/main.js index a2ae1a22b..7b343368e 100644 --- a/repo/js/AutoLeyLineOutcrop/main.js +++ b/repo/js/AutoLeyLineOutcrop/main.js @@ -28,6 +28,7 @@ const ocrRo3 = RecognitionObject.ocr(ocrRegion3.x, ocrRegion3.y, ocrRegion3.widt const ocrRoThis = RecognitionObject.ocrThis; /** * 主函数 - 脚本入口点 + * 1. 全局异常处理,记录日志并发送通知 */ (async function () { try { @@ -37,7 +38,7 @@ const ocrRoThis = RecognitionObject.ocrThis; // 全局错误捕获,记录并发送错误日志 log.error("出错了: {error}", error.message); if (isNotification) { - notification.error("出错了: {error}", error.message); + notification.error("出错了: ${error.message}"); } } finally { @@ -76,7 +77,6 @@ function initialize() { "findLeyLineOutcrop.js", "findLeyLineOutcropByBook.js", "loadSettings.js", - "locateLeyLineOutcrop.js", "processLeyLineOutcrop.js", "recognizeTextInRegion.js" ]; @@ -131,6 +131,7 @@ async function prepareForLeyLineRun() { async function runLeyLineChallenges() { while (currentRunTimes < settings.timesValue) { // 寻找地脉花位置 + // 数据保存在全局变量中 leyLineX,leyLineY if (settings.useAdventurerHandbook) { await findLeyLineOutcropByBook(settings.country, settings.leyLineOutcropType); } else { @@ -542,7 +543,18 @@ async function autoFight(timeout) { logFightResult = fightResult ? "成功" : "失败"; log.info(`战斗结束,战斗结果:${logFightResult}`); cts.cancel(); - await fightTask; + + try { + await fightTask; + } catch (error) { + // 忽略取消任务产生的异常 + if (error.message && error.message.includes("取消")) { + log.debug("战斗任务已正常取消"); + } else { + log.warn(`战斗任务结束时出现异常: ${error.message}`); + } + } + return fightResult; } diff --git a/repo/js/AutoLeyLineOutcrop/manifest.json b/repo/js/AutoLeyLineOutcrop/manifest.json index 3f19def49..4414325b9 100644 --- a/repo/js/AutoLeyLineOutcrop/manifest.json +++ b/repo/js/AutoLeyLineOutcrop/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "全自动地脉花", - "version": "4.1.3", + "version": "4.1.4", "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/findLeyLineOutcrop.js b/repo/js/AutoLeyLineOutcrop/utils/findLeyLineOutcrop.js index 8d26d72cb..29259f059 100644 --- a/repo/js/AutoLeyLineOutcrop/utils/findLeyLineOutcrop.js +++ b/repo/js/AutoLeyLineOutcrop/utils/findLeyLineOutcrop.js @@ -30,4 +30,38 @@ async function (country, type) { // 如果到这里还没找到 throw new Error("寻找地脉花失败,已达最大重试次数"); +} + +/** + * 在地图上定位地脉花 + * @param {string} type - 地脉花类型 + * @returns {Promise} 是否找到地脉花 + */ +this.locateLeyLineOutcrop = +async function (type) { + await sleep(500); // 确保画面稳定 + await genshin.setBigMapZoomLevel(3.0); + + const iconPath = type === "蓝花(经验书)" + ? "assets/icon/Blossom_of_Revelation.png" + : "assets/icon/Blossom_of_Wealth.png"; + + const flowerList = captureGameRegion().findMulti(RecognitionObject.TemplateMatch(file.ReadImageMatSync(iconPath))); + + if (flowerList && flowerList.count > 0) { + currentFlower = flowerList[0]; + + const center = genshin.getPositionFromBigMap(); + const mapZoomLevel = genshin.getBigMapZoomLevel(); + const mapScaleFactor = 2.361; + + leyLineX = (960 - currentFlower.x - 25) * mapZoomLevel / mapScaleFactor + center.x; + leyLineY = (540 - currentFlower.y - 25) * mapZoomLevel / mapScaleFactor + center.y; + + log.info(`找到地脉花的坐标:(${leyLineX}, ${leyLineY})`); + return true; + } else { + log.warn("未找到地脉花"); + return false; + } } \ No newline at end of file diff --git a/repo/js/AutoLeyLineOutcrop/utils/locateLeyLineOutcrop.js b/repo/js/AutoLeyLineOutcrop/utils/locateLeyLineOutcrop.js deleted file mode 100644 index 5d9d63058..000000000 --- a/repo/js/AutoLeyLineOutcrop/utils/locateLeyLineOutcrop.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 在地图上定位地脉花 - * @param {string} type - 地脉花类型 - * @returns {Promise} 是否找到地脉花 - */ -this.locateLeyLineOutcrop = -async function (type) { - await sleep(500); // 确保画面稳定 - await genshin.setBigMapZoomLevel(3.0); - - const iconPath = type === "蓝花(经验书)" - ? "assets/icon/Blossom_of_Revelation.png" - : "assets/icon/Blossom_of_Wealth.png"; - - const flowerList = captureGameRegion().findMulti(RecognitionObject.TemplateMatch(file.ReadImageMatSync(iconPath))); - - if (flowerList && flowerList.count > 0) { - currentFlower = flowerList[0]; - const flowerType = type === "蓝花(经验书)" ? "经验" : "摩拉"; - - const center = genshin.getPositionFromBigMap(); - const mapZoomLevel = genshin.getBigMapZoomLevel(); - const mapScaleFactor = 2.361; - - leyLineX = (960 - currentFlower.x - 25) * mapZoomLevel / mapScaleFactor + center.x; - leyLineY = (540 - currentFlower.y - 25) * mapZoomLevel / mapScaleFactor + center.y; - - log.info(`找到地脉花的坐标:(${leyLineX}, ${leyLineY})`); - return true; - } else { - log.warn("未找到地脉花"); - return false; - } -} \ No newline at end of file diff --git a/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js b/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js index 8bee96f9a..af1b6fcad 100644 --- a/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js +++ b/repo/js/AutoLeyLineOutcrop/utils/processLeyLineOutcrop.js @@ -7,45 +7,68 @@ */ this.processLeyLineOutcrop = async function (timeout, targetPath, retries = 0) { - // 设置最大重试次数,防止死循环 const MAX_RETRIES = 3; + let captureRegion = null; + + try { + // 检查重试次数,避免死循环 + if (retries >= MAX_RETRIES) { + const errorMsg = `开启地脉花失败,已重试${MAX_RETRIES}次,终止处理`; + log.error("我辣么大一个地脉花哪去了?"); + throw new Error(errorMsg); + } - // 如果超过最大重试次数,记录错误并返回,避免死循环 - if (retries >= MAX_RETRIES) { - log.error(`开启地脉花失败,已重试${MAX_RETRIES}次,终止处理`); - log.error("我辣么大一个地脉花哪去了?"); - throw new Error("开启地脉花失败"); - } - - let captureRegion = captureGameRegion(); - let result = captureRegion.find(ocrRo2); - let result2 = captureRegion.find(ocrRo3); - if (result2.text.includes("地脉之花")) { - log.info("识别到地脉之花"); - await switchToFriendshipTeamIfNeeded(); - return; - } - if (result2.text.includes("地脉溢口")) { - log.info("识别到地脉溢口"); - keyPress("F"); - await sleep(300); - keyPress("F"); // 两次重试避免开花失败 - await sleep(500); - } else if (result.text.includes("打倒所有敌人")) { - log.info("地脉花已经打开,直接战斗"); - } else { - log.warn(`未识别到地脉花文本,当前重试次数: ${retries + 1}/${MAX_RETRIES}`); - try { - await pathingScript.runFile(targetPath); - await processLeyLineOutcrop(timeout, targetPath, retries + 1); + // 截图并识别 + captureRegion = captureGameRegion(); + const result = captureRegion.find(ocrRo2); + const result2 = captureRegion.find(ocrRo3); + + // 检查地脉之花状态 - 已完成状态,准备领取奖励 + if (result2.text.includes("地脉之花")) { + log.info("识别到地脉之花,准备领取奖励"); + await switchToFriendshipTeamIfNeeded(); return; - } catch (error) { - throw new Error(`未识别到地脉花: ${error.message}`); + } + + // 处理地脉溢口 + if (result2.text.includes("地脉溢口")) { + log.info("识别到地脉溢口"); + keyPress("F"); + await sleep(300); + keyPress("F"); + await sleep(500); + } else if (result.text.includes("打倒所有敌人")) { + log.info("地脉花已经打开,直接战斗"); + } else { + // 未识别到目标,需要重新导航 + log.warn("未识别到地脉花文本,尝试重新导航"); + await pathingScript.runFile(targetPath); + return await this.processLeyLineOutcrop(timeout, targetPath, retries + 1); + } + + // 执行战斗 + const fightResult = await autoFight(timeout); + if (!fightResult) { + throw new Error("战斗失败"); + } + + // 完成后续操作 + await switchToFriendshipTeamIfNeeded(); + await autoNavigateToReward(); + + } catch (error) { + // 保留原始错误信息 + const errorMsg = `地脉花处理失败 (重试${retries}/${MAX_RETRIES}): ${error.message}`; + log.error(errorMsg); + throw error; + } finally { + // 确保资源释放 + if (captureRegion) { + try { + captureRegion.dispose(); + } catch (disposeError) { + log.warn(`截图资源释放失败: ${disposeError.message}`); + } } } - if(!await autoFight(timeout)){ - throw new Error("战斗失败"); - } - await switchToFriendshipTeamIfNeeded(); - await autoNavigateToReward(); -} \ No newline at end of file +}