diff --git a/repo/js/AutoLeyLineOutcrop/assets/icon/map_setting_button.bmp b/repo/js/AutoLeyLineOutcrop/assets/icon/map_setting_button.bmp new file mode 100644 index 000000000..6460289af Binary files /dev/null and b/repo/js/AutoLeyLineOutcrop/assets/icon/map_setting_button.bmp differ diff --git a/repo/js/AutoLeyLineOutcrop/manifest.json b/repo/js/AutoLeyLineOutcrop/manifest.json index 6e9df593a..0ac894ec1 100644 --- a/repo/js/AutoLeyLineOutcrop/manifest.json +++ b/repo/js/AutoLeyLineOutcrop/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "全自动地脉花", - "version": "4.3.3", + "version": "4.3.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/findLeyLineOutcropByBook.js b/repo/js/AutoLeyLineOutcrop/utils/findLeyLineOutcropByBook.js index bff824ef6..f6e0e1cf3 100644 --- a/repo/js/AutoLeyLineOutcrop/utils/findLeyLineOutcropByBook.js +++ b/repo/js/AutoLeyLineOutcrop/utils/findLeyLineOutcropByBook.js @@ -1,5 +1,8 @@ +// 齿轮图标识别对象 +const mapSettingButtonRo = RecognitionObject.TemplateMatch(file.ReadImageMatSync("assets/icon/map_setting_button.bmp")); + /** - * 通过冒险之证查找地脉花位置 - 【测试中】 + * 通过冒险之证查找地脉花位置 * @param {string} country - 国家名称 * @param {string} type - 地脉花类型 * @returns {Promise} @@ -11,7 +14,8 @@ this.findLeyLineOutcropByBook = async function (country, type) { // 确保运行时位于主界面 keyPress("F1"); - await sleep(1000); + // 开书等待时间延长至2.5s + await sleep(2500); click(300, 550); // 点击讨伐 await sleep(1000); click(500, 200); // 点击筛选 @@ -35,10 +39,28 @@ this.findLeyLineOutcropByBook = async function (country, type) { // 查找并点击停止追踪按钮 await this.findAndCancelTrackingInBook(); - await sleep(1000); - click(1500, 850); - await sleep(1000); - + // 最多重试3次确保大地图正确打开 + for (let retry = 0; retry < 3; retry++) { + await sleep(1000); + click(1500, 850); + // 等待大地图打开延长至 2.5s + await sleep(2500); + + if (await this.checkBigMapOpened()) { + log.info("识别到大地图"); + break; // 成功打开大地图 + } + + if (retry < 2) { // 不是最后一次重试 + log.info(`大地图未正确打开,第${retry + 1}次重试...`); + await genshin.returnMainUi(); + await this.findAndClickCountry(country); + await this.findAndCancelTrackingInBook(); + } else { + throw new Error("大地图打开失败,已重试3次"); + } + } + // 获取地脉花位置 const center = genshin.getPositionFromBigMap(); leyLineX = center.x; @@ -49,6 +71,28 @@ this.findLeyLineOutcropByBook = async function (country, type) { await this.cancelTrackingInMap(); }; +/** + * 检测大地图是否正确打开(通过检测齿轮图标) + * @returns {Promise} 返回是否检测到齿轮图标 + * @private + */ +this.checkBigMapOpened = async function() { + let captureRegion = captureGameRegion(); + try { + // 只在左下角十六分之一区域查找齿轮图标(提高识别效率和准确性) + const searchWidth = genshin.width / 4; + const searchHeight = genshin.height / 4; + const searchX = 0; + const searchY = genshin.height - searchHeight; + + let croppedRegion = captureRegion.DeriveCrop(searchX, searchY, searchWidth, searchHeight); + let result = croppedRegion.Find(mapSettingButtonRo); + return !result.isEmpty(); + } finally { + captureRegion.dispose(); + } +}; + /** * 查找并点击指定国家 * @param {string} country - 国家名称