Began implementing surveying
This commit is contained in:
parent
ec5d09586f
commit
93e6e02bca
4 changed files with 54 additions and 2 deletions
30
lib/ships.js
30
lib/ships.js
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue