铁匠铺更新 (#679)

* Create 1

* Rename repo/js/铁匠铺/assets/枫丹铁匠铺.json to repo/js/铁匠铺/assets/Pathing/枫丹铁匠铺.json

* Rename repo/js/铁匠铺/assets/璃月铁匠铺.json to repo/js/铁匠铺/assets/Pathing/璃月铁匠铺.json

* Rename repo/js/铁匠铺/assets/稻妻铁匠铺.json to repo/js/铁匠铺/assets/Pathing /稻妻铁匠铺.json

* Create 1

* Rename repo/js/铁匠铺/assets/蒙德铁匠铺.json to repo/js/铁匠铺/assets/Pathing/蒙德铁匠铺.json

* Delete repo/js/铁匠铺/assets/Pathing  directory

* Rename repo/js/铁匠铺/assets/须弥铁匠铺.json to repo/js/铁匠铺/assets/Pathing/须弥铁匠铺.json

* Delete repo/js/铁匠铺/assets/Pathing/1

* Add files via upload

* 修改为识图版本

将锻造矿物的选择方式更改为识图

* Add files via upload

* Delete repo/js/铁匠铺/assets/Picture/1

* Add files via upload
This commit is contained in:
呱呱z
2025-05-01 06:23:25 +08:00
committed by GitHub
parent 0d4eee9d5f
commit da34791039
14 changed files with 171 additions and 81 deletions

View File

@@ -45,4 +45,4 @@
"action_params": "" "action_params": ""
} }
] ]
} }

View File

@@ -72,4 +72,4 @@
"action_params": "" "action_params": ""
} }
] ]
} }

View File

@@ -45,4 +45,4 @@
"action_params": "" "action_params": ""
} }
] ]
} }

View File

@@ -54,4 +54,4 @@
"action_params": "" "action_params": ""
} }
] ]
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -1,85 +1,172 @@
(async function () { (async function () {
/// // 设置游戏基础参数
// 读取用户配置 setGameMetrics(1920, 1080, 1.25); // 设置编写脚本环境的游戏分辨率和DPI缩放
/// await genshin.returnMainUi(); // 返回主界面
let smithyName = settings.smithyName != undefined ? settings.smithyName : "须弥铁匠铺";
let ore = settings.ore != undefined ? settings.ore : '';
/// ///
// 定义函数 // 读取用户配置
/// ///
// 自动前往铁匠铺 let smithyName = settings.smithyName || "枫丹铁匠铺";
async function autoSmithy(smithyName) { let ore = settings.ore || "水晶块";
log.info(`自动前往 ${smithyName}`);
try { // 定义矿物名称和图片文件名的映射表
let filePath = `assets/${smithyName}.json`; const ingredientImageMap = {
await pathingScript.runFile(filePath); 萃凝晶: "assets/Picture/CondessenceCrystal.png",
} catch (error) {
log.error(`执行 ${smithyName} 路径时发生错误`); 紫晶块: "assets/Picture/AmethystLump.png",
log.error(error.toString()); 水晶块: "assets/Picture/CrystalChunk.png",
} 星银矿石: "assets/Picture/Starsilver.png",
白铁块: "assets/Picture/WhiteIronChunk.png",
铁块: "assets/Picture/IronChunk.png",
};
// Ore 映射为中文
const OreChineseMap = {
萃凝晶: "萃凝晶",
紫晶块: "紫晶块",
水晶块: "水晶块",
星银矿石: "星银矿石",
白铁块: "白铁块",
铁块: "铁块",
// 添加其他加工设置的中文映射
};
// 获取中文描述和图像路径
const processingKey = settings.ore || "水晶块";
const chineseDescription = OreChineseMap[processingKey];
const imagePath = ingredientImageMap[processingKey];
// 行列数的排列组合
const rows = [1, 2, 3]; // 行数
const cols = [1, 2, 3, 4, 5]; // 列数
const gridCoordinates = [];
// 计算每个行列组合的坐标
for (const row of rows) {
for (const col of cols) {
const ProcessingX = Math.round(135 + (col - 1) * 145);
const ProcessingY = Math.round(245 + (row - 1) * 170);
gridCoordinates.push({ row, col, x: ProcessingX, y: ProcessingY });
} }
}
//确认使用矿石 // 图像识别函数
function determineOre() { function recognizeImage(imagePath, x, y, searchWidth, searchHeight) {
if (ore == '水晶块') try {
{log.info("将使用 水晶块 锻造矿石");} let template = file.ReadImageMatSync(imagePath);
else if (ore == '紫晶块') let recognitionObject = RecognitionObject.TemplateMatch(
{log.info("将使用 紫晶块 锻造矿石");} template,
else if (ore == '萃凝晶') x,
{log.info("将使用 萃凝晶 锻造矿石");} y,
else searchWidth,
{log.info("无指定矿石,将使用 水晶块 锻造矿石");} searchHeight
);
// 设置识别阈值和通道
recognitionObject.threshold = 0.9; // 设置识别阈值为 0.9
recognitionObject.Use3Channels = true; // 使用三通道匹配
let result = captureGameRegion().find(recognitionObject);
return result.isExist() ? result : null;
} catch (error) {
log.error(`图像识别失败,路径: ${imagePath}, 错误: ${error.message}`);
return null;
} }
}
// 自动前往铁匠铺
async function autoSmithy(smithyName) {
log.info(`自动前往 ${smithyName}`);
try {
let filePath = `assets/Pathing/${smithyName}.json`;
await pathingScript.runFile(filePath);
} catch (error) {
log.error(`执行 ${smithyName} 路径时发生错误`);
log.error(error.toString());
}
}
const forgeOre = async function (smithyName) { // 确认使用矿石
await sleep(1000); function determineOre() {
keyPress("F"); await sleep(1000); // 开始交互 if (ore == "水晶块") {
await click(960, 600); await sleep(1000); // 跳过第一个对话 log.info("将使用 水晶块 锻造矿石");
await click(960, 600); await sleep(1000); // 跳过第一个对话 } else if (ore == "紫晶块") {
await click(1375, 500); await sleep(1000); log.info("将使用 紫晶块 锻造矿石");
await click(960, 600); await sleep(1000); // 跳过第二个对话 } else if (ore == "萃凝晶") {
await click(960, 600); await sleep(1000); // 跳过第二个对话 log.info("将使用 萃凝晶 锻造矿石");
log.info("已进入锻造界面,开始锻造"); } else {
log.info("无指定矿石,将使用 水晶块 锻造矿石");
}
}
// 锻造矿石操作
const forgeOre = async function (smithyName) {
await sleep(1000);
keyPress("F");
await sleep(1000); // 开始交互
await click(960, 600);
await sleep(1000); // 跳过第一个对话
await click(960, 600);
await sleep(1000); // 跳过第一个对话
await click(1375, 500);
await sleep(1000);
await click(960, 600);
await sleep(1000); // 跳过第二个对话
await click(960, 600);
await sleep(1000); // 跳过第二个对话
log.info("已进入锻造界面,准备锻造");
// 锻造领取
await click(520, 140);
await sleep(1000); // 选择锻造队列
await click(170, 1010);
await sleep(1000); // 领取全部
await click(960, 900);
await sleep(1000); // 确认
click(220, 150);
await sleep(1000); // 点击"配方"
determineOre(); determineOre();
await click(520, 140); await sleep(1000); // 选择锻造队列
await click(170, 1010); await sleep(1000); // 领取全部
await click(960, 900); await sleep(1000); // 确认
click(220, 150);await sleep(1000);// 点击"配方"
// 根据用户选择的矿石进行锻造 // 根据用户选择的矿石进行锻造
if (ore == '水晶块') if (!imagePath) {
{click(545, 290);} log.error(`未找到矿石图像路径: ${chineseDescription}`);
else if (ore == '紫晶块') } else {
{click(685, 290);} log.info(`开始识别矿石: ${chineseDescription}`);
else if (ore == '萃凝晶')
{click(120, 455);} // 左上角的偏移量
else { const scanOffset = { x: -35, y: -35 };
// 无指定矿石,将使用 水晶块 锻造矿石 let foundIngredient = false;
click(545, 290); for (const coordinate of gridCoordinates) {
const scanX = coordinate.x + scanOffset.x;
const scanY = coordinate.y + scanOffset.y;
const imageResult = recognizeImage(imagePath, scanX, scanY, 70, 70);
if (imageResult) {
log.info(`通过图像识别找到矿石: ${chineseDescription}`);
imageResult.click();
await sleep(2000); // 等待点击生效
foundIngredient = true;
// 点击“开始锻造”3次
click(1645, 1015);
await sleep(3000);
click(1645, 1015);
await sleep(3000);
click(1645, 1015);
await sleep(3000);
break; // 找到矿石后退出循环
}
}
if (!foundIngredient) {
log.error(`未能识别到矿石: ${chineseDescription}`);
}
} }
await sleep(1000);
// 按合成按钮3次
click(1645, 1015);
await sleep(4000);
click(1645, 1015);
await sleep(4000);
click(1645, 1015);
await sleep(4000);
log.info("锻造结束,退出界面");
// 退出锻造界面 // 退出锻造界面
click(1845, 45); log.info("锻造结束,退出界面");
await sleep(1000); keyPress("ESCAPE");
} };
/// await autoSmithy(smithyName); //寻路函数
// main await forgeOre(smithyName);
///
setGameMetrics(1920, 1080, 1);
await autoSmithy(smithyName);// 设置游戏窗口大小和DPI
await forgeOre(smithyName);
})(); })();

View File

@@ -1,13 +1,13 @@
{ {
"manifest_version": 1, "manifest_version": 1,
"name": "自动锻造魔矿", "name": "自动锻造魔矿",
"version": "1.0", "version": "1.1(2025.05.01版)",
"description": "自动选择铁匠铺和使用矿物去锻造魔矿。\n注1:默认选择枫丹铁匠铺,可选择其他地区铁匠铺。由于地图追踪功能不支持室内定位,所以不支持纳塔铁匠铺;\n注2:可选使用水晶矿(默认)、紫晶矿、萃凝晶。\n注3:需要每种矿至少能合成一次。\n鸣谢:寒露,蜜柑魚", "description": "自动选择铁匠铺和使用矿物去锻造魔矿。\n注1:默认选择枫丹铁匠铺,可选择其他地区铁匠铺。由于地图追踪功能不支持室内定位,所以不支持纳塔铁匠铺;\n注2:可选使用水晶矿(默认)、紫晶矿、萃凝晶。\n鸣谢:寒露,蜜柑魚",
"authors": [ "authors": [
{ {
"name": "呱呱z", "name": "呱呱z"
} }
], ],
"settings_ui": "settings.json", "settings_ui": "settings.json",
"main": "main.js" "main": "main.js"
} }

View File

@@ -14,10 +14,13 @@
{ {
"name": "ore", "name": "ore",
"type": "select", "type": "select",
"label": "锻造用矿(默认:水晶", "label": "锻造用矿(默认:水晶",
"options": [ "options": [
"水晶", "水晶",
"紫晶块", "紫晶块",
//"星银矿石",
//"白铁块",
//"铁块",
"萃凝晶" "萃凝晶"
] ]
} }