summaryrefslogtreecommitdiff
path: root/nodejs/automation
diff options
context:
space:
mode:
Diffstat (limited to 'nodejs/automation')
-rw-r--r--nodejs/automation/contracting.ts8
-rw-r--r--nodejs/automation/mining.ts7
-rw-r--r--nodejs/automation/selling.ts4
3 files changed, 9 insertions, 10 deletions
diff --git a/nodejs/automation/contracting.ts b/nodejs/automation/contracting.ts
index 344672a..ab3c606 100644
--- a/nodejs/automation/contracting.ts
+++ b/nodejs/automation/contracting.ts
@@ -58,9 +58,11 @@ async function runProcurement(contract: Contract, ships: Array<Ship>) {
await libShips.navigate(ship, asteroidSymbol);
break;
default:
- // we were either selling or started contracting
- await selling.sell(ship, wantedCargo);
- await libShips.navigate(ship, asteroidSymbol);
+ if (libShips.isFull(ship)) {
+ await selling.sell(ship, wantedCargo);
+ } else {
+ await libShips.navigate(ship, asteroidSymbol);
+ }
}
}
// TODO repurpose the ship
diff --git a/nodejs/automation/mining.ts b/nodejs/automation/mining.ts
index e1230fd..b9db7d4 100644
--- a/nodejs/automation/mining.ts
+++ b/nodejs/automation/mining.ts
@@ -20,12 +20,9 @@ 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<void> {
- ship = dbShips.getShip(ship.symbol) as Ship;
- while (ship.cargo.units <= ship.cargo.capacity * 0.9) {
- ship.cargo = await libShips.extract(ship);
+ while (!libShips.isFull(ship)) {
+ await libShips.extract(ship);
}
}
diff --git a/nodejs/automation/selling.ts b/nodejs/automation/selling.ts
index 987b8ae..04b0e9d 100644
--- a/nodejs/automation/selling.ts
+++ b/nodejs/automation/selling.ts
@@ -19,10 +19,10 @@ export async function sell(ship: Ship, good: string): Promise<Ship> {
// can we sell anything here?
const goods = whatCanBeTradedAt(cargo.goods, market.imports.concat(market.exchange));
for (let i = 0; i < goods.length; i++) {
- const symbol = goods[i].symbol;
- await libShips.sell(ship, good);
+ await libShips.sell(ship, goods[i].symbol);
};
// are we done selling everything we can?
+ ship = dbShips.getShip(ship.symbol);
cargo = utils.categorizeCargo(ship.cargo, good);
if (Object.keys(cargo.goods).length === 0) {
return ship;