[node] fixed mining and selling loop issues
This commit is contained in:
parent
3cb4f4df51
commit
719a9c1a77
4 changed files with 15 additions and 11 deletions
|
@ -58,11 +58,13 @@ async function runProcurement(contract: Contract, ships: Array<Ship>) {
|
||||||
await libShips.navigate(ship, asteroidSymbol);
|
await libShips.navigate(ship, asteroidSymbol);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// we were either selling or started contracting
|
if (libShips.isFull(ship)) {
|
||||||
await selling.sell(ship, wantedCargo);
|
await selling.sell(ship, wantedCargo);
|
||||||
|
} else {
|
||||||
await libShips.navigate(ship, asteroidSymbol);
|
await libShips.navigate(ship, asteroidSymbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// TODO repurpose the ship
|
// TODO repurpose the ship
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,9 @@ export async function mineUntilFullOf(good: string, ship: 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<void> {
|
async function mineUntilFull(ship: Ship): Promise<void> {
|
||||||
ship = dbShips.getShip(ship.symbol) as Ship;
|
while (!libShips.isFull(ship)) {
|
||||||
while (ship.cargo.units <= ship.cargo.capacity * 0.9) {
|
await libShips.extract(ship);
|
||||||
ship.cargo = await libShips.extract(ship);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@ export async function sell(ship: Ship, good: string): Promise<Ship> {
|
||||||
// can we sell anything here?
|
// can we sell anything here?
|
||||||
const goods = whatCanBeTradedAt(cargo.goods, market.imports.concat(market.exchange));
|
const goods = whatCanBeTradedAt(cargo.goods, market.imports.concat(market.exchange));
|
||||||
for (let i = 0; i < goods.length; i++) {
|
for (let i = 0; i < goods.length; i++) {
|
||||||
const symbol = goods[i].symbol;
|
await libShips.sell(ship, goods[i].symbol);
|
||||||
await libShips.sell(ship, good);
|
|
||||||
};
|
};
|
||||||
// are we done selling everything we can?
|
// are we done selling everything we can?
|
||||||
|
ship = dbShips.getShip(ship.symbol);
|
||||||
cargo = utils.categorizeCargo(ship.cargo, good);
|
cargo = utils.categorizeCargo(ship.cargo, good);
|
||||||
if (Object.keys(cargo.goods).length === 0) {
|
if (Object.keys(cargo.goods).length === 0) {
|
||||||
return ship;
|
return ship;
|
||||||
|
|
|
@ -28,7 +28,7 @@ export async function dock(ship: Ship): Promise<void> {
|
||||||
|
|
||||||
export async function extract(ship: Ship): Promise<Cargo> {
|
export async function extract(ship: Ship): Promise<Cargo> {
|
||||||
ship = dbShips.getShip(ship.symbol);
|
ship = dbShips.getShip(ship.symbol);
|
||||||
if (ship.cargo.units >= ship.cargo.capacity * 0.9) return ship.cargo;
|
if (isFull(ship)) return ship.cargo;
|
||||||
// TODO move to a suitable asteroid?
|
// TODO move to a suitable asteroid?
|
||||||
// const asteroidFields = await systems.type({symbol: ship.nav.systemSymbol, type: 'ENGINEERED_ASTEROID'});
|
// const asteroidFields = await systems.type({symbol: ship.nav.systemSymbol, type: 'ENGINEERED_ASTEROID'});
|
||||||
// TODO if there are multiple fields, find the closest one?
|
// TODO if there are multiple fields, find the closest one?
|
||||||
|
@ -55,6 +55,11 @@ export async function extract(ship: Ship): Promise<Cargo> {
|
||||||
return response.data.cargo
|
return response.data.cargo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isFull(ship: Ship): boolean {
|
||||||
|
ship = dbShips.getShip(ship.symbol);
|
||||||
|
return ship.cargo.units >= ship.cargo.capacity * 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
//function hasMount(shipSymbol, mountSymbol) {
|
//function hasMount(shipSymbol, mountSymbol) {
|
||||||
// const ship = dbShips.getShip(shipSymbol);
|
// const ship = dbShips.getShip(shipSymbol);
|
||||||
// return ship.mounts.filter(s => s.symbol === mountSymbol).length > 0;
|
// return ship.mounts.filter(s => s.symbol === mountSymbol).length > 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue