summaryrefslogtreecommitdiff
path: root/nodejs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'nodejs/lib')
-rw-r--r--nodejs/lib/ships.ts17
-rw-r--r--nodejs/lib/systems.ts6
-rw-r--r--nodejs/lib/utils.ts2
3 files changed, 21 insertions, 4 deletions
diff --git a/nodejs/lib/ships.ts b/nodejs/lib/ships.ts
index e4875f8..7daae71 100644
--- a/nodejs/lib/ships.ts
+++ b/nodejs/lib/ships.ts
@@ -88,6 +88,22 @@ export class Ship {
await sleep(response.data.cooldown.remainingSeconds*1000);
return this.cargo;
}
+ //async flightMode(mode: string): Promise<void> {
+ // if (this.nav.flightMode === mode) return;
+ // const response = await send<nav>({endpoint: `/my/ships/${this.symbol}/nav`, method: 'PATCH', payload: { flightmode: mode }});
+ // if (response.error) {
+ // switch(response.error.code) {
+ // case 4214:
+ // const sicite = response.error.data as ShipIsCurrentlyInTransitError;
+ // await sleep(sicite.secondsToArrival * 1000);
+ // return await this.flightMode(mode);
+ // default: // yet unhandled error
+ // debugLog(response);
+ // throw response;
+ // }
+ // }
+ // this.nav = response.data;
+ //}
isFull(): boolean {
return this.cargo.units >= this.cargo.capacity * 0.9;
}
@@ -105,6 +121,7 @@ export class Ship {
}
private async navigateTo(symbol: string): Promise<void> {
await this.orbit();
+ //if (this.fuel.capacity === 0) this.flightMode('BURN');
const response = await send<{fuel: Fuel, nav: Nav}>({endpoint: `/my/ships/${this.symbol}/navigate`, method: 'POST', payload: { waypointSymbol: symbol }}); // TODO events field
if (response.error) {
switch(response.error.code) {
diff --git a/nodejs/lib/systems.ts b/nodejs/lib/systems.ts
index 6f0a830..f07f92b 100644
--- a/nodejs/lib/systems.ts
+++ b/nodejs/lib/systems.ts
@@ -13,13 +13,13 @@ import {
Waypoint,
} from './types.ts'
import {
- isThereAShipAtThisWaypoint,
+ is_there_a_ship_at_this_waypoint,
systemFromWaypoint,
} from './utils.ts';
export async function market(waypoint: Waypoint): Promise<Market> {
const data = dbMarkets.getMarketAtWaypoint(waypoint.symbol);
- if (data && (data.tradeGoods || !isThereAShipAtThisWaypoint(waypoint))) { return data; }
+ if (data && (data.tradeGoods || !is_there_a_ship_at_this_waypoint(waypoint))) { return data; }
const systemSymbol = systemFromWaypoint(waypoint.symbol);
let response = await send<Market>({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint.symbol}/market`});
if (response.error) {
@@ -32,7 +32,7 @@ export async function market(waypoint: Waypoint): Promise<Market> {
export async function shipyard(waypoint: Waypoint): Promise<Shipyard> {
const data = dbShipyards.get(waypoint.symbol);
- if (data && (data.ships || !isThereAShipAtThisWaypoint(waypoint))) { return data; }
+ if (data && (data.ships || !is_there_a_ship_at_this_waypoint(waypoint))) { return data; }
const systemSymbol = systemFromWaypoint(waypoint.symbol);
const response = await send<Shipyard>({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint.symbol}/shipyard`});
if (response.error) {
diff --git a/nodejs/lib/utils.ts b/nodejs/lib/utils.ts
index 24aa3b4..6d051ea 100644
--- a/nodejs/lib/utils.ts
+++ b/nodejs/lib/utils.ts
@@ -40,7 +40,7 @@ export function distance(a: Point, b: Point) {
return Math.sqrt((a.x-b.x)**2 + (a.y-b.y)**2);
}
-export function isThereAShipAtThisWaypoint(waypoint: Waypoint): boolean {
+export function is_there_a_ship_at_this_waypoint(waypoint: Waypoint): boolean {
return getShips().some(s => s.nav.waypointSymbol === waypoint.symbol);
}