@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
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import {UInt16, UInt64} from '@wharfkit/antelope'
|
|
2
|
+
import type {UInt16Type, UInt64Type} from '@wharfkit/antelope'
|
|
3
|
+
import type {ResourceCategory, ResourceTier} from '../types'
|
|
4
|
+
import {getItem} from '../market/items'
|
|
5
|
+
import {getComponentById, getEntityRecipeByItemId, getModuleRecipeByItemId} from '../data/recipes'
|
|
6
|
+
import {
|
|
7
|
+
getModuleCapabilityType,
|
|
8
|
+
isModuleItem,
|
|
9
|
+
MODULE_CRAFTER,
|
|
10
|
+
MODULE_ENGINE,
|
|
11
|
+
MODULE_GATHERER,
|
|
12
|
+
MODULE_GENERATOR,
|
|
13
|
+
MODULE_HAULER,
|
|
14
|
+
MODULE_LOADER,
|
|
15
|
+
MODULE_STORAGE,
|
|
16
|
+
} from '../capabilities/modules'
|
|
17
|
+
import {decodeCraftedItemStats, decodeStat} from '../derivation/crafting'
|
|
18
|
+
import {getStatDefinitions} from '../derivation/stats'
|
|
19
|
+
import {
|
|
20
|
+
computeCrafterCapabilities,
|
|
21
|
+
computeEngineCapabilities,
|
|
22
|
+
computeGathererCapabilities,
|
|
23
|
+
computeGeneratorCapabilities,
|
|
24
|
+
computeHaulerCapabilities,
|
|
25
|
+
computeLoaderCapabilities,
|
|
26
|
+
computeShipHullCapabilities,
|
|
27
|
+
computeWarehouseHullCapabilities,
|
|
28
|
+
} from '../entities/ship-deploy'
|
|
29
|
+
import {computeContainerCapabilities, computeContainerT2Capabilities} from '../entities/container'
|
|
30
|
+
import {
|
|
31
|
+
categoryColors,
|
|
32
|
+
categoryIcons,
|
|
33
|
+
componentIcon,
|
|
34
|
+
itemAbbreviations,
|
|
35
|
+
moduleIcon,
|
|
36
|
+
} from '../data/colors'
|
|
37
|
+
import {ServerContract} from '../contracts'
|
|
38
|
+
|
|
39
|
+
export interface ResolvedItemStat {
|
|
40
|
+
key: string
|
|
41
|
+
label: string
|
|
42
|
+
abbreviation: string
|
|
43
|
+
value: number
|
|
44
|
+
color: string
|
|
45
|
+
category: ResourceCategory
|
|
46
|
+
inverted?: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ResolvedAttributeGroup {
|
|
50
|
+
capability: string
|
|
51
|
+
attributes: {label: string; value: number}[]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type ResolvedItemType = 'resource' | 'component' | 'module' | 'entity'
|
|
55
|
+
|
|
56
|
+
export interface ResolvedModuleSlot {
|
|
57
|
+
name?: string
|
|
58
|
+
installed: boolean
|
|
59
|
+
attributes?: {label: string; value: number}[]
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ResolvedItem {
|
|
63
|
+
itemId: number
|
|
64
|
+
name: string
|
|
65
|
+
icon: string
|
|
66
|
+
abbreviation: string | null
|
|
67
|
+
category?: ResourceCategory
|
|
68
|
+
tier: ResourceTier
|
|
69
|
+
mass: number
|
|
70
|
+
itemType: ResolvedItemType
|
|
71
|
+
stats?: ResolvedItemStat[]
|
|
72
|
+
attributes?: ResolvedAttributeGroup[]
|
|
73
|
+
moduleSlots?: ResolvedModuleSlot[]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function toNum(v: UInt16Type): number {
|
|
77
|
+
return Number(UInt16.from(v).value.toString())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function toBigStats(v: UInt64Type): bigint {
|
|
81
|
+
return BigInt(UInt64.from(v).toString())
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function resolveResource(id: number, stats?: UInt64Type): ResolvedItem {
|
|
85
|
+
const item = getItem(id)
|
|
86
|
+
const cat = item.category
|
|
87
|
+
let resolvedStats: ResolvedItemStat[] | undefined
|
|
88
|
+
if (stats !== undefined) {
|
|
89
|
+
const bigStats = toBigStats(stats)
|
|
90
|
+
const defs = getStatDefinitions(cat)
|
|
91
|
+
const values = [decodeStat(bigStats, 0), decodeStat(bigStats, 1), decodeStat(bigStats, 2)]
|
|
92
|
+
resolvedStats = defs.map((d, i) => ({
|
|
93
|
+
key: d.key,
|
|
94
|
+
label: d.label,
|
|
95
|
+
abbreviation: d.abbreviation,
|
|
96
|
+
value: values[i] ?? 0,
|
|
97
|
+
color: categoryColors[cat],
|
|
98
|
+
category: cat,
|
|
99
|
+
inverted: d.inverted,
|
|
100
|
+
}))
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
itemId: id,
|
|
104
|
+
name: item.displayName,
|
|
105
|
+
icon: categoryIcons[cat] ?? '⬡',
|
|
106
|
+
abbreviation: null,
|
|
107
|
+
category: cat,
|
|
108
|
+
tier: item.tier,
|
|
109
|
+
mass: Number(item.mass.value.toString()),
|
|
110
|
+
itemType: 'resource',
|
|
111
|
+
stats: resolvedStats,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function resolveComponent(id: number, stats?: UInt64Type): ResolvedItem {
|
|
116
|
+
const comp = getComponentById(id)!
|
|
117
|
+
let resolvedStats: ResolvedItemStat[] | undefined
|
|
118
|
+
if (stats !== undefined) {
|
|
119
|
+
const decoded = decodeCraftedItemStats(id, toBigStats(stats))
|
|
120
|
+
resolvedStats = Object.entries(decoded).map(([key, value]) => {
|
|
121
|
+
const allDefs = getStatDefinitions('ore')
|
|
122
|
+
.concat(getStatDefinitions('crystal'))
|
|
123
|
+
.concat(getStatDefinitions('gas'))
|
|
124
|
+
.concat(getStatDefinitions('regolith'))
|
|
125
|
+
.concat(getStatDefinitions('biomass'))
|
|
126
|
+
const def = allDefs.find((d) => d.key === key)
|
|
127
|
+
const statDef = comp.stats.find((s) => s.key === key)
|
|
128
|
+
const cat = (statDef?.source ?? 'ore') as ResourceCategory
|
|
129
|
+
return {
|
|
130
|
+
key,
|
|
131
|
+
label: def?.label ?? key,
|
|
132
|
+
abbreviation: def?.abbreviation ?? key.slice(0, 3).toUpperCase(),
|
|
133
|
+
value,
|
|
134
|
+
color: categoryColors[cat],
|
|
135
|
+
category: cat,
|
|
136
|
+
inverted: def?.inverted,
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
itemId: id,
|
|
142
|
+
name: comp.name,
|
|
143
|
+
icon: itemAbbreviations[id] ?? componentIcon,
|
|
144
|
+
abbreviation: itemAbbreviations[id] ?? null,
|
|
145
|
+
tier: 't1' as ResourceTier,
|
|
146
|
+
mass: comp.mass,
|
|
147
|
+
itemType: 'component',
|
|
148
|
+
stats: resolvedStats,
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function computeCapabilityGroup(
|
|
153
|
+
moduleType: number,
|
|
154
|
+
stats: Record<string, number>
|
|
155
|
+
): ResolvedAttributeGroup | undefined {
|
|
156
|
+
switch (moduleType) {
|
|
157
|
+
case MODULE_ENGINE: {
|
|
158
|
+
const caps = computeEngineCapabilities(stats)
|
|
159
|
+
return {
|
|
160
|
+
capability: 'Engine',
|
|
161
|
+
attributes: [
|
|
162
|
+
{label: 'Thrust', value: caps.thrust},
|
|
163
|
+
{label: 'Drain', value: caps.drain},
|
|
164
|
+
],
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
case MODULE_GENERATOR: {
|
|
168
|
+
const caps = computeGeneratorCapabilities(stats)
|
|
169
|
+
return {
|
|
170
|
+
capability: 'Generator',
|
|
171
|
+
attributes: [
|
|
172
|
+
{label: 'Capacity', value: caps.capacity},
|
|
173
|
+
{label: 'Recharge', value: caps.recharge},
|
|
174
|
+
],
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
case MODULE_GATHERER: {
|
|
178
|
+
const caps = computeGathererCapabilities(stats)
|
|
179
|
+
return {
|
|
180
|
+
capability: 'Gatherer',
|
|
181
|
+
attributes: [
|
|
182
|
+
{label: 'Yield', value: caps.yield},
|
|
183
|
+
{label: 'Drain', value: caps.drain},
|
|
184
|
+
{label: 'Depth', value: caps.depth},
|
|
185
|
+
{label: 'Speed', value: caps.speed},
|
|
186
|
+
],
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
case MODULE_LOADER: {
|
|
190
|
+
const caps = computeLoaderCapabilities(stats)
|
|
191
|
+
return {
|
|
192
|
+
capability: 'Loader',
|
|
193
|
+
attributes: [
|
|
194
|
+
{label: 'Mass', value: caps.mass},
|
|
195
|
+
{label: 'Thrust', value: caps.thrust},
|
|
196
|
+
{label: 'Quantity', value: caps.quantity},
|
|
197
|
+
],
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
case MODULE_CRAFTER: {
|
|
201
|
+
const caps = computeCrafterCapabilities(stats)
|
|
202
|
+
return {
|
|
203
|
+
capability: 'Crafter',
|
|
204
|
+
attributes: [
|
|
205
|
+
{label: 'Speed', value: caps.speed},
|
|
206
|
+
{label: 'Drain', value: caps.drain},
|
|
207
|
+
],
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
case MODULE_HAULER: {
|
|
211
|
+
const caps = computeHaulerCapabilities(stats)
|
|
212
|
+
return {
|
|
213
|
+
capability: 'Hauler',
|
|
214
|
+
attributes: [
|
|
215
|
+
{label: 'Capacity', value: caps.capacity},
|
|
216
|
+
{label: 'Efficiency', value: caps.efficiency},
|
|
217
|
+
{label: 'Drain', value: caps.drain},
|
|
218
|
+
],
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
case MODULE_STORAGE: {
|
|
222
|
+
const str = stats.strength ?? 500
|
|
223
|
+
const fin = stats.fineness ?? 500
|
|
224
|
+
const sat = stats.saturation ?? 500
|
|
225
|
+
const statSum = str + fin + sat
|
|
226
|
+
const pct = 10 + Math.floor((statSum * 10) / 2997)
|
|
227
|
+
return {capability: 'Storage', attributes: [{label: 'Capacity Bonus', value: pct}]}
|
|
228
|
+
}
|
|
229
|
+
default:
|
|
230
|
+
return undefined
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function resolveModule(id: number, stats?: UInt64Type): ResolvedItem {
|
|
235
|
+
const recipe = getModuleRecipeByItemId(id)!
|
|
236
|
+
let attributes: ResolvedAttributeGroup[] | undefined
|
|
237
|
+
if (stats !== undefined) {
|
|
238
|
+
const decoded = decodeCraftedItemStats(id, toBigStats(stats))
|
|
239
|
+
const modType = getModuleCapabilityType(id)
|
|
240
|
+
const group = computeCapabilityGroup(modType, decoded)
|
|
241
|
+
if (group) attributes = [group]
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
itemId: id,
|
|
245
|
+
name: recipe.name,
|
|
246
|
+
icon: itemAbbreviations[id] ?? moduleIcon,
|
|
247
|
+
abbreviation: itemAbbreviations[id] ?? null,
|
|
248
|
+
tier: 't1' as ResourceTier,
|
|
249
|
+
mass: 0,
|
|
250
|
+
itemType: 'module',
|
|
251
|
+
attributes,
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function resolveEntity(
|
|
256
|
+
id: number,
|
|
257
|
+
stats?: UInt64Type,
|
|
258
|
+
modules?: ServerContract.Types.module_entry[]
|
|
259
|
+
): ResolvedItem {
|
|
260
|
+
const recipe = getEntityRecipeByItemId(id)!
|
|
261
|
+
let attributes: ResolvedAttributeGroup[] | undefined
|
|
262
|
+
let moduleSlots: ResolvedModuleSlot[] | undefined
|
|
263
|
+
|
|
264
|
+
if (stats !== undefined) {
|
|
265
|
+
const decoded = decodeCraftedItemStats(id, toBigStats(stats))
|
|
266
|
+
attributes = []
|
|
267
|
+
|
|
268
|
+
let hullCaps: {hullmass: number; capacity: number}
|
|
269
|
+
switch (recipe.id) {
|
|
270
|
+
case 'ship-t1':
|
|
271
|
+
hullCaps = computeShipHullCapabilities(decoded)
|
|
272
|
+
break
|
|
273
|
+
case 'warehouse-t1':
|
|
274
|
+
hullCaps = computeWarehouseHullCapabilities(decoded)
|
|
275
|
+
break
|
|
276
|
+
case 'container':
|
|
277
|
+
hullCaps = computeContainerCapabilities(decoded)
|
|
278
|
+
break
|
|
279
|
+
case 'container-t2':
|
|
280
|
+
hullCaps = computeContainerT2Capabilities(decoded)
|
|
281
|
+
break
|
|
282
|
+
default:
|
|
283
|
+
throw new Error(
|
|
284
|
+
`resolveItem: no capacity formula wired for entity recipe "${recipe.id}"`
|
|
285
|
+
)
|
|
286
|
+
}
|
|
287
|
+
attributes.push({
|
|
288
|
+
capability: 'Hull',
|
|
289
|
+
attributes: [
|
|
290
|
+
{label: 'Mass', value: hullCaps.hullmass},
|
|
291
|
+
{label: 'Capacity', value: hullCaps.capacity},
|
|
292
|
+
],
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (recipe.moduleSlots) {
|
|
297
|
+
moduleSlots = recipe.moduleSlots.map((slot, i) => {
|
|
298
|
+
const mod = modules?.[i]
|
|
299
|
+
if (mod?.installed) {
|
|
300
|
+
const modItemId = Number(mod.installed.item_id.value.toString())
|
|
301
|
+
const modStats = BigInt(mod.installed.stats.toString())
|
|
302
|
+
const decodedStats = decodeCraftedItemStats(modItemId, modStats)
|
|
303
|
+
const modType = getModuleCapabilityType(modItemId)
|
|
304
|
+
const group = computeCapabilityGroup(modType, decodedStats)
|
|
305
|
+
const modRecipe = getModuleRecipeByItemId(modItemId)
|
|
306
|
+
return {
|
|
307
|
+
name: modRecipe?.name ?? 'Module',
|
|
308
|
+
installed: true,
|
|
309
|
+
attributes: group?.attributes,
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return {installed: false}
|
|
313
|
+
})
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
itemId: id,
|
|
318
|
+
name: recipe.name,
|
|
319
|
+
icon: itemAbbreviations[id] ?? componentIcon,
|
|
320
|
+
abbreviation: itemAbbreviations[id] ?? null,
|
|
321
|
+
tier: 't1' as ResourceTier,
|
|
322
|
+
mass: 0,
|
|
323
|
+
itemType: 'entity',
|
|
324
|
+
attributes,
|
|
325
|
+
moduleSlots,
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export function resolveItem(
|
|
330
|
+
itemId: UInt16Type,
|
|
331
|
+
stats?: UInt64Type,
|
|
332
|
+
modules?: ServerContract.Types.module_entry[]
|
|
333
|
+
): ResolvedItem {
|
|
334
|
+
const id = toNum(itemId)
|
|
335
|
+
|
|
336
|
+
if (isModuleItem(id)) return resolveModule(id, stats)
|
|
337
|
+
|
|
338
|
+
if (getComponentById(id)) return resolveComponent(id, stats)
|
|
339
|
+
|
|
340
|
+
if (getEntityRecipeByItemId(id)) return resolveEntity(id, stats, modules)
|
|
341
|
+
|
|
342
|
+
return resolveResource(id, stats)
|
|
343
|
+
}
|