diff options
author | Julien Dessaux | 2024-05-23 23:49:42 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-05-23 23:49:42 +0200 |
commit | 330615936955f464a17aa0b7e39fb04d3f074b06 (patch) | |
tree | f742fa990b47a5226c18446407b8de5c619c6363 /nodejs/lib/ships.ts | |
parent | [node] implement ship purchasing (diff) | |
download | spacetraders-330615936955f464a17aa0b7e39fb04d3f074b06.tar.gz spacetraders-330615936955f464a17aa0b7e39fb04d3f074b06.tar.bz2 spacetraders-330615936955f464a17aa0b7e39fb04d3f074b06.zip |
[node] factorize sortByPrice
Diffstat (limited to '')
-rw-r--r-- | nodejs/lib/ships.ts | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/nodejs/lib/ships.ts b/nodejs/lib/ships.ts index 0e3605f..55a36a5 100644 --- a/nodejs/lib/ships.ts +++ b/nodejs/lib/ships.ts @@ -24,6 +24,7 @@ import { import { is_there_a_ship_at_this_waypoint, shortestPath, + sortByPrice, } from './utils.ts'; export class Ship { @@ -105,6 +106,9 @@ export class Ship { // } // this.nav = response.data; //} + isEmpty(): boolean { + return this.cargo.inventory.some(i => i.symbol !== 'ANTIMATTER'); + } isFull(): boolean { return this.cargo.units >= this.cargo.capacity * 0.9; } @@ -273,14 +277,7 @@ export async function purchaseShip(shipType: string): Promise<Ship> { candidates = backupCandidates; needsNavigate = true; } - candidates.sort(function(a, b) { - if (a.price < b.price) { - return -1; - } else if (a.price > b.price) { - return 1; - } - return 0; - }); + sortByPrice(candidates); if (needsNavigate) { // we did not have a probe in orbit of a shipyard selling ${shipType} // yet, must be early game buying our second probe so let's move the |