summaryrefslogtreecommitdiff
path: root/nodejs/lib
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-29 00:24:51 +0100
committerJulien Dessaux2024-03-29 00:24:51 +0100
commit719a9c1a77733040de8e1c4256b92111dcc53c13 (patch)
tree4cc20d3a386507085840b8880ad4350754fbecf2 /nodejs/lib
parent[node] stop trying to optimize useless things like local database calls (diff)
downloadspacetraders-719a9c1a77733040de8e1c4256b92111dcc53c13.tar.gz
spacetraders-719a9c1a77733040de8e1c4256b92111dcc53c13.tar.bz2
spacetraders-719a9c1a77733040de8e1c4256b92111dcc53c13.zip
[node] fixed mining and selling loop issues
Diffstat (limited to 'nodejs/lib')
-rw-r--r--nodejs/lib/ships.ts7
1 files changed, 6 insertions, 1 deletions
diff --git a/nodejs/lib/ships.ts b/nodejs/lib/ships.ts
index 79b20a6..c673698 100644
--- a/nodejs/lib/ships.ts
+++ b/nodejs/lib/ships.ts
@@ -28,7 +28,7 @@ export async function dock(ship: Ship): Promise<void> {
export async function extract(ship: Ship): Promise<Cargo> {
ship = dbShips.getShip(ship.symbol);
- if (ship.cargo.units >= ship.cargo.capacity * 0.9) return ship.cargo;
+ if (isFull(ship)) return ship.cargo;
// TODO move to a suitable asteroid?
// const asteroidFields = await systems.type({symbol: ship.nav.systemSymbol, type: 'ENGINEERED_ASTEROID'});
// TODO if there are multiple fields, find the closest one?
@@ -55,6 +55,11 @@ export async function extract(ship: Ship): Promise<Cargo> {
return response.data.cargo
}
+export function isFull(ship: Ship): boolean {
+ ship = dbShips.getShip(ship.symbol);
+ return ship.cargo.units >= ship.cargo.capacity * 0.9;
+}
+
//function hasMount(shipSymbol, mountSymbol) {
// const ship = dbShips.getShip(shipSymbol);
// return ship.mounts.filter(s => s.symbol === mountSymbol).length > 0;