@shipload/sdk 1.0.0-next.3 → 1.0.0-next.30

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 (99) hide show
  1. package/lib/shipload.d.ts +1847 -962
  2. package/lib/shipload.js +9088 -4854
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +8957 -4805
  5. package/lib/shipload.m.js.map +1 -1
  6. package/lib/testing.d.ts +856 -0
  7. package/lib/testing.js +3739 -0
  8. package/lib/testing.js.map +1 -0
  9. package/lib/testing.m.js +3733 -0
  10. package/lib/testing.m.js.map +1 -0
  11. package/package.json +15 -2
  12. package/src/capabilities/craftable.ts +51 -0
  13. package/src/capabilities/crafting.test.ts +7 -0
  14. package/src/capabilities/crafting.ts +3 -3
  15. package/src/capabilities/gathering.ts +17 -7
  16. package/src/capabilities/index.ts +0 -1
  17. package/src/capabilities/modules.ts +6 -0
  18. package/src/capabilities/storage.ts +16 -1
  19. package/src/contracts/platform.ts +231 -3
  20. package/src/contracts/server.ts +816 -471
  21. package/src/data/capabilities.ts +14 -329
  22. package/src/data/capability-formulas.ts +76 -0
  23. package/src/data/catalog.ts +0 -5
  24. package/src/data/colors.ts +14 -47
  25. package/src/data/entities.json +46 -10
  26. package/src/data/item-ids.ts +15 -12
  27. package/src/data/items.json +302 -38
  28. package/src/data/kind-registry.json +85 -0
  29. package/src/data/kind-registry.ts +150 -0
  30. package/src/data/metadata.ts +100 -31
  31. package/src/data/recipes-runtime.ts +3 -23
  32. package/src/data/recipes.json +250 -113
  33. package/src/derivation/build-methods.ts +45 -0
  34. package/src/derivation/capabilities.ts +415 -0
  35. package/src/derivation/capability-mappings.ts +117 -0
  36. package/src/derivation/crafting.ts +23 -24
  37. package/src/derivation/index.ts +17 -2
  38. package/src/derivation/reserve-regen.ts +34 -0
  39. package/src/derivation/resources.ts +125 -38
  40. package/src/derivation/stars.test.ts +51 -0
  41. package/src/derivation/stars.ts +15 -0
  42. package/src/derivation/stats.ts +6 -6
  43. package/src/derivation/stratum.ts +15 -19
  44. package/src/derivation/tiers.ts +28 -7
  45. package/src/entities/entity.ts +98 -0
  46. package/src/entities/gamestate.ts +3 -28
  47. package/src/entities/makers.ts +91 -136
  48. package/src/entities/slot-multiplier.ts +39 -0
  49. package/src/errors.ts +10 -15
  50. package/src/format.ts +26 -4
  51. package/src/index-module.ts +189 -47
  52. package/src/managers/actions.ts +252 -83
  53. package/src/managers/base.ts +6 -2
  54. package/src/managers/construction-types.ts +79 -0
  55. package/src/managers/construction.ts +396 -0
  56. package/src/managers/context.ts +11 -1
  57. package/src/managers/entities.ts +18 -66
  58. package/src/managers/epochs.ts +40 -0
  59. package/src/managers/index.ts +17 -1
  60. package/src/managers/locations.ts +25 -29
  61. package/src/managers/nft.ts +28 -0
  62. package/src/managers/plot.ts +127 -0
  63. package/src/nft/atomicassets.abi.json +1342 -0
  64. package/src/nft/atomicassets.ts +237 -0
  65. package/src/nft/atomicdata.ts +130 -0
  66. package/src/nft/buildImmutableData.ts +321 -0
  67. package/src/nft/description.ts +37 -15
  68. package/src/nft/index.ts +3 -0
  69. package/src/resolution/describe-module.ts +5 -8
  70. package/src/resolution/display-name.ts +38 -10
  71. package/src/resolution/resolve-item.ts +22 -20
  72. package/src/scheduling/accessor.ts +68 -22
  73. package/src/scheduling/availability.ts +108 -0
  74. package/src/scheduling/energy.ts +48 -0
  75. package/src/scheduling/lane-core.ts +130 -0
  76. package/src/scheduling/lanes.ts +60 -0
  77. package/src/scheduling/projection.ts +121 -94
  78. package/src/scheduling/schedule.ts +237 -103
  79. package/src/scheduling/task-cargo.ts +46 -0
  80. package/src/shipload.ts +16 -1
  81. package/src/subscriptions/manager.ts +40 -6
  82. package/src/subscriptions/mappers.ts +3 -8
  83. package/src/subscriptions/types.ts +3 -2
  84. package/src/testing/catalog-hash.ts +19 -0
  85. package/src/testing/index.ts +2 -0
  86. package/src/testing/projection-parity.ts +143 -0
  87. package/src/travel/travel.ts +90 -13
  88. package/src/types/capabilities.ts +1 -0
  89. package/src/types/index.ts +0 -1
  90. package/src/types.ts +19 -12
  91. package/src/utils/cargo.ts +27 -0
  92. package/src/utils/display-name.ts +61 -0
  93. package/src/utils/system.ts +25 -24
  94. package/src/capabilities/loading.ts +0 -8
  95. package/src/entities/container.ts +0 -108
  96. package/src/entities/ship-deploy.ts +0 -258
  97. package/src/entities/ship.ts +0 -204
  98. package/src/entities/warehouse.ts +0 -119
  99. package/src/types/entity-traits.ts +0 -69
@@ -1,108 +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 * as schedule from '../scheduling/schedule'
7
-
8
- export interface ContainerStateInput {
9
- id: UInt64Type
10
- owner: string
11
- name: string
12
- coordinates: CoordinatesType | {x: number; y: number; z?: number}
13
- hullmass: number
14
- capacity: number
15
- cargomass?: number
16
- cargo?: ServerContract.Types.cargo_item[]
17
- schedule?: ServerContract.Types.schedule
18
- }
19
-
20
- export class Container extends ServerContract.Types.entity_info {
21
- private _sched?: ScheduleAccessor
22
-
23
- get name(): string {
24
- return this.entity_name
25
- }
26
-
27
- get sched(): ScheduleAccessor {
28
- this._sched ??= new ScheduleAccessor(this)
29
- return this._sched
30
- }
31
-
32
- get isIdle(): boolean {
33
- return this.is_idle
34
- }
35
-
36
- isLoading(now: Date): boolean {
37
- return schedule.isLoading(this, now)
38
- }
39
-
40
- isUnloading(now: Date): boolean {
41
- return schedule.isUnloading(this, now)
42
- }
43
-
44
- get location(): Location {
45
- return Location.from(this.coordinates)
46
- }
47
-
48
- get totalMass(): UInt64 {
49
- return UInt64.from(this.hullmass ?? 0).adding(this.cargomass)
50
- }
51
-
52
- get maxCapacity(): UInt64 {
53
- return UInt64.from(this.capacity)
54
- }
55
-
56
- get availableCapacity(): UInt64 {
57
- const cargo = UInt64.from(this.cargomass)
58
- return cargo.gte(this.maxCapacity) ? UInt64.from(0) : this.maxCapacity.subtracting(cargo)
59
- }
60
-
61
- hasSpace(additionalMass: UInt64): boolean {
62
- return UInt64.from(this.cargomass).adding(additionalMass).lte(this.maxCapacity)
63
- }
64
-
65
- get isFull(): boolean {
66
- return UInt64.from(this.cargomass).gte(this.maxCapacity)
67
- }
68
-
69
- get orbitalAltitude(): number {
70
- return this.coordinates.z?.toNumber() || 0
71
- }
72
- }
73
-
74
- export function computeContainerCapabilities(stats: Record<string, number>): {
75
- hullmass: number
76
- capacity: number
77
- } {
78
- const density = stats['density'] ?? 500
79
- const strength = stats['strength'] ?? 500
80
- const hardness = stats['hardness'] ?? 500
81
- const saturation = stats['saturation'] ?? 500
82
-
83
- const hullmass = 25000 + 75 * density
84
-
85
- const statSum = strength + hardness + saturation
86
- const exponent = statSum / 2997
87
- const capacity = Math.floor(1000000 * 10 ** exponent)
88
-
89
- return {hullmass, capacity}
90
- }
91
-
92
- export function computeContainerT2Capabilities(stats: Record<string, number>): {
93
- hullmass: number
94
- capacity: number
95
- } {
96
- const strength = stats['strength'] ?? 0
97
- const density = stats['density'] ?? 0
98
- const hardness = stats['hardness'] ?? 0
99
- const saturation = stats['saturation'] ?? 0
100
-
101
- const hullmass = 20000 + 50 * density
102
-
103
- const statSum = strength + hardness + saturation
104
- const exponent = statSum / 2500
105
- const capacity = Math.floor(1500000 * 10 ** exponent)
106
-
107
- return {hullmass, capacity}
108
- }
@@ -1,258 +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
-
12
- export function computeShipHullCapabilities(stats: Record<string, number>): {
13
- hullmass: number
14
- capacity: number
15
- } {
16
- const density = stats.density ?? 500
17
- const strength = stats.strength ?? 500
18
- const hardness = stats.hardness ?? 500
19
- const saturation = stats.saturation ?? 500
20
-
21
- const hullmass = 25000 + 75 * density
22
- const statSum = strength + hardness + saturation
23
- const exponent = statSum / 2997.0
24
- const capacity = Math.floor(1000000 * 10 ** exponent)
25
-
26
- return {hullmass, capacity}
27
- }
28
-
29
- export function computeEngineCapabilities(stats: Record<string, number>): {
30
- thrust: number
31
- drain: number
32
- } {
33
- const vol = stats.volatility ?? 500
34
- const thm = stats.thermal ?? 500
35
-
36
- return {
37
- thrust: 400 + Math.floor((vol * 3) / 4),
38
- drain: Math.max(30, 50 - Math.floor(thm / 70)),
39
- }
40
- }
41
-
42
- export function computeGeneratorCapabilities(stats: Record<string, number>): {
43
- capacity: number
44
- recharge: number
45
- } {
46
- const res = stats.resonance ?? 500
47
- const ref = stats.reflectivity ?? 500
48
-
49
- return {
50
- capacity: 300 + Math.floor(res / 6),
51
- recharge: 1 + Math.floor((ref * 3) / 1000),
52
- }
53
- }
54
-
55
- export function computeGathererCapabilities(stats: Record<string, number>): {
56
- yield: number
57
- drain: number
58
- depth: number
59
- speed: number
60
- } {
61
- const str = stats.strength ?? 500
62
- const con = stats.conductivity ?? 500
63
- const ref = stats.reflectivity ?? 500
64
- const tol = stats.tolerance ?? 500
65
-
66
- return {
67
- yield: 200 + str,
68
- drain: Math.max(250, 1250 - Math.floor((con * 25) / 20)),
69
- depth: 200 + Math.floor((tol * 3) / 2),
70
- speed: 100 + Math.floor((ref * 4) / 5),
71
- }
72
- }
73
-
74
- export function computeLoaderCapabilities(stats: Record<string, number>): {
75
- mass: number
76
- thrust: number
77
- quantity: number
78
- } {
79
- const hrd = stats.hardness ?? 500
80
- const pla = stats.plasticity ?? 500
81
-
82
- return {
83
- mass: Math.max(200, 2000 - Math.floor(hrd * 2)),
84
- thrust: 1 + Math.floor(pla / 500),
85
- quantity: 1,
86
- }
87
- }
88
-
89
- export function computeCrafterCapabilities(stats: Record<string, number>): {
90
- speed: number
91
- drain: number
92
- } {
93
- const rea = stats.reactivity ?? 500
94
- const com = stats.composition ?? 500
95
-
96
- return {
97
- speed: 100 + Math.floor((rea * 4) / 5),
98
- drain: Math.max(5, 30 - Math.floor(com / 33)),
99
- }
100
- }
101
-
102
- export function computeHaulerCapabilities(stats: Record<string, number>): {
103
- capacity: number
104
- efficiency: number
105
- drain: number
106
- } {
107
- const res = stats.resonance ?? 500
108
- const con = stats.conductivity ?? 500
109
- const ref = stats.reflectivity ?? 500
110
-
111
- return {
112
- capacity: Math.max(1, 1 + Math.floor(res / 400)),
113
- efficiency: 2000 + con * 6,
114
- drain: Math.max(3, 15 - Math.floor(ref / 80)),
115
- }
116
- }
117
-
118
- export function computeStorageCapabilities(
119
- stats: Record<string, number>,
120
- baseCapacity: number
121
- ): {
122
- capacityBonus: number
123
- } {
124
- const strength = stats.strength ?? 500
125
- const hardness = stats.hardness ?? 500
126
- const saturation = stats.saturation ?? 500
127
-
128
- const statSum = strength + hardness + saturation
129
- const capacityBonus = Math.floor(
130
- (baseCapacity * (10 + Math.floor((statSum * 10) / 2997))) / 100
131
- )
132
-
133
- return {capacityBonus}
134
- }
135
-
136
- export function computeWarehouseHullCapabilities(stats: Record<string, number>): {
137
- hullmass: number
138
- capacity: number
139
- } {
140
- const density = stats.density ?? 500
141
- const strength = stats.strength ?? 500
142
- const hardness = stats.hardness ?? 500
143
- const saturation = stats.saturation ?? 500
144
-
145
- const hullmass = 25000 + 75 * density
146
- const statSum = strength + hardness + saturation
147
- const exponent = statSum / 2997.0
148
- const capacity = Math.floor(20000000 * 10 ** exponent)
149
-
150
- return {hullmass, capacity}
151
- }
152
-
153
- export interface ShipCapabilities {
154
- engines?: {thrust: number; drain: number}
155
- generator?: {capacity: number; recharge: number}
156
- gatherer?: {yield: number; drain: number; depth: number; speed: number}
157
- hauler?: {capacity: number; efficiency: number; drain: number}
158
- loaders?: {mass: number; thrust: number; quantity: number}
159
- crafter?: {speed: number; drain: number}
160
- }
161
-
162
- export function computeShipCapabilities(
163
- modules: {itemId: number; stats: bigint}[]
164
- ): ShipCapabilities {
165
- const ship: ShipCapabilities = {}
166
-
167
- const engineModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_ENGINE)
168
- if (engineModules.length > 0) {
169
- let totalThrust = 0
170
- let totalDrain = 0
171
- for (const m of engineModules) {
172
- const caps = computeEngineCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
173
- totalThrust += caps.thrust
174
- totalDrain += caps.drain
175
- }
176
- ship.engines = {thrust: totalThrust, drain: totalDrain}
177
- }
178
-
179
- const generatorModules = modules.filter(
180
- (m) => getModuleCapabilityType(m.itemId) === MODULE_GENERATOR
181
- )
182
- if (generatorModules.length > 0) {
183
- let totalCapacity = 0
184
- let totalRecharge = 0
185
- for (const m of generatorModules) {
186
- const caps = computeGeneratorCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
187
- totalCapacity += caps.capacity
188
- totalRecharge += caps.recharge
189
- }
190
- ship.generator = {capacity: totalCapacity, recharge: totalRecharge}
191
- }
192
-
193
- const gathererModules = modules.filter(
194
- (m) => getModuleCapabilityType(m.itemId) === MODULE_GATHERER
195
- )
196
- if (gathererModules.length > 0) {
197
- let totalYield = 0
198
- let totalDrain = 0
199
- let totalDepth = 0
200
- let totalSpeed = 0
201
- for (const m of gathererModules) {
202
- const caps = computeGathererCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
203
- totalYield += caps.yield
204
- totalDrain += caps.drain
205
- totalDepth += caps.depth
206
- totalSpeed += caps.speed
207
- }
208
- ship.gatherer = {yield: totalYield, drain: totalDrain, depth: totalDepth, speed: totalSpeed}
209
- }
210
-
211
- const haulerModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_HAULER)
212
- if (haulerModules.length > 0) {
213
- let totalCapacity = 0
214
- let weightedEffNum = 0
215
- let totalDrain = 0
216
- for (const m of haulerModules) {
217
- const caps = computeHaulerCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
218
- totalCapacity += caps.capacity
219
- weightedEffNum += caps.efficiency * caps.capacity
220
- totalDrain += caps.drain
221
- }
222
- ship.hauler = {
223
- capacity: totalCapacity,
224
- efficiency: totalCapacity > 0 ? Math.floor(weightedEffNum / totalCapacity) : 0,
225
- drain: totalDrain,
226
- }
227
- }
228
-
229
- const loaderModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_LOADER)
230
- if (loaderModules.length > 0) {
231
- let totalMass = 0
232
- let totalThrust = 0
233
- let totalQuantity = 0
234
- for (const m of loaderModules) {
235
- const caps = computeLoaderCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
236
- totalMass += caps.mass
237
- totalThrust += caps.thrust
238
- totalQuantity += caps.quantity
239
- }
240
- ship.loaders = {mass: totalMass, thrust: totalThrust, quantity: totalQuantity}
241
- }
242
-
243
- const crafterModules = modules.filter(
244
- (m) => getModuleCapabilityType(m.itemId) === MODULE_CRAFTER
245
- )
246
- if (crafterModules.length > 0) {
247
- let totalSpeed = 0
248
- let totalDrain = 0
249
- for (const m of crafterModules) {
250
- const caps = computeCrafterCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
251
- totalSpeed += caps.speed
252
- totalDrain += caps.drain
253
- }
254
- ship.crafter = {speed: totalSpeed, drain: totalDrain}
255
- }
256
-
257
- return ship
258
- }
@@ -1,204 +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
- getDestinationLocation,
6
- getPositionAt,
7
- getFlightOrigin as travelGetFlightOrigin,
8
- } from '../travel/travel'
9
- import {
10
- type ProjectedEntity,
11
- projectFromCurrentState as sharedProjectFromCurrentState,
12
- projectFromCurrentStateAt as sharedProjectFromCurrentStateAt,
13
- } from '../scheduling/projection'
14
- import {Location} from './location'
15
- import {ScheduleAccessor} from '../scheduling/accessor'
16
- import {InventoryAccessor} from './inventory-accessor'
17
- import type {EntityInventory} from './entity-inventory'
18
- import {
19
- energyPercent as calcEnergyPercent,
20
- needsRecharge as calcNeedsRecharge,
21
- hasEnergyForDistance,
22
- maxTravelDistance,
23
- } from '../capabilities/movement'
24
- import * as schedule from '../scheduling/schedule'
25
-
26
- export interface PackedModuleInput {
27
- itemId: UInt16Type
28
- stats: UInt64Type
29
- }
30
-
31
- export interface ShipStateInput {
32
- id: UInt64Type
33
- owner: string
34
- name: string
35
- coordinates: CoordinatesType | {x: number; y: number; z?: number}
36
- hullmass?: number
37
- capacity?: number
38
- energy?: number
39
- modules?: PackedModuleInput[]
40
- schedule?: ServerContract.Types.schedule
41
- cargo?: ServerContract.Types.cargo_item[]
42
- }
43
-
44
- type MovementEntity = {
45
- engines: ServerContract.Types.movement_stats
46
- generator: ServerContract.Types.energy_stats
47
- energy: UInt16
48
- }
49
-
50
- export class Ship extends ServerContract.Types.entity_info {
51
- private _sched?: ScheduleAccessor
52
- private _inv?: InventoryAccessor
53
-
54
- get name(): string {
55
- return this.entity_name
56
- }
57
-
58
- get inv(): InventoryAccessor {
59
- this._inv ??= new InventoryAccessor(this)
60
- return this._inv
61
- }
62
-
63
- get inventory(): EntityInventory[] {
64
- return this.inv.items
65
- }
66
-
67
- get sched(): ScheduleAccessor {
68
- this._sched ??= new ScheduleAccessor(this)
69
- return this._sched
70
- }
71
-
72
- get maxDistance(): UInt32 {
73
- if (!this.generator || !this.engines) return UInt32.from(0)
74
- return maxTravelDistance(this as MovementEntity)
75
- }
76
-
77
- get isIdle(): boolean {
78
- return this.is_idle
79
- }
80
-
81
- getFlightOrigin(flightTaskIndex: number): Coordinates {
82
- return Coordinates.from(travelGetFlightOrigin(this, flightTaskIndex))
83
- }
84
-
85
- destinationLocation(): Coordinates | undefined {
86
- const dest = getDestinationLocation(this)
87
- return dest ? Coordinates.from(dest) : undefined
88
- }
89
-
90
- positionAt(now: Date): Coordinates {
91
- const taskIndex = this.sched.currentTaskIndex(now)
92
- const progress = this.sched.currentTaskProgress(now)
93
- return Coordinates.from(getPositionAt(this, taskIndex, progress))
94
- }
95
-
96
- isInFlight(now: Date): boolean {
97
- return schedule.isInFlight(this, now)
98
- }
99
-
100
- isRecharging(now: Date): boolean {
101
- return schedule.isRecharging(this, now)
102
- }
103
-
104
- isLoading(now: Date): boolean {
105
- return schedule.isLoading(this, now)
106
- }
107
-
108
- isUnloading(now: Date): boolean {
109
- return schedule.isUnloading(this, now)
110
- }
111
-
112
- isGathering(now: Date): boolean {
113
- return schedule.isGathering(this, now)
114
- }
115
-
116
- get hasEngines(): boolean {
117
- return this.engines !== undefined
118
- }
119
-
120
- get hasGenerator(): boolean {
121
- return this.generator !== undefined
122
- }
123
-
124
- get hasGatherer(): boolean {
125
- return this.gatherer !== undefined
126
- }
127
-
128
- get hasWarp(): boolean {
129
- return this.warp !== undefined
130
- }
131
-
132
- project(): ProjectedEntity {
133
- return sharedProjectFromCurrentState(this)
134
- }
135
-
136
- projectAt(now: Date): ProjectedEntity {
137
- return sharedProjectFromCurrentStateAt(this, now)
138
- }
139
-
140
- get location(): Location {
141
- return Location.from(this.coordinates)
142
- }
143
-
144
- get totalCargoMass(): UInt64 {
145
- return this.inv.totalMass
146
- }
147
-
148
- get totalMass(): UInt64 {
149
- let mass = UInt64.from(this.hullmass ?? 0).adding(this.totalCargoMass)
150
- if (this.loaders) {
151
- mass = mass.adding(UInt64.from(this.loaders.mass).multiplying(this.loaders.quantity))
152
- }
153
- return mass
154
- }
155
-
156
- get maxCapacity(): UInt64 {
157
- return UInt64.from(this.capacity)
158
- }
159
-
160
- hasSpace(goodMass: UInt64, quantity: number): boolean {
161
- return this.totalMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity)
162
- }
163
-
164
- get availableCapacity(): UInt64 {
165
- return this.totalMass.gte(this.maxCapacity)
166
- ? UInt64.from(0)
167
- : this.maxCapacity.subtracting(this.totalMass)
168
- }
169
-
170
- getCargoForItem(goodId: UInt64Type): EntityInventory | undefined {
171
- return this.inv.forItem(goodId)
172
- }
173
-
174
- get sellableCargo(): EntityInventory[] {
175
- return this.inv.sellable
176
- }
177
-
178
- get hasSellableCargo(): boolean {
179
- return this.inv.hasSellable
180
- }
181
-
182
- get sellableGoodsCount(): number {
183
- return this.inv.sellableCount
184
- }
185
-
186
- get isFull(): boolean {
187
- return this.totalMass.gte(this.maxCapacity)
188
- }
189
-
190
- get energyPercent(): number {
191
- if (!this.generator || this.energy === undefined) return 0
192
- return calcEnergyPercent(this as MovementEntity)
193
- }
194
-
195
- get needsRecharge(): boolean {
196
- if (!this.generator || this.energy === undefined) return false
197
- return calcNeedsRecharge(this as MovementEntity)
198
- }
199
-
200
- hasEnergyFor(distance: UInt64): boolean {
201
- if (!this.engines || !this.generator || this.energy === undefined) return false
202
- return hasEnergyForDistance(this as MovementEntity, distance)
203
- }
204
- }
@@ -1,119 +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 inv(): InventoryAccessor {
35
- this._inv ??= new InventoryAccessor(this)
36
- return this._inv
37
- }
38
-
39
- get inventory(): EntityInventory[] {
40
- return this.inv.items
41
- }
42
-
43
- get sched(): ScheduleAccessor {
44
- this._sched ??= new ScheduleAccessor(this)
45
- return this._sched
46
- }
47
-
48
- get isIdle(): boolean {
49
- return this.is_idle
50
- }
51
-
52
- isLoading(now: Date): boolean {
53
- return schedule.isLoading(this, now)
54
- }
55
-
56
- isUnloading(now: Date): boolean {
57
- return schedule.isUnloading(this, now)
58
- }
59
-
60
- get location(): Location {
61
- return Location.from(this.coordinates)
62
- }
63
-
64
- get totalCargoMass(): UInt64 {
65
- return this.inv.totalMass
66
- }
67
-
68
- get maxCapacity(): UInt64 {
69
- return UInt64.from(this.capacity)
70
- }
71
-
72
- get availableCapacity(): UInt64 {
73
- const cargo = this.totalCargoMass
74
- return cargo.gte(this.maxCapacity) ? UInt64.from(0) : this.maxCapacity.subtracting(cargo)
75
- }
76
-
77
- hasSpace(goodMass: UInt64, quantity: number): boolean {
78
- return this.totalCargoMass.adding(goodMass.multiplying(quantity)).lte(this.maxCapacity)
79
- }
80
-
81
- get isFull(): boolean {
82
- return this.totalCargoMass.gte(this.maxCapacity)
83
- }
84
-
85
- getCargoForItem(goodId: UInt64Type): EntityInventory | undefined {
86
- return this.inv.forItem(goodId)
87
- }
88
-
89
- get orbitalAltitude(): number {
90
- return this.coordinates.z?.toNumber() || 0
91
- }
92
-
93
- get totalMass(): UInt64 {
94
- const hull = this.hullmass ? UInt64.from(this.hullmass) : UInt64.from(0)
95
- return hull.adding(this.totalCargoMass)
96
- }
97
- }
98
-
99
- export function computeWarehouseCapabilities(modules: {itemId: number; stats: bigint}[]): {
100
- loaders?: {mass: number; thrust: number; quantity: number}
101
- } {
102
- const warehouse: {loaders?: {mass: number; thrust: number; quantity: number}} = {}
103
-
104
- const loaderModules = modules.filter((m) => getModuleCapabilityType(m.itemId) === MODULE_LOADER)
105
- if (loaderModules.length > 0) {
106
- let totalMass = 0
107
- let totalThrust = 0
108
- let totalQuantity = 0
109
- for (const m of loaderModules) {
110
- const caps = computeLoaderCapabilities(decodeCraftedItemStats(m.itemId, m.stats))
111
- totalMass += caps.mass
112
- totalThrust += caps.thrust
113
- totalQuantity += caps.quantity
114
- }
115
- warehouse.loaders = {mass: totalMass, thrust: totalThrust, quantity: totalQuantity}
116
- }
117
-
118
- return warehouse
119
- }