1
0
Fork 0

Began implementing surveying

This commit is contained in:
Julien Dessaux 2023-06-15 01:02:03 +02:00
parent ec5d09586f
commit 93e6e02bca
Signed by: adyxax
GPG key ID: F92E51B86E07177E
4 changed files with 54 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import * as api from './api.js';
import * as dbConfig from '../database/config.js';
import * as dbShips from '../database/ships.js';
import * as dbSurveys from '../database/surveys.js';
import * as systems from '../lib/systems.js';
export async function extract(ctx) {
@ -47,6 +48,11 @@ export async function dock(ctx) {
return response;
}
function hasMount(shipSymbol, mountSymbol) {
const ship = dbShips.getShip(shipSymbol);
return ship.mounts.filter(s => s.symbol === mountSymbol).length > 0;
}
export async function jump(ctx) {
// TODO
const response = await api.send({endpoint: `/my/ships/${ctx.ship}/jump`, method: 'POST', payload: { systemSymbol: ctx.system }});
@ -156,6 +162,26 @@ export async function ship(ctx) {
}
export async function survey(ctx) {
// TODO
return await api.send({endpoint: `/my/ships/${ctx.symbol}/survey`, method: 'POST'});
if (!hasMount(ctx.symbol, 'MOUNT_SURVEYOR_I')) { // we check if a surveyor is mounted on the ship
return null;
}
const ship = dbShips.getShip(ctx.symbol);
const asteroidFields = await systems.type({symbol: ship.nav.systemSymbol, type: 'ASTEROID_FIELD'});
// TODO if there are multiple fields, find the closest one?
await navigate({symbol: ctx.symbol, waypoint: asteroidFields[0].symbol});
await orbit(ctx);
const response = await api.send({endpoint: `/my/ships/${ctx.symbol}/survey`, method: 'POST'});
api.debugLog(response);
if (response.error !== undefined) {
switch(response.error.code) {
case 4000: // ship is on cooldown
await api.sleep(response.error.data.cooldown.remainingSeconds * 1000);
return await survey(ctx);
default: // yet unhandled error
throw response;
}
}
dbSurveys.set(response.data.surveys[0]);
await api.sleep(response.data.cooldown.remainingSeconds*1000);
return response;
}