-
Notifications
You must be signed in to change notification settings - Fork 23
Add Revive Loop Watchdog and Death Rate Profile Switcher #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d292c80
3430408
769dfaf
0b82a1d
07160e5
fd9adcc
8b28ba7
2a37a41
4176885
992c1bd
78ebaaa
f6915ef
86d1473
9f1d4dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| package dev.shared.halizeur.revive_loop_watchdog; | ||
|
|
||
| import eu.darkbot.api.config.ConfigSetting; | ||
| import eu.darkbot.api.config.annotations.Configuration; | ||
| import eu.darkbot.api.config.annotations.Number; | ||
| import eu.darkbot.api.extensions.Behavior; | ||
| import eu.darkbot.api.extensions.Configurable; | ||
| import eu.darkbot.api.extensions.Feature; | ||
| import eu.darkbot.api.managers.BotAPI; | ||
| import eu.darkbot.api.managers.HeroAPI; | ||
| import eu.darkbot.api.managers.RepairAPI; | ||
|
|
||
| import java.time.Instant; | ||
| import java.time.Duration; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.time.ZoneId; | ||
|
|
||
| @Feature(name = "Revive Loop Watchdog", description = | ||
| "Detects the stuck-on-revive refresh loop bug, pauses the bot, and auto-resumes once it recovers.", | ||
| enabledByDefault = true) | ||
| public class ReviveLoopWatchdog implements Behavior, Configurable<ReviveLoopWatchdog.Config> { | ||
|
|
||
| private static final DateTimeFormatter TIME_FORMAT = | ||
| DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss").withZone(ZoneId.systemDefault()); | ||
|
|
||
| private final HeroAPI hero; | ||
| private final BotAPI bot; | ||
| private final RepairAPI repair; | ||
|
|
||
| private Config config = new Config(); | ||
|
|
||
| private Instant deadSince = null; | ||
| private boolean pausedByWatchdog = false; | ||
|
|
||
| public ReviveLoopWatchdog(HeroAPI hero, BotAPI bot, RepairAPI repair) { | ||
| this.hero = hero; | ||
| this.bot = bot; | ||
| this.repair = repair; | ||
| } | ||
|
|
||
| @Configuration("revive_loop_watchdog.config") | ||
| public static class Config { | ||
| @Number(min = 1, max = 30, step = 1) | ||
| public int STUCK_THRESHOLD_MINUTES = 3; | ||
|
Check warning on line 44 in src/main/java/dev/shared/halizeur/revive_loop_watchdog/ReviveLoopWatchdog.java
|
||
| } | ||
|
|
||
| @Override | ||
| public void setConfig(ConfigSetting<Config> config) { | ||
| this.config = config.getValue(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onTickBehavior() { | ||
| deadSince = null; | ||
| } | ||
|
|
||
| @Override | ||
| public void onStoppedBehavior() { | ||
| if (pausedByWatchdog) { | ||
| checkForRecovery(); | ||
| return; | ||
| } | ||
|
|
||
| if (repair.isDestroyed()) { | ||
| if (deadSince == null) { | ||
| deadSince = Instant.now(); | ||
| } | ||
|
|
||
| long stuckMinutes = Duration.between(deadSince, Instant.now()).toMinutes(); | ||
| if (stuckMinutes >= config.STUCK_THRESHOLD_MINUTES) { | ||
| pauseForStuckLoop(stuckMinutes); | ||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
| } | ||
| } else { | ||
| deadSince = null; | ||
| } | ||
| } | ||
|
|
||
| private void pauseForStuckLoop(long stuckMinutes) { | ||
| if (!bot.isRunning()) { | ||
| // Bot is already stopped for some other reason (e.g. you paused it manually) - | ||
| // not our doing, so don't take ownership of it or auto-resume it later. | ||
| return; | ||
| } | ||
|
|
||
| log("Ship has been destroyed for " + stuckMinutes + "+ minute(s) with no successful revive. " + | ||
| "Assuming the known DarkBot stuck-on-revive refresh loop bug. Pausing bot to stop wasted refreshing."); | ||
| bot.setRunning(false); | ||
| pausedByWatchdog = true; | ||
| } | ||
|
|
||
| private void checkForRecovery() { | ||
| boolean loaded = hero.getLocationInfo() != null && hero.getLocationInfo().isInitialized(); | ||
| boolean alive = !repair.isDestroyed(); | ||
|
|
||
| if (loaded && alive) { | ||
| log("Game has finished loading and ship is confirmed alive again. Resuming bot automatically."); | ||
| pausedByWatchdog = false; | ||
| deadSince = null; | ||
| bot.setRunning(true); | ||
| } | ||
| } | ||
|
|
||
| private void log(String message) { | ||
| System.out.println("[" + TIME_FORMAT.format(Instant.now()) + " | ReviveLoopWatchdog] " + message); | ||
|
Check warning on line 104 in src/main/java/dev/shared/halizeur/revive_loop_watchdog/ReviveLoopWatchdog.java
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.