铁匠铺1.40521新增矿石不足时自动选用备用选项 (#894)
* Delete repo/js/铁匠铺/readme(25.05.20).md * 铁匠铺1.40521新增矿石不足时自动选用备用选项
This commit is contained in:
@@ -2,20 +2,18 @@
|
||||
// 设置通知状态
|
||||
let notice = settings.notice ?? false;
|
||||
|
||||
|
||||
|
||||
// 设置游戏基础参数/初始化
|
||||
setGameMetrics(1920, 1080, 1.25); // 设置编写脚本环境的游戏分辨率和DPI缩放
|
||||
await genshin.returnMainUi(); // 返回主界面
|
||||
setGameMetrics(1920, 1080, 1.25);
|
||||
await genshin.returnMainUi();
|
||||
if (notice) {
|
||||
notification.send("自动锻造矿石脚本开始");
|
||||
}
|
||||
|
||||
///
|
||||
// 读取用户配置
|
||||
///
|
||||
let smithyName = settings.smithyName || "枫丹铁匠铺";
|
||||
let ore = settings.ore || "水晶块";
|
||||
let primaryOre = settings.ore || "水晶块";
|
||||
let secondaryOre = settings.secondaryOre || "萃凝晶"; // 新增备选矿物2
|
||||
let tertiaryOre = settings.tertiaryOre || "紫晶块"; // 新增备选矿物3
|
||||
|
||||
// 定义矿物名称和图片文件名的映射表
|
||||
const ingredientImageMap = {
|
||||
@@ -35,20 +33,13 @@
|
||||
星银矿石: "星银矿石",
|
||||
白铁块: "白铁块",
|
||||
铁块: "铁块",
|
||||
// 添加其他加工设置的中文映射
|
||||
};
|
||||
|
||||
// 获取中文描述和图像路径
|
||||
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 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(150 + (col - 1) * 145);
|
||||
@@ -62,11 +53,8 @@
|
||||
try {
|
||||
let template = file.ReadImageMatSync(imagePath);
|
||||
let recognitionObject = RecognitionObject.TemplateMatch(template, x, y, searchWidth, searchHeight);
|
||||
|
||||
// 设置识别阈值和通道
|
||||
recognitionObject.threshold = 0.85; // 设置识别阈值
|
||||
recognitionObject.Use3Channels = true; // 使用三通道匹配
|
||||
|
||||
recognitionObject.threshold = 0.85;
|
||||
recognitionObject.Use3Channels = true;
|
||||
let result = captureGameRegion().find(recognitionObject);
|
||||
return result.isExist() ? result : null;
|
||||
} catch (error) {
|
||||
@@ -81,9 +69,7 @@
|
||||
|
||||
// 自动前往铁匠铺
|
||||
async function autoSmithy(smithyName) {
|
||||
|
||||
log.info(`自动前往 ${smithyName}`);
|
||||
|
||||
try {
|
||||
let filePath = `assets/Pathing/${smithyName}.json`;
|
||||
await pathingScript.runFile(filePath);
|
||||
@@ -102,102 +88,131 @@
|
||||
}
|
||||
|
||||
// 确认使用矿石
|
||||
function determineOre() {
|
||||
let message;
|
||||
if (ore === "水晶块") {
|
||||
message = "将使用 水晶块 锻造矿石";
|
||||
} else if (ore === "紫晶块") {
|
||||
message = "将使用 紫晶块 锻造矿石";
|
||||
} else if (ore === "萃凝晶") {
|
||||
message = "将使用 萃凝晶 锻造矿石";
|
||||
} else {
|
||||
message = "无指定矿石,将使用 水晶块 锻造矿石";
|
||||
}
|
||||
function determineOre(oreType) {
|
||||
let message = `将使用 ${OreChineseMap[oreType]} 锻造矿石`;
|
||||
log.info(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
// 检查是否需要跳过备选矿物
|
||||
function shouldSkipOre(targetOre, compareOres) {
|
||||
return compareOres.includes(targetOre);
|
||||
}
|
||||
|
||||
// 尝试识别并锻造矿石
|
||||
async function tryForgeOre(oreType, skipCheckOres = []) {
|
||||
if (shouldSkipOre(oreType, skipCheckOres)) {
|
||||
if (notice) {
|
||||
notification.send(`跳过 ${OreChineseMap[oreType]},因为已存在于优先选择中`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const imagePath = ingredientImageMap[oreType];
|
||||
if (!imagePath) {
|
||||
if (notice) {
|
||||
notification.error(`未找到矿石图像路径: ${OreChineseMap[oreType]}`);
|
||||
} else {
|
||||
log.error(`未找到矿石图像路径: ${OreChineseMap[oreType]}`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
log.info(`开始识别矿石: ${OreChineseMap[oreType]}`);
|
||||
const scanOffset = { x: -35, y: -35 };
|
||||
|
||||
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) {
|
||||
imageResult.click();
|
||||
await sleep(2000);
|
||||
if (notice) {
|
||||
notification.send(`通过图像识别找到矿石: ${OreChineseMap[oreType]}`);
|
||||
} else {
|
||||
log.info(`通过图像识别找到矿石: ${OreChineseMap[oreType]}`);
|
||||
}
|
||||
|
||||
determineOre(oreType);
|
||||
// 点击"开始锻造"3次
|
||||
for (let i = 0; i < 3; i++) {
|
||||
await sleep(1000);
|
||||
click(1645, 1015);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (notice) {
|
||||
notification.error(`未能识别到矿石: ${OreChineseMap[oreType]}`);
|
||||
} else {
|
||||
log.error(`未能识别到矿石: ${OreChineseMap[oreType]}`);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 锻造矿石操作
|
||||
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); // 跳过第二个对话
|
||||
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); // 点击"配方"
|
||||
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();
|
||||
// 按优先级尝试识别矿石
|
||||
let forgeSuccess = false;
|
||||
|
||||
// 根据用户选择的矿石进行锻造
|
||||
if (!imagePath) {
|
||||
// 尝试主选矿石
|
||||
if (!forgeSuccess) {
|
||||
forgeSuccess = await tryForgeOre(primaryOre, []);
|
||||
}
|
||||
|
||||
// 如果主选矿石识别失败,尝试备选矿石2(跳过与主选相同的)
|
||||
if (!forgeSuccess) {
|
||||
forgeSuccess = await tryForgeOre(secondaryOre, [primaryOre]);
|
||||
}
|
||||
|
||||
// 如果备选矿石2也识别失败,尝试备选矿石3(跳过与主选和备选2相同的)
|
||||
if (!forgeSuccess) {
|
||||
forgeSuccess = await tryForgeOre(tertiaryOre, [primaryOre, secondaryOre]);
|
||||
}
|
||||
|
||||
// 如果所有矿石都识别失败
|
||||
if (!forgeSuccess) {
|
||||
if (notice) {
|
||||
notification.error(`未找到矿石图像路径: ${chineseDescription}`);
|
||||
notification.error("所有备选矿石都未能识别,结束锻造");
|
||||
} else {
|
||||
log.error(`未找到矿石图像路径: ${chineseDescription}`);
|
||||
}
|
||||
} else {
|
||||
log.info(`开始识别矿石: ${chineseDescription}`);
|
||||
|
||||
// 左上角的偏移量
|
||||
const scanOffset = { x: -35, y: -35 };
|
||||
let foundIngredient = false;
|
||||
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) {
|
||||
imageResult.click();
|
||||
await sleep(2000); // 等待点击生效
|
||||
if (notice) {
|
||||
notification.send(`通过图像识别找到矿石: ${chineseDescription}`);
|
||||
} else {
|
||||
log.info(`通过图像识别找到矿石: ${chineseDescription}`);
|
||||
}
|
||||
foundIngredient = true;
|
||||
|
||||
// 点击“开始锻造”3次
|
||||
{
|
||||
await sleep(1000); click(1645, 1015);
|
||||
await sleep(1000); click(1645, 1015);
|
||||
await sleep(1000); click(1645, 1015);}
|
||||
break; // 找到矿石后退出循环
|
||||
}
|
||||
}
|
||||
if (!foundIngredient) {
|
||||
if (notice) {
|
||||
notification.error(`未能识别到矿石: ${chineseDescription}`);
|
||||
} else {
|
||||
log.error(`未能识别到矿石: ${chineseDescription}`);
|
||||
}
|
||||
log.error("所有备选矿石都未能识别,结束锻造");
|
||||
}
|
||||
}
|
||||
|
||||
// 退出锻造界面
|
||||
await click(520, 140); await sleep(1000); // 选择锻造队列
|
||||
await click(520, 140); await sleep(1000);
|
||||
if (notice) {
|
||||
notification.send("锻造结束,退出界面");
|
||||
} else {
|
||||
log.info("锻造结束,退出界面");
|
||||
}
|
||||
keyPress("ESCAPE");
|
||||
await genshin.returnMainUi();
|
||||
};
|
||||
|
||||
await autoSmithy(smithyName); // 寻路函数
|
||||
await forgeOre(smithyName); // 锻造函数
|
||||
await genshin.returnMainUi(); // 返回主界面
|
||||
|
||||
{ keyDown("S"); await sleep(1000); keyUp("S"); await sleep(1000); } // 后退两步
|
||||
await autoSmithy(smithyName);
|
||||
await forgeOre(smithyName);
|
||||
await genshin.returnMainUi();
|
||||
{ keyDown("S"); await sleep(1000); keyUp("S"); await sleep(1000); }
|
||||
|
||||
if (notice) {
|
||||
notification.send("自动锻造矿石脚本结束");
|
||||
}
|
||||
})();
|
||||
})();
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "自动锻造魔矿",
|
||||
"version": "1.5(2025.05.20版)",
|
||||
"version": "1.40521(2025.05.21版)",
|
||||
"bgi_version": "0.44.0",
|
||||
"description": "自动选择铁匠铺和使用矿物去锻造精锻矿。\n \n使用前请阅读“readme”文件。 \n\n---更新说明--- \n- 修复锻造次数不足3次的问题",
|
||||
"description": "自动选择铁匠铺和使用矿物去锻造精锻矿。\n \n使用前请阅读“readme”文件。 \n---更新说明--- \n- 新增矿石不足时自动选择备用选矿",
|
||||
"tags": ["铁匠铺", "锻造", "精锻用矿"],
|
||||
"authors": [
|
||||
{
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
// ==UserScript==
|
||||
// @name 自动锻造魔矿脚本
|
||||
// @version 1.5
|
||||
// @description 自动前往铁匠铺并锻造魔矿,通过识图模式自动选择矿石
|
||||
// @author 呱呱z
|
||||
// @match 原神版本:5.6;BGI 版本:0.45.1
|
||||
// ==/UserScript==
|
||||
|
||||
/**
|
||||
* === 重要免责声明 ===
|
||||
* 1. 使用风险
|
||||
* - 本脚本为开源学习项目,禁止用于商业用途或违反游戏条款的行为。
|
||||
* - 滥用可能导致游戏账号封禁,开发者不承担任何直接或间接责任。
|
||||
*
|
||||
* 2. 责任限制
|
||||
* - 本脚本按“现状”提供,不承诺兼容性、安全性或功能完整性。
|
||||
* - 因使用本脚本导致的账号、数据、设备损失,开发者概不负责。
|
||||
*
|
||||
* 3. 禁止条款
|
||||
* - 严禁逆向工程、恶意篡改或用于外挂等非法用途。
|
||||
* - 如游戏运营商提出要求,开发者保留随时停止维护的权利。
|
||||
*
|
||||
* 使用即表示您已阅读并同意上述条款。
|
||||
*
|
||||
* Last Updated: 2025-05-12
|
||||
*/
|
||||
|
||||
# 自动锻造魔矿脚本
|
||||
|
||||
## 简介
|
||||
本脚本可自动前往铁匠铺并利用识图模式选择需要的矿石锻造魔矿。
|
||||
|
||||
## 文件结构
|
||||
- **main.js**:负责核心业务逻辑,包括前往铁匠铺和执行锻造任务。
|
||||
- **manifest.json**:脚本配置文件,记录基本信息和设置。
|
||||
- **settings.json**:用户配置文件,用于选择目标铁匠铺和指定矿石。
|
||||
|
||||
## 使用方法
|
||||
1. 将脚本添加至调度器。
|
||||
2. 右键点击脚本以修改JS自定义配置。
|
||||
3. 在配置文件中选择目标城市的铁匠铺(默认选择枫丹铁匠铺),并设定所需矿石(默认:水晶矿)。
|
||||
- 注意:由于地图追踪功能尚不支持室内定位,故纳塔铁匠铺不可用。
|
||||
- 可选矿石:
|
||||
- 默认:水晶矿
|
||||
- 其他:紫晶矿、萃凝晶
|
||||
- 如需使用“星银矿石”、“白铁块”或“铁块”,请打开 `settings.json`,删除对应矿石前的 `//` 注释后保存配置。
|
||||
|
||||
## 后言
|
||||
本脚本目前处于测试阶段,欢迎反馈问题至 QQ:1765137214。
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 1.5(2025.05.20)
|
||||
- 修复锻造次数不足3次的问题
|
||||
|
||||
### 1.4(2025.05.20)
|
||||
- 新增通知功能
|
||||
|
||||
### 1.3(2025.05.15)
|
||||
- 修复选择“萃凝晶”时无法识别的问题
|
||||
- 仓库内新增标签。
|
||||
|
||||
### 1.2(2025.05.12)
|
||||
- 修复选择“萃凝晶”时无法识别的 bug
|
||||
|
||||
### 1.1(2025.05.01)
|
||||
- 优化矿石选取方式,改用识图模式
|
||||
77
repo/js/铁匠铺/readme(25.05.21).md
Normal file
77
repo/js/铁匠铺/readme(25.05.21).md
Normal file
@@ -0,0 +1,77 @@
|
||||
// ==UserScript==
|
||||
// @name 自动锻造魔矿脚本
|
||||
// @version 1.40521
|
||||
// @description 自动前往铁匠铺并锻造魔矿,通过识图模式自动选择矿石
|
||||
// @author 呱呱 z
|
||||
// @match 原神版本:5.6;BGI 版本:0.45.1
|
||||
// ==/UserScript==
|
||||
|
||||
/\*\*
|
||||
|
||||
- === 重要免责声明 ===
|
||||
- 1. 使用风险
|
||||
- - 本脚本为开源学习项目,禁止用于商业用途或违反游戏条款的行为。
|
||||
- - 滥用可能导致游戏账号封禁,开发者不承担任何直接或间接责任。
|
||||
-
|
||||
- 2. 责任限制
|
||||
- - 本脚本按“现状”提供,不承诺兼容性、安全性或功能完整性。
|
||||
- - 因使用本脚本导致的账号、数据、设备损失,开发者概不负责。
|
||||
-
|
||||
- 3. 禁止条款
|
||||
- - 严禁逆向工程、恶意篡改或用于外挂等非法用途。
|
||||
- - 如游戏运营商提出要求,开发者保留随时停止维护的权利。
|
||||
-
|
||||
- 使用即表示您已阅读并同意上述条款。
|
||||
-
|
||||
- Last Updated: 2025-05-12
|
||||
\*/
|
||||
|
||||
# 自动锻造魔矿脚本
|
||||
|
||||
## 简介
|
||||
|
||||
本脚本可自动前往铁匠铺并利用识图模式选择需要的矿石锻造魔矿。
|
||||
|
||||
## 文件结构
|
||||
|
||||
- **main.js**:负责核心业务逻辑,包括前往铁匠铺和执行锻造任务。
|
||||
- **manifest.json**:脚本配置文件,记录基本信息和设置。
|
||||
- **settings.json**:用户配置文件,用于选择目标铁匠铺和指定矿石。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 将脚本添加至调度器。
|
||||
2. 右键点击脚本以修改 JS 自定义配置。
|
||||
3. 在配置文件中选择目标城市的铁匠铺(默认选择枫丹铁匠铺),并设定所需矿石(默认:水晶矿)。
|
||||
- 注意:由于地图追踪功能尚不支持室内定位,故纳塔铁匠铺不可用。
|
||||
- 可选矿石:
|
||||
- 默认:水晶矿
|
||||
- 其他:紫晶矿、萃凝晶
|
||||
- 如需使用“星银矿石”、“白铁块”或“铁块”,请打开 `settings.json`,删除对应矿石前的 `//` 注释后保存配置。
|
||||
|
||||
## 后言
|
||||
|
||||
本脚本目前处于测试阶段,欢迎反馈问题至 QQ:1765137214。
|
||||
|
||||
## 更新日志
|
||||
|
||||
### 1.40521(2025.05.21)
|
||||
|
||||
- 新增矿石不足时自动选择备用选矿
|
||||
|
||||
### 1.4(2025.05.20)
|
||||
|
||||
- 新增通知功能
|
||||
|
||||
### 1.3(2025.05.15)
|
||||
|
||||
- 修复选择“萃凝晶”时无法识别的问题
|
||||
- 仓库内新增标签。
|
||||
|
||||
### 1.2(2025.05.12)
|
||||
|
||||
- 修复选择“萃凝晶”时无法识别的 bug
|
||||
|
||||
### 1.1(2025.05.01)
|
||||
|
||||
- 优化矿石选取方式,改用识图模式
|
||||
@@ -19,14 +19,40 @@
|
||||
{
|
||||
"name": "ore",
|
||||
"type": "select",
|
||||
"label": "锻造用矿(默认:水晶块)",
|
||||
"label": "锻造用矿(默认:水晶块)\n当矿石不足时依次使用",
|
||||
"options": [
|
||||
"水晶块",
|
||||
"紫晶块",
|
||||
"萃凝晶",
|
||||
"星银矿石",
|
||||
//"白铁块",
|
||||
//"铁块",
|
||||
"紫晶块"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "secondaryOre",
|
||||
"type": "select",
|
||||
"label": "备用矿石1(默认:萃凝晶)",
|
||||
"options": [
|
||||
"水晶块",
|
||||
"萃凝晶",
|
||||
//"星银矿石",
|
||||
//"白铁块",
|
||||
//"铁块",
|
||||
"萃凝晶"
|
||||
"紫晶块"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "tertiaryOre",
|
||||
"type": "select",
|
||||
"label": "备用矿石2(默认:紫晶块)",
|
||||
"options": [
|
||||
"水晶块",
|
||||
"萃凝晶",
|
||||
//"星银矿石",
|
||||
//"白铁块",
|
||||
//"铁块",
|
||||
"紫晶块"
|
||||
]
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user