diff options
-rw-r--r-- | nodejs/automation/agent.ts | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/nodejs/automation/agent.ts b/nodejs/automation/agent.ts index 429c83f..9ee0ea8 100644 --- a/nodejs/automation/agent.ts +++ b/nodejs/automation/agent.ts @@ -17,6 +17,7 @@ let state = 0; enum states { start_running_contracts_with_the_command_ship = 0, visit_all_shipyards, + send_the_starting_probe_to_a_shipyard_that_sells_probes, } export async function run(): Promise<void> { @@ -30,13 +31,17 @@ export async function run(): Promise<void> { const ships = getShips(); switch(state) { case states.start_running_contracts_with_the_command_ship: - //await autoContracting.run(ships[0]); + // TODO await autoContracting.run(ships[0]); state++; continue; case states.visit_all_shipyards: await visit_all_shipyards(ships[1]); state++; continue; + case states.send_the_starting_probe_to_a_shipyard_that_sells_probes: + await send_the_starting_probe_to_a_shipyard_that_sells_probes(ships[1]); + state++; + continue; default: debugLog('No more agent processor states implemented, exiting!') return; @@ -48,6 +53,30 @@ export async function run(): Promise<void> { } } +async function send_the_starting_probe_to_a_shipyard_that_sells_probes(probe: Ship) { + const probeWaypoint = await waypoint(probe.nav.waypointSymbol); + const myShipyard = await shipyard(probeWaypoint); + if (myShipyard.shipTypes.some(t => t.type === 'SHIP_PROBE')) return; + // our starting probe is not at a shipyard that sells probes, let's move + const shipyardWaypoints = await trait(probe.nav.systemSymbol, 'SHIPYARD'); + let candidates: Array<{price: number, waypoint: Waypoint}> = []; + for (const w of shipyardWaypoints) { + const shipyardData = await shipyard(w); + const probeData = shipyardData.ships.filter(t => t.type === 'SHIP_PROBE'); + if (probeData.length === 0) continue; + candidates.push({price: probeData[0].purchasePrice, waypoint: w }); + }; + candidates.sort(function(a, b) { + if (a.price < b.price) { + return -1; + } else if (a.price > b.price) { + return 1; + } + return 0; + }); + await probe.navigate(candidates[0].waypoint); +} + async function visit_all_shipyards(probe: Ship) { const probeWaypoint = await waypoint(probe.nav.waypointSymbol); const shipyardWaypoints = await trait(probe.nav.systemSymbol, 'SHIPYARD'); |