[javascript] fixed mining loop
This commit is contained in:
		
					parent
					
						
							
								fcbd9cf56c
							
						
					
				
			
			
				commit
				
					
						3b61a9694d
					
				
			
		
					 3 changed files with 4 additions and 4 deletions
				
			
		| 
						 | 
					@ -12,7 +12,7 @@ export async function mineUntilFullOf(ctx) {
 | 
				
			||||||
		const cargo = utils.categorizeCargo(await mineUntilFull({symbol: ctx.symbol}), ctx.good);
 | 
							const cargo = utils.categorizeCargo(await mineUntilFull({symbol: ctx.symbol}), ctx.good);
 | 
				
			||||||
		const wantedUnits = Object.values(cargo.wanted).reduce((acc, e) => acc += e, 0);
 | 
							const wantedUnits = Object.values(cargo.wanted).reduce((acc, e) => acc += e, 0);
 | 
				
			||||||
		// > 90% full of the valuable goods ?
 | 
							// > 90% full of the valuable goods ?
 | 
				
			||||||
		if (wantedUnits >= cargo.capacity * 0.9) return;
 | 
							if (wantedUnits >= ship.cargo.capacity * 0.9) return;
 | 
				
			||||||
		// we are full but need to sell junk
 | 
							// we are full but need to sell junk
 | 
				
			||||||
		await selling.sell(ship, ctx.good);
 | 
							await selling.sell(ship, ctx.good);
 | 
				
			||||||
		await libShips.navigate({symbol: ship.symbol, waypoint: ctx.asteroidSymbol});
 | 
							await libShips.navigate({symbol: ship.symbol, waypoint: ctx.asteroidSymbol});
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,7 @@ async function mineUntilFull(ctx) {
 | 
				
			||||||
		const ship = dbShips.getShip(ctx.symbol);
 | 
							const ship = dbShips.getShip(ctx.symbol);
 | 
				
			||||||
		if (ship.cargo.units >= ship.cargo.capacity * 0.9) return ship.cargo;
 | 
							if (ship.cargo.units >= ship.cargo.capacity * 0.9) return ship.cargo;
 | 
				
			||||||
		if (await libShips.extract({symbol: ctx.symbol}) === null)
 | 
							if (await libShips.extract({symbol: ctx.symbol}) === null)
 | 
				
			||||||
			ship = await ship(ctx); // refresh the ships status from the server just in case
 | 
								await ship(ctx); // refresh the ships status from the server just in case
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,7 +62,7 @@ export async function jump(ctx) {
 | 
				
			||||||
export async function navigate(ctx) {
 | 
					export async function navigate(ctx) {
 | 
				
			||||||
	const ship = dbShips.getShip(ctx.symbol);
 | 
						const ship = dbShips.getShip(ctx.symbol);
 | 
				
			||||||
	if (ship.nav.waypointSymbol === ctx.waypoint) {
 | 
						if (ship.nav.waypointSymbol === ctx.waypoint) {
 | 
				
			||||||
		return await orbit(ctx);
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	await orbit(ctx);
 | 
						await orbit(ctx);
 | 
				
			||||||
	// TODO if we do not have enough fuel, make a stop to refuel along the way or drift to the destination
 | 
						// TODO if we do not have enough fuel, make a stop to refuel along the way or drift to the destination
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,5 +3,5 @@
 | 
				
			||||||
pkgs.mkShell {
 | 
					pkgs.mkShell {
 | 
				
			||||||
  LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
 | 
					  LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive";
 | 
				
			||||||
  name = "node";
 | 
					  name = "node";
 | 
				
			||||||
  nativeBuildInputs = with pkgs; [ ijq jq nodejs ];
 | 
					  nativeBuildInputs = with pkgs; [ ijq jq nodejs_21 ];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue