1
0
Fork 0

[node] implemented basic procurement trading loop

This commit is contained in:
Julien Dessaux 2024-03-31 09:44:49 +02:00
parent 8819cf9c67
commit a34e4fbed4
Signed by: adyxax
GPG key ID: F92E51B86E07177E
5 changed files with 132 additions and 46 deletions

View file

@ -8,6 +8,7 @@ import { Response } from '../model/api.ts';
import { Contract } from '../model/contract.ts';
import { Ship } from '../model/ship.ts';
import * as api from '../lib/api.ts';
//import * as agents from '../lib/angent.ts';
import * as libContracts from '../lib/contracts.ts';
import * as libShips from '../lib/ships.ts';
@ -30,10 +31,8 @@ export async function init(): Promise<void> {
switch(json.error?.code) {
case 4111: // 4111 means the agent symbol has already been claimed so no server reset happened
// 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]);
await libContracts.getContracts();
await libShips.getShips();
return;
default:
throw json;