summaryrefslogtreecommitdiff
path: root/nodejs/automation
diff options
context:
space:
mode:
authorJulien Dessaux2024-05-21 23:50:13 +0200
committerJulien Dessaux2024-05-21 23:50:13 +0200
commitb1627bf0d7e6992d93530474081265c663b7431b (patch)
tree42cf785aaabd3302b81700aba6597bf3f9d8fcc2 /nodejs/automation
parent[node] implement agent automation that visits all shipyards with the starting... (diff)
downloadspacetraders-b1627bf0d7e6992d93530474081265c663b7431b.tar.gz
spacetraders-b1627bf0d7e6992d93530474081265c663b7431b.tar.bz2
spacetraders-b1627bf0d7e6992d93530474081265c663b7431b.zip
[node] implement automation next step: sending the startup probe to a shipyard that selles probes
Diffstat (limited to 'nodejs/automation')
-rw-r--r--nodejs/automation/agent.ts31
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');