summaryrefslogtreecommitdiff
path: root/nodejs/automation/mining.ts
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-27 15:20:14 +0100
committerJulien Dessaux2024-03-27 15:21:37 +0100
commita1d6b03ec98abbc073b5b73b631da6ea3eae4eb9 (patch)
tree1566c60bf1155e62821d9561ba1cc998b04b8ea5 /nodejs/automation/mining.ts
parent[all] fixed erroneous contracts index (diff)
downloadspacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.gz
spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.tar.bz2
spacetraders-a1d6b03ec98abbc073b5b73b631da6ea3eae4eb9.zip
[node] finished the great typescript rewrite
Diffstat (limited to '')
-rw-r--r--nodejs/automation/mining.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/nodejs/automation/mining.ts b/nodejs/automation/mining.ts
new file mode 100644
index 0000000..5e36de5
--- /dev/null
+++ b/nodejs/automation/mining.ts
@@ -0,0 +1,29 @@
+import * as selling from './selling.js';
+import * as dbShips from '../database/ships.js';
+import * as api from '../lib/api.js';
+import * as libShips from '../lib/ships.js';
+import * as utils from '../lib/utils.js';
+import { Ship } from '../model/ship.ts';
+
+export async function mineUntilFullOf(good: string, ship: Ship, asteroidSymbol: string): Promise<Ship> {
+ // TODO find a good asteroid
+ while(true) {
+ ship = await mineUntilFull(ship);
+ const cargo = utils.categorizeCargo(ship.cargo, good);
+ const wantedUnits = Object.values(cargo.wanted).reduce((acc, e) => acc += e, 0);
+ // > 90% full of the valuable goods ?
+ if (wantedUnits >= ship.cargo.capacity * 0.9) return ship;
+ // we are full but need to sell junk
+ await selling.sell(ship, good);
+ await libShips.navigate(ship, asteroidSymbol);
+ }
+}
+
+// example ctx { symbol: 'ADYXAX-2' }
+// extract the ship's cargo contents when more than 80% full then returns the ships cargo object
+async function mineUntilFull(ship: Ship): Promise<Ship> {
+ for (;ship.cargo.units <= ship.cargo.capacity * 0.9; ship = await libShips.extract(ship)) {}
+ return ship;
+}
+
+// TODO surveying the asteroid field