@shipload/sdk 1.0.0-next.59 → 1.0.0-next.60

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.
@@ -2,10 +2,9 @@ import type {ServerContract} from '../contracts'
2
2
  import {getItem} from '../data/catalog'
3
3
  import {getEntityLayout} from '../data/recipes-runtime'
4
4
  import {decodeStat} from '../derivation/crafting'
5
- import {gathererDepthForTier} from '../derivation/capabilities'
5
+ import {gathererDepthForTier, computeGathererYield} from '../derivation/capabilities'
6
6
  import {applySlotMultiplier, getSlotAmp} from '../entities/slot-multiplier'
7
7
  import {
8
- computeGathererYield,
9
8
  computeGathererDrain,
10
9
  computeLoaderThrust,
11
10
  computeLoaderMass,
@@ -76,7 +75,7 @@ export function resolveLaneGatherer(
76
75
  const con = decodeStat(stats, 2)
77
76
  const layout = getEntityLayout(entityItemId)?.slots ?? []
78
77
  const amp = getSlotAmp(layout, idx)
79
- const yieldVal = applySlotMultiplier(computeGathererYield(str), amp)
78
+ const yieldVal = applySlotMultiplier(computeGathererYield(str, item.tier ?? 1), amp)
80
79
  const drain = computeGathererDrain(con)
81
80
  const depth = gathererDepthForTier(tol, item.tier ?? 1)
82
81
  return {slotIndex: idx, yield: yieldVal, drain, depth, outputPct: amp}
@@ -114,7 +113,7 @@ export function resolveLaneCrafter(
114
113
  const fin = decodeStat(stats, 1)
115
114
  const layout = getEntityLayout(entityItemId)?.slots ?? []
116
115
  const amp = getSlotAmp(layout, idx)
117
- const speed = applySlotMultiplier(computeCrafterSpeed(rea), amp)
116
+ const speed = applySlotMultiplier(computeCrafterSpeed(rea, item.tier ?? 1), amp)
118
117
  const drain = computeCrafterDrain(fin)
119
118
  return {slotIndex: idx, speed, drain, outputPct: amp}
120
119
  }
@@ -134,7 +133,7 @@ export function resolveLaneBuilder(
134
133
  const fin = decodeStat(stats, 1)
135
134
  const layout = getEntityLayout(entityItemId)?.slots ?? []
136
135
  const amp = getSlotAmp(layout, idx)
137
- const speed = applySlotMultiplier(computeBuilderSpeed(res), amp)
136
+ const speed = applySlotMultiplier(computeBuilderSpeed(res, item.tier ?? 1), amp)
138
137
  const drain = computeBuilderDrain(fin)
139
138
  return {slotIndex: idx, speed, drain, outputPct: amp}
140
139
  }
@@ -153,12 +152,13 @@ export function resolveLaneLoader(
153
152
  if (!installed) {
154
153
  return {slotIndex: idx, thrust: 0, mass: 0, outputPct: 0, valid: false}
155
154
  }
155
+ const item = getItem(Number(installed.item_id.value ?? installed.item_id))
156
156
  const stats = BigInt(installed.stats.toString())
157
157
  const ins = decodeStat(stats, 0)
158
158
  const pla = decodeStat(stats, 1)
159
159
  const layout = getEntityLayout(entityItemId)?.slots ?? []
160
160
  const amp = getSlotAmp(layout, idx)
161
- const thrust = applySlotMultiplier(computeLoaderThrust(pla), amp)
161
+ const thrust = applySlotMultiplier(computeLoaderThrust(pla, item.tier ?? 1), amp)
162
162
  const mass = computeLoaderMass(ins)
163
163
  return {slotIndex: idx, thrust, mass, outputPct: amp, valid: true}
164
164
  }
@@ -29,6 +29,7 @@ import {
29
29
  subtractFromStacks,
30
30
  stackToCargoItem,
31
31
  } from '../capabilities/storage'
32
+ import {craftCargoOwnership} from './availability'
32
33
  import * as schedule from './schedule'
33
34
  import type {ScheduleData} from './schedule'
34
35
 
@@ -394,10 +395,13 @@ function applyCraftTask(projected: ProjectedEntity, task: ServerContract.Types.t
394
395
  applyEnergyCost(projected, task)
395
396
  if (task.cargo.length === 0) return
396
397
 
397
- for (let i = 0; i < task.cargo.length - 1; i++) {
398
- removeCargoItem(projected, task.cargo[i])
398
+ const {clustered, ownOutput} = craftCargoOwnership(task)
399
+ if (!clustered) {
400
+ for (let i = 0; i < task.cargo.length - 1; i++) {
401
+ removeCargoItem(projected, task.cargo[i])
402
+ }
399
403
  }
400
- if (task.couplings.length === 0) {
404
+ if (ownOutput) {
401
405
  addCargoItem(projected, task.cargo[task.cargo.length - 1])
402
406
  }
403
407
  }
@@ -0,0 +1,44 @@
1
+ import {describe, expect, test} from 'bun:test'
2
+ import {ServerContract, TaskType} from '../index-module'
3
+ import {taskCargoChanges} from './task-cargo'
4
+
5
+ function cargoItem(itemId: number, quantity: number) {
6
+ return ServerContract.Types.cargo_item.from({item_id: itemId, stats: 0, modules: [], quantity})
7
+ }
8
+
9
+ function craftTask(couplings: ReturnType<typeof coupling>[]) {
10
+ return ServerContract.Types.task.from({
11
+ type: TaskType.CRAFT,
12
+ duration: 60,
13
+ cancelable: 0,
14
+ cargo: [cargoItem(401, 19680), cargoItem(10008, 1968)],
15
+ couplings,
16
+ })
17
+ }
18
+
19
+ function coupling() {
20
+ return ServerContract.Types.coupling.from({
21
+ counterpart: {entity_type: 'warehouse', entity_id: 51},
22
+ hold: 1,
23
+ kind: 3,
24
+ })
25
+ }
26
+
27
+ describe('taskCargoChanges', () => {
28
+ test('a self-craft consumes inputs and delivers the output to the crafter', () => {
29
+ const changes = taskCargoChanges(craftTask([]))
30
+
31
+ expect(changes).toEqual([
32
+ {direction: 'out', item_id: 401, stats: 0n, modules: [], quantity: 19680},
33
+ {direction: 'in', item_id: 10008, stats: 0n, modules: [], quantity: 1968},
34
+ ])
35
+ })
36
+
37
+ test('a coupled craft consumes inputs but does not deliver the output to the crafter', () => {
38
+ const changes = taskCargoChanges(craftTask([coupling()]))
39
+
40
+ expect(changes).toEqual([
41
+ {direction: 'out', item_id: 401, stats: 0n, modules: [], quantity: 19680},
42
+ ])
43
+ })
44
+ })
@@ -38,7 +38,7 @@ export function taskCargoChanges(task: ServerContract.Types.task): TaskCargoChan
38
38
  case TaskType.CRAFT:
39
39
  return [
40
40
  ...items.slice(0, -1).map((i) => toChange(i, 'out')),
41
- toChange(items[items.length - 1], 'in'),
41
+ ...(task.couplings.length > 0 ? [] : [toChange(items[items.length - 1], 'in')]),
42
42
  ]
43
43
  default:
44
44
  return []
package/src/types.ts CHANGED
@@ -85,6 +85,7 @@ export enum HoldKind {
85
85
  BUILD = 4,
86
86
  FLIGHT = 5,
87
87
  UPGRADE = 6,
88
+ SOURCE = 7,
88
89
  }
89
90
 
90
91
  export enum LocationType {