diff --git a/repo/js/爱可菲厨艺机关/main.js b/repo/js/爱可菲厨艺机关/main.js new file mode 100644 index 00000000..9658ee21 --- /dev/null +++ b/repo/js/爱可菲厨艺机关/main.js @@ -0,0 +1,182 @@ +(async function () { + + //初始化配置====================================================================================== + var actiontime = settings.actiontime != undefined && ~~settings.actiontime > 0 ? ~~settings.actiontime : 100; + var TEAM + var AKF = settings.AKF !== undefined ? ( + settings.AKF === "是" ? 1 : + settings.AKF === "否" ? 0 : + settings.AKF === "每天执行" ? 2 + : 0 ) : 0; // 如果settings.AKF完全未定义,也赋予AKF为0 + + /** + * 文字OCR识别封装函数(测试中,未封装完成,后续会优化逻辑) + * @param text 要识别的文字,默认为"空参数" + * @param timeout 超时时间,单位为秒,默认为10秒 + * @param afterBehavior 点击模式,0表示不点击,1表示点击识别到文字的位置,2表示输出模式,默认为0 + * @param debugmodel 调试代码,0表示输入判断模式,1表示输出位置信息,2表示输出判断模式,默认为0 + * @param x OCR识别区域的起始X坐标,默认为0 + * @param y OCR识别区域的起始Y坐标,默认为0 + * @param w OCR识别区域的宽度,默认为1920 + * @param h OCR识别区域的高度,默认为1080 + * @returns 包含识别结果的对象,包括识别的文字、坐标和是否找到的结果 + */ + async function textOCR(text="空参数",timeout=10,afterBehavior=0,debugmodel=0,x=0,y=0,w=1920,h=1080) { + const startTime = new Date(); + var Outcheak = 0 + for (var ii = 0; ii < 10; ii++) + { + // 获取一张截图 + var captureRegion = captureGameRegion(); + var res1 + var res2 + var conuntcottimecot=1; + var conuntcottimecomp=1; + // 对整个区域进行 OCR + var resList = captureRegion.findMulti(RecognitionObject.ocr(x,y,w,h)); + //log.info("OCR 全区域识别结果数量 {len}", resList.count); + if (resList.count !== 0) { + for (let i = 0; i < resList.count; i++) + { // 遍历的是 C# 的 List 对象,所以要用 count,而不是 length + let res = resList[i]; + res1=res.text + conuntcottimecomp++; + if (res.text.includes(text) && debugmodel ==3 ) {return result = { text: res.text, x: res.x, y: res.y, found: true };} + if (res.text.includes(text) && debugmodel !==2 ) { + conuntcottimecot ++; + log.info(`“${res1}”找到`); + if (debugmodel===1 & x===0 & y===0){log.info("全图代码位置:({x},{y},{h},{w})", res.x-10, res.y-10, res.width+10, res.Height+10);}else{log.info("文本OCR完成'{text}'", res.text);} + if (afterBehavior===1){log.info("点击模式:开");await sleep(1000);click(res.x, res.y);}else{if (debugmodel===1 & x===0 & y===0){log.info("点击模式:关")}} + if (afterBehavior===2){log.info("F模式:开");await sleep(100);keyPress("F");}else{if (debugmodel===1 & x===0 & y===0){log.info("F模式:关");}} + if (conuntcottimecot>=conuntcottimecomp/2){return result = { text: res.text, x: res.x, y: res.y, found: true };}else{return result = { found: false};} + } + if (debugmodel ===2 ){ + if (res1 === res2){conuntcottimecot ++;res2=res1;} + //log.info("输出模式:全图代码位置:({x},{y},{h},{w},{string})", res.x-10, res.y-10, res.width+10, res.Height+10, res.text); + if (Outcheak===1){ if (conuntcottimecot>=conuntcottimecomp/2){return result = { text: res.text, x: res.x, y: res.y, found: true };}else{return result = { found: false};}} + }}} + const NowTime = new Date(); + if ((NowTime - startTime)>timeout*1000){if (debugmodel===2){ if (resList.count === 0){return result = {found: false};} else{Outcheak=1;ii=2;} } else {Outcheak=0;if (debugmodel===1 & x===0 & y===0){log.info(`${timeout}秒超时退出,"${text}"未找到`)};return result = {found: false };}} + else{ii=2;if (debugmodel===1 & x===0 & y===0){log.info(`"${text}"识别中……`); } } + await sleep(100); + } + } + +/**====================================================================================== + * 执行质变仪的部署动作,未找到质变仪时返回false结束,找到质变仪时返回true + */ +async function deployTransformer(){ + + await genshin.SwitchParty(TEAM); //切换到指定队伍,必须进行配置,4号位放芭芭拉 + await sleep(1000); + await keyPress("3"); + await sleep(1200); + await keyDown("e"); + await sleep(1000); + await keyUp("e"); + await sleep(1000); + return true; + +} + +/**====================================================================================== + * 执行芭芭拉攻击指令,并等待质变仪完成提示出现。 若超时则强制结束流程。 + */ +async function executeAttack(){ + await sleep(1000); + await keyPress("4"); + await sleep(1200); + await middleButtonClick(); + await sleep(1000); + + log.info(`攻击动作开始,${actiontime}秒后超时退出!一般60秒左右完成!`) + var startTime = new Date(); + await sleep(500); + var NowTime = new Date(); + //芭芭拉攻击指令,等待质变仪完成提示出现,若超时则强制结束流程。 + var getshu = 0; + var lastIncrementTime = 0; // 上次增加getshu的时间 + const intervalTime = 3000; // 3秒的时间间隔,单位为毫秒 + while ((NowTime - startTime)= intervalTime) { + getshu++; + lastIncrementTime = currentTime; + log.warn(`获得料理数量: ${getshu}`); + if (getshu >= 10) { + log.warn("获得料理数量已达10,结束流程!"); + await genshin.returnMainUi(); // 提前退出循环 + return true; + } + } + } + leftButtonClick(); + NowTime = new Date(); + } + + await genshin.returnMainUi(); + throw new Error(`${actiontimein}秒攻击动作超时,结束流程!`); +} + + let nowuidString = settings.nowuid ? settings.nowuid : ""; + + // UID获取存在概率不成功,慎用!请更换背景纯色的名片提高OCR成功率 + let uidNumbers = nowuidString.match(/\d+/g); + if (nowuidString) { + log.debug(`DEBUG:${uidNumbers}`);//调试LOG + await genshin.returnMainUi(); + await keyPress("VK_ESCAPE"); + await sleep(500); + if (uidNumbers && uidNumbers.length > 0) { + // 使用 for...of 循环遍历 uidNumbers 数组 + for (let number of uidNumbers) { + var UIDnow = "UID" + number; + log.debug(`DEBUG:${UIDnow}`); + let UIDD = await textOCR(UIDnow, 1, 0, 0, 112,177, 190, 39); + if (UIDD.found) { + await genshin.returnMainUi(); + throw new Error(`UID "${UIDnow}" 已被禁用,停止刷取!`); + } + } + } + }else{log.warn("未配置禁用UID,继续进行!");} +//main/====================================================================================== + await genshin.returnMainUi(); + //检查用户是否配置队伍============================================ + if (settings.TEAMname === undefined) { + throw new Error("必填!请在配置页面填写队伍名称,3号为爱可菲,4号位芭芭拉!"); // 没选就报错后停止 + }else{TEAM = settings.TEAMname} + + //爱可菲厨艺机关 + try { + var AKFevry = 0; + if (AKF == 2){AKF = 1;AKFevry = 1;} + if (AKF == 1){ + const today = new Date(); + // 判断是否为周一(getDay()返回0-6,1代表周一) + if (today.getDay() == 1 || AKFevry == 1) { + log.info("执行爱可菲烹饪任务"); + if ((await deployTransformer())) {//部署厨艺机关 + log.info("厨艺机关部署成功!"); + } + if ((await executeAttack())) {//芭芭拉攻击指令流程 + log.info("爱可菲烹饪任务执行完成,结束!!"); + } + }else{ + log.info("不执行爱可菲烹饪任务"); + } + }else{ + log.info("爱可菲烹饪任务禁用"); + } + } catch (error) { + log.error(`执行过程中发生错误:${error.message}`); + } finally { + await genshin.returnMainUi(); + } +//main/**====================================================================================== + +})(); + + diff --git a/repo/js/爱可菲厨艺机关/manifest.json b/repo/js/爱可菲厨艺机关/manifest.json new file mode 100644 index 00000000..8a564723 --- /dev/null +++ b/repo/js/爱可菲厨艺机关/manifest.json @@ -0,0 +1,14 @@ +{ + "manifest_version": 1, + "name": "爱可菲自动化", + "version": "1.2", + "bgi_version": "0.44.0", + "description": "爱可菲厨艺机关自动化", + "authors": [ + { + "name": "LCB-茶包" + } + ], + "settings_ui": "settings.json", + "main": "main.js" +} \ No newline at end of file diff --git a/repo/js/爱可菲厨艺机关/settings.json b/repo/js/爱可菲厨艺机关/settings.json new file mode 100644 index 00000000..01036d7a --- /dev/null +++ b/repo/js/爱可菲厨艺机关/settings.json @@ -0,0 +1,30 @@ +[ + { + "name": "TEAMname", + "type": "input-text", + "label": "必填!!队伍名称,3号为爱可菲,4号位芭芭拉!" +}, +{ + "name": "AKF", + "type": "select", + "label": "选题,默认每天执行,可选是:周一执行,否为不执行", + + "options": [ + "是", + "否", + "每天执行" + ] +}, +{ + "name": "actiontime", + "type": "input-text", + "label": "选填,爱可菲厨艺机关超时默认100秒", + "default": "100" +}, +{ + "name": "nowuid", + "type": "input-text", + "label": "慎用,禁止特定执行脚本,用 / 隔开,如12345/99999" +} + +] \ No newline at end of file diff --git a/repo/js/爱可菲厨艺机关/注意使用事项.txt b/repo/js/爱可菲厨艺机关/注意使用事项.txt new file mode 100644 index 00000000..b7aca7f3 --- /dev/null +++ b/repo/js/爱可菲厨艺机关/注意使用事项.txt @@ -0,0 +1,16 @@ +一、使用前请在配置中设置要切换的队伍(必填),否则会自动结束任务。 + +二、脚本用芭芭拉的攻击动作充能爱可菲厨艺机关,请确保切换的队伍3号位爱可菲,4号位为芭芭拉。 + +三、选择“否”为禁用,建议选择周一执行(选择:是),直接加入的调度器就可以,脚本会自动判断是否为星期一从而执行(爱可菲厨艺机关每周10个,周一更新CD)。 + 选择“每天执行”为每次都执行。 + +四、脚本会自动判断是否获得10个料理后自动退出,可能有误差,一般60秒完成,最大超时默认100秒,可自己配置。 + +五、鉴于有人多个号,不一定每个号都有爱可菲,加入UID禁用模式,把不想执行的UID填入即可,用 / 隔开,如12345/99999。 + +六、后言 +1、测试阶段,如有错误,请QQ:119996800联系反馈。 + +七、更新说明 +v.1.0 20250510 发布