1
0
Fork 0

[node] multiple contracting fixes and some more refactoring

This commit is contained in:
Julien Dessaux 2024-04-06 21:36:42 +02:00
parent eeaa64b5ed
commit 3e80bc8a4d
Signed by: adyxax
GPG key ID: F92E51B86E07177E
6 changed files with 65 additions and 46 deletions

View file

@ -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