diff options
author | Julien Dessaux | 2024-03-30 14:22:59 +0100 |
---|---|---|
committer | Julien Dessaux | 2024-03-30 14:22:59 +0100 |
commit | 8819cf9c67e33c76cbac65a9ca2b6ff86786d251 (patch) | |
tree | b9f8c26922909b2b59eaed2c1b2b397835db7c45 /nodejs/automation/init.ts | |
parent | [node] fixed mining and selling loop issues (diff) | |
download | spacetraders-8819cf9c67e33c76cbac65a9ca2b6ff86786d251.tar.gz spacetraders-8819cf9c67e33c76cbac65a9ca2b6ff86786d251.tar.bz2 spacetraders-8819cf9c67e33c76cbac65a9ca2b6ff86786d251.zip |
[node] fixed contracting and implemented renegotiation
Diffstat (limited to '')
-rw-r--r-- | nodejs/automation/init.ts | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/nodejs/automation/init.ts b/nodejs/automation/init.ts index 2850fac..74f42fb 100644 --- a/nodejs/automation/init.ts +++ b/nodejs/automation/init.ts @@ -29,8 +29,11 @@ export async function init(): Promise<void> { if (json.error !== undefined) { switch(json.error?.code) { case 4111: // 4111 means the agent symbol has already been claimed so no server reset happened - await libContracts.contracts(); - await libShips.ships(); + // TODO await agents.agents(); + const contracts = await libContracts.getContracts(); + const ongoing = contracts.filter(c => !c.fulfilled); + const ships = await libShips.getShips(); + if (ongoing.length === 0) libShips.negotiate(ships[0]); return; default: throw json; @@ -42,5 +45,5 @@ export async function init(): Promise<void> { dbContracts.setContract(json.data.contract); dbShips.setShip(json.data.ship); // Temporary fix to fetch the data on the startup probe - await libShips.ships(); + await libShips.getShips(); } |