JS 脚本: 装备或卸下跟随宠物 (#1081)

This commit is contained in:
ftnfurina
2025-06-13 17:33:59 +08:00
committed by GitHub
parent 1ccca8fa5c
commit 0dc55fe4c4
14 changed files with 205 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
# 装备或卸下跟随宠物
## 使用说明
### 装备跟随宠物
1. 修改自定义配置中模式为:`装备`
2. 修改自定义配置中宠物名称
3. 执行脚本即可
### 卸下跟随宠物
1. 修改自定义配置中模式为:`卸下`
2. 执行脚本即可
## 注意事项
+ 请在原神分辨率为 1920x1080 下使用该脚本。
+ 未支持的宠物(作者未拥有(lll¬ω¬)),待有缘人补充。
+ 迷你仙灵·薄红
+ 迷你仙灵·露草
+ 嫣朵拉

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

139
repo/js/FollowsPet/index.js Normal file
View File

@@ -0,0 +1,139 @@
// 最多尝试 2 次拖动屏幕
const DRAG_SCREEN_MAX = 2;
// 宠物与模板的对应关系
const PETS = [
// TODO: 作者未拥有(lll¬ω¬),待有缘人补充
// { name: "迷你仙灵·薄红", file: "" },
// { name: "迷你仙灵·露草", file: "" },
// { name: "嫣朵拉", file: "" },
{ name: '迷你仙灵·苔绿', file: 'assets/moss.png' },
{ name: '迷你仙灵·紫苑', file: 'assets/viola.png' },
{ name: '迷你仙灵·郁金', file: 'assets/curcuma.png' },
{ name: '迷你仙灵·璨光', file: 'assets/brilliance.png' },
{ name: '魔瓶镇灵·利露帕尔', file: 'assets/liloupar.png' },
{ name: '斯露莎', file: 'assets/sorush.png' },
{ name: '初诞灵焰', file: 'assets/firstborn_firesprite.png' },
{ name: '柔柔小章', file: 'assets/itty_bitty_octobaby.png' },
{ name: '缥锦机关·留云', file: 'assets/damasked_device.png' },
{ name: '「式小将」', file: 'assets/shiki_koshou.png' },
];
/**
* 垂直拖动屏幕
* @param x 初始 x 坐标
* @param yStart 起始 y 坐标
* @param yEnd 终点 y 坐标
* @param step 步长
*/
async function verticalDragScreen(x, yStart, yEnd, step = 20) {
moveMouseTo(x, yStart);
await sleep(100);
leftButtonDown();
const yStep = (yEnd - yStart) / step;
for (let i = 1; i <= step; i++) {
await sleep(50);
moveMouseTo(x, Math.floor(yStart + yStep * i));
}
await sleep(1000);
leftButtonUp();
}
/**
* 装备宠物
* @param pet 宠物
*/
async function equipPet(pet) {
// 宠物识别 低精度
const petRo = RecognitionObject.templateMatch(file.readImageMatSync(pet.file));
petRo.threshold = 0.9;
// 开启 3 通道识别区分 迷你仙灵 系列
petRo.use3Channels = true;
for (let i = 0; i < DRAG_SCREEN_MAX; i++) {
// 移开鼠标
moveMouseTo(0, 0);
await sleep(100);
const gameRegion = captureGameRegion();
const petRegion = gameRegion.find(petRo);
if (!petRegion.isExist()) {
// 未找到宠物,尝试拖动屏幕
await verticalDragScreen(1200, 842, 117);
continue;
}
petRegion.click();
await sleep(1000);
// 提升精度
petRo.threshold = 0.97;
const equipRegion = gameRegion.find(petRo);
if (!equipRegion.isExist()) {
// 装备宠物
click(1690, 1015);
await sleep(1000);
}
return log.info(`已装备:${pet.name}`);
}
throw new Error(`未识别到宠物:${pet.name}`);
}
/**
* 卸下宠物
*/
async function removePet() {
const pets = PETS.map(pet => {
const ro = RecognitionObject.templateMatch(file.readImageMatSync(pet.file));
ro.threshold = 0.97;
ro.use3Channels = true;
return { ...pet, ro };
});
for (let i = 0; i < DRAG_SCREEN_MAX; i++) {
// 移开鼠标
moveMouseTo(0, 0);
await sleep(100);
const gameRegion = captureGameRegion();
for (const pet of pets) {
const petRegion = gameRegion.find(pet.ro);
if (!petRegion.isExist()) {
continue;
}
petRegion.click();
await sleep(1000);
click(1690, 1015);
await sleep(1000);
return log.info(`已卸下宠物:${pet.name}`);
}
await verticalDragScreen(1200, 842, 117);
}
log.warn('未找到装备中的宠物');
}
(async () => {
try {
const name = settings.name;
const mode = settings.mode;
if (!name && mode === '装备') {
throw new Error('请先设置宠物名称');
}
if (mode === '装备') {
log.info(`尝试装备:${name}`);
}
else if (mode === '卸下') {
log.info('尝试卸下宠物');
}
// 切回主界面
await genshin.returnMainUi();
// 打开背包
keyPress('VK_B');
await sleep(1000);
// 移动到小道具栏
moveMouseTo(1055, 50);
leftButtonClick();
await sleep(1000);
if (mode === '装备') {
await equipPet(PETS.find(pet => pet.name === name));
}
else if (mode === '卸下') {
await removePet();
}
}
catch (error) {
log.error(error.message);
}
finally {
await genshin.returnMainUi();
}
})();

View File

@@ -0,0 +1,13 @@
{
"name": "装备或卸下跟随宠物",
"description": "带上你的宠物,一起冒险吧!\nPS请在原神分辨率为 1920x1080 下使用该脚本。",
"version": "0.0.1",
"main": "index.js",
"settings_ui": "settings.json",
"authors": [
{
"name": "ftnfurina",
"link": "https://github.com/ftnfurina"
}
]
}

View File

@@ -0,0 +1,31 @@
[
{
"name": "mode",
"type": "select",
"label": "模式",
"options": [
"装备",
"卸下"
],
"default": "装备"
},
{
"name": "name",
"type": "select",
"label": "宠物名称(装备模式可用)",
"options": [
"",
"迷你仙灵·苔绿",
"迷你仙灵·紫苑",
"迷你仙灵·郁金",
"迷你仙灵·璨光",
"魔瓶镇灵·利露帕尔",
"斯露莎",
"初诞灵焰",
"柔柔小章",
"缥锦机关·留云",
"「式小将」"
],
"default": ""
}
]