diff options
author | Julien Dessaux | 2024-03-28 12:11:36 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-03-28 12:11:36 +0100 |
commit | 3cb4f4df51059919b292fefb5f7a3e1ad99c9a91 (patch) | |
tree | bf97a8bdea32985f4c1a95e3759d5044b398789d /nodejs/automation/mining.ts | |
parent | [node] finished the great typescript rewrite (diff) | |
download | spacetraders-3cb4f4df51059919b292fefb5f7a3e1ad99c9a91.tar.gz spacetraders-3cb4f4df51059919b292fefb5f7a3e1ad99c9a91.tar.bz2 spacetraders-3cb4f4df51059919b292fefb5f7a3e1ad99c9a91.zip |
[node] stop trying to optimize useless things like local database calls
Diffstat (limited to '')
-rw-r--r-- | nodejs/automation/mining.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/nodejs/automation/mining.ts b/nodejs/automation/mining.ts index 5e36de5..e1230fd 100644 --- a/nodejs/automation/mining.ts +++ b/nodejs/automation/mining.ts @@ -5,10 +5,11 @@ import * as libShips from '../lib/ships.js'; import * as utils from '../lib/utils.js'; import { Ship } from '../model/ship.ts'; -export async function mineUntilFullOf(good: string, ship: Ship, asteroidSymbol: string): Promise<Ship> { +export async function mineUntilFullOf(good: string, ship: Ship, asteroidSymbol: string): Promise<void> { // TODO find a good asteroid while(true) { - ship = await mineUntilFull(ship); + await mineUntilFull(ship); + ship = dbShips.getShip(ship.symbol) as Ship; const cargo = utils.categorizeCargo(ship.cargo, good); const wantedUnits = Object.values(cargo.wanted).reduce((acc, e) => acc += e, 0); // > 90% full of the valuable goods ? @@ -21,9 +22,11 @@ export async function mineUntilFullOf(good: string, ship: Ship, asteroidSymbol: // 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(ship: Ship): Promise<Ship> { - for (;ship.cargo.units <= ship.cargo.capacity * 0.9; ship = await libShips.extract(ship)) {} - return ship; +async function mineUntilFull(ship: Ship): Promise<void> { + ship = dbShips.getShip(ship.symbol) as Ship; + while (ship.cargo.units <= ship.cargo.capacity * 0.9) { + ship.cargo = await libShips.extract(ship); + } } // TODO surveying the asteroid field |