diff options
author | Julien Dessaux | 2024-04-05 00:42:30 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-04-07 23:01:52 +0200 |
commit | 234770b611df32178382b557df396db220070a7f (patch) | |
tree | 8c768846716eaf892ff75abe84d0f5c00e8519ff /nodejs/automation/mining.ts | |
parent | [node] Fixed basic procurement trading loop (diff) | |
download | spacetraders-234770b611df32178382b557df396db220070a7f.tar.gz spacetraders-234770b611df32178382b557df396db220070a7f.tar.bz2 spacetraders-234770b611df32178382b557df396db220070a7f.zip |
[node] Big Ships lib refactoring
Diffstat (limited to '')
-rw-r--r-- | nodejs/automation/mining.ts | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/nodejs/automation/mining.ts b/nodejs/automation/mining.ts index 272c39a..07fa19b 100644 --- a/nodejs/automation/mining.ts +++ b/nodejs/automation/mining.ts @@ -1,11 +1,8 @@ import * as selling from './selling.js'; import * as dbContracts from '../database/contracts.js'; -import * as dbShips from '../database/ships.js'; -import * as api from '../lib/api.js'; -import * as libShips from '../lib/ships.js'; -import * as utils from '../lib/utils.js'; -import { Contract } from '../model/contract.ts'; -import { Ship } from '../model/ship.ts'; +import { Ship } from '../lib/ships.js'; +import { Contract } from '../lib/types.ts'; +import { categorizeCargo } from '../lib/utils.ts'; export async function mineUntilFullFor(contract: Contract, ship: Ship, asteroidSymbol: string): Promise<void> { // TODO find a good asteroid @@ -13,21 +10,20 @@ export async function mineUntilFullFor(contract: Contract, ship: Ship, asteroidS await mineUntilFull(ship); contract = dbContracts.getContract(contract.id); const deliver = contract.terms.deliver[0]; - ship = dbShips.getShip(ship.symbol); - const cargo = utils.categorizeCargo(ship.cargo, deliver.tradeSymbol); + const cargo = categorizeCargo(ship.cargo, deliver.tradeSymbol); const wantedUnits = Object.values(cargo.wanted).reduce((acc, e) => acc += e, 0); // > 90% full of the valuable goods ? Or just have enough for the contract? if (wantedUnits >= ship.cargo.capacity * 0.9 || cargo.wanted[deliver.tradeSymbol] >= deliver.unitsRequired - deliver.unitsFulfilled) return; // we are full but need to sell junk await selling.sell(ship, deliver.tradeSymbol); - await libShips.navigate(ship, asteroidSymbol); + await ship.navigate(asteroidSymbol); } } async function mineUntilFull(ship: Ship): Promise<void> { - while (!libShips.isFull(ship)) { - await libShips.extract(ship); + while (!ship.isFull()) { + await ship.extract(); } } |