[node] implement automation next step: sending the startup probe to a shipyard that selles probes
This commit is contained in:
parent
d77558b8de
commit
b1627bf0d7
1 changed files with 30 additions and 1 deletions
|
@ -17,6 +17,7 @@ let state = 0;
|
||||||
enum states {
|
enum states {
|
||||||
start_running_contracts_with_the_command_ship = 0,
|
start_running_contracts_with_the_command_ship = 0,
|
||||||
visit_all_shipyards,
|
visit_all_shipyards,
|
||||||
|
send_the_starting_probe_to_a_shipyard_that_sells_probes,
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
|
@ -30,13 +31,17 @@ export async function run(): Promise<void> {
|
||||||
const ships = getShips();
|
const ships = getShips();
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case states.start_running_contracts_with_the_command_ship:
|
case states.start_running_contracts_with_the_command_ship:
|
||||||
//await autoContracting.run(ships[0]);
|
// TODO await autoContracting.run(ships[0]);
|
||||||
state++;
|
state++;
|
||||||
continue;
|
continue;
|
||||||
case states.visit_all_shipyards:
|
case states.visit_all_shipyards:
|
||||||
await visit_all_shipyards(ships[1]);
|
await visit_all_shipyards(ships[1]);
|
||||||
state++;
|
state++;
|
||||||
continue;
|
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:
|
default:
|
||||||
debugLog('No more agent processor states implemented, exiting!')
|
debugLog('No more agent processor states implemented, exiting!')
|
||||||
return;
|
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) {
|
async function visit_all_shipyards(probe: Ship) {
|
||||||
const probeWaypoint = await waypoint(probe.nav.waypointSymbol);
|
const probeWaypoint = await waypoint(probe.nav.waypointSymbol);
|
||||||
const shipyardWaypoints = await trait(probe.nav.systemSymbol, 'SHIPYARD');
|
const shipyardWaypoints = await trait(probe.nav.systemSymbol, 'SHIPYARD');
|
||||||
|
|
Loading…
Add table
Reference in a new issue