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/lib/ships.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 '')
-rw-r--r-- | nodejs/lib/ships.ts | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/nodejs/lib/ships.ts b/nodejs/lib/ships.ts index 7221596..187a87b 100644 --- a/nodejs/lib/ships.ts +++ b/nodejs/lib/ships.ts @@ -18,6 +18,7 @@ import { Fuel, Nav, Registration, + Waypoint, } from './types.ts'; import * as dbAgents from '../database/agents.ts'; @@ -96,14 +97,13 @@ export class Ship { isFull(): boolean { return this.cargo.units >= this.cargo.capacity * 0.9; } - async navigate(waypointSymbol: string): Promise<void> { - if (this.nav.waypointSymbol === waypointSymbol) return; - const d = + async navigate(waypoint: Waypoint): Promise<void> { + if (this.nav.waypointSymbol === waypoint.symbol) return; // TODO compute fuel consumption and refuel if we do not have enough OR if the destination does not sell fuel? await this.refuel(); await this.orbit(); // TODO if we do not have enough fuel, make a stop to refuel along the way or drift to the destination - const response = await send<{fuel: Fuel, nav: Nav}>({endpoint: `/my/ships/${this.symbol}/navigate`, method: 'POST', payload: { waypointSymbol: waypointSymbol }}); // TODO events field + const response = await send<{fuel: Fuel, nav: Nav}>({endpoint: `/my/ships/${this.symbol}/navigate`, method: 'POST', payload: { waypointSymbol: waypoint.symbol }}); // TODO events field if (response.error) { switch(response.error.code) { case 4203: // not enough fuel @@ -117,7 +117,7 @@ export class Ship { case 4214: const sicite = response.error.data as ShipIsCurrentlyInTransitError; await sleep(sicite.secondsToArrival * 1000); - return await this.navigate(waypointSymbol); + return await this.navigate(waypoint); default: // yet unhandled error debugLog(response); throw response; |