js脚本:尘歌壶洞天百宝购买 (#389)

* 向右行走X毫秒

可以选择向右行走多少毫秒

* Add files via upload

* Add files via upload

* Delete 火希芙班.txt

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Delete 尘歌壶洞天百宝购买 directory

---------

Co-authored-by: 辉鸭蛋 <huiyadanli@gmail.com>
This commit is contained in:
迷路の龙王
2025-03-04 10:52:38 +08:00
committed by GitHub
parent 508613a139
commit 6364c13730
5 changed files with 240 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
{
"cloth": {
"x": 670,
"y": 170,
"_name": "布匹"
},
"transientResin": {
"x": 670,
"y": 290,
"_name": "须臾树脂"
},
"heroExp": {
"x": 670,
"y": 410,
"_name": "大英雄的经验"
},
"wandererExp": {
"x": 670,
"y": 530,
"_name": "流浪者的经验"
},
"magicOre": {
"x": 670,
"y": 650,
"_name": "精锻用魔矿"
},
"mora": {
"x": 670,
"y": 770,
"_name": "摩拉"
},
"sacredEssence": {
"x": 670,
"y": 870,
"_name": "祝圣精华"
},
"sacredOintment": {
"x": 670,
"y": 943,
"_name": "祝圣油膏"
}
}

View File

@@ -0,0 +1,117 @@
// main.js
(async function () {
// ==================== 初始化日志 ====================
log.info("======== 脚本启动 ========");
//设置脚本环境的游戏分辨率和DPI缩放
setGameMetrics(1920, 1080, 1.5);
let purchasedCount = 0; // 已成功购买的商品种类
function getDynamicY(y) {
return y - (purchasedCount * 120); // 每个已购商品使后续商品Y-20
}
// ==================== 2. 加载商品坐标 ====================
let items = {};
try {
const itemsText = file.readTextSync("items_coord.json");
items = JSON.parse(itemsText);
log.info("[成功] 商品坐标加载完成");
} catch (e) {
log.error("[致命错误] 商品坐标文件损坏,脚本终止");
return;
}
// ==================== 3. 定义固定按钮坐标 ====================
const FIXED_POS = {
buyCategory: { x: 140, y: 162 }, // 购买类目入口y洞天宝货162摆设,253摆设图纸344洞天珍物435洞天种物526木材617
exchangeBtn: { x: 1750, y: 1020 }, // 兑换按钮
maxQuantity: { x: 1180, y: 602 }, // 数量按钮x(7471180)
confirmBtn: { x: 1170, y: 780 }, // 确认兑换
closePopup: { x: 1700, y: 200 } // 关闭弹窗
};
// ==================== 5. 核心购买逻辑 ====================
async function purchaseItem(itemKey) {
const itemConfig = items[itemKey];
if (!itemConfig) {
log.error(`[配置错误] 未找到 ${itemKey} 的坐标配置`);
return;
}
//log.info(`自定义配置为 ${settings[itemKey]}`);
// 检查购买开关
if (settings[itemKey] !== "是") {
//log.info(`[跳过] ${itemConfig._name || itemKey}`);
return;
}
try {
log.info(`[开始] 正在购买 ${itemConfig._name}`);
// 1. 进入购买类目
click(FIXED_POS.buyCategory.x, FIXED_POS.buyCategory.y);
await sleep(500);
// 动态计算坐标
const targetY = getDynamicY(itemConfig.y);
// 2. 选择商品
click(itemConfig.x, targetY);
await sleep(500);
// 3. 点击兑换
click(FIXED_POS.exchangeBtn.x, FIXED_POS.exchangeBtn.y);
await sleep(500);
// 4. 选择最大数量
click(FIXED_POS.maxQuantity.x, FIXED_POS.maxQuantity.y);
await sleep(500);
// 5. 确认兑换
click(FIXED_POS.confirmBtn.x, FIXED_POS.confirmBtn.y);
await sleep(1000);
// 6. 关闭弹窗
click(FIXED_POS.closePopup.x, FIXED_POS.closePopup.y);
await sleep(500);
purchasedCount++;
log.info(`已购买商品数量: ${purchasedCount}`);
// 输出示例: "已购买商品数量: 3"
log.info(`[成功] ${itemConfig._name} 购买完成`);
} catch (e) {
log.error(`[失败] ${itemConfig._name} 操作异常: ${e.message}`);
// 异常时强制关闭弹窗
click(FIXED_POS.closePopup.x, FIXED_POS.closePopup.y);
await sleep(3000);
}
}
// ==================== 6. 主执行流程 ====================
try {
// 前置操作
keyPress("F");
await sleep(2000);
keyPress("F");
await sleep(1000);
click(1350, 655); // 打开洞天百宝界面
await sleep(500);
// 遍历所有商品
for (const itemKey of Object.keys(items)) {
await purchaseItem(itemKey);
await sleep(500); // 商品间操作间隔
}
} catch (e) {
log.error(`[全局异常] ${e.message}`);
} finally {
keyPress("Escape");
await sleep(2000);
click(1360, 810);//再见
await sleep(1000);
click(1360, 810);//退出对话
await sleep(1000);
log.info("======== 脚本执行结束 ========");
}
})();

View File

@@ -0,0 +1,14 @@
{
"manifest_version": 1,
"name": "尘歌壶洞天百宝购买",
"version": "1.0",
"bgi_version": "0.36.0",
"description": "用于每周一尘歌壶洞天百宝购买,可自定义配置购买须臾树脂,大英雄的经验,流浪者的经验,精锻用魔矿,摩拉,祝圣精华,祝圣油膏",
"authors": [
{
"name": "miludelongwang"
}
],
"settings_ui": "settings.json",
"main": "main.js"
}

View File

@@ -0,0 +1,9 @@
用于每周一尘歌壶洞天百宝购买,可自定义配置购买须臾树脂,大英雄的经验,流浪者的经验,精锻用魔矿,摩拉,祝圣精华,祝圣油膏
请于阿园附近(显示有对话交互)开始脚本
由于自定义配置表单7个之后不显示所以布匹的配置为空无法购买
后面可能会添加摆设,摆设图纸,洞天珍物,洞天种物,木材的购买
默认购买最大数量,暂时不支持自定义数量购买

View File

@@ -0,0 +1,58 @@
[
// {
// "name": "cloth",
// "type": "select",
// "label": "布匹",
// "options": ["是", "否"],
// "default": "否"
// },
{
"name": "transientResin",
"type": "select",
"label": "须臾树脂",
"options": ["是", "否"],
"default": "否"
},
{
"name": "heroExp",
"type": "select",
"label": "大英雄的经验",
"options": ["是", "否"],
"default": "否"
},
{
"name": "wandererExp",
"type": "select",
"label": "流浪者的经验",
"options": ["是", "否"],
"default": "否"
},
{
"name": "magicOre",
"type": "select",
"label": "精锻用魔矿",
"options": ["是", "否"],
"default": "否"
},
{
"name": "mora",
"type": "select",
"label": "摩拉",
"options": ["是", "否"],
"default": "否"
},
{
"name": "sacredEssence",
"type": "select",
"label": "祝圣精华",
"options": ["是", "否"],
"default": "否"
},
{
"name": "sacredOintment",
"type": "select",
"label": "祝圣油膏",
"options": ["是", "否"],
"default": "是"
}
]