From 36cc33f9e96a38ecea98ac8d26275b4828347d80 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 1 Jul 2023 23:13:13 +0200 Subject: Moved the nodejs agent to its own subfolder to make room for my haskell agent --- nodejs/automation/mining.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 nodejs/automation/mining.js (limited to 'nodejs/automation/mining.js') diff --git a/nodejs/automation/mining.js b/nodejs/automation/mining.js new file mode 100644 index 0000000..f35af36 --- /dev/null +++ b/nodejs/automation/mining.js @@ -0,0 +1,34 @@ +import * as dbShips from '../database/ships.js'; +import * as api from '../lib/api.js'; +import * as ships from '../lib/ships.js'; + +// example ctx { good: 'SILVER_ORE', symbol: 'ADYXAX-2' } +// returns the number of units of the good the ship holds +export async function mineUntilFullOf(ctx) { + while(true) { + let cargo = await mineUntilFull({symbol: ctx.symbol}); + let good = cargo.inventory.filter(i => i.symbol === ctx.good)[0]; + const antimatter = cargo.inventory.filter(i => i.symbol === 'ANTIMATTER')[0]; + const junk = cargo.inventory.filter(i => i.symbol !== ctx.good && i.symbol !== 'ANTIMATTER'); + if ((good?.units ?? 0) + (antimatter?.units ?? 0) >= cargo.capacity * 0.9) { // > 90% full of the valuable goods + return good.units; + } else { // we are full but need to sell junk + for (let i=0; i= ship.cargo.capacity * 0.9) return ship.cargo; + if (await ships.extract({symbol: ctx.symbol}) === null) + ship = await ship(ctx); // refresh the ships status from the server just in case + } +} + +// TODO surveying the asteroid field -- cgit v1.2.3