summaryrefslogtreecommitdiff
path: root/nodejs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'nodejs/lib')
-rw-r--r--nodejs/lib/ships.ts10
-rw-r--r--nodejs/lib/systems.ts16
2 files changed, 16 insertions, 10 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;
diff --git a/nodejs/lib/systems.ts b/nodejs/lib/systems.ts
index 97aa6e3..d4b3be5 100644
--- a/nodejs/lib/systems.ts
+++ b/nodejs/lib/systems.ts
@@ -8,15 +8,15 @@ import * as dbSystems from '../database/systems.ts';
import {
Market,
System,
- Waypoint
+ Waypoint,
} from './types.ts'
import { systemFromWaypoint } from './utils.ts';
-export async function market(waypointSymbol: string): Promise<Market> {
- const data = dbMarkets.getMarketAtWaypoint(waypointSymbol);
+export async function market(waypoint: Waypoint): Promise<Market> {
+ const data = dbMarkets.getMarketAtWaypoint(waypoint.symbol);
if (data) { return data; }
- const systemSymbol = systemFromWaypoint(waypointSymbol);
- let response = await send<Market>({endpoint: `/systems/${systemSymbol}/waypoints/${waypointSymbol}/market`});
+ const systemSymbol = systemFromWaypoint(waypoint.symbol);
+ let response = await send<Market>({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint.symbol}/market`});
if (response.error) {
debugLog(response);
throw response;
@@ -55,6 +55,12 @@ export async function type(system: string, typeSymbol: string): Promise<Array<Wa
return ws.filter(s => s.type === typeSymbol);
}
+export async function waypoint(waypointSymbol: string): Promise<Waypoint> {
+ const systemSymbol = systemFromWaypoint(waypointSymbol);
+ const w = await waypoints(systemSymbol);
+ return w.filter(w => w.symbol === waypointSymbol)[0];
+}
+
export async function waypoints(systemSymbol: string): Promise<Array<Waypoint>> {
const s = await system(systemSymbol);
const updated = dbSystems.getSystemUpdated(systemSymbol);