diff options
author | Julien Dessaux | 2023-07-01 23:13:13 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-07-01 23:13:13 +0200 |
commit | 36cc33f9e96a38ecea98ac8d26275b4828347d80 (patch) | |
tree | 653dcea7e656ec815fc0a1fa5664a6b89abccaa3 /automation/mining.js | |
parent | Fixed prepared statements (diff) | |
download | spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.gz spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.tar.bz2 spacetraders-36cc33f9e96a38ecea98ac8d26275b4828347d80.zip |
Moved the nodejs agent to its own subfolder to make room for my haskell agent
Diffstat (limited to 'automation/mining.js')
-rw-r--r-- | automation/mining.js | 34 |
1 files changed, 0 insertions, 34 deletions
diff --git a/automation/mining.js b/automation/mining.js deleted file mode 100644 index f35af36..0000000 --- a/automation/mining.js +++ /dev/null @@ -1,34 +0,0 @@ -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<junk.length; ++i) { - await ships.sell({symbol: ctx.symbol, good: junk[i].symbol, units: junk[i].units}); - } - } - } -} - -// example ctx { symbol: 'ADYXAX-2' } -// extract the ship's cargo contents when more than 80% full then returns the ships cargo object -async function mineUntilFull(ctx) { - while(true) { - const ship = dbShips.getShip(ctx.symbol); - if (ship.cargo.units >= 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 |