From 3e80bc8a4d3127d17dbc3f52301d33a79e53a980 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Sat, 6 Apr 2024 21:36:42 +0200 Subject: [node] multiple contracting fixes and some more refactoring --- nodejs/lib/ships.ts | 3 +++ 1 file changed, 3 insertions(+) (limited to 'nodejs/lib/ships.ts') diff --git a/nodejs/lib/ships.ts b/nodejs/lib/ships.ts index 187a87b..67dca00 100644 --- a/nodejs/lib/ships.ts +++ b/nodejs/lib/ships.ts @@ -130,6 +130,7 @@ export class Ship { this.nav.status = 'IN_ORBIT'; // we arrive in orbit } async negotiate(): Promise { + await this.dock(); const response = await send<{contract: Contract}>({endpoint: `/my/ships/${this.symbol}/negotiate/contract`, method: 'POST'}); if (response.error) { switch(response.error.code) { @@ -142,6 +143,7 @@ export class Ship { throw response; } } + dbContracts.setContract(response.data.contract); return response.data.contract; } async orbit(): Promise { @@ -180,6 +182,7 @@ export class Ship { dbAgents.setAgent(response.data.agent); } async refuel(): Promise { + if (this.fuel.current === this.fuel.capacity) return; // TODO check if our current waypoint has a marketplace (and sells fuel)? await this.dock(); const response = await send<{agent: Agent, fuel: Fuel}>({endpoint: `/my/ships/${this.symbol}/refuel`, method: 'POST'}); // TODO transaction field -- cgit v1.2.3