diff --git a/repo/js/AutoRefinedCondensationResin/README.md b/repo/js/AutoRefinedCondensationResin/README.md new file mode 100644 index 00000000..ecbd21dd --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/README.md @@ -0,0 +1,20 @@ +# 自动合成浓缩树脂脚本 + +## 功能特点 +1. **多国合成台支持**:可前往蒙德/璃月/稻妻/枫丹合成台 +2. **智能时间判定**: + - 00:00~04:00 视为前一天 + - 自动适应游戏内时间机制 +3. **灵活执行设置**: + - 支持每日自动执行 + - 可指定每周特定日期执行 +4. **精准识别技术**: + - 使用OCR确保操作准确性 + - 仅支持中文游戏界面 + +## 参数说明 +| 参数名 | 类型 | 说明 | +|------------|------------|----------------------------------------------------------------------| +| location | 下拉选择 | **合成台位置**
可选:蒙德/璃月/稻妻/枫丹
默认:璃月合成台 | +| everyDay | 复选框 | **每日执行开关**
开启后无视星期设置,每日自动执行 | +| week | 文本输入 | **指定执行星期**
格式:逗号分隔数字(1=周一,7=周日)
例:`2,3,4,5,6,7` | \ No newline at end of file diff --git a/repo/js/AutoRefinedCondensationResin/assets/Pathing/枫丹合成台.json b/repo/js/AutoRefinedCondensationResin/assets/Pathing/枫丹合成台.json new file mode 100644 index 00000000..87df6a46 --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/assets/Pathing/枫丹合成台.json @@ -0,0 +1,30 @@ +{ + "info": { + "name": "枫丹合成台", + "type": "collect", + "author": "naralan", + "version": "1.0", + "description": "", + "bgi_version": "0.42.3" + }, + "positions": [ + { + "id": 1, + "action": "", + "move_mode": "walk", + "type": "teleport", + "x": 4509.25, + "y": 3624.5, + "action_params": "" + }, + { + "id": 2, + "action": "", + "move_mode": "walk", + "type": "path", + "x": 4479.5, + "y": 3627.8, + "action_params": "" + } + ] +} \ No newline at end of file diff --git a/repo/js/AutoRefinedCondensationResin/assets/Pathing/璃月合成台.json b/repo/js/AutoRefinedCondensationResin/assets/Pathing/璃月合成台.json new file mode 100644 index 00000000..d5804a7b --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/assets/Pathing/璃月合成台.json @@ -0,0 +1,39 @@ +{ + "info": { + "name": "璃月合成台", + "type": "collect", + "author": "naralan", + "version": "1.0", + "description": "", + "bgi_version": "0.42.3" + }, + "positions": [ + { + "id": 1, + "x": 281.5, + "y": -674, + "action": "", + "move_mode": "walk", + "action_params": "", + "type": "teleport" + }, + { + "id": 2, + "x": 264, + "y": -660, + "action": "", + "move_mode": "walk", + "action_params": "", + "type": "path" + }, + { + "id": 3, + "x": 267.8, + "y": -652.5, + "action": "", + "move_mode": "walk", + "action_params": "", + "type": "path" + } + ] +} \ No newline at end of file diff --git a/repo/js/AutoRefinedCondensationResin/assets/Pathing/稻妻合成台.json b/repo/js/AutoRefinedCondensationResin/assets/Pathing/稻妻合成台.json new file mode 100644 index 00000000..0197c53e --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/assets/Pathing/稻妻合成台.json @@ -0,0 +1,39 @@ +{ + "info": { + "name": "稻妻合成台", + "type": "collect", + "author": "naralan", + "version": "1.0", + "description": "", + "bgi_version": "0.42.3" + }, + "positions": [ + { + "id": 1, + "action": "", + "move_mode": "walk", + "type": "teleport", + "x": -4399.5, + "y": -3053, + "action_params": "" + }, + { + "id": 3, + "action": "", + "move_mode": "walk", + "type": "path", + "x": -4416.5, + "y": -3076.7, + "action_params": "" + }, + { + "id": 4, + "action": "", + "move_mode": "walk", + "type": "path", + "x": -4434, + "y": -3093.2, + "action_params": "" + } + ] +} \ No newline at end of file diff --git a/repo/js/AutoRefinedCondensationResin/assets/Pathing/蒙德合成台.json b/repo/js/AutoRefinedCondensationResin/assets/Pathing/蒙德合成台.json new file mode 100644 index 00000000..286ea79b --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/assets/Pathing/蒙德合成台.json @@ -0,0 +1,39 @@ +{ + "info": { + "name": "蒙德合成台", + "type": "collect", + "author": "naralan", + "version": "1.0", + "description": "", + "bgi_version": "0.42.3" + }, + "positions": [ + { + "id": 1, + "action": "", + "move_mode": "walk", + "type": "teleport", + "x": -872.75, + "y": 2275.5, + "action_params": "" + }, + { + "id": 2, + "action": "", + "move_mode": "walk", + "type": "path", + "x": -886, + "y": 2267, + "action_params": "" + }, + { + "id": 2, + "action": "", + "move_mode": "walk", + "type": "path", + "x": -889.8, + "y": 2267.5, + "action_params": "" + } + ] +} \ No newline at end of file diff --git a/repo/js/AutoRefinedCondensationResin/assets/RecognitionObject/Condensed_Resin.png b/repo/js/AutoRefinedCondensationResin/assets/RecognitionObject/Condensed_Resin.png new file mode 100644 index 00000000..ea7ef5a0 Binary files /dev/null and b/repo/js/AutoRefinedCondensationResin/assets/RecognitionObject/Condensed_Resin.png differ diff --git a/repo/js/AutoRefinedCondensationResin/assets/RecognitionObject/confirm.png b/repo/js/AutoRefinedCondensationResin/assets/RecognitionObject/confirm.png new file mode 100644 index 00000000..7b88427c Binary files /dev/null and b/repo/js/AutoRefinedCondensationResin/assets/RecognitionObject/confirm.png differ diff --git a/repo/js/AutoRefinedCondensationResin/main.js b/repo/js/AutoRefinedCondensationResin/main.js new file mode 100644 index 00000000..562c7f65 --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/main.js @@ -0,0 +1,208 @@ +// 识图资料 +const confirmRo = RecognitionObject.TemplateMatch(file.ReadImageMatSync("assets/RecognitionObject/confirm.png")); +const CondensedResin = RecognitionObject.TemplateMatch(file.ReadImageMatSync("assets/RecognitionObject/Condensed_Resin.png")); +// 读取配置文件 +const location = settings.location; +const settingsWeek = settings.week; +const everyDay = settings.everyDay; + +// 执行路径 +async function AutoPath(locationName) { + try { + let filePath = `assets/Pathing/${locationName}.json`; + await pathingScript.runFile(filePath); + return true; + } catch (error) { + log.error(`执行 ${locationName} 路径时发生错误`); + log.error(error.message); + } + + return false; +} + +// 合成浓缩树脂 +async function condensedResin() { + let captureRegion = captureGameRegion(); + // 记录是否找到合成台 + let Alchemy = false; + let retryCount = 0; + const maxRetries = 2; // 最大重试次数 + + while (!Alchemy && retryCount <= maxRetries) { + // 对整个区域进行 OCR + let resList = captureRegion.findMulti(RecognitionObject.ocrThis); + for (let i = 0; i < resList.count; i++) { + if (resList[i].text.includes("合成")) { + // 找到合成台,点击合成台 + log.info("寻找合成台成功,开始与合成台交互"); + keyDown("VK_MENU");// Alt + await sleep(1000); + click(resList[i].x + 30, resList[i].y + 30); // 点击合成台选项 + await sleep(1000); + click(resList[i].x + 30, resList[i].y + 30); // 跳过合成台对话 + await sleep(1500); + keyUp("VK_MENU");// Alt + await sleep(1000); + + // 图像识别浓缩树脂 + let Resin = captureGameRegion().find(CondensedResin); + if (Resin.isExist()) { + Resin.click(); + log.info("找到浓缩树脂,开始合成体力"); + await sleep(750); + let confirm = captureGameRegion().find(confirmRo); + if (confirm.isExist()) { + confirm.click(); // 点击合成 + await sleep(5000); + click(975, 900); // 点击确认,关闭合成成功资料 + log.info("已完成合成浓缩树脂"); + } + } else { + log.warn("未能识别到浓缩树脂,不合成"); + } + await sleep(1000); + click(1845, 50); // 关闭页面 + await sleep(2000); + Alchemy = true; + break; // 找到合成台后跳出循环 + } + } + + if (!Alchemy) { + retryCount++; + if (retryCount <= maxRetries) { + log.warn(`未找到合成台,进行第 (${retryCount}/${maxRetries}) 次重试`); + await sleep(1500); + + // 重新尝试路径执行 + try { + await AutoPath(location); + await sleep(1000); + captureRegion = captureGameRegion(); // 刷新捕获区域 + } catch (error) { + log.error(`路径重试失败: ${error.message}`); + } + } + } + } + + if (!Alchemy) { + log.error(`连续${maxRetries}次未能找到合成台,中止任务`); + } + return Alchemy; +} + +(async function () { + function validateAndStoreNumbers(input) { + // 定义存储结果的数组 + let storedNumbers = []; + + // 使用正则表达式检测是否符合期望格式 + const regex = /^(\b([1-9]|1[0-5])\b)(,(\b([1-9]|1[0-5])\b))*$/; + + // 检测输入字符串是否符合正则表达式 + if (regex.test(input)) { + // 将输入字符串按逗号分割成数组 + const numbers = input.split(','); + + // 将分割后的数字字符串转换为整数并存储到数组中 + storedNumbers = numbers.map(Number); + + return storedNumbers; + } else { + return false + } + } + + // 获取调整后的星期几(考虑00:00~04:00视为前一天) + function getAdjustedDayOfWeek() { + const now = new Date(); + let dayOfWeek = now.getDay(); // 0-6 (0是周日) + const hours = now.getHours(); + + // 如果时间在00:00~04:00之间,视为前一天 + if (hours < 4) { + dayOfWeek = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 前一天 + log.info(`当前时间 ${now.getHours()}:${now.getMinutes()},视为前一天(星期 ${dayOfWeek === 0 ? 7 : dayOfWeek})`); + } else { + log.info(`当前时间 ${now.getHours()}:${now.getMinutes()},使用当天(星期 ${dayOfWeek === 0 ? 7 : dayOfWeek})`); + } + + // 转换为1-7格式(7代表周日) + return dayOfWeek === 0 ? 7 : dayOfWeek; + } + + + + + //main/====================================================================================== + setGameMetrics(1920, 1080, 1) + await genshin.returnMainUi(); + + // 判断设置合法性 + var items = []; + + // 每天都合成体力,开启后无视星期设定,运行完直接return跳出 + if (everyDay) { + log.info("已开启每天都合成体力,无视星期设置"); + try { + if (!location) { + location = "璃月合成台"; + log.info(`未设置传送位置,默认前往 ${location}...`); + } + log.info(`正在前往 ${location} 合成浓缩树脂`); + await AutoPath(location); + await sleep(1000); + log.info("寻找合成台"); + await condensedResin(); + await sleep(1000); + await genshin.returnMainUi(); + return; + } catch (e) { + log.error("传送失败,请检查设置"); + return; + } + } + + if (settingsWeek && !everyDay) { + items = validateAndStoreNumbers(settingsWeek); + if (!items) { + log.error("星期设置格式错误,请使用类似'1,3,5,7'的格式"); + return; + } + + // 获取调整后的星期几(考虑00:00~04:00视为前一天) + const dayOfWeek = getAdjustedDayOfWeek(); + + // 检查当前星期是否在用户设置的范围内 + if (items.includes(dayOfWeek)) { + try { + // 读取配置文件 + if (!location) { + location = "璃月合成台"; + log.info(`未设置传送位置,默认前往 ${location}...`); + } + log.info(`今天是星期 ${dayOfWeek},正在前往 ${location} 合成浓缩树脂`); + await AutoPath(location); + await sleep(1000); + log.info("寻找合成台"); + await condensedResin(); + await sleep(1000); + await genshin.returnMainUi(); + } catch (e) { + log.error("传送失败,请检查设置"); + return; + } + } else { + log.info(`今天是星期 ${dayOfWeek},不需要合成体力`); + return; + } + } else if (!everyDay) { + log.error("还没有设置需要在星期几合成体力呢"); + log.error("请在调试器里添加本脚本->右键JS脚本->修改JS脚本自定义配置."); + return; + } + + //main/**====================================================================================== + +})(); \ No newline at end of file diff --git a/repo/js/AutoRefinedCondensationResin/manifest.json b/repo/js/AutoRefinedCondensationResin/manifest.json new file mode 100644 index 00000000..66afa073 --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/manifest.json @@ -0,0 +1,15 @@ +{ + "manifest_version": 1, + "name": "自动合成浓缩树脂", + "version": "1.0", + "bgi_version": "0.47.0", + "description": "\n可前往多国合成台自动合成浓缩树脂(仅支持中文语言)。\n通过OCR技术确保准确进入合成台并完成合成操作。\n可设置特定星期执行任务(例:输入\"1,3,5,7\"在周一/三/五/日执行)。\n特殊时间处理:00:00~04:00视为前一天。", + "tags": [], + "authors": [ + { + "name": "蜜柑魚" + } + ], + "settings_ui": "settings.json", + "main": "main.js" +} \ No newline at end of file diff --git a/repo/js/AutoRefinedCondensationResin/settings.json b/repo/js/AutoRefinedCondensationResin/settings.json new file mode 100644 index 00000000..d4af67c4 --- /dev/null +++ b/repo/js/AutoRefinedCondensationResin/settings.json @@ -0,0 +1,28 @@ +[ + { + "name": "location", + "type": "select", + "label": "合成台位置(默认:璃月合成台)", + "options": [ + "蒙德合成台", + "璃月合成台", + "稻妻合成台", + //"须弥合成台", + //"纳塔合成台", + "枫丹合成台" + ], + "default": "璃月合成台" + }, + { + "name": "everyDay", + "type": "checkbox", + "label": "每日合成开关(开启后无视下方设定)", + "default": true + }, + { + "name": "week", + "type": "input-text", + "label": "指定执行星期\n(使用\",\"分割多个星期几)\n例:输入\"2,3,4,5,6,7\",会在星期2,3,4,5,6,日才合成体力", + "default": "2,3,4,5,6,7" + } +] \ No newline at end of file