@shipload/sdk 2.0.0-rc12 → 2.0.0-rc14
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/lib/shipload.d.ts +137 -57
- package/lib/shipload.js +636 -335
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +626 -334
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/capabilities/modules.ts +3 -3
- package/src/capabilities/storage.ts +6 -9
- package/src/contracts/server.ts +37 -34
- package/src/data/colors.ts +19 -1
- package/src/data/recipes.ts +3 -3
- package/src/derivation/crafting.ts +46 -32
- package/src/derivation/stratum.ts +12 -0
- package/src/entities/container.ts +1 -0
- package/src/entities/makers.ts +126 -11
- package/src/entities/ship-deploy.ts +9 -14
- package/src/entities/ship.ts +16 -4
- package/src/entities/warehouse.ts +36 -1
- package/src/index-module.ts +22 -5
- package/src/managers/actions.ts +48 -8
- package/src/nft/description.ts +31 -30
- package/src/nft/deserializers.ts +8 -8
- package/src/resolution/describe-module.ts +165 -0
- package/src/resolution/resolve-item.ts +60 -37
- package/src/scheduling/projection.ts +17 -4
- package/src/types/capabilities.ts +5 -0
|
@@ -10,22 +10,29 @@ import {
|
|
|
10
10
|
MODULE_ENGINE,
|
|
11
11
|
MODULE_GATHERER,
|
|
12
12
|
MODULE_GENERATOR,
|
|
13
|
+
MODULE_HAULER,
|
|
13
14
|
MODULE_LOADER,
|
|
14
15
|
MODULE_STORAGE,
|
|
15
16
|
} from '../capabilities/modules'
|
|
16
|
-
import {decodeCraftedItemStats} from '../derivation/crafting'
|
|
17
|
-
import {deriveResourceStats} from '../derivation/stratum'
|
|
17
|
+
import {decodeCraftedItemStats, decodeStat} from '../derivation/crafting'
|
|
18
18
|
import {getStatDefinitions} from '../derivation/stats'
|
|
19
19
|
import {
|
|
20
20
|
computeEngineCapabilities,
|
|
21
21
|
computeGathererCapabilities,
|
|
22
22
|
computeGeneratorCapabilities,
|
|
23
|
+
computeHaulerCapabilities,
|
|
23
24
|
computeLoaderCapabilities,
|
|
24
25
|
computeManufacturingCapabilities,
|
|
25
26
|
computeShipHullCapabilities,
|
|
26
27
|
} from '../entities/ship-deploy'
|
|
27
28
|
import {computeContainerCapabilities} from '../entities/container'
|
|
28
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
categoryColors,
|
|
31
|
+
categoryIcons,
|
|
32
|
+
componentIcon,
|
|
33
|
+
itemAbbreviations,
|
|
34
|
+
moduleIcon,
|
|
35
|
+
} from '../data/colors'
|
|
29
36
|
import {ServerContract} from '../contracts'
|
|
30
37
|
|
|
31
38
|
export interface ResolvedItemStat {
|
|
@@ -55,6 +62,7 @@ export interface ResolvedItem {
|
|
|
55
62
|
itemId: number
|
|
56
63
|
name: string
|
|
57
64
|
icon: string
|
|
65
|
+
abbreviation: string | null
|
|
58
66
|
category?: ResourceCategory
|
|
59
67
|
tier: ResourceTier
|
|
60
68
|
mass: number
|
|
@@ -68,19 +76,19 @@ function toNum(v: UInt16Type): number {
|
|
|
68
76
|
return Number(UInt16.from(v).value.toString())
|
|
69
77
|
}
|
|
70
78
|
|
|
71
|
-
function
|
|
79
|
+
function toBigStats(v: UInt64Type): bigint {
|
|
72
80
|
return BigInt(UInt64.from(v).toString())
|
|
73
81
|
}
|
|
74
82
|
|
|
75
|
-
function resolveResource(id: number,
|
|
83
|
+
function resolveResource(id: number, stats?: UInt64Type): ResolvedItem {
|
|
76
84
|
const item = getItem(id)
|
|
77
85
|
const cat = item.category
|
|
78
|
-
let
|
|
79
|
-
if (
|
|
80
|
-
const
|
|
86
|
+
let resolvedStats: ResolvedItemStat[] | undefined
|
|
87
|
+
if (stats !== undefined) {
|
|
88
|
+
const bigStats = toBigStats(stats)
|
|
81
89
|
const defs = getStatDefinitions(cat)
|
|
82
|
-
const values = [
|
|
83
|
-
|
|
90
|
+
const values = [decodeStat(bigStats, 0), decodeStat(bigStats, 1), decodeStat(bigStats, 2)]
|
|
91
|
+
resolvedStats = defs.map((d, i) => ({
|
|
84
92
|
key: d.key,
|
|
85
93
|
label: d.label,
|
|
86
94
|
abbreviation: d.abbreviation,
|
|
@@ -94,20 +102,21 @@ function resolveResource(id: number, seed?: UInt64Type): ResolvedItem {
|
|
|
94
102
|
itemId: id,
|
|
95
103
|
name: String(item.name),
|
|
96
104
|
icon: categoryIcons[cat] ?? '⬡',
|
|
105
|
+
abbreviation: null,
|
|
97
106
|
category: cat,
|
|
98
107
|
tier: item.tier,
|
|
99
108
|
mass: Number(item.mass.value.toString()),
|
|
100
109
|
itemType: 'resource',
|
|
101
|
-
stats,
|
|
110
|
+
stats: resolvedStats,
|
|
102
111
|
}
|
|
103
112
|
}
|
|
104
113
|
|
|
105
|
-
function resolveComponent(id: number,
|
|
114
|
+
function resolveComponent(id: number, stats?: UInt64Type): ResolvedItem {
|
|
106
115
|
const comp = getComponentById(id)!
|
|
107
|
-
let
|
|
108
|
-
if (
|
|
109
|
-
const decoded = decodeCraftedItemStats(id,
|
|
110
|
-
|
|
116
|
+
let resolvedStats: ResolvedItemStat[] | undefined
|
|
117
|
+
if (stats !== undefined) {
|
|
118
|
+
const decoded = decodeCraftedItemStats(id, toBigStats(stats))
|
|
119
|
+
resolvedStats = Object.entries(decoded).map(([key, value]) => {
|
|
111
120
|
const allDefs = getStatDefinitions('metal')
|
|
112
121
|
.concat(getStatDefinitions('precious'))
|
|
113
122
|
.concat(getStatDefinitions('gas'))
|
|
@@ -130,11 +139,12 @@ function resolveComponent(id: number, seed?: UInt64Type): ResolvedItem {
|
|
|
130
139
|
return {
|
|
131
140
|
itemId: id,
|
|
132
141
|
name: comp.name,
|
|
133
|
-
icon:
|
|
142
|
+
icon: itemAbbreviations[id] ?? componentIcon,
|
|
143
|
+
abbreviation: itemAbbreviations[id] ?? null,
|
|
134
144
|
tier: 't1' as ResourceTier,
|
|
135
145
|
mass: comp.mass,
|
|
136
146
|
itemType: 'component',
|
|
137
|
-
stats,
|
|
147
|
+
stats: resolvedStats,
|
|
138
148
|
}
|
|
139
149
|
}
|
|
140
150
|
|
|
@@ -196,6 +206,17 @@ function computeCapabilityGroup(
|
|
|
196
206
|
],
|
|
197
207
|
}
|
|
198
208
|
}
|
|
209
|
+
case MODULE_HAULER: {
|
|
210
|
+
const caps = computeHaulerCapabilities(stats)
|
|
211
|
+
return {
|
|
212
|
+
capability: 'Hauler',
|
|
213
|
+
attributes: [
|
|
214
|
+
{label: 'Capacity', value: caps.capacity},
|
|
215
|
+
{label: 'Efficiency', value: caps.efficiency},
|
|
216
|
+
{label: 'Drain', value: caps.drain},
|
|
217
|
+
],
|
|
218
|
+
}
|
|
219
|
+
}
|
|
199
220
|
case MODULE_STORAGE: {
|
|
200
221
|
const str = stats.strength ?? 500
|
|
201
222
|
const duc = stats.ductility ?? 500
|
|
@@ -209,19 +230,20 @@ function computeCapabilityGroup(
|
|
|
209
230
|
}
|
|
210
231
|
}
|
|
211
232
|
|
|
212
|
-
function resolveModule(id: number,
|
|
233
|
+
function resolveModule(id: number, stats?: UInt64Type): ResolvedItem {
|
|
213
234
|
const recipe = getModuleRecipeByItemId(id)!
|
|
214
235
|
let attributes: ResolvedAttributeGroup[] | undefined
|
|
215
|
-
if (
|
|
216
|
-
const
|
|
236
|
+
if (stats !== undefined) {
|
|
237
|
+
const decoded = decodeCraftedItemStats(id, toBigStats(stats))
|
|
217
238
|
const modType = getModuleCapabilityType(id)
|
|
218
|
-
const group = computeCapabilityGroup(modType,
|
|
239
|
+
const group = computeCapabilityGroup(modType, decoded)
|
|
219
240
|
if (group) attributes = [group]
|
|
220
241
|
}
|
|
221
242
|
return {
|
|
222
243
|
itemId: id,
|
|
223
244
|
name: recipe.name,
|
|
224
|
-
icon:
|
|
245
|
+
icon: itemAbbreviations[id] ?? moduleIcon,
|
|
246
|
+
abbreviation: itemAbbreviations[id] ?? null,
|
|
225
247
|
tier: 't1' as ResourceTier,
|
|
226
248
|
mass: 0,
|
|
227
249
|
itemType: 'module',
|
|
@@ -231,20 +253,20 @@ function resolveModule(id: number, seed?: UInt64Type): ResolvedItem {
|
|
|
231
253
|
|
|
232
254
|
function resolveEntity(
|
|
233
255
|
id: number,
|
|
234
|
-
|
|
256
|
+
stats?: UInt64Type,
|
|
235
257
|
modules?: ServerContract.Types.module_entry[]
|
|
236
258
|
): ResolvedItem {
|
|
237
259
|
const recipe = getEntityRecipeByItemId(id)!
|
|
238
260
|
let attributes: ResolvedAttributeGroup[] | undefined
|
|
239
261
|
let moduleSlots: ResolvedModuleSlot[] | undefined
|
|
240
262
|
|
|
241
|
-
if (
|
|
242
|
-
const
|
|
263
|
+
if (stats !== undefined) {
|
|
264
|
+
const decoded = decodeCraftedItemStats(id, toBigStats(stats))
|
|
243
265
|
attributes = []
|
|
244
266
|
|
|
245
267
|
const isShip = recipe.id === 'ship-t1'
|
|
246
268
|
if (isShip) {
|
|
247
|
-
const hullCaps = computeShipHullCapabilities(
|
|
269
|
+
const hullCaps = computeShipHullCapabilities(decoded)
|
|
248
270
|
attributes.push({
|
|
249
271
|
capability: 'Hull',
|
|
250
272
|
attributes: [
|
|
@@ -253,7 +275,7 @@ function resolveEntity(
|
|
|
253
275
|
],
|
|
254
276
|
})
|
|
255
277
|
} else {
|
|
256
|
-
const containerCaps = computeContainerCapabilities(
|
|
278
|
+
const containerCaps = computeContainerCapabilities(decoded)
|
|
257
279
|
attributes.push({
|
|
258
280
|
capability: 'Hull',
|
|
259
281
|
attributes: [
|
|
@@ -269,10 +291,10 @@ function resolveEntity(
|
|
|
269
291
|
const mod = modules?.[i]
|
|
270
292
|
if (mod?.installed) {
|
|
271
293
|
const modItemId = Number(mod.installed.item_id.value.toString())
|
|
272
|
-
const
|
|
273
|
-
const
|
|
294
|
+
const modStats = BigInt(mod.installed.stats.toString())
|
|
295
|
+
const decodedStats = decodeCraftedItemStats(modItemId, modStats)
|
|
274
296
|
const modType = getModuleCapabilityType(modItemId)
|
|
275
|
-
const group = computeCapabilityGroup(modType,
|
|
297
|
+
const group = computeCapabilityGroup(modType, decodedStats)
|
|
276
298
|
const modRecipe = getModuleRecipeByItemId(modItemId)
|
|
277
299
|
return {
|
|
278
300
|
name: modRecipe?.name ?? 'Module',
|
|
@@ -287,7 +309,8 @@ function resolveEntity(
|
|
|
287
309
|
return {
|
|
288
310
|
itemId: id,
|
|
289
311
|
name: recipe.name,
|
|
290
|
-
icon:
|
|
312
|
+
icon: itemAbbreviations[id] ?? componentIcon,
|
|
313
|
+
abbreviation: itemAbbreviations[id] ?? null,
|
|
291
314
|
tier: 't1' as ResourceTier,
|
|
292
315
|
mass: 0,
|
|
293
316
|
itemType: 'entity',
|
|
@@ -298,16 +321,16 @@ function resolveEntity(
|
|
|
298
321
|
|
|
299
322
|
export function resolveItem(
|
|
300
323
|
itemId: UInt16Type,
|
|
301
|
-
|
|
324
|
+
stats?: UInt64Type,
|
|
302
325
|
modules?: ServerContract.Types.module_entry[]
|
|
303
326
|
): ResolvedItem {
|
|
304
327
|
const id = toNum(itemId)
|
|
305
328
|
|
|
306
|
-
if (isModuleItem(id)) return resolveModule(id,
|
|
329
|
+
if (isModuleItem(id)) return resolveModule(id, stats)
|
|
307
330
|
|
|
308
|
-
if (getComponentById(id)) return resolveComponent(id,
|
|
331
|
+
if (getComponentById(id)) return resolveComponent(id, stats)
|
|
309
332
|
|
|
310
|
-
if (getEntityRecipeByItemId(id)) return resolveEntity(id,
|
|
333
|
+
if (getEntityRecipeByItemId(id)) return resolveEntity(id, stats, modules)
|
|
311
334
|
|
|
312
|
-
return resolveResource(id,
|
|
335
|
+
return resolveResource(id, stats)
|
|
313
336
|
}
|
|
@@ -211,7 +211,9 @@ function applyGatherTask(
|
|
|
211
211
|
): void {
|
|
212
212
|
if (!options.complete) return
|
|
213
213
|
applyEnergyCost(projected, task)
|
|
214
|
-
|
|
214
|
+
if (!task.entitytarget) {
|
|
215
|
+
applyAddCargoTask(projected, task)
|
|
216
|
+
}
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
function applyCraftTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
|
|
@@ -259,11 +261,22 @@ function applyTask(projected: ProjectedEntity, task: ServerContract.Types.task):
|
|
|
259
261
|
}
|
|
260
262
|
}
|
|
261
263
|
|
|
262
|
-
export
|
|
264
|
+
export interface ProjectionOptions {
|
|
265
|
+
upToTaskIndex?: number
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export function projectEntity(entity: Projectable, options?: ProjectionOptions): ProjectedEntity {
|
|
263
269
|
const projected = createProjectedEntity(entity)
|
|
264
270
|
if (!entity.schedule || entity.schedule.tasks.length === 0) return projected
|
|
265
|
-
|
|
266
|
-
|
|
271
|
+
|
|
272
|
+
const tasks = entity.schedule.tasks
|
|
273
|
+
const taskCount =
|
|
274
|
+
options?.upToTaskIndex !== undefined
|
|
275
|
+
? Math.max(0, Math.min(options.upToTaskIndex, tasks.length))
|
|
276
|
+
: tasks.length
|
|
277
|
+
|
|
278
|
+
for (let i = 0; i < taskCount; i++) {
|
|
279
|
+
applyTask(projected, tasks[i])
|
|
267
280
|
}
|
|
268
281
|
return projected
|
|
269
282
|
}
|
|
@@ -40,6 +40,7 @@ export interface EntityCapabilities {
|
|
|
40
40
|
loaders?: ServerContract.Types.loader_stats
|
|
41
41
|
gatherer?: ServerContract.Types.gatherer_stats
|
|
42
42
|
crafter?: ServerContract.Types.crafter_stats
|
|
43
|
+
hauler?: ServerContract.Types.hauler_stats
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export interface EntityState {
|
|
@@ -69,3 +70,7 @@ export function capsHasGatherer(caps: EntityCapabilities): boolean {
|
|
|
69
70
|
export function capsHasMass(caps: EntityCapabilities): boolean {
|
|
70
71
|
return caps.hullmass !== undefined
|
|
71
72
|
}
|
|
73
|
+
|
|
74
|
+
export function capsHasHauler(caps: EntityCapabilities): boolean {
|
|
75
|
+
return caps.hauler !== undefined
|
|
76
|
+
}
|