@shipload/sdk 2.0.0-rc13 → 2.0.0-rc15

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.
@@ -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 {categoryColors, categoryIcons, componentIcon, itemIcons, moduleIcon} from '../data/colors'
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 toBigSeed(v: UInt64Type): bigint {
79
+ function toBigStats(v: UInt64Type): bigint {
72
80
  return BigInt(UInt64.from(v).toString())
73
81
  }
74
82
 
75
- function resolveResource(id: number, seed?: UInt64Type): ResolvedItem {
83
+ function resolveResource(id: number, stats?: UInt64Type): ResolvedItem {
76
84
  const item = getItem(id)
77
85
  const cat = item.category
78
- let stats: ResolvedItemStat[] | undefined
79
- if (seed !== undefined) {
80
- const derived = deriveResourceStats(toBigSeed(seed))
86
+ let resolvedStats: ResolvedItemStat[] | undefined
87
+ if (stats !== undefined) {
88
+ const bigStats = toBigStats(stats)
81
89
  const defs = getStatDefinitions(cat)
82
- const values = [derived.stat1, derived.stat2, derived.stat3]
83
- stats = defs.map((d, i) => ({
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,28 +102,29 @@ 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, seed?: UInt64Type): ResolvedItem {
114
+ function resolveComponent(id: number, stats?: UInt64Type): ResolvedItem {
106
115
  const comp = getComponentById(id)!
107
- let stats: ResolvedItemStat[] | undefined
108
- if (seed !== undefined) {
109
- const decoded = decodeCraftedItemStats(id, toBigSeed(seed))
110
- stats = Object.entries(decoded).map(([key, value]) => {
111
- const allDefs = getStatDefinitions('metal')
112
- .concat(getStatDefinitions('precious'))
116
+ let resolvedStats: ResolvedItemStat[] | undefined
117
+ if (stats !== undefined) {
118
+ const decoded = decodeCraftedItemStats(id, toBigStats(stats))
119
+ resolvedStats = Object.entries(decoded).map(([key, value]) => {
120
+ const allDefs = getStatDefinitions('ore')
121
+ .concat(getStatDefinitions('crystal'))
113
122
  .concat(getStatDefinitions('gas'))
114
- .concat(getStatDefinitions('mineral'))
115
- .concat(getStatDefinitions('organic'))
123
+ .concat(getStatDefinitions('regolith'))
124
+ .concat(getStatDefinitions('biomass'))
116
125
  const def = allDefs.find((d) => d.key === key)
117
126
  const statDef = comp.stats.find((s) => s.key === key)
118
- const cat = (statDef?.source ?? 'metal') as ResourceCategory
127
+ const cat = (statDef?.source ?? 'ore') as ResourceCategory
119
128
  return {
120
129
  key,
121
130
  label: def?.label ?? key,
@@ -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: itemIcons[id] ?? componentIcon,
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,11 +206,22 @@ 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
- const duc = stats.ductility ?? 500
202
- const pur = stats.purity ?? 500
203
- const statSum = str + duc + pur
222
+ const fin = stats.fineness ?? 500
223
+ const sat = stats.saturation ?? 500
224
+ const statSum = str + fin + sat
204
225
  const pct = 10 + Math.floor((statSum * 10) / 2997)
205
226
  return {capability: 'Storage', attributes: [{label: 'Capacity Bonus', value: pct}]}
206
227
  }
@@ -209,19 +230,20 @@ function computeCapabilityGroup(
209
230
  }
210
231
  }
211
232
 
212
- function resolveModule(id: number, seed?: UInt64Type): ResolvedItem {
233
+ function resolveModule(id: number, stats?: UInt64Type): ResolvedItem {
213
234
  const recipe = getModuleRecipeByItemId(id)!
214
235
  let attributes: ResolvedAttributeGroup[] | undefined
215
- if (seed !== undefined) {
216
- const stats = decodeCraftedItemStats(id, toBigSeed(seed))
236
+ if (stats !== undefined) {
237
+ const decoded = decodeCraftedItemStats(id, toBigStats(stats))
217
238
  const modType = getModuleCapabilityType(id)
218
- const group = computeCapabilityGroup(modType, stats)
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: itemIcons[id] ?? moduleIcon,
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
- seed?: UInt64Type,
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 (seed !== undefined) {
242
- const stats = decodeCraftedItemStats(id, toBigSeed(seed))
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(stats)
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(stats)
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 modSeed = BigInt(mod.installed.seed.toString())
273
- const modStats = decodeCraftedItemStats(modItemId, modSeed)
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, modStats)
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: itemIcons[id] ?? componentIcon,
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
- seed?: UInt64Type,
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, seed)
329
+ if (isModuleItem(id)) return resolveModule(id, stats)
307
330
 
308
- if (getComponentById(id)) return resolveComponent(id, seed)
331
+ if (getComponentById(id)) return resolveComponent(id, stats)
309
332
 
310
- if (getEntityRecipeByItemId(id)) return resolveEntity(id, seed, modules)
333
+ if (getEntityRecipeByItemId(id)) return resolveEntity(id, stats, modules)
311
334
 
312
- return resolveResource(id, seed)
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
- applyAddCargoTask(projected, task)
214
+ if (!task.entitytarget) {
215
+ applyAddCargoTask(projected, task)
216
+ }
215
217
  }
216
218
 
217
219
  function applyCraftTask(projected: ProjectedEntity, task: ServerContract.Types.task): void {
@@ -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
+ }
package/src/types.ts CHANGED
@@ -113,7 +113,7 @@ export interface Distance {
113
113
  distance: UInt16
114
114
  }
115
115
 
116
- export type ResourceCategory = 'metal' | 'precious' | 'gas' | 'mineral' | 'organic'
116
+ export type ResourceCategory = 'ore' | 'crystal' | 'gas' | 'regolith' | 'biomass'
117
117
  export type ResourceTier = 't1' | 't2' | 't3' | 't4' | 't5'
118
118
 
119
119
  @Struct.type('item')