@shipload/sdk 1.0.0-next.11 → 1.0.0-next.13
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 +779 -984
- package/lib/shipload.js +2203 -2738
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +2186 -2712
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +713 -0
- package/lib/testing.js +3065 -0
- package/lib/testing.js.map +1 -0
- package/lib/testing.m.js +3059 -0
- package/lib/testing.m.js.map +1 -0
- package/package.json +14 -1
- package/src/data/kind-registry.json +78 -0
- package/src/data/kind-registry.ts +133 -0
- package/src/derivation/capabilities.ts +397 -0
- package/src/derivation/crafting.ts +1 -1
- package/src/entities/entity.ts +98 -0
- package/src/entities/makers.ts +75 -228
- package/src/index-module.ts +30 -34
- package/src/managers/entities.ts +18 -114
- package/src/managers/index.ts +1 -1
- package/src/nft/atomicdata.ts +2 -0
- package/src/nft/description.ts +1 -1
- package/src/resolution/resolve-item.ts +3 -2
- package/src/subscriptions/manager.ts +2 -5
- package/src/subscriptions/mappers.ts +3 -12
- package/src/testing/catalog-hash.ts +19 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/projection-parity.ts +143 -0
- package/src/types/index.ts +0 -1
- package/src/types.ts +0 -9
- package/src/entities/container.ts +0 -123
- package/src/entities/extractor.ts +0 -144
- package/src/entities/factory.ts +0 -135
- package/src/entities/nexus.ts +0 -29
- package/src/entities/ship-deploy.ts +0 -316
- package/src/entities/ship.ts +0 -221
- package/src/entities/warehouse.ts +0 -136
- package/src/types/entity-traits.ts +0 -171
package/src/entities/makers.ts
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
1
|
import {Name, UInt16, UInt32, UInt64, UInt8} from '@wharfkit/antelope'
|
|
2
|
+
import type {NameType, UInt64Type} from '@wharfkit/antelope'
|
|
2
3
|
import {ServerContract} from '../contracts'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {Factory, computeFactoryCapabilities, type FactoryStateInput} from './factory'
|
|
9
|
-
import {
|
|
10
|
-
ITEM_EXTRACTOR_T1_PACKED,
|
|
11
|
-
ITEM_FACTORY_T1_PACKED,
|
|
12
|
-
ITEM_SHIP_T1_PACKED,
|
|
13
|
-
ITEM_WAREHOUSE_T1_PACKED,
|
|
14
|
-
} from '../data/item-ids'
|
|
15
|
-
import {getEntityLayout, type EntitySlot} from '../data/recipes-runtime'
|
|
4
|
+
import {Entity} from './entity'
|
|
5
|
+
import {getKindMeta, getTemplateMeta} from '../data/kind-registry'
|
|
6
|
+
import type {EntityTypeName} from '../data/kind-registry'
|
|
7
|
+
import {getEntityLayout} from '../data/recipes-runtime'
|
|
8
|
+
import type {EntitySlot} from '../data/recipes-runtime'
|
|
16
9
|
import {itemMetadata} from '../data/metadata'
|
|
17
10
|
import {getItem} from '../data/catalog'
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
MODULE_STORAGE,
|
|
21
|
-
moduleAccepts,
|
|
22
|
-
moduleSlotTypeToCode,
|
|
23
|
-
} from '../capabilities/modules'
|
|
24
|
-
import {computeShipCapabilities, computeStorageCapabilities} from './ship-deploy'
|
|
11
|
+
import {getModuleCapabilityType, moduleAccepts, moduleSlotTypeToCode} from '../capabilities/modules'
|
|
12
|
+
import {computeEntityCapabilities} from '../derivation/capabilities'
|
|
25
13
|
import type {InstalledModule} from './slot-multiplier'
|
|
26
|
-
|
|
14
|
+
|
|
15
|
+
export interface PackedModuleInput {
|
|
16
|
+
itemId: number
|
|
17
|
+
stats: bigint
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface EntityStateInput {
|
|
21
|
+
id: UInt64Type
|
|
22
|
+
owner: NameType
|
|
23
|
+
name: string
|
|
24
|
+
coordinates: {x: number; y: number; z?: number}
|
|
25
|
+
hullmass?: number
|
|
26
|
+
capacity?: number
|
|
27
|
+
cargomass?: number
|
|
28
|
+
energy?: number
|
|
29
|
+
modules?: PackedModuleInput[]
|
|
30
|
+
schedule?: ServerContract.Types.schedule
|
|
31
|
+
cargo?: ServerContract.Types.cargo_item[]
|
|
32
|
+
}
|
|
27
33
|
|
|
28
34
|
function assignModulesToSlots(
|
|
29
|
-
|
|
35
|
+
slots: EntitySlot[],
|
|
30
36
|
modules: PackedModuleInput[],
|
|
31
37
|
entityLabel: string
|
|
32
38
|
): ServerContract.Types.module_entry[] {
|
|
33
|
-
const layout = getEntityLayout(packedEntityItemId)
|
|
34
|
-
const slots = layout?.slots ?? []
|
|
35
39
|
const result: Array<{type: number; installed?: ServerContract.Types.packed_module}> = slots.map(
|
|
36
40
|
(s) => ({type: moduleSlotTypeToCode(s.type), installed: undefined})
|
|
37
41
|
)
|
|
38
42
|
|
|
39
43
|
for (const mod of modules) {
|
|
40
|
-
const
|
|
41
|
-
const modType = getModuleCapabilityType(itemId)
|
|
44
|
+
const modType = getModuleCapabilityType(mod.itemId)
|
|
42
45
|
const slotIdx = result.findIndex((r) => !r.installed && moduleAccepts(r.type, modType))
|
|
43
46
|
if (slotIdx === -1) {
|
|
44
47
|
let modName: string
|
|
45
48
|
try {
|
|
46
|
-
modName = getItem(itemId).name
|
|
49
|
+
modName = getItem(mod.itemId).name
|
|
47
50
|
} catch {
|
|
48
|
-
modName = itemMetadata[itemId]?.name ?? `item ${itemId}`
|
|
51
|
+
modName = itemMetadata[mod.itemId]?.name ?? `item ${mod.itemId}`
|
|
49
52
|
}
|
|
50
53
|
throw new Error(
|
|
51
54
|
`No compatible slot for module ${modName} (type ${modType}) on ${entityLabel}`
|
|
@@ -71,236 +74,80 @@ function toInstalledModules(entries: ServerContract.Types.module_entry[]): Insta
|
|
|
71
74
|
if (!entry.installed) return
|
|
72
75
|
installed.push({
|
|
73
76
|
slotIndex,
|
|
74
|
-
itemId: Number(
|
|
75
|
-
stats: BigInt(
|
|
77
|
+
itemId: Number(entry.installed.item_id.value),
|
|
78
|
+
stats: BigInt(entry.installed.stats.toString()),
|
|
76
79
|
})
|
|
77
80
|
})
|
|
78
81
|
return installed
|
|
79
82
|
}
|
|
80
83
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const {capacityBonus} = computeStorageCapabilities(stats, baseCapacity)
|
|
87
|
-
totalBonus += capacityBonus
|
|
88
|
-
}
|
|
89
|
-
return totalBonus
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function deriveShipFromModules(
|
|
93
|
-
moduleEntries: ServerContract.Types.module_entry[],
|
|
94
|
-
layout: EntitySlot[],
|
|
95
|
-
baseCapacity: number
|
|
96
|
-
): {
|
|
97
|
-
capabilities: ReturnType<typeof computeShipCapabilities>
|
|
98
|
-
finalCapacity: number
|
|
99
|
-
} {
|
|
100
|
-
const installed = toInstalledModules(moduleEntries)
|
|
101
|
-
const capabilities = computeShipCapabilities(installed, layout)
|
|
102
|
-
const totalBonus = computeStorageBonus(installed, baseCapacity)
|
|
103
|
-
return {capabilities, finalCapacity: baseCapacity + totalBonus}
|
|
84
|
+
const ZERO_HULL_STATS: Record<string, number> = {
|
|
85
|
+
density: 0,
|
|
86
|
+
strength: 0,
|
|
87
|
+
hardness: 0,
|
|
88
|
+
saturation: 0,
|
|
104
89
|
}
|
|
105
90
|
|
|
106
|
-
export function
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
owner: Name.from(state.owner),
|
|
111
|
-
entity_name: state.name,
|
|
112
|
-
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
113
|
-
cargomass: UInt32.from(0),
|
|
114
|
-
cargo: state.cargo || [],
|
|
115
|
-
is_idle: !state.schedule,
|
|
116
|
-
current_task_elapsed: UInt32.from(0),
|
|
117
|
-
current_task_remaining: UInt32.from(0),
|
|
118
|
-
pending_tasks: [],
|
|
119
|
-
}
|
|
120
|
-
if (state.hullmass !== undefined) info.hullmass = UInt32.from(state.hullmass)
|
|
121
|
-
if (state.energy !== undefined) info.energy = UInt16.from(state.energy)
|
|
122
|
-
if (state.schedule) info.schedule = state.schedule
|
|
123
|
-
|
|
124
|
-
let moduleEntries: ServerContract.Types.module_entry[] = []
|
|
125
|
-
const shipLayout = getEntityLayout(ITEM_SHIP_T1_PACKED)?.slots ?? []
|
|
126
|
-
if (state.modules && state.modules.length > 0) {
|
|
127
|
-
moduleEntries = assignModulesToSlots(ITEM_SHIP_T1_PACKED, state.modules, 'Ship T1')
|
|
128
|
-
const {capabilities, finalCapacity} = deriveShipFromModules(
|
|
129
|
-
moduleEntries,
|
|
130
|
-
shipLayout,
|
|
131
|
-
state.capacity ?? 0
|
|
132
|
-
)
|
|
133
|
-
if (capabilities.engines) info.engines = capabilities.engines
|
|
134
|
-
if (capabilities.generator) info.generator = capabilities.generator
|
|
135
|
-
if (capabilities.gatherer) info.gatherer = capabilities.gatherer
|
|
136
|
-
if (capabilities.hauler) info.hauler = capabilities.hauler
|
|
137
|
-
if (capabilities.loaders) info.loaders = capabilities.loaders
|
|
138
|
-
if (capabilities.crafter) info.crafter = capabilities.crafter
|
|
139
|
-
if (state.capacity !== undefined) info.capacity = UInt32.from(finalCapacity)
|
|
140
|
-
} else {
|
|
141
|
-
moduleEntries = assignModulesToSlots(ITEM_SHIP_T1_PACKED, [], 'Ship T1')
|
|
142
|
-
if (state.capacity !== undefined) info.capacity = UInt32.from(state.capacity)
|
|
91
|
+
export function makeEntity(packedItemId: number, state: EntityStateInput): Entity {
|
|
92
|
+
const template = getTemplateMeta(packedItemId)
|
|
93
|
+
if (!template) {
|
|
94
|
+
throw new Error(`Unknown packed entity item ID: ${packedItemId}`)
|
|
143
95
|
}
|
|
144
96
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
return new Ship(entityInfo)
|
|
149
|
-
}
|
|
97
|
+
const kind = template.kind.toString() as EntityTypeName
|
|
98
|
+
const layout = getEntityLayout(packedItemId)?.slots ?? []
|
|
99
|
+
const mods = state.modules ?? []
|
|
150
100
|
|
|
151
|
-
export function makeWarehouse(state: WarehouseStateInput): Warehouse {
|
|
152
101
|
const info: Record<string, unknown> = {
|
|
153
|
-
type:
|
|
102
|
+
type: template.kind,
|
|
154
103
|
id: UInt64.from(state.id),
|
|
155
104
|
owner: Name.from(state.owner),
|
|
156
105
|
entity_name: state.name,
|
|
157
106
|
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
158
|
-
|
|
159
|
-
cargomass: UInt32.from(0),
|
|
107
|
+
cargomass: UInt32.from(state.cargomass ?? 0),
|
|
160
108
|
cargo: state.cargo || [],
|
|
161
109
|
is_idle: !state.schedule,
|
|
162
110
|
current_task_elapsed: UInt32.from(0),
|
|
163
111
|
current_task_remaining: UInt32.from(0),
|
|
164
112
|
pending_tasks: [],
|
|
165
113
|
}
|
|
166
|
-
if (state.hullmass !== undefined) info.hullmass = UInt32.from(state.hullmass)
|
|
167
|
-
if (state.schedule) info.schedule = state.schedule
|
|
168
|
-
|
|
169
|
-
let moduleEntries: ServerContract.Types.module_entry[] = []
|
|
170
|
-
const warehouseLayout = getEntityLayout(ITEM_WAREHOUSE_T1_PACKED)?.slots ?? []
|
|
171
|
-
if (state.modules && state.modules.length > 0) {
|
|
172
|
-
moduleEntries = assignModulesToSlots(
|
|
173
|
-
ITEM_WAREHOUSE_T1_PACKED,
|
|
174
|
-
state.modules,
|
|
175
|
-
'Warehouse T1'
|
|
176
|
-
)
|
|
177
|
-
const installed = toInstalledModules(moduleEntries)
|
|
178
|
-
const capabilities = computeWarehouseCapabilities(installed, warehouseLayout)
|
|
179
|
-
if (capabilities.loaders) info.loaders = capabilities.loaders
|
|
180
|
-
|
|
181
|
-
const totalBonus = computeStorageBonus(installed, state.capacity)
|
|
182
|
-
info.capacity = UInt32.from(state.capacity + totalBonus)
|
|
183
|
-
} else {
|
|
184
|
-
moduleEntries = assignModulesToSlots(ITEM_WAREHOUSE_T1_PACKED, [], 'Warehouse T1')
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
info.modules = moduleEntries
|
|
188
|
-
|
|
189
|
-
const entityInfo = ServerContract.Types.entity_info.from(info)
|
|
190
|
-
return new Warehouse(entityInfo)
|
|
191
|
-
}
|
|
192
114
|
|
|
193
|
-
export function makeExtractor(state: ExtractorStateInput): Extractor {
|
|
194
|
-
const info: Record<string, unknown> = {
|
|
195
|
-
type: Name.from('extractor'),
|
|
196
|
-
id: UInt64.from(state.id),
|
|
197
|
-
owner: Name.from(state.owner),
|
|
198
|
-
entity_name: state.name,
|
|
199
|
-
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
200
|
-
cargomass: UInt32.from(0),
|
|
201
|
-
cargo: state.cargo || [],
|
|
202
|
-
is_idle: !state.schedule,
|
|
203
|
-
current_task_elapsed: UInt32.from(0),
|
|
204
|
-
current_task_remaining: UInt32.from(0),
|
|
205
|
-
pending_tasks: [],
|
|
206
|
-
}
|
|
207
|
-
if (state.hullmass !== undefined) info.hullmass = UInt32.from(state.hullmass)
|
|
208
115
|
if (state.energy !== undefined) info.energy = UInt16.from(state.energy)
|
|
209
116
|
if (state.schedule) info.schedule = state.schedule
|
|
210
|
-
if (state.capacity !== undefined) info.capacity = UInt32.from(state.capacity)
|
|
211
117
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
state.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
const capabilities = computeExtractorCapabilities(installed, layout)
|
|
221
|
-
if (capabilities.generator) info.generator = capabilities.generator
|
|
222
|
-
if (capabilities.gatherer) info.gatherer = capabilities.gatherer
|
|
223
|
-
}
|
|
118
|
+
if (kind === 'container') {
|
|
119
|
+
info.modules = []
|
|
120
|
+
if (state.hullmass !== undefined) info.hullmass = UInt32.from(state.hullmass)
|
|
121
|
+
if (state.capacity !== undefined) info.capacity = UInt32.from(state.capacity)
|
|
122
|
+
} else {
|
|
123
|
+
const entityLabel = getKindMeta(template.kind)?.defaultLabel ?? kind
|
|
124
|
+
const moduleEntries = assignModulesToSlots(layout, mods, entityLabel)
|
|
125
|
+
info.modules = moduleEntries
|
|
224
126
|
|
|
225
|
-
|
|
127
|
+
const installed = toInstalledModules(moduleEntries)
|
|
128
|
+
const caps = computeEntityCapabilities(ZERO_HULL_STATS, packedItemId, installed, layout)
|
|
226
129
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
130
|
+
if (state.hullmass !== undefined) {
|
|
131
|
+
info.hullmass = UInt32.from(state.hullmass)
|
|
132
|
+
} else if (installed.length > 0) {
|
|
133
|
+
info.hullmass = UInt32.from(caps.hullmass)
|
|
134
|
+
}
|
|
230
135
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
entity_name: state.name,
|
|
237
|
-
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
238
|
-
cargomass: UInt32.from(0),
|
|
239
|
-
cargo: state.cargo || [],
|
|
240
|
-
is_idle: !state.schedule,
|
|
241
|
-
current_task_elapsed: UInt32.from(0),
|
|
242
|
-
current_task_remaining: UInt32.from(0),
|
|
243
|
-
pending_tasks: [],
|
|
244
|
-
}
|
|
245
|
-
if (state.hullmass !== undefined) info.hullmass = UInt32.from(state.hullmass)
|
|
246
|
-
if (state.energy !== undefined) info.energy = UInt16.from(state.energy)
|
|
247
|
-
if (state.schedule) info.schedule = state.schedule
|
|
248
|
-
if (state.capacity !== undefined) info.capacity = UInt32.from(state.capacity)
|
|
136
|
+
if (state.capacity !== undefined) {
|
|
137
|
+
info.capacity = UInt32.from(state.capacity)
|
|
138
|
+
} else {
|
|
139
|
+
info.capacity = UInt32.from(caps.capacity)
|
|
140
|
+
}
|
|
249
141
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const installed = toInstalledModules(moduleEntries)
|
|
258
|
-
const capabilities = computeFactoryCapabilities(installed, layout)
|
|
259
|
-
if (capabilities.generator) info.generator = capabilities.generator
|
|
260
|
-
if (capabilities.crafter) info.crafter = capabilities.crafter
|
|
142
|
+
if (caps.engines) info.engines = caps.engines
|
|
143
|
+
if (caps.generator) info.generator = caps.generator
|
|
144
|
+
if (caps.gatherer) info.gatherer = caps.gatherer
|
|
145
|
+
if (caps.loaders) info.loaders = caps.loaders
|
|
146
|
+
if (caps.crafter) info.crafter = caps.crafter
|
|
147
|
+
if (caps.hauler) info.hauler = caps.hauler
|
|
148
|
+
if (caps.warp) info.warp = caps.warp
|
|
261
149
|
}
|
|
262
150
|
|
|
263
|
-
info.modules = moduleEntries
|
|
264
|
-
|
|
265
151
|
const entityInfo = ServerContract.Types.entity_info.from(info)
|
|
266
|
-
return new
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export function makeContainer(state: ContainerStateInput): Container {
|
|
270
|
-
const entityInfo = ServerContract.Types.entity_info.from({
|
|
271
|
-
type: Name.from('container'),
|
|
272
|
-
id: UInt64.from(state.id),
|
|
273
|
-
owner: Name.from(state.owner),
|
|
274
|
-
entity_name: state.name,
|
|
275
|
-
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
276
|
-
hullmass: UInt32.from(state.hullmass),
|
|
277
|
-
capacity: UInt32.from(state.capacity),
|
|
278
|
-
cargomass: UInt32.from(state.cargomass || 0),
|
|
279
|
-
cargo: state.cargo || [],
|
|
280
|
-
modules: [],
|
|
281
|
-
is_idle: !state.schedule,
|
|
282
|
-
current_task_elapsed: UInt32.from(0),
|
|
283
|
-
current_task_remaining: UInt32.from(0),
|
|
284
|
-
pending_tasks: [],
|
|
285
|
-
schedule: state.schedule,
|
|
286
|
-
})
|
|
287
|
-
return new Container(entityInfo)
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export function makeNexus(state: NexusStateInput): Nexus {
|
|
291
|
-
const entityInfo = ServerContract.Types.entity_info.from({
|
|
292
|
-
type: Name.from('nexus'),
|
|
293
|
-
id: UInt64.from(state.id),
|
|
294
|
-
owner: Name.from(state.owner),
|
|
295
|
-
entity_name: state.name,
|
|
296
|
-
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
297
|
-
cargomass: UInt32.from(0),
|
|
298
|
-
cargo: [],
|
|
299
|
-
modules: [],
|
|
300
|
-
is_idle: true,
|
|
301
|
-
current_task_elapsed: UInt32.from(0),
|
|
302
|
-
current_task_remaining: UInt32.from(0),
|
|
303
|
-
pending_tasks: [],
|
|
304
|
-
})
|
|
305
|
-
return new Nexus(entityInfo)
|
|
152
|
+
return new Entity(entityInfo)
|
|
306
153
|
}
|
package/src/index-module.ts
CHANGED
|
@@ -10,28 +10,19 @@ export {Types as ServerTypes} from './contracts/server'
|
|
|
10
10
|
export {Types as PlatformTypes} from './contracts/platform'
|
|
11
11
|
|
|
12
12
|
import type {ServerContract} from './contracts'
|
|
13
|
+
import type {Entity as EntityType} from './entities/entity'
|
|
13
14
|
|
|
14
15
|
export {Shipload} from './shipload'
|
|
15
|
-
export {
|
|
16
|
-
export type
|
|
17
|
-
export
|
|
18
|
-
export type
|
|
19
|
-
export
|
|
20
|
-
export type
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export {
|
|
24
|
-
export type {
|
|
25
|
-
export {Nexus} from './entities/nexus'
|
|
26
|
-
export type {NexusStateInput} from './entities/nexus'
|
|
27
|
-
export {
|
|
28
|
-
makeShip,
|
|
29
|
-
makeWarehouse,
|
|
30
|
-
makeExtractor,
|
|
31
|
-
makeFactory,
|
|
32
|
-
makeContainer,
|
|
33
|
-
makeNexus,
|
|
34
|
-
} from './entities/makers'
|
|
16
|
+
export {Entity} from './entities/entity'
|
|
17
|
+
export type Ship = EntityType
|
|
18
|
+
export type Warehouse = EntityType
|
|
19
|
+
export type Container = EntityType
|
|
20
|
+
export type Extractor = EntityType
|
|
21
|
+
export type Factory = EntityType
|
|
22
|
+
export type Nexus = EntityType
|
|
23
|
+
export {makeEntity} from './entities/makers'
|
|
24
|
+
export type {EntityStateInput, PackedModuleInput} from './entities/makers'
|
|
25
|
+
export type {InstalledModule} from './entities/slot-multiplier'
|
|
35
26
|
|
|
36
27
|
export type movement_stats = ServerContract.Types.movement_stats
|
|
37
28
|
export type energy_stats = ServerContract.Types.energy_stats
|
|
@@ -57,7 +48,7 @@ export {
|
|
|
57
48
|
EpochsManager,
|
|
58
49
|
ActionsManager,
|
|
59
50
|
} from './managers'
|
|
60
|
-
export type {
|
|
51
|
+
export type {LocationStratum} from './managers'
|
|
61
52
|
export type {EntityRefInput} from './managers/actions'
|
|
62
53
|
|
|
63
54
|
export {
|
|
@@ -203,21 +194,24 @@ export {
|
|
|
203
194
|
ENTITY_EXTRACTOR,
|
|
204
195
|
ENTITY_FACTORY,
|
|
205
196
|
ENTITY_CONTAINER,
|
|
206
|
-
|
|
207
|
-
warehouseTraits,
|
|
208
|
-
extractorTraits,
|
|
209
|
-
factoryTraits,
|
|
210
|
-
containerTraits,
|
|
197
|
+
ENTITY_NEXUS,
|
|
211
198
|
getEntityClass,
|
|
212
199
|
getPackedEntityType,
|
|
213
|
-
|
|
200
|
+
getKindMeta,
|
|
201
|
+
getTemplateMeta,
|
|
202
|
+
kindCan,
|
|
203
|
+
CAP_WRAP,
|
|
204
|
+
CAP_UNDEPLOY,
|
|
205
|
+
CAP_DEMOLISH,
|
|
206
|
+
CAP_MODULES,
|
|
214
207
|
isShip,
|
|
215
208
|
isWarehouse,
|
|
216
209
|
isExtractor,
|
|
217
210
|
isFactory,
|
|
218
211
|
isContainer,
|
|
219
|
-
|
|
220
|
-
|
|
212
|
+
isNexus,
|
|
213
|
+
} from './data/kind-registry'
|
|
214
|
+
export type {EntityTypeName, KindMeta, TemplateMeta} from './data/kind-registry'
|
|
221
215
|
export * from './capabilities'
|
|
222
216
|
|
|
223
217
|
export {
|
|
@@ -274,8 +268,6 @@ export {
|
|
|
274
268
|
} from './derivation/crafting'
|
|
275
269
|
export type {StackInput, CategoryStacks, RecipeSlotInput} from './derivation/crafting'
|
|
276
270
|
|
|
277
|
-
export {computeContainerCapabilities, computeContainerT2Capabilities} from './entities/container'
|
|
278
|
-
|
|
279
271
|
export {
|
|
280
272
|
computeShipHullCapabilities,
|
|
281
273
|
computeEngineCapabilities,
|
|
@@ -286,12 +278,16 @@ export {
|
|
|
286
278
|
computeCrafterCapabilities,
|
|
287
279
|
computeWarehouseHullCapabilities,
|
|
288
280
|
computeStorageCapabilities,
|
|
289
|
-
|
|
281
|
+
computeContainerCapabilities,
|
|
282
|
+
computeContainerT2Capabilities,
|
|
283
|
+
computeWarpCapabilities,
|
|
284
|
+
computeBaseCapacity,
|
|
285
|
+
computeEntityCapabilities,
|
|
290
286
|
GATHERER_DEPTH_TABLE,
|
|
291
287
|
GATHERER_DEPTH_MAX_TIER,
|
|
292
288
|
gathererDepthForTier,
|
|
293
|
-
} from './
|
|
294
|
-
export type {
|
|
289
|
+
} from './derivation/capabilities'
|
|
290
|
+
export type {GathererDepthParams, ComputedCapabilities} from './derivation/capabilities'
|
|
295
291
|
|
|
296
292
|
export {resolveItem} from './resolution/resolve-item'
|
|
297
293
|
export type {
|
package/src/managers/entities.ts
CHANGED
|
@@ -1,147 +1,51 @@
|
|
|
1
1
|
import {Name, type NameType, type UInt64Type} from '@wharfkit/antelope'
|
|
2
2
|
import {BaseManager} from './base'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {Container} from '../entities/container'
|
|
6
|
-
import {Extractor} from '../entities/extractor'
|
|
7
|
-
import {Factory} from '../entities/factory'
|
|
8
|
-
import {Nexus} from '../entities/nexus'
|
|
3
|
+
import {Entity} from '../entities/entity'
|
|
4
|
+
import type {EntityTypeName} from '../data/kind-registry'
|
|
9
5
|
import type {ServerContract} from '../contracts'
|
|
10
6
|
|
|
11
|
-
export type
|
|
7
|
+
export type {EntityTypeName} from '../data/kind-registry'
|
|
12
8
|
|
|
13
9
|
export class EntitiesManager extends BaseManager {
|
|
14
|
-
async getEntity(
|
|
15
|
-
id: UInt64Type
|
|
16
|
-
): Promise<Ship | Warehouse | Extractor | Factory | Container | Nexus> {
|
|
10
|
+
async getEntity(id: UInt64Type): Promise<Entity> {
|
|
17
11
|
const result = await this.server.readonly('getentity', {
|
|
18
12
|
entity_id: id,
|
|
19
13
|
})
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
return new Entity(result as ServerContract.Types.entity_info)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getProjection(id: UInt64Type, taskCount?: number): Promise<unknown> {
|
|
18
|
+
return this.server.readonly('getprojstate', {
|
|
19
|
+
entity_id: id,
|
|
20
|
+
task_count: taskCount,
|
|
21
|
+
})
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
async getEntities(
|
|
25
25
|
owner: NameType | ServerContract.Types.player_row,
|
|
26
|
-
|
|
27
|
-
): Promise<
|
|
26
|
+
kind?: EntityTypeName
|
|
27
|
+
): Promise<Entity[]> {
|
|
28
28
|
const ownerName = this.resolveOwner(owner)
|
|
29
29
|
const result = await this.server.readonly('getentities', {
|
|
30
30
|
owner: ownerName,
|
|
31
|
-
entity_type:
|
|
31
|
+
entity_type: kind,
|
|
32
32
|
})
|
|
33
33
|
const entities = result as ServerContract.Types.entity_info[]
|
|
34
|
-
return entities.map((
|
|
34
|
+
return entities.map((e) => new Entity(e))
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async getSummaries(
|
|
38
38
|
owner: NameType | ServerContract.Types.player_row,
|
|
39
|
-
|
|
39
|
+
kind?: EntityTypeName
|
|
40
40
|
): Promise<ServerContract.Types.entity_summary[]> {
|
|
41
41
|
const ownerName = this.resolveOwner(owner)
|
|
42
42
|
const result = await this.server.readonly('getsummaries', {
|
|
43
43
|
owner: ownerName,
|
|
44
|
-
entity_type:
|
|
44
|
+
entity_type: kind,
|
|
45
45
|
})
|
|
46
46
|
return result as ServerContract.Types.entity_summary[]
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
async getShip(id: UInt64Type): Promise<Ship> {
|
|
50
|
-
return (await this.getEntity(id)) as Ship
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async getWarehouse(id: UInt64Type): Promise<Warehouse> {
|
|
54
|
-
return (await this.getEntity(id)) as Warehouse
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async getContainer(id: UInt64Type): Promise<Container> {
|
|
58
|
-
return (await this.getEntity(id)) as Container
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async getExtractor(id: UInt64Type): Promise<Extractor> {
|
|
62
|
-
return (await this.getEntity(id)) as Extractor
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async getFactory(id: UInt64Type): Promise<Factory> {
|
|
66
|
-
return (await this.getEntity(id)) as Factory
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async getShips(owner: NameType | ServerContract.Types.player_row): Promise<Ship[]> {
|
|
70
|
-
return (await this.getEntities(owner, 'ship')) as Ship[]
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async getWarehouses(owner: NameType | ServerContract.Types.player_row): Promise<Warehouse[]> {
|
|
74
|
-
return (await this.getEntities(owner, 'warehouse')) as Warehouse[]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async getContainers(owner: NameType | ServerContract.Types.player_row): Promise<Container[]> {
|
|
78
|
-
return (await this.getEntities(owner, 'container')) as Container[]
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async getExtractors(owner: NameType | ServerContract.Types.player_row): Promise<Extractor[]> {
|
|
82
|
-
return (await this.getEntities(owner, 'extractor')) as Extractor[]
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async getFactories(owner: NameType | ServerContract.Types.player_row): Promise<Factory[]> {
|
|
86
|
-
return (await this.getEntities(owner, 'factory')) as Factory[]
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async getShipSummaries(
|
|
90
|
-
owner: NameType | ServerContract.Types.player_row
|
|
91
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
92
|
-
return this.getSummaries(owner, 'ship')
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async getWarehouseSummaries(
|
|
96
|
-
owner: NameType | ServerContract.Types.player_row
|
|
97
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
98
|
-
return this.getSummaries(owner, 'warehouse')
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async getContainerSummaries(
|
|
102
|
-
owner: NameType | ServerContract.Types.player_row
|
|
103
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
104
|
-
return this.getSummaries(owner, 'container')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async getExtractorSummaries(
|
|
108
|
-
owner: NameType | ServerContract.Types.player_row
|
|
109
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
110
|
-
return this.getSummaries(owner, 'extractor')
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async getFactorySummaries(
|
|
114
|
-
owner: NameType | ServerContract.Types.player_row
|
|
115
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
116
|
-
return this.getSummaries(owner, 'factory')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async getNexus(id: UInt64Type): Promise<Nexus> {
|
|
120
|
-
return (await this.getEntity(id)) as Nexus
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async getNexuses(owner: NameType | ServerContract.Types.player_row): Promise<Nexus[]> {
|
|
124
|
-
return (await this.getEntities(owner, 'nexus')) as Nexus[]
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async getNexusSummaries(
|
|
128
|
-
owner: NameType | ServerContract.Types.player_row
|
|
129
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
130
|
-
return this.getSummaries(owner, 'nexus')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private wrapEntity(
|
|
134
|
-
entity: ServerContract.Types.entity_info
|
|
135
|
-
): Ship | Warehouse | Extractor | Factory | Container | Nexus {
|
|
136
|
-
if (entity.type.equals('ship')) return new Ship(entity)
|
|
137
|
-
if (entity.type.equals('warehouse')) return new Warehouse(entity)
|
|
138
|
-
if (entity.type.equals('extractor')) return new Extractor(entity)
|
|
139
|
-
if (entity.type.equals('factory')) return new Factory(entity)
|
|
140
|
-
if (entity.type.equals('container')) return new Container(entity)
|
|
141
|
-
if (entity.type.equals('nexus')) return new Nexus(entity)
|
|
142
|
-
throw new Error(`unknown entity type: ${entity.type}`)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
49
|
private resolveOwner(owner: NameType | ServerContract.Types.player_row): Name {
|
|
146
50
|
if (typeof owner === 'object' && owner !== null && 'owner' in owner) {
|
|
147
51
|
return owner.owner
|
package/src/managers/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export {GameContext} from './context'
|
|
2
2
|
export {BaseManager} from './base'
|
|
3
3
|
export {EntitiesManager} from './entities'
|
|
4
|
-
export type {
|
|
4
|
+
export type {EntityTypeName} from './entities'
|
|
5
5
|
export {PlayersManager} from './players'
|
|
6
6
|
export {LocationsManager} from './locations'
|
|
7
7
|
export type {LocationStratum} from './locations'
|
package/src/nft/atomicdata.ts
CHANGED
package/src/nft/description.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
ITEM_WARP_T1,
|
|
26
26
|
} from '../data/item-ids'
|
|
27
27
|
import {decodeStat} from '../derivation/crafting'
|
|
28
|
-
import {gathererDepthForTier} from '../
|
|
28
|
+
import {gathererDepthForTier} from '../derivation/capabilities'
|
|
29
29
|
import {getItem} from '../data/catalog'
|
|
30
30
|
|
|
31
31
|
function idiv(a: number, b: number): number {
|