Skip to content

Commit

Permalink
fix: Make miner wait on cooldown before extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Sep 25, 2023
1 parent 93c2f32 commit 7b95300
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/cli/lib/behavior/behavior.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class MultiJob {
DateTime Function() getNow = defaultGetNow,
}) async {
for (var i = 0; i < 10; i++) {
shipInfo(ship, '$name ${state.jobIndex}');
shipDetail(ship, '$name ${state.jobIndex}');
jobAssert(
state.jobIndex >= 0 && state.jobIndex < jobFunctions.length,
'Invalid job index ${state.jobIndex}',
Expand All @@ -161,12 +161,12 @@ class MultiJob {
caches,
ship,
);
shipInfo(ship, '$name ${state.jobIndex} $result');
shipDetail(ship, '$name ${state.jobIndex} $result');
if (result.isComplete) {
state.jobIndex++;
if (state.jobIndex >= jobFunctions.length) {
state.isComplete = true;
shipInfo(ship, '$name complete!');
shipDetail(ship, '$name complete!');
return null;
}
}
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/lib/behavior/miner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,14 @@ Future<JobResult> doMineJob(
// Both surveying and mining require being undocked.
await undockIfNeeded(api, caches.ships, ship);

// We need to be off cooldown to continue.
final expiration = ship.cooldown.expiration;
if (expiration != null && expiration.isAfter(getNow())) {
final duration = expiration.difference(getNow());
shipDetail(ship, 'Waiting ${approximateDuration(duration)} on cooldown.');
return JobResult.wait(expiration);
}

// See if we have a good survey to mine.
final maybeSurvey = await surveyWorthMining(
db,
Expand Down

0 comments on commit 7b95300

Please sign in to comment.