From 966b2bf983f868311c81af72344600a41a6ea0cd Mon Sep 17 00:00:00 2001 From: Jamis Date: Sat, 30 Aug 2025 21:45:35 +0800 Subject: [PATCH] AbundantOre 0.4 (#1776) --- repo/js/AbundantOre/README.md | 27 ++++----- repo/js/AbundantOre/main.js | 99 +++++++++++++++---------------- repo/js/AbundantOre/manifest.json | 2 +- repo/js/AbundantOre/settings.json | 27 ++++----- 4 files changed, 72 insertions(+), 83 deletions(-) diff --git a/repo/js/AbundantOre/README.md b/repo/js/AbundantOre/README.md index d2a770c15..e877f1bb0 100644 --- a/repo/js/AbundantOre/README.md +++ b/repo/js/AbundantOre/README.md @@ -2,31 +2,24 @@ 该脚本按挖矿路线的效率从高到低挖矿,记录矿产资源的刷新时间,自动规划挖矿路线,可选挖矿种类和挖矿区域。 -- 目前支持5种运行模式 - 1. 最速480矿 - - 刷满480个矿石即停止 +- 脚本将在启动后持续挖矿,直到以下三个条件中的**任一**条件满足 + 1. 挖矿的个数达到预定数值 + 1. 挖矿持续时间达到预定数值 + 1. 当前时间已过预定时间范围 - 1. 挖指定数目的矿 - - 需要在下面的输入框中填一个数字,代表要挖矿的个数 + 填写一个中国标准时间(CST)的时间范围或时间点。 - 1. 挖一段时间 - - 需要在下面的输入框中填一个数字,代表分钟数 + 例如填写时间`10:30`,如果我们在`7:00`开始挖矿,那么将在挖矿约3个半小时后停止。 - 1. 挖到某个时间点 - - 需要在下面的输入框中填一个停止挖矿的时间点,例如`3:55`、`23:30`等。若已过当前时间则代表第二天的该时间点,比如开始运行时间是`23:30`,填写`3:55`则表示一直挖矿到第二天的`3:55`。 - - (WIP)也可以填一个时间段,例如`22:30~3:55`。若不在此时间段内则不会开始挖矿。 + 例如填写时间`03:50`,如果我们在`22:00`开始挖矿,那么将在第二天`03:50`左右停止。 - 1. 挖所有矿 + 例如填写时间`23:00~03:50`,如果我们在`23:30`开始挖矿,那么将在第二天`03:50`左右停止;如果我们在`22:30`开始挖矿,脚本会因不在预设时间范围内立即停止。 - 顾名思义 +如果三个条件均未填写,脚本将在挖完所有的矿后停止。注意如果第一次运行这个脚本,这个过程可能持续十数个小时。 - 地面挖矿队伍中必须有诺艾尔,只挖水下的矿则无此限制。 - 矿产资源的刷新时间记录在脚本目录下`local/persistent_data.json`文件中,升级或重新安装BetterGI可能导致该记录丢失,请自行备份。 +- 如果勾选了`跳过所有战斗`选项,将不会运行所有需要打败怪物的挖矿路线。但角色仍可能在运行部分路线时被路过的怪物摸两下,请仍保证队伍有一定的生存能力。 ## 进阶使用 diff --git a/repo/js/AbundantOre/main.js b/repo/js/AbundantOre/main.js index c2b216ea9..d3f3886d4 100644 --- a/repo/js/AbundantOre/main.js +++ b/repo/js/AbundantOre/main.js @@ -367,56 +367,60 @@ async function main() { } } - const original_inventory = await get_inventory(); - const start_time = Date.now(); - var target_yield = null; - var target_running_minutes = null; - var run_until_hour = null; - var run_until_minute = null; - var run_until_unix_time = null; - switch (settings.arg_mode) { - case "最速480矿": - target_yield = 480; - break; - case "挖指定数目的矿(手动填写)": - target_yield = Number(settings.arg_amount); - break; - case "挖一段时间(手动填写)": - target_running_minutes = Number(settings.arg_amount); - break; - case "挖,直到某个时间(手动填写)": - [run_until_hour, run_until_minute] = settings.arg_amount.replace(":", ":").split(":").map(Number); - const current_unix_time = Date.now(); - const current_cst_time = (current_unix_time / 1000 + 8 * 3600) % 86400 / 3600; - var diff_hours = run_until_hour + run_until_minute / 60 - current_cst_time; - if (diff_hours < 0) { - diff_hours += 24; + const get_current_cst_hour = () => (Date.now() / 1000 + 8 * 3600) % 86400 / 3600; + var run_until_unix_time = settings.target_running_minutes ? (Date.now() + Number(settings.target_running_minutes) * 60 * 1000) : null; + if (settings.time_range) { + const time_range = settings.time_range.replace("~", "~").replace(":", ":"); + if (time_range.includes("~")) { + + const [ + [start_h, start_m], + [end_h, end_m] + ] = time_range.split("~").map(i => i.split(":").map(Number)); + const start_time = start_h + start_m / 60; + const end_time = end_h + end_m / 60; + const current_time = get_current_cst_hour(); + if (start_time < end_time && !(current_time >= start_time && current_time < end_time)) { + // format like 01:30~03:50 + log.info("不在允许运行的时间内,退出"); + return; } - run_until_unix_time = current_unix_time + diff_hours * 3600 * 1000; - break; - case "挖所有矿": - break; - default: - log.error("Unknown running mode"); - return; - } - log.info("已有水晶块{a}个,紫晶块{b}个,萃凝晶{c}个", original_inventory.crystal_chunks, original_inventory.amethyst_lumps, original_inventory.condessence_crystals); - if (target_yield !== null) { - log.info("将挖矿{a}个", target_yield); - } else if (target_running_minutes !== null) { - log.info("将挖矿{a}分钟", target_running_minutes); - } else if (run_until_hour !== null && run_until_minute !== null && run_until_unix_time !== null) { - const num_hours = (run_until_unix_time - Date.now()) / 1000 / 3600; - log.info("将挖矿到{h}:{m}({nh}小时后)", String(run_until_hour).padStart(2, "0"), String(run_until_minute).padStart(2, "0"), num_hours.toFixed(2)); - } else { - log.info("将标挖所有矿"); + if (start_time > end_time && current_time < start_time && current_time > end_time) { + // format like 23:30~4:00 + log.info("不在允许运行的时间内,退出"); + return; + } + const run_until_unix_time2 = ((end_time - current_time + 24) % 24) * 3600 * 1000 + Date.now(); + run_until_unix_time = Math.min(run_until_unix_time2, run_until_unix_time || Number.MAX_VALUE); + } else { + // format like 03:50 + const [end_h, end_m] = time_range.split(":").map(Number); + const end_time = end_h + end_m / 60; + const run_until_unix_time2 = (end_time - get_current_cst_hour() + 24) % 24 * 3600 * 1000 + Date.now(); + run_until_unix_time = Math.min(run_until_unix_time2, run_until_unix_time || Number.MAX_VALUE); + } } + const original_inventory = await get_inventory(); + log.info("已有水晶块{a}个,紫晶块{b}个,萃凝晶{c}个", original_inventory.crystal_chunks, original_inventory.amethyst_lumps, original_inventory.condessence_crystals); + const target_yield = settings.target_amount ? Math.floor(Number(settings.target_amount)) : null; + if (target_yield && !run_until_unix_time) { + log.info("将挖矿{a}个", target_yield); + } else if (!target_yield && run_until_unix_time) { + const running_minutes = Math.round((run_until_unix_time - Date.now()) / 60 / 1000); + log.info("将挖矿{a}分钟", running_minutes); + } else if (target_yield && run_until_unix_time) { + const running_minutes = Math.round((run_until_unix_time - Date.now()) / 60 / 1000); + log.info("将挖矿{a}个或{b}分钟,任何一个先发生", target_yield, running_minutes); + } else { + log.info("将持续挖矿"); + } + + const start_time = Date.now(); var accurate_yield = 0; var estimated_yield = 0; var cached_inventory_data = null; - var finished = false; const current_states = new Set(); while (!finished) { @@ -449,13 +453,6 @@ async function main() { finished = true; break; } - if (target_running_minutes !== null) { - const duration_mins = (Date.now() - start_time) / 1000 / 60; - if (duration_mins > target_running_minutes) { - finished = true; - break; - } - } if (run_until_unix_time !== null && Date.now() >= run_until_unix_time) { finished = true; break; @@ -487,4 +484,4 @@ async function main() { (async function() { await main(); -})(); +})(); \ No newline at end of file diff --git a/repo/js/AbundantOre/manifest.json b/repo/js/AbundantOre/manifest.json index a5b87bab6..6017a2da1 100644 --- a/repo/js/AbundantOre/manifest.json +++ b/repo/js/AbundantOre/manifest.json @@ -2,7 +2,7 @@ "bgi_version": "0.49.0", "manifest_version": 1, "name": "矿产资源批发", - "version": "0.3", + "version": "0.4", "description": "自动记录矿石刷新时间,优先选择效率最高的路线,支持按区域、种类、数量自动规划挖矿路线", "authors": [ { diff --git a/repo/js/AbundantOre/settings.json b/repo/js/AbundantOre/settings.json index d1339b455..ff7b98be0 100644 --- a/repo/js/AbundantOre/settings.json +++ b/repo/js/AbundantOre/settings.json @@ -1,25 +1,24 @@ [ { - "name": "arg_mode", - "type": "select", - "label": "运行模式👇", - "options": [ - "最速480矿", - "挖指定数目的矿(手动填写)", - "挖一段时间(手动填写)", - "挖,直到某个时间(手动填写)", - "挖所有矿" - ] + "name": "target_amount", + "type": "input-text", + "default": 480, + "label": "终止条件,满足任一条件即停止\n---------------------------------------------------------------\n 1. 挖矿的个数,空表示无限制👇" }, { - "name": "arg_amount", + "name": "target_running_minutes", "type": "input-text", - "label": "挖矿的数量(例如300)👇\n或持续的分钟数(例如30)👇\n或CST时间点(例如03:55或23:30)👇" + "label": " 2. 运行分钟数,如120,空表示无限制👇" + }, + { + "name": "time_range", + "type": "input-text", + "label": " 3. 只在此时间段内运行,如23:30~03:50,空表示无限制👇" }, { "name": "exclude_fights", "type": "checkbox", - "label": "跳过有战斗👇" + "label": "---------------------------------------------------------------\n跳过有战斗👇" }, { "name": "exclude_natlan", @@ -88,4 +87,4 @@ "type": "input-text", "label": "(仅多帐号适用)区分帐号的唯一ID" } -] +] \ No newline at end of file