@shipload/sdk 1.0.0-next.6 → 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.
Files changed (155) hide show
  1. package/lib/scan.d.ts +52 -0
  2. package/lib/scan.js +162 -0
  3. package/lib/scan.js.map +1 -0
  4. package/lib/scan.m.js +152 -0
  5. package/lib/scan.m.js.map +1 -0
  6. package/lib/shipload.d.ts +3589 -1363
  7. package/lib/shipload.js +15700 -5454
  8. package/lib/shipload.js.map +1 -1
  9. package/lib/shipload.m.js +15423 -5402
  10. package/lib/shipload.m.js.map +1 -1
  11. package/lib/testing.d.ts +1173 -0
  12. package/lib/testing.js +4947 -0
  13. package/lib/testing.js.map +1 -0
  14. package/lib/testing.m.js +4941 -0
  15. package/lib/testing.m.js.map +1 -0
  16. package/package.json +20 -2
  17. package/src/capabilities/craftable.test.ts +82 -0
  18. package/src/capabilities/craftable.ts +82 -0
  19. package/src/capabilities/crafting.test.ts +35 -0
  20. package/src/capabilities/crafting.ts +34 -7
  21. package/src/capabilities/gathering.test.ts +29 -0
  22. package/src/capabilities/gathering.ts +37 -19
  23. package/src/capabilities/hauling.ts +0 -5
  24. package/src/capabilities/index.ts +0 -1
  25. package/src/capabilities/modules.ts +42 -0
  26. package/src/capabilities/movement.ts +1 -1
  27. package/src/capabilities/storage.ts +16 -1
  28. package/src/contracts/platform.ts +231 -3
  29. package/src/contracts/server.ts +1518 -501
  30. package/src/coordinates/address.ts +88 -0
  31. package/src/coordinates/constants.test.ts +15 -0
  32. package/src/coordinates/constants.ts +23 -0
  33. package/src/coordinates/index.ts +15 -0
  34. package/src/coordinates/memo.test.ts +47 -0
  35. package/src/coordinates/memo.ts +20 -0
  36. package/src/coordinates/permutation.ts +77 -0
  37. package/src/coordinates/regions.ts +48 -0
  38. package/src/coordinates/sectors.ts +115 -0
  39. package/src/data/capabilities.ts +49 -18
  40. package/src/data/capability-formulas.ts +26 -14
  41. package/src/data/catalog.ts +0 -5
  42. package/src/data/colors.ts +13 -47
  43. package/src/data/entities.json +379 -14
  44. package/src/data/item-ids.ts +48 -12
  45. package/src/data/items.json +301 -74
  46. package/src/data/kind-registry.json +195 -0
  47. package/src/data/kind-registry.ts +182 -0
  48. package/src/data/metadata.ts +277 -48
  49. package/src/data/recipes-runtime.ts +6 -23
  50. package/src/data/recipes.json +2074 -173
  51. package/src/derivation/build-methods.test.ts +13 -0
  52. package/src/derivation/build-methods.ts +48 -0
  53. package/src/derivation/capabilities.test.ts +348 -0
  54. package/src/derivation/capabilities.ts +692 -0
  55. package/src/derivation/capability-mappings.ts +60 -16
  56. package/src/derivation/crafting.test.ts +17 -0
  57. package/src/derivation/crafting.ts +56 -33
  58. package/src/derivation/index.ts +27 -2
  59. package/src/derivation/recipe-usage.test.ts +88 -0
  60. package/src/derivation/recipe-usage.ts +141 -0
  61. package/src/derivation/reserve-regen.ts +34 -0
  62. package/src/derivation/resources.ts +9 -1
  63. package/src/derivation/rollups.test.ts +55 -0
  64. package/src/derivation/rollups.ts +72 -0
  65. package/src/derivation/stars.test.ts +67 -0
  66. package/src/derivation/stars.ts +25 -0
  67. package/src/derivation/stat-scaling.ts +12 -0
  68. package/src/derivation/stats.ts +6 -6
  69. package/src/derivation/stratum.ts +26 -22
  70. package/src/derivation/tiers.ts +40 -7
  71. package/src/derivation/upgrades.ts +14 -0
  72. package/src/derivation/wormhole.ts +154 -0
  73. package/src/entities/entity.ts +102 -0
  74. package/src/entities/gamestate.ts +3 -28
  75. package/src/entities/makers.ts +141 -135
  76. package/src/entities/slot-multiplier.ts +43 -0
  77. package/src/errors.ts +12 -16
  78. package/src/format.ts +26 -4
  79. package/src/index-module.ts +333 -35
  80. package/src/managers/actions.ts +668 -103
  81. package/src/managers/base.ts +6 -2
  82. package/src/managers/cluster.test.ts +39 -0
  83. package/src/managers/cluster.ts +53 -0
  84. package/src/managers/construction-types.ts +80 -0
  85. package/src/managers/construction.ts +443 -0
  86. package/src/managers/context.ts +29 -1
  87. package/src/managers/coordinates.ts +14 -0
  88. package/src/managers/entities.ts +27 -66
  89. package/src/managers/epochs.ts +40 -0
  90. package/src/managers/index.ts +20 -1
  91. package/src/managers/locations.ts +25 -29
  92. package/src/managers/nft.test.ts +14 -0
  93. package/src/managers/nft.ts +70 -0
  94. package/src/managers/players.ts +25 -0
  95. package/src/managers/plot.ts +122 -0
  96. package/src/nft/atomicassets.abi.json +1342 -0
  97. package/src/nft/atomicassets.ts +237 -0
  98. package/src/nft/atomicdata.ts +130 -0
  99. package/src/nft/buildImmutableData.ts +385 -0
  100. package/src/nft/description.ts +225 -52
  101. package/src/nft/index.ts +3 -0
  102. package/src/planner/index.ts +242 -0
  103. package/src/planner/planner.test.ts +334 -0
  104. package/src/resolution/describe-module.ts +43 -25
  105. package/src/resolution/display-name.ts +38 -10
  106. package/src/resolution/resolve-item.test.ts +48 -0
  107. package/src/resolution/resolve-item.ts +112 -58
  108. package/src/scan/index.ts +244 -0
  109. package/src/scan/scan-wasm.base64.ts +2 -0
  110. package/src/scheduling/accessor.ts +65 -23
  111. package/src/scheduling/availability.test.ts +204 -0
  112. package/src/scheduling/availability.ts +211 -0
  113. package/src/scheduling/cancel.test.ts +542 -0
  114. package/src/scheduling/cancel.ts +254 -0
  115. package/src/scheduling/cluster-stock.test.ts +31 -0
  116. package/src/scheduling/cluster-stock.ts +15 -0
  117. package/src/scheduling/energy.ts +47 -0
  118. package/src/scheduling/idle-resolve.ts +45 -0
  119. package/src/scheduling/jobs.ts +71 -0
  120. package/src/scheduling/lane-core.ts +128 -0
  121. package/src/scheduling/lanes.test.ts +250 -0
  122. package/src/scheduling/lanes.ts +227 -0
  123. package/src/scheduling/projection.ts +257 -133
  124. package/src/scheduling/schedule.test.ts +119 -0
  125. package/src/scheduling/schedule.ts +257 -117
  126. package/src/scheduling/task-cargo.test.ts +44 -0
  127. package/src/scheduling/task-cargo.ts +46 -0
  128. package/src/scheduling/unwrap.test.ts +86 -0
  129. package/src/scheduling/unwrap.ts +190 -0
  130. package/src/shipload.ts +26 -1
  131. package/src/subscriptions/manager.cluster.test.ts +51 -0
  132. package/src/subscriptions/manager.ts +245 -172
  133. package/src/subscriptions/mappers.ts +5 -8
  134. package/src/subscriptions/types.ts +28 -3
  135. package/src/testing/catalog-hash.ts +19 -0
  136. package/src/testing/index.ts +2 -0
  137. package/src/testing/projection-parity.ts +167 -0
  138. package/src/travel/reach.ts +21 -0
  139. package/src/travel/route-planner.ts +288 -0
  140. package/src/travel/route-simulator.ts +170 -0
  141. package/src/travel/travel.ts +188 -122
  142. package/src/types/capabilities.ts +37 -8
  143. package/src/types/entity.ts +3 -3
  144. package/src/types/index.ts +0 -1
  145. package/src/types.ts +51 -16
  146. package/src/utils/cargo.test.ts +14 -0
  147. package/src/utils/cargo.ts +29 -0
  148. package/src/utils/display-name.ts +70 -0
  149. package/src/utils/system.ts +15 -16
  150. package/src/capabilities/loading.ts +0 -8
  151. package/src/entities/container.ts +0 -123
  152. package/src/entities/ship-deploy.ts +0 -295
  153. package/src/entities/ship.ts +0 -221
  154. package/src/entities/warehouse.ts +0 -127
  155. package/src/types/entity-traits.ts +0 -69
@@ -1,295 +0,0 @@
1
- import {decodeCraftedItemStats} from '../derivation/crafting'
2
- import {
3
- getModuleCapabilityType,
4
- MODULE_CRAFTER,
5
- MODULE_ENGINE,
6
- MODULE_GATHERER,
7
- MODULE_GENERATOR,
8
- MODULE_HAULER,
9
- MODULE_LOADER,
10
- } from '../capabilities/modules'
11
- import {getItem} from '../data/catalog'
12
-
13
- export function computeShipHullCapabilities(stats: Record<string, number>): {
14
- hullmass: number
15
- capacity: number
16
- } {
17
- const density = stats.density
18
- const strength = stats.strength
19
- const hardness = stats.hardness
20
- const saturation = stats.saturation
21
-
22
- const hullmass = 25000 + 75 * density
23
- const statSum = strength + hardness + saturation
24
- const exponent = statSum / 2997.0
25
- const capacity = Math.floor(1000000 * 10 ** exponent)
26
-
27
- return {hullmass, capacity}
28
- }
29
-
30
- export function computeEngineCapabilities(stats: Record<string, number>): {
31
- thrust: number
32
- drain: number
33
- } {
34
- const vol = stats.volatility
35
- const thm = stats.thermal
36
-
37
- return {
38
- thrust: 400 + Math.floor((vol * 3) / 4),
39
- drain: Math.max(30, 50 - Math.floor(thm / 70)),
40
- }
41
- }
42
-
43
- export function computeGeneratorCapabilities(stats: Record<string, number>): {
44
- capacity: number
45
- recharge: number
46
- } {
47
- const com = stats.composition
48
- const fin = stats.fineness
49
-
50
- return {
51
- capacity: 300 + Math.floor(com / 6),
52
- recharge: 1 + Math.floor((fin * 3) / 1000),
53
- }
54
- }
55
-
56
- export interface GathererDepthParams {
57
- readonly floor: number
58
- readonly slope: number
59
- }
60
-
61
- export const GATHERER_DEPTH_TABLE: readonly GathererDepthParams[] = [
62
- {floor: 500, slope: 5},
63
- {floor: 2000, slope: 11},
64
- {floor: 7000, slope: 16},
65
- {floor: 15000, slope: 18},
66
- {floor: 25000, slope: 19},
67
- {floor: 35000, slope: 16},
68
- {floor: 46000, slope: 12},
69
- {floor: 53500, slope: 10},
70
- {floor: 60000, slope: 5},
71
- {floor: 63500, slope: 2},
72
- ]
73
-
74
- export const GATHERER_DEPTH_MAX_TIER = 10
75
-
76
- export function gathererDepthForTier(tol: number, tier: number): number {
77
- if (tier < 1 || tier > GATHERER_DEPTH_MAX_TIER) {
78
- throw new Error(`gatherer tier out of range: ${tier}`)
79
- }
80
- const p = GATHERER_DEPTH_TABLE[tier - 1]
81
- return p.floor + tol * p.slope
82
- }
83
-
84
- export function computeGathererCapabilities(
85
- stats: Record<string, number>,
86
- tier: number
87
- ): {
88
- yield: number
89
- drain: number
90
- depth: number
91
- speed: number
92
- } {
93
- const str = stats.strength
94
- const con = stats.conductivity
95
- const ref = stats.reflectivity
96
- const tol = stats.tolerance
97
-
98
- return {
99
- yield: 200 + str,
100
- drain: Math.max(250, 1250 - Math.floor((con * 25) / 20)),
101
- depth: gathererDepthForTier(tol, tier),
102
- speed: 100 + Math.floor((ref * 4) / 5),
103
- }
104
- }
105
-
106
- export function computeLoaderCapabilities(stats: Record<string, number>): {
107
- mass: number
108
- thrust: number
109
- quantity: number
110
- } {
111
- const insulation = stats.insulation
112
- const plasticity = stats.plasticity
113
-
114
- return {
115
- mass: Math.max(200, 2000 - Math.floor(insulation * 2)),
116
- thrust: 1 + Math.floor(plasticity / 500),
117
- quantity: 1,
118
- }
119
- }
120
-
121
- export function computeCrafterCapabilities(stats: Record<string, number>): {
122
- speed: number
123
- drain: number
124
- } {
125
- const rea = stats.reactivity
126
- const fin = stats.fineness
127
-
128
- return {
129
- speed: 100 + Math.floor((rea * 4) / 5),
130
- drain: Math.max(5, 30 - Math.floor(fin / 33)),
131
- }
132
- }
133
-
134
- export function computeHaulerCapabilities(stats: Record<string, number>): {
135
- capacity: number
136
- efficiency: number
137
- drain: number
138
- } {
139
- const fineness = stats.fineness
140
- const conductivity = stats.conductivity
141
- const composition = stats.composition
142
-
143
- return {
144
- capacity: Math.max(1, 1 + Math.floor(fineness / 400)),
145
- efficiency: 2000 + conductivity * 6,
146
- drain: Math.max(3, 15 - Math.floor(composition / 80)),
147
- }
148
- }
149
-
150
- export function computeStorageCapabilities(
151
- stats: Record<string, number>,
152
- baseCapacity: number
153
- ): {
154
- capacityBonus: number
155
- } {
156
- const strength = stats.strength
157
- const density = stats.density
158
- const hardness = stats.hardness
159
- const saturation = stats.saturation
160
-
161
- const statSum = strength + density + hardness + saturation
162
- const capacityBonus = Math.floor(
163
- (baseCapacity * (10 + Math.floor((statSum * 10) / 2997))) / 100
164
- )
165
-
166
- return {capacityBonus}
167
- }
168
-
169
- export function computeWarehouseHullCapabilities(stats: Record<string, number>): {
170
- hullmass: number
171
- capacity: number
172
- } {
173
- const density = stats.density
174
- const strength = stats.strength
175
- const hardness = stats.hardness
176
- const saturation = stats.saturation
177
-
178
- const hullmass = 25000 + 75 * density
179
- const statSum = strength + hardness + saturation
180
- const exponent = statSum / 2997.0
181
- const capacity = Math.floor(20000000 * 10 ** exponent)
182
-
183
- return {hullmass, capacity}
184
- }
185
-
186
- export interface ShipCapabilities {
187
- engines?: {thrust: number; drain: number}
188
- generator?: {capacity: number; recharge: number}
189
- gatherer?: {yield: number; drain: number; depth: number; speed: number}
190
- hauler?: {capacity: number; efficiency: number; drain: number}
191
- loaders?: {mass: number; thrust: number; quantity: number}
192
- crafter?: {speed: number; drain: number}
193
- }
194
-
195
- export function computeShipCapabilities(
196
- modules: {itemId: number; stats: bigint}[]
197
- ): ShipCapabilities {
198
- const ship: ShipCapabilities = {}
199
-
200
- const engineModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_ENGINE)
201
- if (engineModules.length > 0) {
202
- let totalThrust = 0
203
- let totalDrain = 0
204
- for (const m of engineModules) {
205
- const caps = computeEngineCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
206
- totalThrust += caps.thrust
207
- totalDrain += caps.drain
208
- }
209
- ship.engines = {thrust: totalThrust, drain: totalDrain}
210
- }
211
-
212
- const generatorModules = modules.filter(
213
- (m) => getModuleCapabilityType(m.itemId) === MODULE_GENERATOR
214
- )
215
- if (generatorModules.length > 0) {
216
- let totalCapacity = 0
217
- let totalRecharge = 0
218
- for (const m of generatorModules) {
219
- const caps = computeGeneratorCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
220
- totalCapacity += caps.capacity
221
- totalRecharge += caps.recharge
222
- }
223
- ship.generator = {capacity: totalCapacity, recharge: totalRecharge}
224
- }
225
-
226
- const gathererModules = modules.filter(
227
- (m) => getModuleCapabilityType(m.itemId) === MODULE_GATHERER
228
- )
229
- if (gathererModules.length > 0) {
230
- let totalYield = 0
231
- let totalDrain = 0
232
- let maxDepth = 0
233
- let totalSpeed = 0
234
- for (const m of gathererModules) {
235
- const tier = getItem(m.itemId).tier
236
- const caps = computeGathererCapabilities(
237
- decodeCraftedItemStats(m.itemId, m.stats),
238
- tier
239
- )
240
- totalYield += caps.yield
241
- totalDrain += caps.drain
242
- if (caps.depth > maxDepth) maxDepth = caps.depth
243
- totalSpeed += caps.speed
244
- }
245
- ship.gatherer = {yield: totalYield, drain: totalDrain, depth: maxDepth, speed: totalSpeed}
246
- }
247
-
248
- const haulerModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_HAULER)
249
- if (haulerModules.length > 0) {
250
- let totalCapacity = 0
251
- let weightedEffNum = 0
252
- let totalDrain = 0
253
- for (const m of haulerModules) {
254
- const caps = computeHaulerCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
255
- totalCapacity += caps.capacity
256
- weightedEffNum += caps.efficiency * caps.capacity
257
- totalDrain += caps.drain
258
- }
259
- ship.hauler = {
260
- capacity: totalCapacity,
261
- efficiency: totalCapacity > 0 ? Math.floor(weightedEffNum / totalCapacity) : 0,
262
- drain: totalDrain,
263
- }
264
- }
265
-
266
- const loaderModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_LOADER)
267
- if (loaderModules.length > 0) {
268
- let totalMass = 0
269
- let totalThrust = 0
270
- let totalQuantity = 0
271
- for (const m of loaderModules) {
272
- const caps = computeLoaderCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
273
- totalMass += caps.mass
274
- totalThrust += caps.thrust
275
- totalQuantity += caps.quantity
276
- }
277
- ship.loaders = {mass: totalMass, thrust: totalThrust, quantity: totalQuantity}
278
- }
279
-
280
- const crafterModules = modules.filter(
281
- (m) => getModuleCapabilityType(m.itemId) === MODULE_CRAFTER
282
- )
283
- if (crafterModules.length > 0) {
284
- let totalSpeed = 0
285
- let totalDrain = 0
286
- for (const m of crafterModules) {
287
- const caps = computeCrafterCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
288
- totalSpeed += caps.speed
289
- totalDrain += caps.drain
290
- }
291
- ship.crafter = {speed: totalSpeed, drain: totalDrain}
292
- }
293
-
294
- return ship
295
- }
@@ -1,221 +0,0 @@
1
- import {type UInt16, type UInt16Type, UInt32, UInt64, type UInt64Type} from '@wharfkit/antelope'
2
- import {ServerContract} from '../contracts'
3
- import {Coordinates, type CoordinatesType} from '../types'
4
- import {
5
- type FloatPosition,
6
- getDestinationLocation,
7
- getInterpolatedPosition,
8
- getPositionAt,
9
- getFlightOrigin as travelGetFlightOrigin,
10
- } from '../travel/travel'
11
- import {
12
- type ProjectedEntity,
13
- projectFromCurrentState as sharedProjectFromCurrentState,
14
- projectFromCurrentStateAt as sharedProjectFromCurrentStateAt,
15
- } from '../scheduling/projection'
16
- import {Location} from './location'
17
- import {ScheduleAccessor} from '../scheduling/accessor'
18
- import {InventoryAccessor} from './inventory-accessor'
19
- import type {EntityInventory} from './entity-inventory'
20
- import {
21
- energyPercent as calcEnergyPercent,
22
- needsRecharge as calcNeedsRecharge,
23
- hasEnergyForDistance,
24
- maxTravelDistance,
25
- } from '../capabilities/movement'
26
- import * as schedule from '../scheduling/schedule'
27
-
28
- export interface PackedModuleInput {
29
- itemId: UInt16Type
30
- stats: UInt64Type
31
- }
32
-
33
- export interface ShipStateInput {
34
- id: UInt64Type
35
- owner: string
36
- name: string
37
- coordinates: CoordinatesType | {x: number; y: number; z?: number}
38
- hullmass?: number
39
- capacity?: number
40
- energy?: number
41
- modules?: PackedModuleInput[]
42
- schedule?: ServerContract.Types.schedule
43
- cargo?: ServerContract.Types.cargo_item[]
44
- }
45
-
46
- type MovementEntity = {
47
- engines: ServerContract.Types.movement_stats
48
- generator: ServerContract.Types.energy_stats
49
- energy: UInt16
50
- }
51
-
52
- export class Ship extends ServerContract.Types.entity_info {
53
- private _sched?: ScheduleAccessor
54
- private _inv?: InventoryAccessor
55
-
56
- get name(): string {
57
- return this.entity_name
58
- }
59
-
60
- get entityClass(): 'mobile' {
61
- return 'mobile'
62
- }
63
-
64
- get canUndeploy(): boolean {
65
- return true
66
- }
67
-
68
- get inv(): InventoryAccessor {
69
- this._inv ??= new InventoryAccessor(this)
70
- return this._inv
71
- }
72
-
73
- get inventory(): EntityInventory[] {
74
- return this.inv.items
75
- }
76
-
77
- get sched(): ScheduleAccessor {
78
- this._sched ??= new ScheduleAccessor(this)
79
- return this._sched
80
- }
81
-
82
- get maxDistance(): UInt32 {
83
- if (!this.generator || !this.engines) return UInt32.from(0)
84
- return maxTravelDistance(this as MovementEntity)
85
- }
86
-
87
- get isIdle(): boolean {
88
- return this.is_idle
89
- }
90
-
91
- getFlightOrigin(flightTaskIndex: number): Coordinates {
92
- return Coordinates.from(travelGetFlightOrigin(this, flightTaskIndex))
93
- }
94
-
95
- destinationLocation(): Coordinates | undefined {
96
- const dest = getDestinationLocation(this)
97
- return dest ? Coordinates.from(dest) : undefined
98
- }
99
-
100
- /** Chain-tile coordinates at `now`. For smooth visual position use interpolatedPositionAt. */
101
- positionAt(now: Date): Coordinates {
102
- const taskIndex = this.sched.currentTaskIndex(now)
103
- const progress = this.sched.currentTaskProgress(now)
104
- return Coordinates.from(getPositionAt(this, taskIndex, progress))
105
- }
106
-
107
- interpolatedPositionAt(now: Date): FloatPosition {
108
- const taskIndex = this.sched.currentTaskIndex(now)
109
- const progress = this.sched.currentTaskProgressFloat(now)
110
- return getInterpolatedPosition(this, taskIndex, progress)
111
- }
112
-
113
- isInFlight(now: Date): boolean {
114
- return schedule.isInFlight(this, now)
115
- }
116
-
117
- isRecharging(now: Date): boolean {
118
- return schedule.isRecharging(this, now)
119
- }
120
-
121
- isLoading(now: Date): boolean {
122
- return schedule.isLoading(this, now)
123
- }
124
-
125
- isUnloading(now: Date): boolean {
126
- return schedule.isUnloading(this, now)
127
- }
128
-
129
- isGathering(now: Date): boolean {
130
- return schedule.isGathering(this, now)
131
- }
132
-
133
- get hasEngines(): boolean {
134
- return this.engines !== undefined
135
- }
136
-
137
- get hasGenerator(): boolean {
138
- return this.generator !== undefined
139
- }
140
-
141
- get hasGatherer(): boolean {
142
- return this.gatherer !== undefined
143
- }
144
-
145
- get hasWarp(): boolean {
146
- return this.warp !== undefined
147
- }
148
-
149
- project(): ProjectedEntity {
150
- return sharedProjectFromCurrentState(this)
151
- }
152
-
153
- projectAt(now: Date): ProjectedEntity {
154
- return sharedProjectFromCurrentStateAt(this, now)
155
- }
156
-
157
- get location(): Location {
158
- return Location.from(this.coordinates)
159
- }
160
-
161
- get totalCargoMass(): UInt64 {
162
- return this.inv.totalMass
163
- }
164
-
165
- get totalMass(): UInt64 {
166
- let mass = UInt64.from(this.hullmass ?? 0).adding(this.totalCargoMass)
167
- if (this.loaders) {
168
- mass = mass.adding(UInt64.from(this.loaders.mass).multiplying(this.loaders.quantity))
169
- }
170
- return mass
171
- }
172
-
173
- get maxCapacity(): UInt64 {
174
- return UInt64.from(this.capacity)
175
- }
176
-
177
- hasSpace(goodMass: UInt64, quantity: number): boolean {
178
- return this.totalMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity)
179
- }
180
-
181
- get availableCapacity(): UInt64 {
182
- return this.totalMass.gte(this.maxCapacity)
183
- ? UInt64.from(0)
184
- : this.maxCapacity.subtracting(this.totalMass)
185
- }
186
-
187
- getCargoForItem(goodId: UInt64Type): EntityInventory | undefined {
188
- return this.inv.forItem(goodId)
189
- }
190
-
191
- get sellableCargo(): EntityInventory[] {
192
- return this.inv.sellable
193
- }
194
-
195
- get hasSellableCargo(): boolean {
196
- return this.inv.hasSellable
197
- }
198
-
199
- get sellableGoodsCount(): number {
200
- return this.inv.sellableCount
201
- }
202
-
203
- get isFull(): boolean {
204
- return this.totalMass.gte(this.maxCapacity)
205
- }
206
-
207
- get energyPercent(): number {
208
- if (!this.generator || this.energy === undefined) return 0
209
- return calcEnergyPercent(this as MovementEntity)
210
- }
211
-
212
- get needsRecharge(): boolean {
213
- if (!this.generator || this.energy === undefined) return false
214
- return calcNeedsRecharge(this as MovementEntity)
215
- }
216
-
217
- hasEnergyFor(distance: UInt64): boolean {
218
- if (!this.engines || !this.generator || this.energy === undefined) return false
219
- return hasEnergyForDistance(this as MovementEntity, distance)
220
- }
221
- }
@@ -1,127 +0,0 @@
1
- import {UInt64, type UInt64Type} from '@wharfkit/antelope'
2
- import {ServerContract} from '../contracts'
3
- import type {CoordinatesType} from '../types'
4
- import {Location} from './location'
5
- import {ScheduleAccessor} from '../scheduling/accessor'
6
- import {InventoryAccessor} from './inventory-accessor'
7
- import type {EntityInventory} from './entity-inventory'
8
- import * as schedule from '../scheduling/schedule'
9
- import type {PackedModuleInput} from './ship'
10
- import {decodeCraftedItemStats} from '../derivation/crafting'
11
- import {getModuleCapabilityType, MODULE_LOADER} from '../capabilities/modules'
12
- import {computeLoaderCapabilities} from './ship-deploy'
13
-
14
- export interface WarehouseStateInput {
15
- id: UInt64Type
16
- owner: string
17
- name: string
18
- coordinates: CoordinatesType | {x: number; y: number; z?: number}
19
- hullmass?: number
20
- capacity: number
21
- modules?: PackedModuleInput[]
22
- schedule?: ServerContract.Types.schedule
23
- cargo?: ServerContract.Types.cargo_item[]
24
- }
25
-
26
- export class Warehouse extends ServerContract.Types.entity_info {
27
- private _sched?: ScheduleAccessor
28
- private _inv?: InventoryAccessor
29
-
30
- get name(): string {
31
- return this.entity_name
32
- }
33
-
34
- get entityClass(): 'building' {
35
- return 'building'
36
- }
37
-
38
- get canDemolish(): boolean {
39
- return true
40
- }
41
-
42
- get inv(): InventoryAccessor {
43
- this._inv ??= new InventoryAccessor(this)
44
- return this._inv
45
- }
46
-
47
- get inventory(): EntityInventory[] {
48
- return this.inv.items
49
- }
50
-
51
- get sched(): ScheduleAccessor {
52
- this._sched ??= new ScheduleAccessor(this)
53
- return this._sched
54
- }
55
-
56
- get isIdle(): boolean {
57
- return this.is_idle
58
- }
59
-
60
- isLoading(now: Date): boolean {
61
- return schedule.isLoading(this, now)
62
- }
63
-
64
- isUnloading(now: Date): boolean {
65
- return schedule.isUnloading(this, now)
66
- }
67
-
68
- get location(): Location {
69
- return Location.from(this.coordinates)
70
- }
71
-
72
- get totalCargoMass(): UInt64 {
73
- return this.inv.totalMass
74
- }
75
-
76
- get maxCapacity(): UInt64 {
77
- return UInt64.from(this.capacity)
78
- }
79
-
80
- get availableCapacity(): UInt64 {
81
- const cargo = this.totalCargoMass
82
- return cargo.gte(this.maxCapacity) ? UInt64.from(0) : this.maxCapacity.subtracting(cargo)
83
- }
84
-
85
- hasSpace(goodMass: UInt64, quantity: number): boolean {
86
- return this.totalCargoMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity)
87
- }
88
-
89
- get isFull(): boolean {
90
- return this.totalCargoMass.gte(this.maxCapacity)
91
- }
92
-
93
- getCargoForItem(goodId: UInt64Type): EntityInventory | undefined {
94
- return this.inv.forItem(goodId)
95
- }
96
-
97
- get orbitalAltitude(): number {
98
- return this.coordinates.z?.toNumber() || 0
99
- }
100
-
101
- get totalMass(): UInt64 {
102
- const hull = this.hullmass ? UInt64.from(this.hullmass) : UInt64.from(0)
103
- return hull.adding(this.totalCargoMass)
104
- }
105
- }
106
-
107
- export function computeWarehouseCapabilities(modules: {itemId: number; stats: bigint}[]): {
108
- loaders?: {mass: number; thrust: number; quantity: number}
109
- } {
110
- const warehouse: {loaders?: {mass: number; thrust: number; quantity: number}} = {}
111
-
112
- const loaderModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_LOADER)
113
- if (loaderModules.length > 0) {
114
- let totalMass = 0
115
- let totalThrust = 0
116
- let totalQuantity = 0
117
- for (const m of loaderModules) {
118
- const caps = computeLoaderCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
119
- totalMass += caps.mass
120
- totalThrust += caps.thrust
121
- totalQuantity += caps.quantity
122
- }
123
- warehouse.loaders = {mass: totalMass, thrust: totalThrust, quantity: totalQuantity}
124
- }
125
-
126
- return warehouse
127
- }
@@ -1,69 +0,0 @@
1
- import {Name} from '@wharfkit/antelope'
2
-
3
- export const ENTITY_SHIP = Name.from('ship')
4
- export const ENTITY_WAREHOUSE = Name.from('warehouse')
5
- export const ENTITY_CONTAINER = Name.from('container')
6
-
7
- export type EntityTypeName = 'ship' | 'warehouse' | 'container'
8
-
9
- export interface EntityTraits {
10
- typeName: Name
11
- isMovable: boolean
12
- hasEnergy: boolean
13
- hasLoaders: boolean
14
- notFoundError: string
15
- }
16
-
17
- export const shipTraits: EntityTraits = {
18
- typeName: ENTITY_SHIP,
19
- isMovable: true,
20
- hasEnergy: true,
21
- hasLoaders: true,
22
-
23
- notFoundError: 'ship not found',
24
- }
25
-
26
- export const warehouseTraits: EntityTraits = {
27
- typeName: ENTITY_WAREHOUSE,
28
- isMovable: false,
29
- hasEnergy: false,
30
- hasLoaders: true,
31
-
32
- notFoundError: 'warehouse not found',
33
- }
34
-
35
- export const containerTraits: EntityTraits = {
36
- typeName: ENTITY_CONTAINER,
37
- isMovable: true,
38
- hasEnergy: false,
39
- hasLoaders: false,
40
-
41
- notFoundError: 'container not found',
42
- }
43
-
44
- export function getEntityTraits(entityType: Name | EntityTypeName): EntityTraits {
45
- const typeName = typeof entityType === 'string' ? entityType : entityType.toString()
46
-
47
- switch (typeName) {
48
- case 'ship':
49
- return shipTraits
50
- case 'warehouse':
51
- return warehouseTraits
52
- case 'container':
53
- return containerTraits
54
- default:
55
- throw new Error(`Unknown entity type: ${typeName}`)
56
- }
57
- }
58
-
59
- export function isShip(entity: {type?: Name}): boolean {
60
- return entity.type?.equals(ENTITY_SHIP) ?? false
61
- }
62
-
63
- export function isWarehouse(entity: {type?: Name}): boolean {
64
- return entity.type?.equals(ENTITY_WAREHOUSE) ?? false
65
- }
66
-
67
- export function isContainer(entity: {type?: Name}): boolean {
68
- return entity.type?.equals(ENTITY_CONTAINER) ?? false
69
- }