diff options
author | Julien Dessaux | 2024-04-06 10:55:11 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-04-07 23:01:52 +0200 |
commit | eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac (patch) | |
tree | 4c9ebcfd01773bb6c34e66e1325cf40739dae17f /nodejs/automation/selling.ts | |
parent | [node] Big Ships lib refactoring (diff) | |
download | spacetraders-eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac.tar.gz spacetraders-eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac.tar.bz2 spacetraders-eeaa64b5ed54cee8f4ffc85f96178e9799c1a8ac.zip |
[node] waypoints usage refactoring
Diffstat (limited to 'nodejs/automation/selling.ts')
-rw-r--r-- | nodejs/automation/selling.ts | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/nodejs/automation/selling.ts b/nodejs/automation/selling.ts index bc586fe..6cb7d32 100644 --- a/nodejs/automation/selling.ts +++ b/nodejs/automation/selling.ts @@ -10,10 +10,11 @@ import { // example ctx { ship: {XXX}, keep: 'SILVER_ORE' } export async function sell(ship: Ship, good: string): Promise<Ship> { outer: while(true) { + const waypoint = await libSystems.waypoint(ship.nav.waypointSymbol); // first lets see what we want to sell let cargo = categorizeCargo(ship.cargo, good); // get the marketdata from our location - const market = await libSystems.market(ship.nav.waypointSymbol); + const market = await libSystems.market(waypoint); // can we sell anything here? const goods = whatCanBeTradedAt(cargo.goods, market.imports.concat(market.exchange)); for (let i = 0; i < goods.length; i++) { @@ -42,22 +43,22 @@ export async function sell(ship: Ship, good: string): Promise<Ship> { }); // check from the closest one if they import what we need to sell for (let i = 0; i < markets.length; i++) { - const waypointSymbol = markets[i].data.symbol; - const market = await libSystems.market(waypointSymbol); + const waypoint = await libSystems.waypoint(markets[i].data.symbol); + const market = await libSystems.market(waypoint); // if we have no data on the market we need to go there and see // and if we have data and can sell there we need to go too if (market === null || whatCanBeTradedAt(cargo.goods, market.imports).length > 0) { - await ship.navigate(waypointSymbol); + await ship.navigate(waypoint); continue outer; } } // check from the closest one if they exchange what we need to sell for (let i = 0; i < markets.length; i++) { - const waypointSymbol = markets[i].data.symbol; - const market = await libSystems.market(waypointSymbol); + const waypoint = await libSystems.waypoint(markets[i].data.symbol); + const market = await libSystems.market(waypoint); // if we can sell there we need to go if (whatCanBeTradedAt(cargo.goods, market.exchange).length > 0) { - await ship.navigate(waypointSymbol); + await ship.navigate(waypoint); continue outer; } } |