From 5512d49a583e9dff681ac84c99a316838164c59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E7=B4=AB=E7=83=9Fowo?= <232029620+jiangziyanowo@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:12:24 +0800 Subject: [PATCH] =?UTF-8?q?AutoMonday-V1.3.3=E7=89=88=E6=9C=AC=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20(#2260)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 修复了部分设备在某些任务运行结束后未能及时回到主页面导致后续任务无法正常执行的bug 2. 修复了偶尔会被电气水晶摸到的bug 3. 修改了多不合理、不安全的地方 4. 按照宝贝兔兔和氨气老师的修改意见进行了补充修改 5. Ciallo~(∠・ω< )⌒☆ --- repo/js/AutoMonday/README.md | 4 + repo/js/AutoMonday/main.js | 189 +++++++++++++++++-------------- repo/js/AutoMonday/manifest.json | 2 +- 3 files changed, 107 insertions(+), 88 deletions(-) diff --git a/repo/js/AutoMonday/README.md b/repo/js/AutoMonday/README.md index d56cd91c0..5d253d38b 100644 --- a/repo/js/AutoMonday/README.md +++ b/repo/js/AutoMonday/README.md @@ -41,6 +41,10 @@ --------------------------------------------------------------------------------------------------------------------------------- ## 更新日志 +### 1.3.3(2025.10.27) +1. 修复了部分设备在某些任务运行结束后未能及时回到主页面导致后续任务无法正常执行的bug +2. 修复了偶尔会被电气水晶摸到的bug +3. 修改了多不合理、不安全的地方 ### 1.3.2(2025.10.24) 1. 修改了账户名的获取逻辑:删除了原有的ocr获取uid,改为手动输入的方式(历史记录会受到影响,但避免了后续出现bug的可能性) ### 1.3.1(2025.10.09) diff --git a/repo/js/AutoMonday/main.js b/repo/js/AutoMonday/main.js index 89579be1e..14c8fa8a9 100644 --- a/repo/js/AutoMonday/main.js +++ b/repo/js/AutoMonday/main.js @@ -1,4 +1,68 @@ (async function () { + // ===== 1. 预处理部分 ===== + + // 人机验证 + if (!settings.ifCheck) { log.error("请阅读readme文件并做好相关设置后再运行此脚本!"); return; } + + //初始化配置 + var TEAM; + var Material = settings.Material; + const actiontime = 180;//最大等待时间,单位秒 + const BH = `assets/RecognitionObject/${Material}.png`; + const ZHIBIANYI = "assets/RecognitionObject/zhibian.png"; + const CHA = "assets/RecognitionObject/cha.png"; + const ifAkf = settings.ifAkf; + const chargingMethod = settings.chargingMethod; + const ifCooking = settings.ifCooking; + const ifduanZao = settings.ifduanZao; + const ifShouling = settings.ifShouling; + const ifMijing = settings.ifMijing; + const ifbuyNet = settings.ifbuyNet; + const ifbuyTzq = settings.ifbuyTzq; + const ifZBY = settings.ifZBY; + const ifYB = settings.ifYB; + const food = settings.food; // 要烹饪的食物 + const cookCount = settings.cookCount;//烹饪数量 + const mineral = settings.mineral;// 矿石种类 + const mineralFile = `assets/RecognitionObject/${mineral}.png`;// 矿石模板路径 + const BossPartyName = settings.BossPartyName;// 战斗队伍 + let mijingCount = 1;// 自动秘境计数 + // OCR对象用于检测战斗文本 + const ocrRo2 = RecognitionObject.Ocr(0, 0, genshin.width, genshin.height); + + // 创建材质到ITEM的映射表 + // 养成道具=1,食物=2,材料=3 + const materialToItemMap = { + "牛角": 1, + "苹果": 2, "日落果": 2, "泡泡桔": 2, + "白铁块": 3, "水晶块": 3, "薄荷": 3, "菜": 3, + "鸡腿": 3, "蘑菇": 3, "鸟蛋": 3, "兽肉": 3, "甜甜花": 3 + }; + + // 直接通过映射获取ITEM值(未匹配时默认0) + const ITEM = materialToItemMap[Material] || 0; + + if (chargingMethod == "法器角色充能" && settings.TEAMname === undefined) { + log.error("您选择了法器角色充能,请在配置页面填写包含法器角色的队伍名称!!!"); + return;// 没选就报错后停止 + } + //检查用户是否配置队伍 + if (ifAkf && settings.TEAMname === undefined) { + log.error("您选择了拥有爱可菲,请在配置页面填写包含爱可菲的队伍名称!!!"); + return;// 没选就报错后停止 + } + + TEAM = settings.TEAMname; + + const username = settings.username || "默认账户"; + const cdRecordPath = `record/${username}_cd.txt`;// 修改CD记录文件路径,包含用户名 + + //设置分辨率和缩放 + setGameMetrics(1920, 1080, 1); + await genshin.returnMainUi(); + + // ===== 2. 子函数定义部分 ===== + /** * 封装函数,执行图片识别及点击操作(测试中,未封装完成,后续会优化逻辑) * @param {string} imagefilePath - 模板图片路径 @@ -204,13 +268,19 @@ // 质变仪判断逻辑 if (deployed) { + await sleep(800); + + await keyDown("S"); + await sleep(500); + await keyUp("S"); + if (chargingMethod == "法器角色充能") { const ifbblIn = await includes("芭芭拉"); if (!ifbblIn) { throw new Error("队伍中未包含角色:芭芭拉"); } } while ((NowTime - startTime) < actiontime * 1000) { - await textOCR("质变产生了以下物质", 0.7, 1, 0, 539, 251, 800, 425); - if (result.found) { + const ocrRes = await textOCR("质变产生了以下物质", 0.7, 1, 0, 539, 251, 800, 425); + if (ocrRes.found) { click(970, 760); if (!ifAkf) { return true; } await sleep(150); @@ -279,7 +349,7 @@ await sleep(1000); await click(1067, 57);//点开背包,可做图像识别优化 - await textOCR("小道具", 3, 0, 0, 126, 17, 99, 53); if (!result.found) { throw new Error("未打开'小道具'页面,请确保背包已正确打开并切换到小道具标签页"); }//确认在小道具界面 + const bagOk = await textOCR("小道具", 3, 0, 0, 126, 17, 99, 53); if (!bagOk.found) { throw new Error("未打开'小道具'页面,请确保背包已正确打开并切换到小道具标签页"); }//确认在小道具界面 await sleep(500); await imageRecognitionEnhanced(ZHIBIANYI, 1, 1, 0);//识别质变仪图片 if (!result.found) { @@ -347,7 +417,7 @@ await click(440, 1008); //选择最大数量 await sleep(1000); await click(1792, 1019); //质变按钮 - await textOCR("参量质变仪", 3, 0, 0, 828, 253, 265, 73); if (!result.found) { log.error("单种材料不足,退出!"); } + const zbPanel = await textOCR("参量质变仪", 3, 0, 0, 828, 253, 265, 73); if (!zbPanel.found) { log.error("单种材料不足,退出!"); } await sleep(1000); await click(1183, 764); //确认 ; await sleep(1000); @@ -525,9 +595,19 @@ let fightResult = false; while (Date.now() - startTime < timeout) { - if (recognizeFightText(captureGameRegion())) { - fightResult = true; - break; + let captureRegion = null; + try { + captureRegion = captureGameRegion(); + if (recognizeFightText(captureRegion)) { + fightResult = true; + break; + } + } finally { + // 确保捕获的区域被正确释放 + if (captureRegion) { + captureRegion.dispose(); + captureRegion = null; + } } await sleep(1000); } @@ -570,9 +650,10 @@ await sleep(1000); + let success; for (let attempt = 0; attempt < 10; attempt++) { success = await textOCR("启动", 0.5, 0, 3, 1210, 500, 85, 85); - if (success.found) { + if (!success || !success.found) { keyPress("F"); break; } else { @@ -851,7 +932,7 @@ await imageRecognitionEnhanced(mineralFile, 10, 1, 0, 40, 210, 720, 770) await sleep(1500); - for (i = 0; i < 4; i++) { + for (let i = 0; i < 4; i++) { click(1760, 1015);// 开始锻造 await sleep(300); } @@ -884,7 +965,7 @@ await switchPartyIfNeeded(BossPartyName); await sleep(5000); - for (i = 1; i <= 10; i++) { + for (let i = 1; i <= 10; i++) { if (i % 2 == 0) { await AutoPath("爆炎树"); } else if (i % 2 != 0) { await AutoPath("急冻树"); } await sleep(10); @@ -977,7 +1058,7 @@ click(1670, 1015); await sleep(800); - for (i = 0; i < 7; i++) {// 拉满拉满,TMD全部拉满 + for (let i = 0; i < 7; i++) {// 拉满拉满,TMD全部拉满 click(1290, 600); await sleep(150); } @@ -1014,16 +1095,17 @@ await AutoPath("投资券"); - await sleep(800); + await sleep(1000); keyPress("F"); - await sleep(800); + await sleep(1000); click(960, 540); await sleep(2000); - await textOCR("我要结算投资回报", 3, 1, 0, 1325, 550, 250, 55); + await textOCR("我要结算", 3, 1, 0, 1325, 550, 250, 55); - await sleep(800); + await sleep(1000); click(960, 540); + await sleep(1000); const notHave = await textOCR("没有投资券", 3, 0, 0, 830, 925, 160, 50); if (notHave.found) { @@ -1033,15 +1115,10 @@ click(960, 540); await sleep(1500); - click(960, 540); - await sleep(1500); - - await sleep(2000); - click(1700, 1000); await sleep(1000); - for (i = 0; i < 8; i++) { + for (let i = 0; i < 8; i++) { click(1295, 600); await sleep(100); } @@ -1058,8 +1135,9 @@ await textOCR("我要结算", 3, 1, 0, 1325, 500, 250, 80); - await sleep(800); + await sleep(1000); click(960, 540); + await sleep(1000); } keyPress("F"); await sleep(1000); @@ -1069,7 +1147,7 @@ click(1235, 815); await sleep(1000); click(1620, 1020); - await sleep(1000); + await sleep(2500); click(1620, 1020); @@ -1080,69 +1158,7 @@ await writeCDRecords(updatedRecords); } - - //main/====================================================================================== - - // 人机验证 - if (!settings.ifCheck) { log.error("请阅读readme文件并做好相关设置后再运行此脚本!"); return; } - - //初始化配置 - var TEAM; - var Material = settings.Material; - const actiontime = 180;//最大等待时间,单位秒 - const BH = `assets/RecognitionObject/${Material}.png`; - const ZHIBIANYI = typeof settings.ZHIBIANY === 'string' && settings.ZHIBIANYI.trim() !== '' ? settings.ZHIBIANYI : "assets/RecognitionObject/zhibian.png"; - const CHA = "assets/RecognitionObject/cha.png" - const ifAkf = settings.ifAkf; - const chargingMethod = settings.chargingMethod; - const ifCooking = settings.ifCooking; - const ifduanZao = settings.ifduanZao; - const ifShouling = settings.ifShouling; - const ifMijing = settings.ifMijing; - const ifbuyNet = settings.ifbuyNet; - const ifbuyTzq = settings.ifbuyTzq; - const ifZBY = settings.ifZBY; - const ifYB = settings.ifYB; - const food = settings.food; // 要烹饪的食物 - const cookCount = settings.cookCount;//烹饪数量 - const mineral = settings.mineral;// 矿石种类 - const mineralFile = `assets/RecognitionObject/${mineral}.png`// 矿石模板路径 - const BossPartyName = settings.BossPartyName;// 战斗队伍 - let mijingCount = 1;// 自动秘境计数 - // OCR对象用于检测战斗文本 - const ocrRo2 = RecognitionObject.Ocr(0, 0, genshin.width, genshin.height); - - // 创建材质到ITEM的映射表 - // 养成道具=1,食物=2,材料=3 - const materialToItemMap = { - "牛角": 1, - "苹果": 2, "日落果": 2, "泡泡桔": 2, - "白铁块": 3, "水晶块": 3, "薄荷": 3, "菜": 3, - "鸡腿": 3, "蘑菇": 3, "鸟蛋": 3, "兽肉": 3, "甜甜花": 3 - }; - - // 直接通过映射获取ITEM值(未匹配时默认0) - ITEM = materialToItemMap[Material] || 0; - - if (chargingMethod == "法器角色充能" && settings.TEAMname === undefined) { - log.error("您选择了法器角色充能,请在配置页面填写包含法器角色的队伍名称!!!"); - return;// 没选就报错后停止 - } - //检查用户是否配置队伍 - if (ifAkf && settings.TEAMname === undefined) { - log.error("您选择了拥有爱可菲,请在配置页面填写包含爱可菲的队伍名称!!!"); - return;// 没选就报错后停止 - } - - TEAM = settings.TEAMname; - - const username = settings.username || "默认账户"; - const cdRecordPath = `record/${username}_cd.txt`;// 修改CD记录文件路径,包含用户名 - - //设置分辨率和缩放 - setGameMetrics(1920, 1080, 1); - await genshin.returnMainUi(); - + // ===== 3. 主函数执行部分 ===== try { if (ifZBY) { await autoZhibian(); }// 质变仪 @@ -1174,5 +1190,4 @@ await genshin.returnMainUi(); } - //main/====================================================================================== })(); diff --git a/repo/js/AutoMonday/manifest.json b/repo/js/AutoMonday/manifest.json index 5e93bf38c..aff0c98ee 100644 --- a/repo/js/AutoMonday/manifest.json +++ b/repo/js/AutoMonday/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "全自动周一", - "version": "1.3.2", + "version": "1.3.3", "tags": [ "周常", "纪行",