@shipload/sdk 2.0.0-rc1 → 2.0.0-rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +349 -1
- package/lib/shipload.d.ts +809 -314
- package/lib/shipload.js +2745 -1740
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +2158 -1154
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -2
- package/src/capabilities/extraction.ts +30 -0
- package/src/capabilities/guards.ts +43 -0
- package/src/capabilities/index.ts +5 -0
- package/src/capabilities/loading.ts +8 -0
- package/src/capabilities/movement.ts +29 -0
- package/src/capabilities/storage.ts +67 -0
- package/src/contracts/server.ts +506 -183
- package/src/data/items.json +16 -0
- package/src/derivation/index.ts +25 -0
- package/src/derivation/location-size.ts +15 -0
- package/src/derivation/resources.ts +141 -0
- package/src/derivation/stratum.ts +116 -0
- package/src/entities/cargo-utils.ts +98 -3
- package/src/entities/container.ts +70 -0
- package/src/entities/entity-inventory.ts +13 -9
- package/src/entities/inventory-accessor.ts +46 -0
- package/src/entities/location.ts +31 -17
- package/src/entities/makers.ts +69 -0
- package/src/entities/player.ts +2 -1
- package/src/entities/ship.ts +93 -440
- package/src/entities/warehouse.ts +29 -145
- package/src/errors.ts +4 -4
- package/src/index-module.ts +62 -4
- package/src/managers/actions.ts +75 -31
- package/src/managers/entities.ts +22 -5
- package/src/managers/locations.ts +34 -15
- package/src/managers/trades.ts +7 -7
- package/src/market/items.ts +31 -0
- package/src/market/market.ts +12 -13
- package/src/scheduling/accessor.ts +82 -0
- package/src/scheduling/projection.ts +126 -54
- package/src/scheduling/schedule.ts +24 -0
- package/src/trading/collect.ts +25 -26
- package/src/trading/deal.ts +8 -9
- package/src/trading/trade.ts +9 -9
- package/src/travel/travel.ts +69 -8
- package/src/types/capabilities.ts +79 -0
- package/src/types/entity-traits.ts +70 -0
- package/src/types/entity.ts +36 -0
- package/src/types/index.ts +3 -0
- package/src/types.ts +92 -15
- package/src/utils/hash.ts +1 -1
- package/src/utils/system.ts +97 -4
- package/src/data/goods.json +0 -23
- package/src/market/goods.ts +0 -31
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipload/sdk",
|
|
3
3
|
"description": "SDKs for Shipload",
|
|
4
|
-
"version": "2.0.0-
|
|
4
|
+
"version": "2.0.0-rc3",
|
|
5
5
|
"homepage": "https://github.com/shipload/sdk",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "lib/shipload.js",
|
|
8
8
|
"module": "lib/shipload.m.js",
|
|
9
9
|
"types": "lib/shipload.d.ts",
|
|
10
|
-
"unpkg": "lib/shipload.bundle.js",
|
|
11
10
|
"sideEffects": false,
|
|
12
11
|
"files": [
|
|
13
12
|
"lib/*",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {UInt16, UInt32} from '@wharfkit/antelope'
|
|
2
|
+
import {ServerContract} from '../contracts'
|
|
3
|
+
import {PRECISION} from '../types'
|
|
4
|
+
|
|
5
|
+
export function calc_extraction_duration(
|
|
6
|
+
extractor: ServerContract.Types.extractor_stats,
|
|
7
|
+
cargoMass: number,
|
|
8
|
+
stratum: number,
|
|
9
|
+
richness: number
|
|
10
|
+
): UInt32 {
|
|
11
|
+
const rate = extractor.rate.toNumber()
|
|
12
|
+
const efficiency = extractor.efficiency.toNumber()
|
|
13
|
+
const drill = extractor.drill.toNumber()
|
|
14
|
+
|
|
15
|
+
const rateProduct = Math.floor((rate * richness * efficiency) / PRECISION)
|
|
16
|
+
if (rateProduct === 0) return UInt32.from(0)
|
|
17
|
+
|
|
18
|
+
const extractionTime = Math.floor((cargoMass * PRECISION) / rateProduct)
|
|
19
|
+
const drillTime = Math.floor(stratum / drill)
|
|
20
|
+
|
|
21
|
+
return UInt32.from(extractionTime + drillTime)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function calc_extraction_energy(
|
|
25
|
+
extractor: ServerContract.Types.extractor_stats,
|
|
26
|
+
duration: number
|
|
27
|
+
): UInt16 {
|
|
28
|
+
const energy = Math.floor((duration * extractor.drain.toNumber()) / PRECISION)
|
|
29
|
+
return UInt16.from(energy)
|
|
30
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EnergyCapability,
|
|
3
|
+
ExtractorCapability,
|
|
4
|
+
LoaderCapability,
|
|
5
|
+
MassCapability,
|
|
6
|
+
MovementCapability,
|
|
7
|
+
ScheduleCapability,
|
|
8
|
+
StorageCapability,
|
|
9
|
+
TradeCapability,
|
|
10
|
+
} from '../types/capabilities'
|
|
11
|
+
import {Entity} from '../types/entity'
|
|
12
|
+
|
|
13
|
+
export function canMove(e: Entity): e is Entity & MovementCapability & EnergyCapability {
|
|
14
|
+
return 'engines' in e && 'generator' in e && 'energy' in e
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function hasEnergy(e: Entity): e is Entity & EnergyCapability {
|
|
18
|
+
return 'energy' in e
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function hasStorage(e: Entity): e is Entity & StorageCapability {
|
|
22
|
+
return 'capacity' in e && 'cargo' in e
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function hasLoaders(e: Entity): e is Entity & LoaderCapability {
|
|
26
|
+
return 'loaders' in e && e.loaders !== undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function hasTrade(e: Entity): e is Entity & TradeCapability {
|
|
30
|
+
return 'trade' in e && e.trade !== undefined
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function hasMass(e: Entity): e is Entity & MassCapability {
|
|
34
|
+
return 'hullmass' in e
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function hasSchedule(e: Entity): e is Entity & ScheduleCapability {
|
|
38
|
+
return 'schedule' in e
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function hasExtractor(e: Entity): e is Entity & ExtractorCapability {
|
|
42
|
+
return 'extractor' in e && e.extractor !== undefined
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import {UInt32, UInt64} from '@wharfkit/antelope'
|
|
2
|
+
import {LoaderCapability} from '../types/capabilities'
|
|
3
|
+
|
|
4
|
+
export function calcLoadDuration(entity: LoaderCapability, cargoMass: UInt64): UInt32 {
|
|
5
|
+
const totalThrust = entity.loaders.thrust.toNumber() * entity.loaders.quantity.toNumber()
|
|
6
|
+
if (totalThrust === 0) return UInt32.from(0)
|
|
7
|
+
return UInt32.from(Math.ceil(Number(cargoMass) / totalThrust))
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {UInt32, UInt64} from '@wharfkit/antelope'
|
|
2
|
+
import {EnergyCapability, MovementCapability} from '../types/capabilities'
|
|
3
|
+
import {PRECISION} from '../types'
|
|
4
|
+
|
|
5
|
+
export function maxTravelDistance(entity: MovementCapability): UInt32 {
|
|
6
|
+
return UInt32.from(entity.generator.capacity)
|
|
7
|
+
.dividing(entity.engines.drain)
|
|
8
|
+
.multiplying(PRECISION)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function calcEnergyUsage(entity: MovementCapability, distance: UInt64): UInt64 {
|
|
12
|
+
return distance.dividing(PRECISION).multiplying(entity.engines.drain)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function hasEnergyForDistance(
|
|
16
|
+
entity: MovementCapability & EnergyCapability,
|
|
17
|
+
distance: UInt64
|
|
18
|
+
): boolean {
|
|
19
|
+
const usage = calcEnergyUsage(entity, distance)
|
|
20
|
+
return UInt64.from(entity.energy).gte(usage)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function energyPercent(entity: MovementCapability & EnergyCapability): number {
|
|
24
|
+
return (Number(entity.energy) / Number(entity.generator.capacity)) * 100
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function needsRecharge(entity: MovementCapability & EnergyCapability): boolean {
|
|
28
|
+
return UInt64.from(entity.energy).lt(entity.generator.capacity)
|
|
29
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {UInt32, UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
2
|
+
import {ServerContract} from '../contracts'
|
|
3
|
+
import {StorageCapability} from '../types/capabilities'
|
|
4
|
+
import {getItem} from '../market/items'
|
|
5
|
+
|
|
6
|
+
export interface HasCargo {
|
|
7
|
+
cargo: ServerContract.Types.cargo_item[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface HasCapacity {
|
|
11
|
+
capacity: UInt32
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface HasCargomass {
|
|
15
|
+
cargomass: UInt32
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function calcCargoMass(entity: HasCargo): UInt64 {
|
|
19
|
+
let mass = UInt64.from(0)
|
|
20
|
+
for (const item of entity.cargo) {
|
|
21
|
+
const good = getItem(item.item_id)
|
|
22
|
+
mass = mass.adding(good.mass.multiplying(item.quantity))
|
|
23
|
+
}
|
|
24
|
+
return mass
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function calcCargoValue(entity: HasCargo): UInt64 {
|
|
28
|
+
let value = UInt64.from(0)
|
|
29
|
+
for (const item of entity.cargo) {
|
|
30
|
+
value = value.adding(item.unit_cost.multiplying(item.quantity))
|
|
31
|
+
}
|
|
32
|
+
return value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function availableCapacity(entity: StorageCapability): UInt64 {
|
|
36
|
+
const cargoMass = calcCargoMass(entity)
|
|
37
|
+
return entity.capacity.gt(cargoMass)
|
|
38
|
+
? UInt64.from(entity.capacity).subtracting(cargoMass)
|
|
39
|
+
: UInt64.from(0)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function availableCapacityFromMass(capacity: UInt64Type, cargoMass: UInt64Type): UInt64 {
|
|
43
|
+
const cap = UInt64.from(capacity)
|
|
44
|
+
const mass = UInt64.from(cargoMass)
|
|
45
|
+
return cap.gt(mass) ? cap.subtracting(mass) : UInt64.from(0)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function hasSpace(entity: StorageCapability, goodMass: UInt64, quantity: number): boolean {
|
|
49
|
+
const additional = goodMass.multiplying(quantity)
|
|
50
|
+
return availableCapacity(entity).gte(additional)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function hasSpaceForMass(
|
|
54
|
+
capacity: UInt64Type,
|
|
55
|
+
currentMass: UInt64Type,
|
|
56
|
+
additionalMass: UInt64Type
|
|
57
|
+
): boolean {
|
|
58
|
+
return UInt64.from(currentMass).adding(additionalMass).lte(capacity)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function isFull(entity: HasCapacity & HasCargomass): boolean {
|
|
62
|
+
return UInt64.from(entity.cargomass).gte(entity.capacity)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function isFullFromMass(capacity: UInt64Type, cargoMass: UInt64Type): boolean {
|
|
66
|
+
return UInt64.from(cargoMass).gte(capacity)
|
|
67
|
+
}
|