diff --git a/repo/js/七圣召唤七日历练全自动/assets/dragToVerify.png b/repo/js/七圣召唤七日历练全自动/assets/dragToVerify.png new file mode 100644 index 000000000..25774253a Binary files /dev/null and b/repo/js/七圣召唤七日历练全自动/assets/dragToVerify.png differ diff --git a/repo/js/七圣召唤七日历练全自动/main.js b/repo/js/七圣召唤七日历练全自动/main.js index 561ea61b3..56e1d764b 100644 --- a/repo/js/七圣召唤七日历练全自动/main.js +++ b/repo/js/七圣召唤七日历练全自动/main.js @@ -7,6 +7,68 @@ const strategyRunRecordFile = "牌组策略/各策略胜败记录.json"; let strategyRunRecord = {}; let minFallbackStrategyScore = 0.25; +/** + * 查找模板图片并拖动到指定位置 + * @param {string} templatePath - 模板图片路径 + * @param {number} targetX - 拖动目标位置X坐标 + * @param {number} targetY - 拖动目标位置Y坐标 + * @param {number} [maxAttempts=3] - 最大尝试次数 + * @returns {Promise} 是否成功完成拖动 + */ +async function dragTemplateToPosition(templatePath, targetX, targetY, maxAttempts = 3) { + // 创建模板识别对象 + const templateRo = RecognitionObject.TemplateMatch(file.ReadImageMatSync(templatePath)); + await sleep(200); + moveMouseTo(100, 50);//避免鼠标遮挡 + await sleep(200); + for (let attempt = 0; attempt < maxAttempts; attempt++) { + try { + // 捕获游戏区域并查找模板 + const captureRegion = captureGameRegion(); + let foundRegion = captureRegion.find(templateRo); + + if (foundRegion.isEmpty()) { + log.warn(`第 ${attempt + 1} 次尝试: 未找到模板图片 ${templatePath}`); + if (attempt < maxAttempts - 1) { + await sleep(1000); // 等待1秒后重试 + continue; + } else { + log.error(`所有尝试失败: 未找到模板图片 ${templatePath}`); + return false; + } + } + + log.info(`找到模板图片,位置: (${foundRegion.x}, ${foundRegion.y}),开始拖动到 (${targetX}, ${targetY})`); + await sleep(300); + moveMouseTo(200, 100);//重置鼠标位置 + leftButtonDown(); + await sleep(500); + moveMouseTo(foundRegion.x, foundRegion.y); + await sleep(500); + moveMouseTo(targetX, targetY); + await sleep(500); + leftButtonUp(); + await sleep(500); + moveMouseTo(50, 50);//移动鼠标位置,避免检测失败 + await sleep(400); + foundRegion = captureGameRegion().Find(templateRo); + log.info(`模板图片拖动后位置: (${foundRegion.x}, ${foundRegion.y})`); + if(Math.abs(foundRegion.x - targetX) < 3 && Math.abs(foundRegion.y - targetY) < 3){ + log.info("拖动操作完成"); + return true; + } + + } catch (error) { + log.error(`第 ${attempt + 1} 次尝试时发生错误: ${error}`); + if (attempt < maxAttempts - 1) { + await sleep(1000); + } + } + } + + return false; +} + // 切换到指定的队伍 async function switchCardTeam(Name, shareCode) { let captureRegion = captureGameRegion(); @@ -331,16 +393,11 @@ const detectCardPlayer = async () => { await genshin.setBigMapZoomLevel(1.0); //放大地图 await sleep(300); - //地图拖动到指定位置 - moveMouseTo(200, 200); - leftButtonDown(); - await sleep(500); - moveMouseTo(170, 320); - await sleep(500); - moveMouseTo(970, 1000); - await sleep(500); - leftButtonUp(); - await sleep(500); + await dragTemplateToPosition("assets/dragToVerify.png", // 模板图片路径 + 1449, // 目标X坐标 + 988, // 目标Y坐标 + 3 // 最大尝试次数 + ); // 获取游戏区域截图 const captureRegion = captureGameRegion(); @@ -979,3 +1036,4 @@ async function main() { } })(); + diff --git a/repo/js/七圣召唤七日历练全自动/manifest.json b/repo/js/七圣召唤七日历练全自动/manifest.json index 7495b73d0..78dc1c274 100644 --- a/repo/js/七圣召唤七日历练全自动/manifest.json +++ b/repo/js/七圣召唤七日历练全自动/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "打牌一条龙", - "version": "2.8", + "version": "2.9", "description": "完成每周的七圣召唤七日历练(来客挑战)。详见README.md", "tags": [ "七圣召唤"