[node] implement agent automation that visits all shipyards with the starting probe
This commit is contained in:
parent
92ef1e8c2e
commit
d77558b8de
6 changed files with 101 additions and 12 deletions
|
@ -88,6 +88,22 @@ export class Ship {
|
|||
await sleep(response.data.cooldown.remainingSeconds*1000);
|
||||
return this.cargo;
|
||||
}
|
||||
//async flightMode(mode: string): Promise<void> {
|
||||
// if (this.nav.flightMode === mode) return;
|
||||
// const response = await send<nav>({endpoint: `/my/ships/${this.symbol}/nav`, method: 'PATCH', payload: { flightmode: mode }});
|
||||
// if (response.error) {
|
||||
// switch(response.error.code) {
|
||||
// case 4214:
|
||||
// const sicite = response.error.data as ShipIsCurrentlyInTransitError;
|
||||
// await sleep(sicite.secondsToArrival * 1000);
|
||||
// return await this.flightMode(mode);
|
||||
// default: // yet unhandled error
|
||||
// debugLog(response);
|
||||
// throw response;
|
||||
// }
|
||||
// }
|
||||
// this.nav = response.data;
|
||||
//}
|
||||
isFull(): boolean {
|
||||
return this.cargo.units >= this.cargo.capacity * 0.9;
|
||||
}
|
||||
|
@ -105,6 +121,7 @@ export class Ship {
|
|||
}
|
||||
private async navigateTo(symbol: string): Promise<void> {
|
||||
await this.orbit();
|
||||
//if (this.fuel.capacity === 0) this.flightMode('BURN');
|
||||
const response = await send<{fuel: Fuel, nav: Nav}>({endpoint: `/my/ships/${this.symbol}/navigate`, method: 'POST', payload: { waypointSymbol: symbol }}); // TODO events field
|
||||
if (response.error) {
|
||||
switch(response.error.code) {
|
||||
|
|
|
@ -13,13 +13,13 @@ import {
|
|||
Waypoint,
|
||||
} from './types.ts'
|
||||
import {
|
||||
isThereAShipAtThisWaypoint,
|
||||
is_there_a_ship_at_this_waypoint,
|
||||
systemFromWaypoint,
|
||||
} from './utils.ts';
|
||||
|
||||
export async function market(waypoint: Waypoint): Promise<Market> {
|
||||
const data = dbMarkets.getMarketAtWaypoint(waypoint.symbol);
|
||||
if (data && (data.tradeGoods || !isThereAShipAtThisWaypoint(waypoint))) { return data; }
|
||||
if (data && (data.tradeGoods || !is_there_a_ship_at_this_waypoint(waypoint))) { return data; }
|
||||
const systemSymbol = systemFromWaypoint(waypoint.symbol);
|
||||
let response = await send<Market>({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint.symbol}/market`});
|
||||
if (response.error) {
|
||||
|
@ -32,7 +32,7 @@ export async function market(waypoint: Waypoint): Promise<Market> {
|
|||
|
||||
export async function shipyard(waypoint: Waypoint): Promise<Shipyard> {
|
||||
const data = dbShipyards.get(waypoint.symbol);
|
||||
if (data && (data.ships || !isThereAShipAtThisWaypoint(waypoint))) { return data; }
|
||||
if (data && (data.ships || !is_there_a_ship_at_this_waypoint(waypoint))) { return data; }
|
||||
const systemSymbol = systemFromWaypoint(waypoint.symbol);
|
||||
const response = await send<Shipyard>({endpoint: `/systems/${systemSymbol}/waypoints/${waypoint.symbol}/shipyard`});
|
||||
if (response.error) {
|
||||
|
|
|
@ -40,7 +40,7 @@ export function distance(a: Point, b: Point) {
|
|||
return Math.sqrt((a.x-b.x)**2 + (a.y-b.y)**2);
|
||||
}
|
||||
|
||||
export function isThereAShipAtThisWaypoint(waypoint: Waypoint): boolean {
|
||||
export function is_there_a_ship_at_this_waypoint(waypoint: Waypoint): boolean {
|
||||
return getShips().some(s => s.nav.waypointSymbol === waypoint.symbol);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue