diff --git a/repo/js/AutoFontaineLeyLine/README.md b/repo/js/AutoFontaineLeyLine/README.md index fee7279e..b8875106 100644 --- a/repo/js/AutoFontaineLeyLine/README.md +++ b/repo/js/AutoFontaineLeyLine/README.md @@ -111,3 +111,16 @@ 1. 优化树脂识别OCR区域。 2. log显示优化。 3. 修复图像识别构造函数错误。 + +### v.3.2版本:20250705 + +- **新功能**: +1. 新增默认使用开冒险之证寻找地脉花,比之前更稳定。 +2. 新增识别同一线路上的两种地脉花,绕过执行非目标地脉花。 +3. 新增死亡检测,死亡后自动恢复后继续执行。 + +- **优化**: +4. 优化JS配置显示。 +5. 优化线路2第五朵花的特殊处理,解决开花和战斗区域太远的问题。 +6. 优化设定默认使用异步战斗。 +7. 优化领奖速度。 \ No newline at end of file diff --git a/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-da.bmp b/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-da.bmp new file mode 100644 index 00000000..fc9467fc Binary files /dev/null and b/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-da.bmp differ diff --git a/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-da2.bmp b/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-da2.bmp new file mode 100644 index 00000000..39c054b4 Binary files /dev/null and b/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-da2.bmp differ diff --git a/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-lank.bmp b/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-lank.bmp index 152c192a..3ba14ee7 100644 Binary files a/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-lank.bmp and b/repo/js/AutoFontaineLeyLine/assets/model/DIMAIHUA-lank.bmp differ diff --git a/repo/js/AutoFontaineLeyLine/assets/枫丹地脉花-路线2 秋分山西侧锚点左下/线路修复/枫丹地脉花-路线2 秋分山西侧锚点左下-5:秋分山左左下下_特殊处理.json b/repo/js/AutoFontaineLeyLine/assets/枫丹地脉花-路线2 秋分山西侧锚点左下/线路修复/枫丹地脉花-路线2 秋分山西侧锚点左下-5:秋分山左左下下_特殊处理.json new file mode 100644 index 00000000..b0a86cfb --- /dev/null +++ b/repo/js/AutoFontaineLeyLine/assets/枫丹地脉花-路线2 秋分山西侧锚点左下/线路修复/枫丹地脉花-路线2 秋分山西侧锚点左下-5:秋分山左左下下_特殊处理.json @@ -0,0 +1,19 @@ +{ + "info": { + "name": "枫丹地脉花-路线2 秋分山西侧锚点左下-5:秋分山左左下下_特殊处理", + "type": "collect", + "author": "平面镜&LCB茶包", + "version": "1.0", + "description": "", + "bgi_version": "0.44.3" + }, + "positions": [ + { + "id": 1, + "x": 4393.71826171875, + "y": 2265.736083984375, + "move_mode": "walk", + "type": "path" + } + ] +} \ No newline at end of file diff --git a/repo/js/AutoFontaineLeyLine/main.js b/repo/js/AutoFontaineLeyLine/main.js index 191f8e54..6f7a43bc 100644 --- a/repo/js/AutoFontaineLeyLine/main.js +++ b/repo/js/AutoFontaineLeyLine/main.js @@ -17,7 +17,7 @@ } else { if (afterBehavior===1){if (xa===0 & ya===0){log.info("点击模式:开");}await sleep(1000);click(res.x+xa, res.y+ya);}else{if (debugmodel===1 & xa===0 & ya===0){log.info("点击模式:关")}} if (afterBehavior===2){if (xa===0 & ya===0){log.info("F模式:开");}await sleep(1000);keyPress("F");}else{if (debugmodel===1 & xa===0 & ya===0){log.info("F模式:关")}} - if (debugmodel===1 & xa===0 & ya===0){log.info("全图代码位置:({x},{y},{h},{w})", res.x-10, res.y-10, res.width+10, res.Height+10);}else{ log.info("识别到图片");} + if (debugmodel===1 & xa===0 & ya===0){log.info("全图代码位置:({x},{y},{h},{w})", res.x-10, res.y-10, res.width+10, res.Height+10);}else{if(ii<=1) log.info("识别到元素");} return result = { x: res.x+xa, y: res.y+ya, w:res.width,h:res.Height,found: true } } const NowTime = new Date(); @@ -27,34 +27,55 @@ await sleep(1200); } + //ocr封装函数 async function Textocr(wenzi="空参数",chaotime=10,clickocr=0,debugcode=0,x=0,y=0,w=1920,h=1080) { const startTime = new Date(); for (let ii = 0; ii < 10; ii++) { - // 获取一张截图 let captureRegion = captureGameRegion(); let res1 - // 对整个区域进行 OCR let resList = captureRegion.findMulti(RecognitionObject.ocr(x,y,w,h)); - //log.info("OCR 全区域识别结果数量 {len}", resList.count); - for (let i = 0; i < resList.count; i++) - { // 遍历的是 C# 的 List 对象,所以要用 count,而不是 length - let res = resList[i]; - res1=res.text - if (res.text===wenzi) { - log.info(`·${res1}·识别到`); - if (debugcode===1){if (x===0 & y===0){log.info("全图代码位置:({x},{y},{h},{w})", res.x-10, res.y-10, res.width+10, res.Height+10);return result = { text: res.text, x: res.x, y: res.y, found: true }}}else{if (x===0 & y===0){log.info("文本OCR完成'{text}'", res.text);}} + for (let i = 0; i < resList.count; i++) { + let res = resList[i]; + res1=res.text + if (res.text === wenzi) { + if(ii<=1)log.info(`·${res1}·识别到`) + if (debugcode === 1){ + if (x === 0 & y === 0){ + log.info("全图代码位置:({x},{y},{h},{w})", res.x-10, res.y-10, res.width+10, res.Height+10); + return result = { text: res.text, x: res.x, y: res.y, found: true }} + } + else{if (x === 0 & y === 0){log.info("文本OCR完成'{text}'", res.text);} + } if (clickocr===1){await sleep(1000);click(res.x, res.y);} if (clickocr===2){await sleep(100);keyPress("F");} - return result = { text: res.text, x: res.x, y: res.y, found: true } - } - if (debugcode===2 && !res.isEmpty()){ - // log.info("({x},{y},{h},{w})", res.x-10, res.y-10, res.width+10, res.Height+10); + if (debugcode===3){ + break; + } + return result = { text: res.text, x: res.x, y: res.y, found: true } + } + if (debugcode===2 && !res.isEmpty()){ return result = { text: res.text, x: res.x, y: res.y, found: true } } } + + if (debugcode===3 && (resList.count <=0 || res1!=wenzi) ){ + return result = { found: true } + } + const NowTime = new Date(); - if (Math.abs(NowTime - startTime)>chaotime*1000){if (x===0 & y===0){log.info(`${chaotime}秒超时退出,·${wenzi}·未找到`);}return result = {found: false };}else{ii=8;log.info(`·${wenzi}·识别中……`); if(x !== 840 && x !== 1188){keyPress("w")}; } + if (Math.abs(NowTime - startTime)>chaotime*1000){ + if (x===0 & y===0){ + log.info(`${chaotime}秒超时退出,·${wenzi}·未找到`); + } + return result = {found: false}; + } + else{ + ii=8; + if(x !== 840 && x !== 1188){ + keyPress("w") + }; + } await sleep(100); } } @@ -63,18 +84,22 @@ var SMODEL = settings.SMODEL ? settings.SMODEL : false; // false 公版BETTERGI,true 自编译版本LCB var SHUOVER=0 //0初始状态,1队伍配置标志,2结束线路,3线路出错 var haoganq=0 //0初始状态,1好感队伍配置标志 - var SHUV = settings.shuv ? settings.shuv : 1; // 1 单线路,2 树脂耗尽 var Rewards = settings.Rewards ? settings.Rewards : false; // ture 领取冒险点奖励,false 不领取冒险点奖励 var Fligtin = false; //领取冒险点奖励标志。 var tolerance = 30; var position ={}; + var position_another ={}; + var repeatRoute = false;//线路重复标志 var Lastexecution = false;//线路执行标志,用于判断上一线路是否执行。 - var Fightquick = settings.Fightquick ? settings.Fightquick : false; - var Fighttimeout = settings.timeout * 1000 ? settings.timeout * 1000 : 240000;//战斗超时时间,默认为240秒 + var Fightquick = settings.Fightquick ? settings.Fightquick : true; + var Fighttimeout = settings.timeout * 1000 ? settings.timeout * 1000 : 180000;//战斗超时时间,默认为240秒 const ocrRegion2 = { x: 0, y: 200, width: 300, height: 300 }; // 追踪任务区域 const ocrRo2 = RecognitionObject.ocr(ocrRegion2.x, ocrRegion2.y, ocrRegion2.width, ocrRegion2.height); const ocrRegion1 = { x: 800, y: 200, width: 300, height: 100 }; // 中心区域 const ocrRo1 = RecognitionObject.ocr(ocrRegion1.x, ocrRegion1.y, ocrRegion1.width, ocrRegion1.height); + const ocrRegion3 = { x: 906, y: 928, width: 161, height: 100 }; // 下方区域 + const ocrRo3 = RecognitionObject.ocr(ocrRegion3.x, ocrRegion3.y, ocrRegion3.width, ocrRegion3.height); + var method= settings.method ? settings.method : "冒险之证"; var Rewardsuse = settings.Rewardsuse ? settings.Rewardsuse : "1/2"; var resinTypes = Rewardsuse.split("/"); var rewards = []; @@ -86,49 +111,61 @@ } rewards.push(resinType); } + const resinTypeMap = ["","使用1个浓缩树脂,获取2倍产出", "使用20个原粹树脂", "使用1个脆弱树脂,获取3倍产出", "使用1个须臾树脂,获取3倍产出"]; + const golbalRewards = ["","浓缩树脂","原粹树脂","脆弱树脂","须臾树脂"]; // 对应四种树脂 // 根据 rewards 数组长度,依次赋值给对应的变量 - if (rewards.length > 0) onerewards = resinTypeMap[rewards[0]]; - if (rewards.length > 1) secendrewards = resinTypeMap[rewards[1]]; - if (rewards.length > 2) threendrewards = resinTypeMap[rewards[2]]; - if (rewards.length > 3) fourdrewards = resinTypeMap[rewards[3]]; - - log.info(`使用树脂类型数量:${rewards.length}`); - log.info(`优先使用的树脂类型:${onerewards} --> ${secendrewards} --> ${threendrewards} --> ${fourdrewards}`); - - // return + if (rewards.length > 0) onerewards = golbalRewards[rewards[0]]; + if (rewards.length > 1) secendrewards = golbalRewards[rewards[1]]; + if (rewards.length > 2) threendrewards = golbalRewards[rewards[2]]; + if (rewards.length > 3) fourdrewards = golbalRewards[rewards[3]]; + const golbalRewardText = [onerewards, secendrewards, threendrewards, fourdrewards].filter(Boolean);//过滤树脂使用类型 + var doneCount = 0; filePath = "" // 读取原始次数配置 var rawTimes = settings.times*2 ? settings.times : "6"; - var color = settings.color ? settings.color : 1; - var BIAOZZ = "assets/model/BIAOZ.bmp" + const colorMap = { + "1-蓝花(经验花)": 1, + "2-黄花(摩拉花)": 2 + }; + var color = colorMap[settings.color] || 1; + const modelMap = { + "1-次数刷取": 1, + "2-树脂耗尽": 2 + }; + var SHUV = modelMap[settings.shuv] || 1; + var BIAOZZ = "assets/model/BIAOZ.bmp" var timesValue = 12; // 设置默认值 var num = parseFloat(rawTimes) * 2; // 直接计算乘以2后的值,并尝试转换为浮点数 - // 如果输入是有效的数字,并且在合理范围内,则更新timesValue if (/^-?\d+\.?\d*$/.test(rawTimes) && num >= 1 && num <= 198) { timesValue = Math.max(1, Math.min(198, Math.floor(num))); // 确保timesValue为整数,并且不超过上限 } var timesConfig = { value: timesValue }; - if (color == 2){ var DIMAIHUA = "assets/model/DIMAIHUA-huank.bmp";} - else if (color == 1){var DIMAIHUA = "assets/model/DIMAIHUA-lank.bmp";} - else{var DIMAIHUA = "assets/model/DIMAIHUA-lank.bmp";} + log.warn(`全自动枫丹地脉花: v3.2 - ${SHUV}.${color}.${rawTimes}`);//调试LOG + log.warn(`使用树脂类型数量:${rewards.length}`); + log.warn(`使用树脂顺序:${golbalRewardText.join(" ->")}`); + + if (color == 2){ var DIMAIHUA = "assets/model/DIMAIHUA-huank.bmp";var DIMAIHUA2 = "assets/model/DIMAIHUA-lank.bmp";} + else if (color == 1){var DIMAIHUA = "assets/model/DIMAIHUA-lank.bmp";var DIMAIHUA2 = "assets/model/DIMAIHUA-huank.bmp";} + else{var DIMAIHUA = "assets/model/DIMAIHUA-lank.bmp";;var DIMAIHUA2 = "assets/model/DIMAIHUA-huank.bmp";} + var DIMAIHUA3 = "assets/model/DIMAIHUA-da.bmp" + var DIMAIHUA4 = "assets/model/DIMAIHUA-da2.bmp" var condensedResin = "assets/model/condensed_resin_count.png"; var originalResin = "assets/model/original_resin_count.png"; var fragileResin = "assets/model/fragile_resin_count.png"; var momentResin = "assets/model/moment_resin_count.png"; var oneResin = "assets/model/one.png"; - - log.debug(`DEBUG:${SHUV}.${color}.${rawTimes}`);//调试LOG - if (Rewards){log.warn("结束后领励练点和提交每日!");if(settings.nh === undefined || settings.nh === "") {log.warn("好感队未配置,领奖励时不切换队伍")}} - if (settings.nh === undefined || settings.nh === "") { log.warn("好感队禁用!");haoganq=0}else{var haogandui = settings.nh;haoganq=1;if(settings.n === undefined ) {throw new Error("好感队已经设置,请填战斗队伍!")}} - if (settings.n === undefined || settings.n === "") { log.warn("队伍名称未配置,不更换队伍!");SHUOVER=1;} - if (SHUV == 1) {log.warn(`线路模式 :' 按次数刷取 ${timesConfig.value/2} 次' `);}else{log.warn("线路模式 :' 设定使用的树脂类型耗尽模式(最多99次) '");timesConfig.value = 198;} - if (color == 1) {log.warn("地脉类型 :' 蓝色-经验书花!'");}else{log.warn("地脉类型 :' 黄色-摩拉花!'")} + + if (Rewards){log.warn("结束后领励练点和提交每日...");if(settings.nh === undefined || settings.nh === "") {log.warn("好感队未配置,领奖励时不切换队伍..")}} + if (SHUV == 1) {log.warn(`线路模式 : <<按次数刷取>> ${timesConfig.value/2} 次 `);}else{log.warn("线路模式 : 设定使用的树脂类型<<耗尽模式>>(最多99次)... '");timesConfig.value = 198;} + if (color == 1) {log.warn("地脉类型 : <<蓝色-经验花>>...");}else{log.warn("地脉类型 : '<<黄色-摩拉花>>...")} + if (settings.n === undefined || settings.n === "") { log.warn("队伍名称未配置,不更换队伍...");SHUOVER=1;} + if (settings.nh === undefined || settings.nh === "") { log.warn("好感队禁用...");haoganq=0}else{var haogandui = settings.nh;haoganq=1;if(settings.n === undefined ) {throw new Error("好感队已经设置,请填战斗队伍...")}} let nowuidString = settings.nowuid ? settings.nowuid : ""; setGameMetrics(1920, 1080, 1); @@ -235,43 +272,188 @@ const allFlowerCoords = [ // 线路1 - { line: 1, flower: 1, x: 773, y: 669 }, - { line: 1, flower: 2, x: 846, y: 696 }, - { line: 1, flower: 3, x: 902, y: 762 }, - { line: 1, flower: 4, x: 912, y: 812 }, - { line: 1, flower: 5, x: 876, y: 840 }, - { line: 1, flower: 6, x: 815, y: 788 }, + { line: 1, flower: 1, x: 773, y: 669 , xR: 4760.80029296875 , yR: 2574.517578125 }, + { line: 1, flower: 2, x: 846, y: 696 , xR: 4653.67138671875 , yR: 2531.894287109375 }, + { line: 1, flower: 3, x: 902, y: 762 , xR: 4568.48828125 , yR: 2433.225341796875 }, + { line: 1, flower: 4, x: 912, y: 812 , xR: 4553.5107421875 , yR: 2358.491943359375 }, + { line: 1, flower: 5, x: 876, y: 840 , xR: 4607.455078125 , yR: 2316.584716796875 }, + { line: 1, flower: 6, x: 815, y: 788 , xR: 4700.13818359375 , yR: 2393.348876953125 }, // 线路2 - { line: 2, flower: 1, x: 1160, y: 716 }, - { line: 2, flower: 2, x: 1155, y: 766 }, - { line: 2, flower: 3, x: 1117, y: 801 }, - { line: 2, flower: 4, x: 1082, y: 896 }, - { line: 2, flower: 5, x: 1013, y: 883 }, + { line: 2, flower: 1, x: 1160, y: 716 , xR: 4183.26953125 , yR: 2502.36962890625 }, + { line: 2, flower: 2, x: 1155, y: 766 , xR: 4190.03271484375 , yR: 2426.40625 }, + { line: 2, flower: 3, x: 1117, y: 801 , xR: 4246.28271484375 , yR: 2374.04833984375 }, + { line: 2, flower: 4, x: 1082, y: 896 , xR: 4299.75146484375 , yR: 2232.588134765625 }, + { line: 2, flower: 5, x: 1013, y: 883 , xR: 4402.5263671875 , yR: 2253.2724609375 }, // 线路3√ - { line: 3, flower: 1, x: 1216, y: 661 }, - { line: 3, flower: 2, x: 1230, y: 685 }, - { line: 3, flower: 3, x: 1282, y: 642 }, - { line: 3, flower: 4, x: 1335, y: 639 }, + { line: 3, flower: 1, x: 1216, y: 661 , xR: 4098.6328125 , yR: 2584.1611328125 }, + { line: 3, flower: 2, x: 1230, y: 685 , xR: 4063.5205078125 , yR: 2564.291259765625 }, + { line: 3, flower: 3, x: 1282, y: 642 , xR: 3999.6552734375 , yR: 2613.181640625 }, + { line: 3, flower: 4, x: 1335, y: 639 , xR: 3921.345703125 , yR: 2617.813232421875 }, // 线路4 - { line: 4, flower: 1, x: 965, y: 672 }, - { line: 4, flower: 2, x: 921, y: 660 }, - { line: 4, flower: 3, x: 886, y: 660 }, - { line: 4, flower: 4, x: 876, y: 625 }, + { line: 4, flower: 1, x: 965, y: 672 , xR: 2932.47265625 , yR: 3583.896728515625 }, + { line: 4, flower: 2, x: 921, y: 660 , xR: 3008.40234375 , yR: 3602.593017578125 }, + { line: 4, flower: 3, x: 886, y: 660 , xR: 3077.185546875 , yR: 3602.835693359375 }, + { line: 4, flower: 4, x: 876, y: 625 , xR: 3091.7978515625 , yR: 3654.750732421875 }, // 线路5 - { line: 5, flower: 1, x: 727, y: 153 }, - { line: 5, flower: 2, x: 752, y: 78 }, - { line: 5, flower: 3, x: 712, y: 47 }, - { line: 5, flower: 4, x: 643, y: 4 }, + { line: 5, flower: 1, x: 727, y: 153 , xR: 4556.0986328125 , yR: 4762.41748046875 }, + { line: 5, flower: 2, x: 752, y: 78 , xR: 4517.81201171875 , yR: 4866.47802734375 }, + { line: 5, flower: 3, x: 712, y: 47 , xR: 4578.63134765625 , yR: 4913.2822265625 }, + { line: 5, flower: 4, x: 643, y: 4 , xR: 4679.46875 , yR: 4977.8310546875 }, // 线路6 - { line: 6, flower: 1, x: 0, y: 0 },//开始已经检测,不用复检 - { line: 6, flower: 2, x: 469, y: 369 },//315 54 - { line: 6, flower: 3, x: 400, y: 343 },//289 - { line: 6, flower: 4, x: 371, y: 281 },//227 379 290 - ]; + { line: 6, flower: 1, x: 0, y: 0 , xR: 4962.818359375 , yR: 4395.8056640625 }, + { line: 6, flower: 2, x: 469, y: 369 , xR: 4952.037109375 , yR: 4468.8408203125 }, + { line: 6, flower: 3, x: 400, y: 343 , xR: 5043.3564453125 , yR: 4479.98974609375 }, + { line: 6, flower: 4, x: 371, y: 281 , xR: 5087.0234375 , yR: 4573.26708984375 }, + ]; + async function PathCheak(findFlower=0) { + + if (method=="拖动地图"){findFlower = findFlower === 0 ? 1 : 0;} + + if (findFlower == 0){ + return await PathCheak0(); + }else + if (findFlower == 1){ + return await PathCheak1(); + } + } + + async function PathCheak0() { + + repeatRoute = false; + var bigMapPosition={x:0,y:0}; + + await genshin.returnMainUi(); + log.info("重置地图中,打开冒险之证寻找地脉花..."); + await genshin.tp(2297.60, -824.45); + await genshin.returnMainUi(); + + for(let i = 0;i<5;i++){ + await sleep(700); + await keyPress("VK_ESCAPE"); + await sleep(300); + + for(let j=0;j<5;j++){ + let book = await Textocr("冒险之证",3,0,0,113,626,630,430); + if (book.found){ + await click(book.x+40,book.y+10); + await sleep(500); + } + let bookconfirm = await Textocr("冒险之证",0.1,0,3,113,626,630,430); + if (bookconfirm.found){ + break + }else{ + continue + } + } + + let crusade = await await Textocr("讨伐",5,1,0,127,98,437,900); + if (!crusade.found){ + log.info("冒险之证打开错误T..."); + continue; + } + + await sleep(500); + await click(860,683); + + let dimai = await imageRecognition(DIMAIHUA3,2,0,0,400,248,550,370); + if (!dimai.found){ + await sleep(500); + await click(956,288); + await sleep(500); + await moveMouseTo(956,282); + await sleep(100); + await leftButtonDown(); + await sleep(100); + await moveMouseTo(956,275); + await sleep(100); + await moveMouseTo(956,273); + await sleep(100); + await leftButtonUp(); + let dimai2 = await imageRecognition(DIMAIHUA3,1,0,0,400,248,550,370); + if (!dimai2.found){continue} + } + + await sleep(200); + if (color==1){ + await imageRecognition(DIMAIHUA4,2,1,0,400,248,550,370); + }else{ + await imageRecognition(DIMAIHUA3,2,1,0,400,248,550,370); + } + + let fontaine = await Textocr("枫丹",1,0,0,1031,641,250,240); + if (!fontaine.found){ + await sleep(1000); + await click(1562,787); + await sleep(1000); + let fontaine1 = await Textocr("枫丹",1,1,0,1031,641,250,240); + if(!fontaine1.found){await click(1524,670);} + await sleep(1000); + let fontaine2 = await Textocr("枫丹",1,0,0,1031,641,250,240); + if (!fontaine2.found){continue} + } + + for(let i=0;i<5;i++){ + await sleep(500); + await click(1529,846); + await sleep(500); + await click(1529,846); + await sleep(1500); + let crusade = await await Textocr("讨伐",0,1,0,127,98,437,900); + if (crusade.found){ + continue + }else{ + break + } + } + + try{ + bigMapPosition = genshin.getPositionFromBigMap(); + if (bigMapPosition.x >= 2900 && bigMapPosition.y <= 5100 ){ + log.info("区域正确..."); + break; + }else{ + log.info("区域错误..."); + } + } + catch(error){ + log.info("冒险之证打开错误G...", error); + continue; + } + } + + const bigMapZoomLevel = genshin.getBigMapZoomLevel(); + // log.info(`当前大地图坐标: X:${Math.floor(bigMapPosition.X)} / Y:${Math.floor(bigMapPosition.Y)}`); + // log.info(`当前大地图缩放:${bigMapZoomLevel}`); + const RealPosition ={x: bigMapPosition.X,y: bigMapPosition.Y} + position = await findFlowerPositionWithTolerance(RealPosition,10,allFlowerCoords); + if (position){ + log.info(`找到地脉花的线路:|X:${Math.floor(bigMapPosition.X)}|Y:${Math.floor(bigMapPosition.Y)}|线路:${position.line}|序号:${position.flower}|`); + let XIAN_another = await imageRecognition(DIMAIHUA2,1,0,0,0); + if (XIAN_another.found){ + if (XIAN_another.found){ + let recognizedCoord_another = { x: ( bigMapPosition.X+((960-(XIAN_another.x+XIAN_another.w/2))*(5-bigMapZoomLevel))), y: ( bigMapPosition.Y+((540-(XIAN_another.y+XIAN_another.h/2)))*(5-bigMapZoomLevel))}; + position_another = await findFlowerPositionWithTolerance(recognizedCoord_another, 10,allFlowerCoords); + log.info(`找到另一个线路:|X:${Math.floor( bigMapPosition.X+((960-(XIAN_another.x+XIAN_another.w/2))*(5-bigMapZoomLevel)))}|Y:${Math.floor( bigMapPosition.Y+((540-(XIAN_another.y+XIAN_another.h/2)))*(5-bigMapZoomLevel))}|线路:${position_another.line}|序号:${position_another.flower}|`); + } + } + + if (position_another.line == position.line){ + log.info("线路重合,绕过模式打开...");repeatRoute = true; + }else{ + log.info("线路正常...");repeatRoute = false; + } + + return true + } + else{ + return false + } + } // 输出选择的线路 async function PathCheak1() { + repeatRoute = false; await genshin.returnMainUi(); log.info("重置地图中,关闭自定义标记,快速拖动模式寻找地脉花……"); await genshin.tp(2297.60, -824.45); @@ -294,7 +476,7 @@ await sleep(500); await click(1446,350); await sleep(500); - let XIAN6 = await imageRecognition(DIMAIHUA,1,0,0,387,0,700,200);if (XIAN6.found){ + let XIAN6 = await imageRecognition(DIMAIHUA,0.5,0,0,387,0,700,200);if (XIAN6.found){ log.info("地脉花位置: X:"+XIAN6.x+" Y:"+XIAN6.y); position = {line:6,flower:1}; return true }//return true @@ -310,11 +492,24 @@ await sleep(500); let XIAN123 = await imageRecognition(DIMAIHUA,1,0,0,0,0,1720,1080); if (XIAN123.found){ + + let XIAN123_another = await imageRecognition(DIMAIHUA2,0.5,0,0,0,0,1720,1080); + if (XIAN123_another.found){ + log.info("地脉花位置_another: X:"+XIAN123_another.x+" Y:"+XIAN123_another.y); + const recognizedCoord_another = { x: XIAN123_another.x, y: XIAN123_another.y }; + position_another = await findFlowerPositionWithTolerance(recognizedCoord_another, tolerance,allFlowerCoords); + } + log.info("地脉花位置: X:"+XIAN123.x+" Y:"+XIAN123.y); const recognizedCoord = { x: XIAN123.x, y: XIAN123.y }; - position = findFlowerPositionWithTolerance(recognizedCoord, tolerance); - if (position.line==3){position = findFlowerPositionWithTolerance(recognizedCoord, tolerance);} + position = await findFlowerPositionWithTolerance(recognizedCoord, tolerance,allFlowerCoords); + + if (position.line == 3){position = await findFlowerPositionWithTolerance(recognizedCoord, tolerance,allFlowerCoords);} + if (position) { + + if (position_another.line == position.line){log.info("线路重合,谨慎模式打开...");repeatRoute = true;} + return true; } else { log.info(`无法找到花朵位置(在容错范围内)。`);return false; @@ -325,10 +520,22 @@ await sleep(800); let XIAN4 = await imageRecognition(DIMAIHUA,1,0,0); if (XIAN4.found){ + + let XIAN4_another = await imageRecognition(DIMAIHUA2,0.5,0,0); + if (XIAN4_another.found){ + log.info("地脉花位置_another: X:"+XIAN4_another.x+" Y:"+XIAN4_another.y); + const recognizedCoord_another = { x: XIAN4_another.x, y: XIAN4_another.y }; + position_another = await findFlowerPositionWithTolerance(recognizedCoord_another, tolerance,allFlowerCoords); + } + log.info("地脉花位置: X:"+XIAN4.x+" Y:"+XIAN4.y); const recognizedCoord = { x: XIAN4.x, y: XIAN4.y }; - position = findFlowerPositionWithTolerance(recognizedCoord, tolerance); + position = await findFlowerPositionWithTolerance(recognizedCoord, tolerance,allFlowerCoords); + if (position) { + + if (position_another.line == position.line){log.info("线路重合,谨慎模式打开...");repeatRoute = true;} + return true; } else { log.info(`无法找到花朵位置(在容错范围内)。`);return false; @@ -337,28 +544,47 @@ await sleep(500); await moveMouseTo(1064,1079); await sleep(200); - let XIAN66 = await imageRecognition(DIMAIHUA,1,0,0); - if (XIAN66.found){ - log.info("地脉花位置: X:"+XIAN66.x+" Y:"+XIAN66.y); - const recognizedCoord = { x: XIAN66.x, y: XIAN66.y }; - position = findFlowerPositionWithTolerance(recognizedCoord, tolerance); + let XIAN56 = await imageRecognition(DIMAIHUA,1,0,0); + if (XIAN56.found){ + + let XIAN56_another = await imageRecognition(DIMAIHUA2,0.5,0,0); + if (XIAN56_another.found){ + log.info("地脉花位置_another: X:"+XIAN56_another.x+" Y:"+XIAN56_another.y); + const recognizedCoord_another = { x: XIAN56_another.x, y: XIAN56_another.y }; + position_another = await findFlowerPositionWithTolerance(recognizedCoord_another, tolerance,allFlowerCoords); + } + + log.info("地脉花位置: X:"+XIAN56.x+" Y:"+XIAN56.y); + const recognizedCoord = { x: XIAN56.x, y: XIAN56.y }; + position = await findFlowerPositionWithTolerance(recognizedCoord, tolerance,allFlowerCoords); + if (position) { + + if (position_another.line == position.line){log.info("线路重合,谨慎模式打开...");repeatRoute = true;} + return true; } else { log.info(`无法找到花朵位置(在容错范围内)。`);return false; - } + } + }else{throw new Error("线路出错,退出!")} } - function findFlowerPositionWithTolerance(coord, tolerance) { + function findFlowerPositionWithTolerance(coord, tolerance,allFlowerCoordsIn) { + let closestFlower = null; // 用于记录最近的花朵 let closestDistance = Infinity; // 初始化最近距离为无穷大 let matches = []; // 用于存储所有匹配的花朵 // 遍历所有花朵坐标,检查是否在容错范围内 - for (let i = 0; i < allFlowerCoords.length; i++) { - const flower = allFlowerCoords[i]; - const distance = Math.sqrt(Math.pow(flower.x - coord.x, 2) + Math.pow(flower.y - coord.y, 2)); + for (let i = 0; i < allFlowerCoordsIn.length; i++) { + const flower = allFlowerCoordsIn[i]; + + if (tolerance == 10){ + var distance = Math.sqrt(Math.pow(flower.xR - coord.x, 2) + Math.pow(flower.yR - coord.y, 2)); + }else{ + var distance = Math.sqrt(Math.pow(flower.x - coord.x, 2) + Math.pow(flower.y - coord.y, 2)); + } if (distance <= tolerance) { matches.push(flower); // 在容错范围内,添加到匹配列表 @@ -487,11 +713,11 @@ for (let j = 0;j < 2;j++) { for (let i = 0;i < rewards.length;i++) { - let SHU = await Textocr(resinTypeMap[rewards[i]],0.3,0,0,510,380,640,600); + let SHU = await Textocr(resinTypeMap[rewards[i]],0.1,0,0,510,380,640,600); if (SHU.found){ if (resinTypeMap[rewards[i]] == "使用20个原粹树脂") { - let BUC = await Textocr("补充",0.2,0,0,1150,440,210,130); + let BUC = await Textocr("补充",0.1,0,0,1150,440,210,130); if (BUC.found) {continue;} } @@ -564,7 +790,7 @@ log.info("未检测到浓缩树脂图标"); } - var originalResinCountRa = await imageRecognition(originalResin,0.1, 0, 0,1555,0,75,80); + var originalResinCountRa = await imageRecognition(originalResin,0.1, 0, 0,1555,0,90,80); if (originalResinCountRa.found) { // await moveMouseTo(originalResinCountRa.x,originalResinCountRa.y); let countArea = await Textocr("",0.5, 0, 2,originalResinCountRa.x+originalResinCountRa.w,originalResinCountRa.y,originalResinCountRa.w*3,originalResinCountRa.h);// @@ -675,6 +901,13 @@ logFightResult = fightResult ? "成功" : "失败"; log.info(`战斗结束,战斗结果:${logFightResult}`); cts.cancel(); + if(!fightResult){ + Lastexecution = false; + await genshin.returnMainUi(); + await sleep(1000); + await genshin.tp(2297.60, -824.45); + await genshin.returnMainUi(); + } return fightResult; } @@ -702,13 +935,16 @@ let noTextCount = 0; const successKeywords = ["挑战达成", "战斗胜利", "挑战成功"]; const failureKeywords = ["挑战失败"]; + const recovery = ["复苏"]; // 循环检测直到超时 while (Date.now() - startTime < Fighttimeout) { try { let captureRegion = captureGameRegion(); let result = captureRegion.find(ocrRo1); + let result3 = captureRegion.find(ocrRo3); let text = result.text; + let text3 = result3.text; // 检查成功关键词 for (let keyword of successKeywords) { @@ -727,6 +963,17 @@ return; } } + + // 检查复苏关键词 + for (let keyword of recovery) { + if (text3.includes(keyword)) { + log.warn("检测到战斗失败关键词: {0}", keyword); + await sleep(1000); + result3.click(); + resolve(false); + return; + } + } //战斗区域 let foundText = recognizeFightText(captureRegion); @@ -758,50 +1005,58 @@ } })(); }); - } - + } + //重新战斗次数 var retryCount = 0; var executedCount = 0; async function Veinfligt() { - // 定义路线常量 + // 定义路线常量 var selectedPath = pathingMap[`路线${position.line} ${['厄里那斯', '秋分山西侧锚点左下', '秋分山西侧锚点右', '柔灯港上锚点', '新枫丹科学院左锚点', '芒索斯山东麓'][position.line - 1]}`] var selectedFolder = folderMap[`路线${position.line} ${['厄里那斯', '秋分山西侧锚点左下', '秋分山西侧锚点右', '柔灯港上锚点', '新枫丹科学院左锚点', '芒索斯山东麓'][position.line - 1]}`] - + executedCount = (position.flower-1)*2+0; Lastexecution = false; - log.info(`开始执行第 ${position.line} 线路的第 ${executedCount/2 + 1}/${selectedPath.length/2} 朵地脉花...`); + log.info(`开始执行第 ${position.line} 线路的第 ${executedCount/2 + 1}/${selectedPath.length/2} 朵地脉花...`); for (let i = 0; i < selectedPath.length; i += 2){ if (executedCount/2 + 1 > selectedPath.length/2) { - // if (executedCount>99) {log.info("未找到地脉花,重新尝试..."); return true;} - log.info("本线路执行完毕..."); - break;} + break; + } if (doneCount >= timesConfig.value/2){ SHUOVER=2;log.info(`地脉花执行完成 ${timesConfig.value/2} 次,结束执行...`); return true; - } + } const jsonFile1 = selectedPath[i+position.flower*2-2]; if (jsonFile1 == undefined) { log.info(`本线路完结,未达设定执行次数 ${timesConfig.value/2} ,继续执行...`); return true; } + + if (repeatRoute && (executedCount/2 + 1 + i) == position_another.flower) { + log.info(`线路混合其他类型地脉花,跳过...`); + SMODEL = false; + continue; + }else{ + log.info(`线路正常,继续...`); + SMODEL = settings.SMODEL ? settings.SMODEL : false; + } + const jsonFile2 = selectedPath[i+position.flower*2-1]; // 执行单个到达地脉花路径文件1 - const choicePath = `${selectedFolder}${jsonFile1}` + const choicePath = `${selectedFolder}${jsonFile1}` log.info(`开始执行前往都地脉花:${jsonFile1}`); if(SMODEL){ if (!Lastexecution || (position.line==1 && (i+position.flower*2-2)==8)) { if(position.line==2 && (i+position.flower*2-2)==8 && Lastexecution){ await pathingScript.runFile("assets/枫丹地脉花-路线2 秋分山西侧锚点左下/线路修复/枫丹地脉花-路线2 秋分山西侧锚点左下-5:秋分山左左下下1-线路修复.json");} - else - { + else{ if(position.line==2 && (i+position.flower*2-2)==8)//特殊处理 { let pathDic = JSON.parse(file.readTextSync(choicePath)); @@ -810,7 +1065,9 @@ await genshin.returnMainUi(); pathDic["positions"].splice(0, 1); await pathingScript.run(JSON.stringify(pathDic)); - }else{await pathingScript.runFile(`${selectedFolder}${jsonFile1}`);} + }else{ + await pathingScript.runFile(`${selectedFolder}${jsonFile1}`); + } } } else @@ -841,10 +1098,16 @@ }else{await pathingScript.runFile(`${selectedFolder}${jsonFile1}`);} } - } + } // 寻找地脉溢口,找到地脉花就领奖,没有找到就直接战斗,再尝试领奖 - if (await VeinEntrance()){ + if (await VeinEntrance()){ + + if(position.line==2 && (i+position.flower*2-2)==8){ + + await pathingScript.runFile("assets/枫丹地脉花-路线2 秋分山西侧锚点左下/线路修复/枫丹地脉花-路线2 秋分山西侧锚点左下-5:秋分山左左下下_特殊处理.json"); + } + await sleep(1000); await dispatcher.addTimer(new RealtimeTimer("AutoPick", { forceInteraction: false})); await keyPress("F"); log.warn("开始战斗..."); @@ -852,7 +1115,6 @@ shouldContinueChecking = true; checkRewardPage();// 执行自动战斗并同步检测领奖页面 - if (!Fightquick){ await dispatcher.runTask(new SoloTask("AutoFight")); //固定执行两次战斗,执行自动战斗,配置器中的设置建议填你的队伍打一次大概得时间 await sleep(1000); @@ -869,8 +1131,9 @@ //退出执行 SHUOVER=2; return false; - } + } } + await keyPress("1");//防止战斗后处于特殊状态寻路异常,例如火神上摩托车,1号位不要放类似角色 } shouldContinueChecking = true; @@ -878,7 +1141,7 @@ log.info(`开始执行寻找地脉花奖励:${jsonFile2}`); await dispatcher.addTimer(new RealtimeTimer("AutoPick", { forceInteraction: false})); await pathingScript.runFile(`${selectedFolder}${jsonFile2}`); - await sleep(3000); + await sleep(2000); // 领取奖励,开始找地脉口 log.info(`开始本线路第 ${executedCount/2+1} 朵花的奖励领取`); if (haoganq==1){log.info(`切换好感队伍:'${haogandui}'`);await genshin.returnMainUi(); await sleep(1000);await genshin.SwitchParty(haogandui);} @@ -921,13 +1184,21 @@ } } } - }else{log.warn("未配置禁用UID,继续进行!");} + } try { //根据SHUOVER决定模式 while (SHUOVER<=1){ Fligtin = true ; //领取冒险点奖励标志。 - if (!(await PathCheak1())){;await leftButtonUp();throw new Error("未找到地脉花,退出!")}else{await leftButtonUp();await genshin.returnMainUi();} + if (!(await PathCheak(0))){ + await leftButtonUp(); + log.info("未找到地脉花,更换寻找方式,重试...") + if (!(await PathCheak(1))) + { + await leftButtonUp();await genshin.returnMainUi(); + throw new Error("未找到地脉花,退出!") + } + } //第一次执行选择队伍 if (SHUOVER == 0){await genshin.returnMainUi(); await sleep(1000);await genshin.SwitchParty(settings.n);await sleep(500);} diff --git a/repo/js/AutoFontaineLeyLine/manifest.json b/repo/js/AutoFontaineLeyLine/manifest.json index b1c31c2e..294cd4ad 100644 --- a/repo/js/AutoFontaineLeyLine/manifest.json +++ b/repo/js/AutoFontaineLeyLine/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 1, "name": "全自动枫丹地脉花", - "version": "3.1", + "version": "3.2", "bgi_version": "0.44.8", "description": "枫丹地脉花,蓝花金花通用。生存压力大,请带盾奶;避免纯水输出,请注意说明文件。如有BUG请联系作者QQ:119996800", "tags": [ diff --git a/repo/js/AutoFontaineLeyLine/settings.json b/repo/js/AutoFontaineLeyLine/settings.json index 31e6530b..441e877c 100644 --- a/repo/js/AutoFontaineLeyLine/settings.json +++ b/repo/js/AutoFontaineLeyLine/settings.json @@ -1,41 +1,50 @@ [ +{ + "name": "method", + "type": "select", + "label": "默认:通过 <冒险之证> 寻找地脉花,一般不用改\n可选:通过 <拖动地图> 为原始方法,按需要选择", + "options": [ + "冒险之证", + "拖动地图" + ] +}, { "name": "n", "type": "input-text", - "label": "选填,战斗队伍,默认不更换队伍,如需好感队则必填" + "label": "选填:战斗队伍,默认不更换队伍,如需好感队则必填" }, { "name": "nh", "type": "input-text", - "label": "选填,好感队伍,如设定领奖前切换,同时战斗队伍必填" + "label": "选填:好感队伍,如设定领奖前切换,同时战斗队伍必填" }, { "name": "times", "type": "input-text", - "label": "选填,按刷取次数,默认6次,最多99次,树脂耗尽模式下无效" + "label": "选填:按刷取次数,默认6次,最多99次,树脂耗尽模式下无效" }, { "name": "shuv", "type": "select", - "label": "默认:“1”为按上面的次数刷取,选“2”为耗尽树脂模式", + "label": "默认:<1> 为按上面的次数刷取,可选 <2> 为耗尽树脂模式", "options": [ - "1", - "2" + "1-次数刷取", + "2-树脂耗尽" ] }, { "name": "color", "type": "select", - "label": "默认:蓝花(经验花)选“1” / 黄花(摩拉花)选“2”", + "label": "默认:<1-蓝花(经验花)>,可选<2-黄花(摩拉花)>", "options": [ - "1", - "2" + "1-蓝花(经验花)", + "2-黄花(摩拉花)" ] }, { "name": "Rewardsuse", "type": "input-text", - "label": "树脂顺序,1=浓缩树脂/2=原粹树脂/3=脆弱树脂/4=须臾树脂\n用`/`隔开,填写对应的树脂数字即可,默认:1/2\n表示先使用浓缩树脂,再使用原粹树脂,不填的不使用" + "label": "树脂设定:1=浓缩/2=原粹/3=脆弱/4=须臾\n用`/`隔开:填写对应的树脂<数字>即可\n默认:1/2 (表示先用浓缩后原粹,直至用完,不填的不使用)" }, { "name": "nowuid", @@ -55,11 +64,11 @@ { "name": "Fightquick", "type": "checkbox", - "label": "开启:异步检测战斗结束,即地脉花长出后马上停止战斗\n开启后,下方的超时时间才有效\n开启后,建议关闭配置组中的“自动检测战斗结束”选项\n关闭:使用传统打开队伍界面进行判断战斗结束" + "label": "默认开启:异步检测战斗结束,即地脉花长出后马上停止战斗\n开启后,建议关闭配置组中的<自动检测战斗结束>选项\n不启用:使用传统<打开队伍界面>进行判断战斗结束" }, { "name": "timeout", "type": "input-text", - "label": "最长战斗超时时间,单位秒,默认240秒" + "label": "启用<异步检测战斗结束>开启后,下方填写的超时时间才有效\n默认180秒,建议和配置组的战斗超时一致" } ] \ No newline at end of file