diff --git a/repo/js/FollowsPet/README.md b/repo/js/FollowsPet/README.md new file mode 100644 index 00000000..f3ca53d0 --- /dev/null +++ b/repo/js/FollowsPet/README.md @@ -0,0 +1,22 @@ +# 装备或卸下跟随宠物 + +## 使用说明 + +### 装备跟随宠物 + +1. 修改自定义配置中模式为:`装备` +2. 修改自定义配置中宠物名称 +3. 执行脚本即可 + +### 卸下跟随宠物 + +1. 修改自定义配置中模式为:`卸下` +2. 执行脚本即可 + +## 注意事项 + ++ 请在原神分辨率为 1920x1080 下使用该脚本。 ++ 未支持的宠物(作者未拥有(lll¬ω¬)),待有缘人补充。 + + 迷你仙灵·薄红 + + 迷你仙灵·露草 + + 嫣朵拉 \ No newline at end of file diff --git a/repo/js/FollowsPet/assets/brilliance.png b/repo/js/FollowsPet/assets/brilliance.png new file mode 100644 index 00000000..4df9e052 Binary files /dev/null and b/repo/js/FollowsPet/assets/brilliance.png differ diff --git a/repo/js/FollowsPet/assets/curcuma.png b/repo/js/FollowsPet/assets/curcuma.png new file mode 100644 index 00000000..42b3be0d Binary files /dev/null and b/repo/js/FollowsPet/assets/curcuma.png differ diff --git a/repo/js/FollowsPet/assets/damasked_device.png b/repo/js/FollowsPet/assets/damasked_device.png new file mode 100644 index 00000000..d72273f2 Binary files /dev/null and b/repo/js/FollowsPet/assets/damasked_device.png differ diff --git a/repo/js/FollowsPet/assets/firstborn_firesprite.png b/repo/js/FollowsPet/assets/firstborn_firesprite.png new file mode 100644 index 00000000..1328d277 Binary files /dev/null and b/repo/js/FollowsPet/assets/firstborn_firesprite.png differ diff --git a/repo/js/FollowsPet/assets/itty_bitty_octobaby.png b/repo/js/FollowsPet/assets/itty_bitty_octobaby.png new file mode 100644 index 00000000..d96a265c Binary files /dev/null and b/repo/js/FollowsPet/assets/itty_bitty_octobaby.png differ diff --git a/repo/js/FollowsPet/assets/liloupar.png b/repo/js/FollowsPet/assets/liloupar.png new file mode 100644 index 00000000..3c1536c5 Binary files /dev/null and b/repo/js/FollowsPet/assets/liloupar.png differ diff --git a/repo/js/FollowsPet/assets/moss.png b/repo/js/FollowsPet/assets/moss.png new file mode 100644 index 00000000..69cc7562 Binary files /dev/null and b/repo/js/FollowsPet/assets/moss.png differ diff --git a/repo/js/FollowsPet/assets/shiki_koshou.png b/repo/js/FollowsPet/assets/shiki_koshou.png new file mode 100644 index 00000000..80c2bdcf Binary files /dev/null and b/repo/js/FollowsPet/assets/shiki_koshou.png differ diff --git a/repo/js/FollowsPet/assets/sorush.png b/repo/js/FollowsPet/assets/sorush.png new file mode 100644 index 00000000..cd017cb8 Binary files /dev/null and b/repo/js/FollowsPet/assets/sorush.png differ diff --git a/repo/js/FollowsPet/assets/viola.png b/repo/js/FollowsPet/assets/viola.png new file mode 100644 index 00000000..8f1d1ecb Binary files /dev/null and b/repo/js/FollowsPet/assets/viola.png differ diff --git a/repo/js/FollowsPet/index.js b/repo/js/FollowsPet/index.js new file mode 100644 index 00000000..b1e8e12e --- /dev/null +++ b/repo/js/FollowsPet/index.js @@ -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(); + } +})(); diff --git a/repo/js/FollowsPet/manifest.json b/repo/js/FollowsPet/manifest.json new file mode 100644 index 00000000..6e5f7c56 --- /dev/null +++ b/repo/js/FollowsPet/manifest.json @@ -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" + } + ] +} \ No newline at end of file diff --git a/repo/js/FollowsPet/settings.json b/repo/js/FollowsPet/settings.json new file mode 100644 index 00000000..68c566ff --- /dev/null +++ b/repo/js/FollowsPet/settings.json @@ -0,0 +1,31 @@ +[ + { + "name": "mode", + "type": "select", + "label": "模式", + "options": [ + "装备", + "卸下" + ], + "default": "装备" + }, + { + "name": "name", + "type": "select", + "label": "宠物名称(装备模式可用)", + "options": [ + "", + "迷你仙灵·苔绿", + "迷你仙灵·紫苑", + "迷你仙灵·郁金", + "迷你仙灵·璨光", + "魔瓶镇灵·利露帕尔", + "斯露莎", + "初诞灵焰", + "柔柔小章", + "缥锦机关·留云", + "「式小将」" + ], + "default": "" + } +] \ No newline at end of file