mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-20 04:10:00 +08:00
更新JS脚本AbundantOre:改进异常检测逻辑 (#2442)
* improve anomaly detection logic * add newline * Add newline
This commit is contained in:
3
repo/js/AbundantOre/assets/flaky_end_paths.conf
Normal file
3
repo/js/AbundantOre/assets/flaky_end_paths.conf
Normal file
@@ -0,0 +1,3 @@
|
||||
07-水晶块-层岩巨渊·地下矿区-巨渊主矿区-西北-3个.json
|
||||
08-水晶块-层岩巨渊·地下矿区-临时主矿道-东-2个.json
|
||||
10-水晶块-层岩巨渊·地下矿区-临时主矿道-南-2个.json
|
||||
@@ -134,6 +134,25 @@ function load_statistics_data() {
|
||||
statistics = JSON.parse(file.readTextSync("assets/statistics.json")).data;
|
||||
}
|
||||
|
||||
const flaky_end_paths = new Set();
|
||||
|
||||
function load_flaky_end_paths() {
|
||||
let file_content = "";
|
||||
try {
|
||||
file_content = file.readTextSync("assets/flaky_end_paths.conf");
|
||||
} catch (error) {}
|
||||
for (let l of file_content.split("\n")) {
|
||||
l = l.trim();
|
||||
if (l.length === 0) {
|
||||
continue;
|
||||
}
|
||||
if (l.startsWith("//") || l.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
flaky_end_paths.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
async function flush_persistent_data() {
|
||||
await file.writeText("local/persistent_data.json", JSON.stringify(persistent_data, null, " "));
|
||||
}
|
||||
@@ -327,6 +346,7 @@ async function get_inventory() {
|
||||
}
|
||||
|
||||
let last_script_end_pos = [null, null];
|
||||
let last_script_normal_completion = true;
|
||||
|
||||
async function run_pathing_script(name, path_state_change, current_states) {
|
||||
path_state_change ||= {};
|
||||
@@ -391,6 +411,7 @@ async function run_pathing_script(name, path_state_change, current_states) {
|
||||
} catch (e) {}
|
||||
return [null, null];
|
||||
})();
|
||||
log.debug("Character current pos ({x},{y})", curr_pos[0], curr_pos[1]);
|
||||
let character_moved = false;
|
||||
if (curr_pos[0] === null || last_script_end_pos[0] === null) {
|
||||
character_moved = curr_pos[0] !== last_script_end_pos[0] || curr_pos[1] !== last_script_end_pos[1];
|
||||
@@ -400,15 +421,22 @@ async function run_pathing_script(name, path_state_change, current_states) {
|
||||
character_moved = dist > 5;
|
||||
log.debug("Character moved distance of {dist}", dist);
|
||||
}
|
||||
if (!character_moved && flaky_end_paths.has(name) && last_script_normal_completion) {
|
||||
log.debug("Assuming script successfully completed");
|
||||
character_moved = true;
|
||||
}
|
||||
last_script_end_pos = curr_pos;
|
||||
if (elapsed_time <= 5000) {
|
||||
in_memory_skip_tasks.add(name);
|
||||
log.warn("脚本运行时间小于5秒,可能发生了错误,不写记录");
|
||||
last_script_normal_completion = false;
|
||||
} else if (!character_moved) {
|
||||
in_memory_skip_tasks.add(name);
|
||||
log.warn("角色未移动,可能发生了错误,不写记录");
|
||||
last_script_normal_completion = false;
|
||||
} else {
|
||||
await mark_task_finished(name);
|
||||
last_script_normal_completion = true;
|
||||
}
|
||||
} else {
|
||||
throw new Error("Cancelled");
|
||||
@@ -430,6 +458,7 @@ async function main() {
|
||||
load_persistent_data();
|
||||
load_disabled_paths();
|
||||
load_statistics_data();
|
||||
load_flaky_end_paths();
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
// Run an empty pathing script to give BGI a chance to switch team if the user specifies one.
|
||||
await pathingScript.runFile("assets/empty_pathing.json");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"bgi_version": "0.50.0",
|
||||
"manifest_version": 1,
|
||||
"name": "矿产资源批发",
|
||||
"version": "0.23",
|
||||
"version": "0.24",
|
||||
"description": "自动记录矿石刷新时间,优先选择效率最高的路线,支持按区域、种类、数量自动规划挖矿路线",
|
||||
"authors": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user