summaryrefslogtreecommitdiff
path: root/nodejs/lib
diff options
context:
space:
mode:
authorJulien Dessaux2024-03-18 01:16:01 +0100
committerJulien Dessaux2024-03-18 01:17:03 +0100
commitfcbd9cf56c565bd5f7bfea5c683acb3aa88e568b (patch)
treeecf3f8a3263452390605371b5d67a01cfd530c5d /nodejs/lib
parent[javascript] Implementing market data gathering and caching (diff)
downloadspacetraders-fcbd9cf56c565bd5f7bfea5c683acb3aa88e568b.tar.gz
spacetraders-fcbd9cf56c565bd5f7bfea5c683acb3aa88e568b.tar.bz2
spacetraders-fcbd9cf56c565bd5f7bfea5c683acb3aa88e568b.zip
[javascript] Implement the selling loop of the contracting automation
Diffstat (limited to 'nodejs/lib')
-rw-r--r--nodejs/lib/ships.js2
-rw-r--r--nodejs/lib/utils.js15
2 files changed, 16 insertions, 1 deletions
diff --git a/nodejs/lib/ships.js b/nodejs/lib/ships.js
index f6cb027..6415cdb 100644
--- a/nodejs/lib/ships.js
+++ b/nodejs/lib/ships.js
@@ -139,7 +139,7 @@ export async function refuel(ctx) {
}
export async function sell(ctx) {
- // TODO check if our current waypoint has a marketplace (and sells fuel)?
+ // TODO check if our current waypoint has a marketplace?
await dock(ctx);
const ship = dbShips.getShip(ctx.symbol);
const response = await api.send({endpoint: `/my/ships/${ctx.symbol}/sell`, method: 'POST', payload: { symbol: ctx.good, units: ctx.units }});
diff --git a/nodejs/lib/utils.js b/nodejs/lib/utils.js
index 1d2e451..a2c8128 100644
--- a/nodejs/lib/utils.js
+++ b/nodejs/lib/utils.js
@@ -1,3 +1,18 @@
+// cargo is a ship.cargo object, want is an optional symbol
+export function categorizeCargo(cargo, want) {
+ const wanted = cargo.inventory.filter(i => i.symbol === want || i.symbol === 'ANTIMATTER');
+ const goods = cargo.inventory.filter(i => i.symbol !== want && i.symbol !== 'ANTIMATTER');
+ const wobj = wanted.reduce(function(acc, e) {
+ acc[e.symbol] = e.units;
+ return acc;
+ }, {});
+ const gobj = goods.reduce(function(acc, e) {
+ acc[e.symbol] = e.units;
+ return acc;
+ }, {});
+ return {wanted: wobj, goods: gobj};
+}
+
export function systemFromWaypoint(waypoint) {
return waypoint.split('-').slice(0,2).join('-');
}