@shipload/sdk 2.0.0-rc2 → 2.0.0-rc20
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 +1 -349
- package/lib/shipload.d.ts +1658 -1126
- package/lib/shipload.js +6847 -3082
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +6468 -2793
- package/lib/shipload.m.js.map +1 -1
- package/package.json +6 -4
- package/src/capabilities/crafting.ts +22 -0
- package/src/capabilities/gathering.ts +36 -0
- package/src/capabilities/guards.ts +3 -8
- package/src/capabilities/hauling.ts +22 -0
- package/src/capabilities/index.ts +4 -1
- package/src/capabilities/modules.ts +57 -0
- package/src/capabilities/storage.ts +101 -9
- package/src/contracts/server.ts +717 -293
- package/src/data/capabilities.ts +408 -0
- package/src/data/categories.ts +55 -0
- package/src/data/colors.ts +71 -0
- package/src/data/items.json +17 -0
- package/src/data/locations.ts +53 -0
- package/src/data/nebula-adjectives.json +211 -0
- package/src/data/nebula-nouns.json +151 -0
- package/src/data/recipes.ts +587 -0
- package/src/data/syllables.json +1386 -780
- package/src/data/tiers.ts +45 -0
- package/src/derivation/crafting.ts +287 -0
- package/src/derivation/index.ts +30 -0
- package/src/derivation/location-size.ts +15 -0
- package/src/derivation/resources.ts +136 -0
- package/src/derivation/stats.ts +146 -0
- package/src/derivation/stratum.ts +134 -0
- package/src/derivation/tiers.ts +54 -0
- package/src/entities/cargo-utils.ts +10 -68
- package/src/entities/container.ts +37 -0
- package/src/entities/entity-inventory.ts +13 -13
- package/src/entities/inventory-accessor.ts +2 -6
- package/src/entities/location.ts +5 -200
- package/src/entities/makers.ts +136 -17
- package/src/entities/player.ts +1 -274
- package/src/entities/ship-deploy.ts +258 -0
- package/src/entities/ship.ts +28 -34
- package/src/entities/warehouse.ts +35 -7
- package/src/errors.ts +59 -5
- package/src/format.ts +12 -0
- package/src/index-module.ts +233 -50
- package/src/managers/actions.ts +138 -88
- package/src/managers/context.ts +19 -9
- package/src/managers/index.ts +0 -1
- package/src/managers/locations.ts +2 -85
- package/src/market/items.ts +93 -0
- package/src/nft/description.ts +176 -0
- package/src/nft/deserializers.ts +81 -0
- package/src/nft/index.ts +2 -0
- package/src/resolution/describe-module.ts +165 -0
- package/src/resolution/display-name.ts +39 -0
- package/src/resolution/resolve-item.ts +343 -0
- package/src/scheduling/projection.ts +220 -67
- package/src/scheduling/schedule.ts +2 -2
- package/src/shipload.ts +10 -5
- package/src/subscriptions/connection.ts +154 -0
- package/src/subscriptions/debug.ts +17 -0
- package/src/subscriptions/index.ts +5 -0
- package/src/subscriptions/manager.ts +240 -0
- package/src/subscriptions/mappers.ts +28 -0
- package/src/subscriptions/types.ts +143 -0
- package/src/travel/travel.ts +30 -17
- package/src/types/capabilities.ts +11 -14
- package/src/types/entity-traits.ts +3 -4
- package/src/types/entity.ts +9 -6
- package/src/types.ts +61 -55
- package/src/utils/system.ts +66 -53
- package/src/capabilities/extraction.ts +0 -37
- package/src/data/goods.json +0 -23
- package/src/managers/trades.ts +0 -119
- package/src/market/goods.ts +0 -31
- package/src/market/market.ts +0 -208
- package/src/market/rolls.ts +0 -8
- package/src/trading/collect.ts +0 -938
- package/src/trading/deal.ts +0 -207
- package/src/trading/trade.ts +0 -203
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipload/sdk",
|
|
3
3
|
"description": "SDKs for Shipload",
|
|
4
|
-
"version": "2.0.0-
|
|
4
|
+
"version": "2.0.0-rc20",
|
|
5
5
|
"homepage": "https://github.com/shipload/sdk",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "lib/shipload.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"prepare": "make"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@wharfkit/antelope": "
|
|
19
|
+
"@wharfkit/antelope": "1.2.0",
|
|
20
20
|
"@wharfkit/contract": "^1.2.1",
|
|
21
21
|
"@wharfkit/session": "^1.3.1",
|
|
22
22
|
"tslib": "^2.1.0"
|
|
@@ -56,8 +56,10 @@
|
|
|
56
56
|
"tsconfig-paths": "^4.1.1",
|
|
57
57
|
"typedoc": "^0.23.14",
|
|
58
58
|
"typedoc-plugin-mermaid": "^1.10.0",
|
|
59
|
-
"typescript": "^4.1.2"
|
|
60
|
-
|
|
59
|
+
"typescript": "^4.1.2"
|
|
60
|
+
},
|
|
61
|
+
"overrides": {
|
|
62
|
+
"@wharfkit/antelope": "1.2.0"
|
|
61
63
|
},
|
|
62
64
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
63
65
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {UInt16, UInt32} from '@wharfkit/antelope'
|
|
2
|
+
import {CRAFT_ENERGY_DIVISOR} from '../types'
|
|
3
|
+
import type {EntityCapabilities} from '../types/capabilities'
|
|
4
|
+
import {ServerContract} from '../contracts'
|
|
5
|
+
|
|
6
|
+
export interface CrafterCapability {
|
|
7
|
+
crafter: ServerContract.Types.crafter_stats
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function capsHasCrafter(caps: EntityCapabilities): boolean {
|
|
11
|
+
return caps.crafter !== undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function calc_craft_duration(speed: number, totalInputMass: number): UInt32 {
|
|
15
|
+
const duration = Math.floor(totalInputMass / speed)
|
|
16
|
+
return UInt32.from(Math.max(duration, 1))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function calc_craft_energy(drain: number, totalInputMass: number): UInt16 {
|
|
20
|
+
const raw = Math.floor((totalInputMass * drain) / CRAFT_ENERGY_DIVISOR)
|
|
21
|
+
return UInt16.from(Math.min(raw, 65535))
|
|
22
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {UInt16, UInt32} from '@wharfkit/antelope'
|
|
2
|
+
import {ServerContract} from '../contracts'
|
|
3
|
+
import {PRECISION} from '../types'
|
|
4
|
+
|
|
5
|
+
const GATHER_TIME_SCALE = 100
|
|
6
|
+
const DEPTH_PENALTY_DIVISOR = 5000
|
|
7
|
+
const SPEED_TIME_SCALE = 300
|
|
8
|
+
|
|
9
|
+
export function calc_gather_duration(
|
|
10
|
+
gatherer: ServerContract.Types.gatherer_stats,
|
|
11
|
+
itemMass: number,
|
|
12
|
+
quantity: number,
|
|
13
|
+
stratum: number,
|
|
14
|
+
richness: number
|
|
15
|
+
): UInt32 {
|
|
16
|
+
const yieldValue = gatherer.yield.toNumber()
|
|
17
|
+
const speed = gatherer.speed.toNumber()
|
|
18
|
+
|
|
19
|
+
if (yieldValue === 0 || speed === 0 || richness === 0) return UInt32.from(0)
|
|
20
|
+
|
|
21
|
+
const massFactor = Math.sqrt(itemMass)
|
|
22
|
+
const depthPenalty = 1 + stratum / DEPTH_PENALTY_DIVISOR
|
|
23
|
+
const richnessMul = richness / 1000
|
|
24
|
+
const gatherTime =
|
|
25
|
+
(quantity * massFactor * GATHER_TIME_SCALE * depthPenalty) / (yieldValue * richnessMul)
|
|
26
|
+
const speedTime = SPEED_TIME_SCALE * Math.log(1 + stratum / speed)
|
|
27
|
+
return UInt32.from(Math.floor(gatherTime + speedTime))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function calc_gather_energy(
|
|
31
|
+
gatherer: ServerContract.Types.gatherer_stats,
|
|
32
|
+
duration: number
|
|
33
|
+
): UInt16 {
|
|
34
|
+
const energy = Math.floor((duration * gatherer.drain.toNumber()) / PRECISION)
|
|
35
|
+
return UInt16.from(energy)
|
|
36
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EnergyCapability,
|
|
3
|
-
|
|
3
|
+
GathererCapability,
|
|
4
4
|
LoaderCapability,
|
|
5
5
|
MassCapability,
|
|
6
6
|
MovementCapability,
|
|
7
7
|
ScheduleCapability,
|
|
8
8
|
StorageCapability,
|
|
9
|
-
TradeCapability,
|
|
10
9
|
} from '../types/capabilities'
|
|
11
10
|
import {Entity} from '../types/entity'
|
|
12
11
|
|
|
@@ -26,10 +25,6 @@ export function hasLoaders(e: Entity): e is Entity & LoaderCapability {
|
|
|
26
25
|
return 'loaders' in e && e.loaders !== undefined
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
export function hasTrade(e: Entity): e is Entity & TradeCapability {
|
|
30
|
-
return 'trade' in e && e.trade !== undefined
|
|
31
|
-
}
|
|
32
|
-
|
|
33
28
|
export function hasMass(e: Entity): e is Entity & MassCapability {
|
|
34
29
|
return 'hullmass' in e
|
|
35
30
|
}
|
|
@@ -38,6 +33,6 @@ export function hasSchedule(e: Entity): e is Entity & ScheduleCapability {
|
|
|
38
33
|
return 'schedule' in e
|
|
39
34
|
}
|
|
40
35
|
|
|
41
|
-
export function
|
|
42
|
-
return '
|
|
36
|
+
export function hasGatherer(e: Entity): e is Entity & GathererCapability {
|
|
37
|
+
return 'gatherer' in e && e.gatherer !== undefined
|
|
43
38
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const BASE_HAUL_PENALTY_MILLI = 300
|
|
2
|
+
const HAULER_EFFICIENCY_DENOM = 10000
|
|
3
|
+
const PRECISION = 10000
|
|
4
|
+
|
|
5
|
+
export function computeHaulPenalty(
|
|
6
|
+
totalThrust: number,
|
|
7
|
+
haulCount: number,
|
|
8
|
+
avgEfficiency: number
|
|
9
|
+
): number {
|
|
10
|
+
if (haulCount === 0) return totalThrust
|
|
11
|
+
const penaltyMilli =
|
|
12
|
+
1000 +
|
|
13
|
+
Math.floor(
|
|
14
|
+
(haulCount * BASE_HAUL_PENALTY_MILLI * (HAULER_EFFICIENCY_DENOM - avgEfficiency)) /
|
|
15
|
+
HAULER_EFFICIENCY_DENOM
|
|
16
|
+
)
|
|
17
|
+
return Math.floor((totalThrust * 1000) / penaltyMilli)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function computeHaulerDrain(distance: number, drain: number, haulCount: number): number {
|
|
21
|
+
return Math.floor(distance / PRECISION) * drain * haulCount
|
|
22
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const ITEM_ENGINE_T1 = 10100
|
|
2
|
+
export const ITEM_GENERATOR_T1 = 10101
|
|
3
|
+
export const ITEM_GATHERER_T1 = 10102
|
|
4
|
+
export const ITEM_LOADER_T1 = 10103
|
|
5
|
+
export const ITEM_CRAFTER_T1 = 10104
|
|
6
|
+
export const ITEM_STORAGE_T1 = 10105
|
|
7
|
+
export const ITEM_HAULER_T1 = 10106
|
|
8
|
+
|
|
9
|
+
export const MODULE_ANY = 0
|
|
10
|
+
export const MODULE_ENGINE = 1
|
|
11
|
+
export const MODULE_GENERATOR = 2
|
|
12
|
+
export const MODULE_GATHERER = 3
|
|
13
|
+
export const MODULE_LOADER = 4
|
|
14
|
+
export const MODULE_WARP = 5
|
|
15
|
+
export const MODULE_CRAFTER = 6
|
|
16
|
+
export const MODULE_LAUNCHER = 7
|
|
17
|
+
export const MODULE_STORAGE = 8
|
|
18
|
+
export const MODULE_HAULER = 9
|
|
19
|
+
|
|
20
|
+
export interface PackedModule {
|
|
21
|
+
itemId: number
|
|
22
|
+
stats: bigint
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface ModuleEntry {
|
|
26
|
+
type: number
|
|
27
|
+
installed?: PackedModule
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function moduleAccepts(slotType: number, moduleType: number): boolean {
|
|
31
|
+
return slotType === MODULE_ANY || slotType === moduleType
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function getModuleCapabilityType(itemId: number): number {
|
|
35
|
+
switch (itemId) {
|
|
36
|
+
case ITEM_ENGINE_T1:
|
|
37
|
+
return MODULE_ENGINE
|
|
38
|
+
case ITEM_GENERATOR_T1:
|
|
39
|
+
return MODULE_GENERATOR
|
|
40
|
+
case ITEM_GATHERER_T1:
|
|
41
|
+
return MODULE_GATHERER
|
|
42
|
+
case ITEM_LOADER_T1:
|
|
43
|
+
return MODULE_LOADER
|
|
44
|
+
case ITEM_CRAFTER_T1:
|
|
45
|
+
return MODULE_CRAFTER
|
|
46
|
+
case ITEM_STORAGE_T1:
|
|
47
|
+
return MODULE_STORAGE
|
|
48
|
+
case ITEM_HAULER_T1:
|
|
49
|
+
return MODULE_HAULER
|
|
50
|
+
default:
|
|
51
|
+
return 0xff
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isModuleItem(itemId: number): boolean {
|
|
56
|
+
return getModuleCapabilityType(itemId) !== 0xff
|
|
57
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {UInt32, UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
1
|
+
import {UInt16, UInt32, UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
2
2
|
import {ServerContract} from '../contracts'
|
|
3
3
|
import {StorageCapability} from '../types/capabilities'
|
|
4
|
-
import {
|
|
4
|
+
import {getItem} from '../market/items'
|
|
5
|
+
import {INSUFFICIENT_ITEM_QUANTITY} from '../errors'
|
|
5
6
|
|
|
6
7
|
export interface HasCargo {
|
|
7
8
|
cargo: ServerContract.Types.cargo_item[]
|
|
@@ -15,21 +16,40 @@ export interface HasCargomass {
|
|
|
15
16
|
cargomass: UInt32
|
|
16
17
|
}
|
|
17
18
|
|
|
19
|
+
interface MassInput {
|
|
20
|
+
item_id: UInt16
|
|
21
|
+
quantity: UInt32
|
|
22
|
+
modules: ServerContract.Types.module_entry[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function calcCargoItemMass(item: MassInput): UInt64 {
|
|
26
|
+
const itemDef = getItem(item.item_id)
|
|
27
|
+
let mass = UInt64.from(itemDef.mass).multiplying(item.quantity)
|
|
28
|
+
|
|
29
|
+
for (const mod of item.modules) {
|
|
30
|
+
if (mod.installed) {
|
|
31
|
+
const modDef = getItem(mod.installed.item_id)
|
|
32
|
+
mass = mass.adding(modDef.mass)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return mass
|
|
37
|
+
}
|
|
38
|
+
|
|
18
39
|
export function calcCargoMass(entity: HasCargo): UInt64 {
|
|
19
40
|
let mass = UInt64.from(0)
|
|
20
41
|
for (const item of entity.cargo) {
|
|
21
|
-
|
|
22
|
-
mass = mass.adding(good.mass.multiplying(item.quantity))
|
|
42
|
+
mass = mass.adding(calcCargoItemMass(item))
|
|
23
43
|
}
|
|
24
44
|
return mass
|
|
25
45
|
}
|
|
26
46
|
|
|
27
|
-
export function
|
|
28
|
-
let
|
|
29
|
-
for (const
|
|
30
|
-
|
|
47
|
+
export function calcStacksMass(stacks: CargoStack[]): UInt64 {
|
|
48
|
+
let mass = UInt64.from(0)
|
|
49
|
+
for (const s of stacks) {
|
|
50
|
+
mass = mass.adding(calcCargoItemMass(s))
|
|
31
51
|
}
|
|
32
|
-
return
|
|
52
|
+
return mass
|
|
33
53
|
}
|
|
34
54
|
|
|
35
55
|
export function availableCapacity(entity: StorageCapability): UInt64 {
|
|
@@ -65,3 +85,75 @@ export function isFull(entity: HasCapacity & HasCargomass): boolean {
|
|
|
65
85
|
export function isFullFromMass(capacity: UInt64Type, cargoMass: UInt64Type): boolean {
|
|
66
86
|
return UInt64.from(cargoMass).gte(capacity)
|
|
67
87
|
}
|
|
88
|
+
|
|
89
|
+
export interface CargoStack {
|
|
90
|
+
item_id: UInt16
|
|
91
|
+
quantity: UInt32
|
|
92
|
+
stats: UInt64
|
|
93
|
+
modules: ServerContract.Types.module_entry[]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function cargoItemToStack(item: ServerContract.Types.cargo_item): CargoStack {
|
|
97
|
+
return {
|
|
98
|
+
item_id: UInt16.from(item.item_id),
|
|
99
|
+
quantity: UInt32.from(item.quantity),
|
|
100
|
+
stats: item.stats,
|
|
101
|
+
modules: item.modules ?? [],
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function stackToCargoItem(stack: CargoStack): ServerContract.Types.cargo_item {
|
|
106
|
+
return ServerContract.Types.cargo_item.from({
|
|
107
|
+
item_id: stack.item_id,
|
|
108
|
+
quantity: stack.quantity,
|
|
109
|
+
stats: stack.stats,
|
|
110
|
+
modules: stack.modules,
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function statsEquals(a: UInt64, b: UInt64): boolean {
|
|
115
|
+
return a.equals(b)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function stackIdentityEqual(a: CargoStack, b: CargoStack): boolean {
|
|
119
|
+
return a.item_id.equals(b.item_id) && statsEquals(a.stats, b.stats)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function stackKey(s: CargoStack): string {
|
|
123
|
+
return `${s.item_id.toNumber()}:${s.stats.toString()}`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function stacksEqual(a: CargoStack, b: CargoStack): boolean {
|
|
127
|
+
return stackIdentityEqual(a, b) && a.quantity.equals(b.quantity)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function mergeStacks(stacks: CargoStack[], add: CargoStack): CargoStack[] {
|
|
131
|
+
const idx = stacks.findIndex((s) => stackIdentityEqual(s, add))
|
|
132
|
+
if (idx === -1) {
|
|
133
|
+
return [...stacks, {...add}]
|
|
134
|
+
}
|
|
135
|
+
const result = stacks.slice()
|
|
136
|
+
result[idx] = {
|
|
137
|
+
...result[idx],
|
|
138
|
+
quantity: UInt32.from(result[idx].quantity.adding(add.quantity)),
|
|
139
|
+
}
|
|
140
|
+
return result
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function removeFromStacks(stacks: CargoStack[], remove: CargoStack): CargoStack[] {
|
|
144
|
+
const idx = stacks.findIndex((s) => stackIdentityEqual(s, remove))
|
|
145
|
+
if (idx === -1) {
|
|
146
|
+
throw new Error(INSUFFICIENT_ITEM_QUANTITY)
|
|
147
|
+
}
|
|
148
|
+
const target = stacks[idx]
|
|
149
|
+
if (target.quantity.lt(remove.quantity)) {
|
|
150
|
+
throw new Error(INSUFFICIENT_ITEM_QUANTITY)
|
|
151
|
+
}
|
|
152
|
+
const remaining = UInt32.from(target.quantity.subtracting(remove.quantity))
|
|
153
|
+
if (remaining.equals(UInt32.from(0))) {
|
|
154
|
+
return [...stacks.slice(0, idx), ...stacks.slice(idx + 1)]
|
|
155
|
+
}
|
|
156
|
+
const result = stacks.slice()
|
|
157
|
+
result[idx] = {...target, quantity: remaining}
|
|
158
|
+
return result
|
|
159
|
+
}
|