Files
bettergi-scripts-list/repo/js/爱可菲厨艺机关/main.js
kaedelcb cc200ad041 爱可菲厨艺机关 (#758)
* Delete repo/js/参量质变仪 directory

* Add files via upload

* 爱可菲厨艺机关自动化

1、脚本用芭芭拉的攻击动作充能爱可菲厨艺机关,请确保切换的队伍3号位爱可菲,4号位为芭芭拉。
2、选择“否”为禁用,建议选择周一执行(选择:是),直接加入的调度器就可以,脚本会自动判断是否为星期一从而执行(爱可菲厨艺机关每周10个,周一更新CD)。
    选择“每天执行”为每次都执行。
3、脚本会自动判断是否获得10个料理后自动退出,可能有误差,一般60秒完成,最大超时默认100秒,可自己配置。
4、鉴于有人多个好不一定都有爱可菲,加入UID禁用模式,把不想执行的UID填入即可,用 / 隔开,如12345/99999。

* Delete repo/js/爱可菲厨艺机关 directory

* 爱可菲厨艺机关

一、使用前请在配置中设置要切换的队伍(必填),否则会自动结束任务。
二、脚本用芭芭拉的攻击动作充能爱可菲厨艺机关,请确保切换的队伍3号位爱可菲,4号位为芭芭拉。
三、选择“否”为禁用,建议选择周一执行(选择:是),直接加入的调度器就可以,脚本会自动判断是否为星期一从而执行(爱可菲厨艺机关每周10个,周一更新CD)。
    选择“每天执行”为每次都执行。
四、脚本会自动判断是否获得10个料理后自动退出,可能有误差,一般60秒完成,最大超时默认100秒,可自己配置。
五、鉴于有人多个号,不一定每个号都有爱可菲,加入UID禁用模式,把不想执行的UID填入即可,用 / 隔开,如12345/99999。
2025-05-10 02:13:17 +08:00

183 lines
9.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(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)<actiontime*1000){
const result = await textOCR("获得", 0.2, 0, 3, 159, 494, 75, 44);
if (result.found) {
const currentTime = new Date().getTime();
if (currentTime - lastIncrementTime >= 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-61代表周一
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/**======================================================================================
})();