1.0.0-alpha.0 • Published 3 years ago

spacing-guild v1.0.0-alpha.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Spacing Guild

GitHub package.json version

A library of useful features for SpaceTraders API


Contents


Installation

npm i spacing-guild --save


Usage

Using Navigator

import { Navigator, ITradeRoute } from "spacing-guild";

// ...

const edric: Navigator = new Navigator(locations, ship);
const route: ITradeRoute = edric.navigate();

Example result

{
  "destination": "OE-PM",
  "cargo": [
    { "good": "FUEL", "quantity": 3, "totalVolume": 3 },
    { "good": "METALS", "quantity": 10, "totalVolume": 10 },
    { "good": "DRONES", "quantity": 2, "totalVolume": 4 },
    { "good": "FUEL", "quantity": 33, "totalVolume": 33 }
  ]
}

Using Mentat

import { Mentat } from "spacing-guild";

// ...

const distance: number = Mentat.calculateLocationDistance(locationA, locationB);
const inRange: number = Mentat.validateRange(ship, range, location);

Build

npm i

npm run build


Documentation

Navigator

The Navigator class is will decide the most profitable, possible trade from the ship's current location

It will return an object with 2 properties: Destination and Cargo

  • Destination is a location type object that can be used when setting the flight plan.
  • Cargo contains all the goods that should be bought from current marketplace and in what quantities, as well as the FUEL required for the trip. These goods should then be sold at the destination's marketplace.

Navigator class takes 2 arguments

  • locations : A list of location objects to parse through
  • ship : The ship object

Once a Navigator object is created, it automatically parses the locations and sets a list of all available trades. This list will then be used in the navigate() method to narrow down the possible trades based on the method's arguments.

note: In the following table, the column Type will contain some custom interfaces. Please refer to the Interfaces typescript file for information

MethodsArgumentsTypeDescription
updateLocationsDatavoid
locationsILocations[]The list of locations
updateShipDatavoid
shipIShipThe ship object
navigatereturns ITradeRoute
params (optional){range: number, fuelMargin: number}
range is a number to limit the search for trade routes
fuelMargin is a number representing a percentage (ex. 5 is 5%) to include as error margin when calculating the FUEL needed for a trip
strict (optional)boolean (default false)Default is false. If true it throws errors instead of returning void in cases where trades are impossible

NOTES

  • If one of the profitable trades happens to be FUEL, it adds an extra entry with FUEL.
  • This should not be sold as it can be used for further traveling and save costs because it was bought in a better price.
  • If there is space left and no more available trades on destination, the remaining space will be empty.
  • Currently this only works within the ship's system. Intersystem route plotting is the future. #TODO

Mentat

The Mentat class is solely responsible for various calculations. All methods are public static and return either a number or a boolean.

note: In the following table, the column Type will contain some custom interfaces. Please refer to the Interfaces typescript file for information

MethodsArgumentsTypeDescription
calculateFuelToTravelreturns numberCalculates the amount of fuel required to travel from location to destination
shipIShip
locationILocation
destinationILocation
calculateFuelQuantityreturns numberCalculates the remaining fuel needed to reach the quantity required for travel. Considers existing fuel in the ship. Adds extra fuel depending on the margin.
shipIShip
fuelToTravelnumber
marginnumber (optional)
calculateDistancereturns numberCalculates the distance between 2 points
axnumber
aynumber
bxnumber
bynumber
calculateLocationDistancereturns numberCalculates the distance between 2 locations
aILocation
bILocation
calculatePricePerVolumereturns numberCalculates the price per volume of a good. (Ex.If a unit of MACHINERY is 2 volumes and is priced at 10, then the price per volume is 5)
pricePerUnitnumber
volumePerUnitnumber
calculateGoodProfitPerVolreturns numberCalculates the profit per volume of a good bought in local marketplace and sold on another marketplace
aIGood
bIGood
calculateGoodProfitreturns numberCalculates the gross gain of selling a good
goodIGood
amountnumber
calculateGoodCostreturns numberCalculates the cost of buying a good
goodIGood
amountnumber
calculateFuelToTravelCostreturns numberCalculates the cost of fuel
amountnumber
unitCostnumber
calculateCargoVolumereturns numberCalculates the total volume of a good
goodIGood
shipIShip
calculateGoodQuantityreturns numberCalculates the quantity of a good based on the available cargo space
spacenumber
volumePerUnitnumber
calculateProfitPerDUreturns numberCalculates the profit per Distance Unit based on fuel cost, goods profit and distance to marketplace from the ship's position. The Profit per DU metric is used to sort the trades. The highest PpDU route is the best trade available
aGoodIGood
bGoodIGood
shipIShip
locationILocation
destinationILocation
fuelUnitCostnumber
calculateFuelToTravelVolumereturns numberCalculates the volume of FUEL
amountnumber
calculateGoodVolumereturns numberCalculates the volume of a good's quantity
amountnumber
goodIGood
calculateRemainingSpaceAfterRefuelreturns numberCalculates the available cargo space after buying the fuel necessary for the route
shipIShip
fuelQuantitynumber
validateRangereturns booleanValidates if a location is within the given range of the ship
shipIShip
rangenumber
locationILocation