diff options
author | Julien Dessaux | 2024-04-06 21:36:42 +0200 |
---|---|---|
committer | Julien Dessaux | 2024-04-07 23:01:52 +0200 |
commit | 3e80bc8a4d3127d17dbc3f52301d33a79e53a980 (patch) | |
tree | 41caed2075ed39f8eec5f3465aded203ae377c58 /nodejs/lib/ships.ts | |
parent | [node] waypoints usage refactoring (diff) | |
download | spacetraders-3e80bc8a4d3127d17dbc3f52301d33a79e53a980.tar.gz spacetraders-3e80bc8a4d3127d17dbc3f52301d33a79e53a980.tar.bz2 spacetraders-3e80bc8a4d3127d17dbc3f52301d33a79e53a980.zip |
[node] multiple contracting fixes and some more refactoring
Diffstat (limited to '')
-rw-r--r-- | nodejs/lib/ships.ts | 3 |
1 files changed, 3 insertions, 0 deletions
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<Contract> { + 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<void> { @@ -180,6 +182,7 @@ export class Ship { dbAgents.setAgent(response.data.agent); } async refuel(): Promise<void> { + 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 |