summaryrefslogtreecommitdiff
path: root/nodejs/automation
diff options
context:
space:
mode:
authorJulien Dessaux2023-10-19 01:58:06 +0200
committerJulien Dessaux2023-10-19 01:58:06 +0200
commit378b5a5ffbcf2beab46a56ae42a926b786af0877 (patch)
tree8523ba4b73c10b80fd433caf64bd52e4dfc1ebd8 /nodejs/automation
parent[haskell] add missing indices (diff)
downloadspacetraders-378b5a5ffbcf2beab46a56ae42a926b786af0877.tar.gz
spacetraders-378b5a5ffbcf2beab46a56ae42a926b786af0877.tar.bz2
spacetraders-378b5a5ffbcf2beab46a56ae42a926b786af0877.zip
[javascript] implemented contract fulfillment
Diffstat (limited to 'nodejs/automation')
-rw-r--r--nodejs/automation/contracting.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/nodejs/automation/contracting.js b/nodejs/automation/contracting.js
index c051b03..a02c1c6 100644
--- a/nodejs/automation/contracting.js
+++ b/nodejs/automation/contracting.js
@@ -34,7 +34,7 @@ async function runProcurement(contract, ships) {
const asteroidFields = await systems.type({symbol: ships[0].nav.systemSymbol, type: 'ASTEROID_FIELD'});
const asteroidField = asteroidFields[0].symbol;
ships.forEach(async function(ship) {
- while (!contract.fulfilled) {
+ while (!dbContracts.getContract(contract.id).fulfilled) {
ship = dbShips.getShip(ship.symbol);
let goodCargo = ship.cargo.inventory.filter(i => i.symbol === wantedCargo)[0];
// If we are in transit, we wait until we arrive
@@ -49,8 +49,9 @@ async function runProcurement(contract, ships) {
case deliveryPoint:
if (goodCargo !== undefined) { // we could be here if a client restart happens right after selling before we navigate away
console.log(`delivering ${goodCargo.units} of ${wantedCargo}`);
- await contracts.deliver({contract: contract.id, symbol: ship.symbol, good: wantedCargo, units: goodCargo.units });
- // TODO check if contract is fulfilled!
+ if (await contracts.deliver({id: contract.id, symbol: ship.symbol, good: wantedCargo, units: goodCargo.units })) {
+ break;
+ }
}
await libShips.navigate({symbol: ship.symbol, waypoint: asteroidField});
break;
@@ -58,5 +59,6 @@ async function runProcurement(contract, ships) {
await libShips.navigate({symbol: ship.symbol, waypoint: asteroidField});
}
}
+ // TODO repurpose the ship
});
}