[javascript] Implement the selling loop of the contracting automation
This commit is contained in:
parent
1b1df83ffd
commit
fcbd9cf56c
5 changed files with 110 additions and 16 deletions
|
@ -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 }});
|
||||
|
|
|
@ -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('-');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue