优化【料理制作及食材加工】js脚本 (#1265)

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* 新增标签
This commit is contained in:
呱呱z
2025-07-03 20:48:34 +08:00
committed by GitHub
parent 3ed9b5fc47
commit 2554a8fbcf
10 changed files with 533 additions and 228 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

View File

@@ -0,0 +1,22 @@
{
"macroEvents": [
{"type": 2, "mouseX": 1200, "mouseY": 901, "time": 0},
{"type": 2, "mouseX": 1200, "mouseY": 801, "time": 50},
{"type": 2, "mouseX": 1200, "mouseY": 701, "time": 100},
{"type": 2, "mouseX": 1200, "mouseY": 601, "time": 150},
{"type": 2, "mouseX": 1200, "mouseY": 501, "time": 200},
{"type": 2, "mouseX": 1200, "mouseY": 401, "time": 250},
{"type": 2, "mouseX": 1200, "mouseY": 301, "time": 300},
{"type": 2, "mouseX": 1200, "mouseY": 201, "time": 350},
{"type": 2, "mouseX": 1200, "mouseY": 200, "mouseButton": "Left", "time": 400}
],
"info": {
"name": "",
"description": "",
"x": 0,
"y": 0,
"width": 1920,
"height": 1080,
"recordDpi": 1
}
}

View File

@@ -0,0 +1,22 @@
{
"macroEvents": [
{"type": 2, "mouseX": 1200, "mouseY": 901, "time": 0},
{"type": 2, "mouseX": 1200, "mouseY": 801, "time": 50},
{"type": 2, "mouseX": 1200, "mouseY": 701, "time": 100},
{"type": 2, "mouseX": 1200, "mouseY": 601, "time": 150},
{"type": 2, "mouseX": 1200, "mouseY": 501, "time": 200},
{"type": 2, "mouseX": 1200, "mouseY": 401, "time": 250},
{"type": 2, "mouseX": 1200, "mouseY": 301, "time": 300},
{"type": 2, "mouseX": 1200, "mouseY": 205, "time": 350},
{"type": 2, "mouseX": 1200, "mouseY": 204, "mouseButton": "Left", "time": 400}
],
"info": {
"name": "",
"description": "",
"x": 0,
"y": 0,
"width": 1920,
"height": 1080,
"recordDpi": 1
}
}

View File

@@ -0,0 +1,3 @@
{"macroEvents":[{"type":6,"mouseX":0,"mouseY":-120,"time":0},
{"type":6,"mouseX":0,"mouseY":0,"time":100}],
"info":{"name":"","description":"","x":0,"y":0,"width":1920,"height":1080,"recordDpi":1}}

View File

@@ -0,0 +1,29 @@
{
"info": {
"name": "璃月杂货商东升旁灶台",
"type": "collect",
"author": "吉吉喵",
"version": "1.0",
"description": "",
"bgi_version": "0.42.3"
},
"positions": [
{
"id": 1,
"x": 267.92,
"y": -665.01,
"action": "force_tp",
"move_mode": "walk",
"type": "teleport"
},
{
"id": 2,
"x": 255.099609375,
"y": -680.1826171875,
"type": "target",
"move_mode": "walk",
"action": "",
"action_params": ""
}
]
}

View File

@@ -16,231 +16,400 @@
let sausageNum = settings.sausageNum ?? 0;
await sleep(1000);
await pathingScript.runFile("assets/前往蒙德灶台.json");
keyPress("F");
await sleep(1000);
await pathingScript.runFile("assets/璃月杂货商东升旁灶台.json");
//制作料理
if (foodName) {
click(910, 51);//选择料理
/**
F交互区
**/
// 定义一个函数用于模拟按键操作
async function simulateKeyOperations(key, duration) {
keyDown(key);
await sleep(duration);
keyUp(key);
await sleep(500); // 释放按键后等待 500 毫秒
}
// 识别 F 图标
async function recognizeFIcon() {
const fDialogueRo = RecognitionObject.TemplateMatch(
file.ReadImageMatSync("assets/F_Dialogue.png"),
1101,
400,
36,
400
);
let ra = captureGameRegion();
let fRes = ra.find(fDialogueRo);
if (!fRes.isExist()) {
let f_attempts = 0; // 初始化尝试次数
while (f_attempts < 3) { // 最多尝试 3 次
f_attempts++;
log.info(`当前尝试次数:${f_attempts}`);
if (f_attempts === 1 || f_attempts === 2) {
// 第一次未找到 F 图标
await simulateKeyOperations("S", 200); // 后退 200 毫秒
log.info("执行后退操作");
await sleep(200);
await simulateKeyOperations("W", 600); // 前进 600 毫秒
log.info("执行前进操作");
} else if (f_attempts === 3) {
// 第二次未找到 F 图标
log.info("重新加载路径文件");
const filePath = `assets/璃月杂货商东升旁灶台.json`;
log.info(`加载路径文件:${filePath}`);
await pathingScript.runFile(filePath);
await sleep(500);
}
// 重新获取游戏区域截图
ra = captureGameRegion();
fRes = ra.find(fDialogueRo);
// 打印识别结果
log.info(`识别结果:${fRes.isExist()}`);
// 如果识别成功,立即退出循环
if (fRes.isExist()) {
log.info("识别成功,退出循环");
break;
}
await sleep(500);
}
}
// 如果尝试次数已达上限,返回 null
if (!fRes.isExist()) {
log.error("尝试次数已达上限");
return null;
}
return fRes;
}
// 识别 Cooking 图标
async function recognizeCookingIcon(centerYF) {
const cookingRo = RecognitionObject.TemplateMatch(
file.ReadImageMatSync("assets/Cooking.png"),
1176,
centerYF - 18, // 以 F 图标的中心,向上偏移 18 像素
27, // 宽度范围
36 // 高度范围
);
let ra = captureGameRegion();
let cookingRes = ra.find(cookingRo);
if (cookingRes.isExist()) {
log.info("找到 灶台 图标");
return cookingRes;
} else {
log.info("未找到 灶台 图标");
return null;
}
}
// 主逻辑函数
async function main() {
// 识别 F 图标
let fRes = await recognizeFIcon();
if (!fRes) {
log.error("未能识别 F 图标,退出任务");
return;
}
// 获取 F 图标的中心点 Y 坐标
let centerYF = Math.round(fRes.y + fRes.height / 2);
const maxScrollAttempts = 5; // 最大滚轮操作次数限制
let scrollAttempts = 0;
while (scrollAttempts < maxScrollAttempts) {
// 识别 灶台 图标
let cookingRes = await recognizeCookingIcon(centerYF);
if (cookingRes) {
// log.info("找到 灶台 图标");
return cookingRes; // 识别成功,返回结果
}
// 如果未找到 Cooking 图标,执行滚轮操作
log.info(`未找到 Cooking 图标,执行滚轮操作,当前尝试次数:${scrollAttempts + 1}`);
await keyMouseScript.runFile(`assets/滚轮下翻.json`);
await sleep(1000);
// 重新识别 F 图标,获取最新的中心点
fRes = await recognizeFIcon();
if (!fRes) {
log.error("滚轮操作后,未能重新识别 F 图标,退出任务");
return;
}
centerYF = Math.round(fRes.y + fRes.height / 2); // 更新 F 图标的中心点 Y 坐标
// 增加尝试次数
scrollAttempts++;
}
// 如果超过最大滚轮操作次数,返回 null
log.error(`滚轮操作次数已达上限 ${maxScrollAttempts} 次,未能找到 Cooking 图标`);
return null;
}
try {
// 识别 Cooking 图标
const cookingRes = await main();
if (!cookingRes) {
log.error("未能识别 灶台 图标,退出任务");
return;
}
// 按下 F 键
keyPress("F");
await sleep(1000);
click(170, 1020);//筛选
//制作料理
if (foodName) {
click(910, 51);//选择料理
await sleep(1000);
click(170, 1020);//筛选
await sleep(1000);
click(195, 1020);//重置
await sleep(1000);
click(110, 110);//输入名字
await sleep(1000);
inputText(`${foodName}`);
await sleep(500);
click(490, 1020);//确认筛选
await sleep(1000);
click(180, 180);//选择第一个食物
await sleep(2000);
click(1690, 1015);//制作
await sleep(1000);
click(795, 1015);//自动烹饪
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of foodNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(4000);//等待烹饪
click(960, 1045); //点击任意处
await sleep(1000);
click(960, 1045); //点击任意处
await sleep(1000);
};
//食材加工
click(1010, 50); //选择食材加工
await sleep(1000);
click(195, 1020);//重置
click(255, 1020); //全部领取
await sleep(1000);
click(110, 110);//输入名字
click(960, 1045); //点击任意处
await sleep(1000);
inputText(`${foodName}`);
await sleep(500);
click(490, 1020);//确认筛选
click(960, 1045); //点击任意处
await sleep(1000);
click(180, 180);//选择第一个食物
click(960, 1045); //点击任意处
await sleep(2000);
click(1690, 1015);//制作
if (flourNum) {
click(175, 190);//flour
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of flourNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (creamNum) {
click(770, 190);//cream
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of creamNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (smokedPoultryNum) {
click(920, 190);//smokedPoultry
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of smokedPoultryNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (butterNum) {
click(1060, 190);//butter
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of butterNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (hamNum) {
click(1210, 190);//ham
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of hamNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (sugarNum) {
click(175, 375);//sugar
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of sugarNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (spiceNum) {
click(325, 375);//spice
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of spiceNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (crabRoeNum) {
click(475, 375);//crabRoe
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of crabRoeNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (jamNum) {
click(620, 375);//jam
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of jamNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (cheeseNum) {
click(770, 375);//cheese
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of cheeseNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (baconNum) {
click(915, 375);//bacon
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of baconNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (sausageNum) {
click(1060, 375);//sausage
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of sausageNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
await genshin.returnMainUi();
await sleep(1000);
click(795, 1015);//自动烹饪
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of foodNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(4000);//等待烹饪
keyPress("ESCAPE");
keyDown("S");
await sleep(1500);
keyPress("ESCAPE");
await sleep(1500);
};
keyUp("S");
await sleep(1000);
//食材加工
} catch (error) {
log.error(`执行按键或鼠标操作时发生错误:${error.message}`);
}
click(1010, 50);//选择食材加工
await sleep(1000);
click(255, 1020);//全部领取
await sleep(1000);
keyPress("ESCAPE");//点击任意处
await sleep(2000);
if (flourNum) {
click(175, 190);//flour
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of flourNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (creamNum) {
click(770, 190);//cream
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of creamNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (smokedPoultryNum) {
click(920, 190);//smokedPoultry
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of smokedPoultryNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (butterNum) {
click(1060, 190);//butter
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of butterNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (hamNum) {
click(1210, 190);//ham
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of hamNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (sugarNum) {
click(175, 375);//sugar
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of sugarNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (spiceNum) {
click(325, 375);//spice
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of spiceNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (crabRoeNum) {
click(475, 375);//crabRoe
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of crabRoeNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (jamNum) {
click(620, 375);//jam
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of jamNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (cheeseNum) {
click(770, 375);//cheese
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of cheeseNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (baconNum) {
click(915, 375);//bacon
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of baconNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
if (sausageNum) {
click(1060, 375);//sausage
await sleep(1000);
click(1690, 1015);//制作
await sleep(1000);
click(965, 455);//输入数量
await sleep(1000);
for (const char of sausageNum) {
keyPress(char);
await sleep(500);
}
click(1190, 755);//确认
await sleep(1000);
};
await genshin.returnMainUi();
// 发送通知
notification.send("烹饪脚本结束");
})();

View File

@@ -1,14 +1,19 @@
{
"manifest_version": 1,
"name": "料理制作及食材加工",
"version": "1.2",
"description": "自动烹饪料理以及加工食材,需要0.44.6及以上版本",
"authors": [
{
"name": "柒叶子",
"link": "https://github.com/511760049"
}
],
"settings_ui": "settings.json",
"main": "main.js"
"manifest_version": 1,
"name": "料理制作及食材加工",
"version": "1.3",
"bgi_version": "0.44.6", 
"tags": ["食材加工", "料理制作"],
"description": "自动烹饪料理以及加工食材,需要0.44.6及以上版本",
"authors": [
{
"name": "柒叶子",
"link": "https://github.com/511760049"
},
{
"name": "呱呱z"
}
],
"settings_ui": "settings.json",
"main": "main.js"
}

View File

@@ -0,0 +1,55 @@
# 料理制作及食材加工脚本
本脚本用于料理的制作和食材加工。可根据配置自动选择料理和各类食材进行批量制作。
## 功能简介
- 自动前往指定灶台
- 自动筛选并制作指定料理,可自定义数量
- 自动领取并加工多种食材(如面粉、奶油、火腿等),每种食材数量可单独配置
- 制作完成后自动返回主界面并发送通知
## 使用方法
1. 通过 BetterGI 脚本设置界面填写各项参数(料理名、数量、各类食材数量等)
## 参数说明
| 参数名 | 说明 | 默认值 |
| ---------------- | -------------- | ------ |
| foodName | 料理名称 | 0 |
| foodNum | 料理制作数量 | 1 |
| flourNum | 面粉加工数量 | 0 |
| creamNum | 奶油加工数量 | 0 |
| smokedPoultryNum | 熏禽肉加工数量 | 0 |
| butterNum | 黄油加工数量 | 0 |
| hamNum | 火腿加工数量 | 0 |
| sugarNum | 糖加工数量 | 0 |
| spiceNum | 香辛料加工数量 | 0 |
| crabRoeNum | 蟹黄加工数量 | 0 |
| jamNum | 果酱加工数量 | 0 |
| cheeseNum | 奶酪加工数量 | 0 |
| baconNum | 培根加工数量 | 0 |
| sausageNum | 香肠加工数量 | 0 |
## 注意事项
- 请确保游戏窗口分辨率为 16:9否则可能点击异常
- 脚本运行期间请勿手动干预,以免流程异常
- 由于是模拟点击,请保证材料的充足,避免造成加工错误的问题
## 结束
脚本执行完毕后会自动返回主界面并发送“烹饪脚本结束”通知。
---
如有问题或建议,欢迎反馈交流!
## 更新日志
### 1.320250709
- 优化灶台路径
- 优化灶台交互
- 优化未进入烹饪界面导致的一系列问题