@shipload/sdk 1.0.0-next.2 → 1.0.0-next.21
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 +1731 -1044
- package/lib/shipload.js +6758 -4523
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +6649 -4479
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +833 -0
- package/lib/testing.js +3647 -0
- package/lib/testing.js.map +1 -0
- package/lib/testing.m.js +3641 -0
- package/lib/testing.m.js.map +1 -0
- package/package.json +15 -2
- package/src/capabilities/gathering.ts +17 -7
- package/src/capabilities/modules.ts +9 -0
- package/src/capabilities/storage.ts +1 -1
- package/src/contracts/platform.ts +211 -3
- package/src/contracts/server.ts +723 -438
- package/src/data/capabilities.ts +9 -329
- package/src/data/capability-formulas.ts +76 -0
- package/src/data/catalog.ts +0 -5
- package/src/data/colors.ts +14 -28
- package/src/data/entities.json +46 -10
- package/src/data/item-ids.ts +17 -13
- package/src/data/items.json +308 -37
- package/src/data/kind-registry.json +85 -0
- package/src/data/kind-registry.ts +150 -0
- package/src/data/metadata.ts +99 -24
- package/src/data/recipes-runtime.ts +3 -23
- package/src/data/recipes.json +265 -96
- package/src/derivation/build-methods.ts +45 -0
- package/src/derivation/capabilities.ts +414 -0
- package/src/derivation/capability-mappings.ts +117 -0
- package/src/derivation/crafting.ts +23 -24
- package/src/derivation/index.ts +8 -2
- package/src/derivation/reserve-regen.ts +34 -0
- package/src/derivation/resources.ts +125 -38
- package/src/derivation/stats.ts +1 -2
- package/src/derivation/stratum.ts +15 -19
- package/src/derivation/tiers.ts +28 -7
- package/src/entities/entity.ts +98 -0
- package/src/entities/gamestate.ts +3 -28
- package/src/entities/makers.ts +75 -129
- package/src/entities/slot-multiplier.ts +37 -0
- package/src/errors.ts +10 -15
- package/src/format.ts +26 -4
- package/src/index-module.ts +151 -40
- package/src/managers/actions.ts +184 -82
- package/src/managers/base.ts +2 -2
- package/src/managers/construction-types.ts +68 -0
- package/src/managers/construction.ts +292 -0
- package/src/managers/context.ts +9 -0
- package/src/managers/entities.ts +18 -66
- package/src/managers/epochs.ts +40 -0
- package/src/managers/index.ts +16 -1
- package/src/managers/locations.ts +2 -20
- package/src/managers/nft.ts +28 -0
- package/src/managers/plot.ts +123 -0
- package/src/nft/atomicassets.ts +231 -0
- package/src/nft/atomicdata.ts +130 -0
- package/src/nft/buildImmutableData.ts +319 -0
- package/src/nft/description.ts +45 -13
- package/src/nft/index.ts +3 -0
- package/src/resolution/describe-module.ts +5 -8
- package/src/resolution/display-name.ts +38 -10
- package/src/resolution/resolve-item.ts +20 -12
- package/src/scheduling/accessor.ts +4 -0
- package/src/scheduling/projection.ts +79 -27
- package/src/scheduling/schedule.ts +15 -1
- package/src/scheduling/task-cargo.ts +46 -0
- package/src/shipload.ts +5 -0
- package/src/subscriptions/manager.ts +40 -6
- package/src/subscriptions/mappers.ts +3 -8
- package/src/subscriptions/types.ts +3 -2
- 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/travel/travel.ts +61 -2
- package/src/types/index.ts +0 -1
- package/src/types.ts +17 -12
- package/src/utils/cargo.ts +27 -0
- package/src/utils/system.ts +25 -24
- package/src/entities/container.ts +0 -108
- package/src/entities/ship-deploy.ts +0 -258
- package/src/entities/ship.ts +0 -204
- package/src/entities/warehouse.ts +0 -119
- package/src/types/entity-traits.ts +0 -69
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import type {UInt64, UInt32} from '@wharfkit/antelope'
|
|
2
|
+
import {BaseManager} from './base'
|
|
3
|
+
import type {ServerContract} from '../contracts'
|
|
4
|
+
import {PlotManager} from './plot'
|
|
5
|
+
import {getItem} from '../data/catalog'
|
|
6
|
+
import {calc_craft_duration} from '../capabilities/crafting'
|
|
7
|
+
import {TaskType} from '../types'
|
|
8
|
+
import type {
|
|
9
|
+
BuildableTarget,
|
|
10
|
+
FinalizerEntityRef,
|
|
11
|
+
InboundTransfer,
|
|
12
|
+
Reservation,
|
|
13
|
+
SourceCargoStack,
|
|
14
|
+
SourceEntityRef,
|
|
15
|
+
} from './construction-types'
|
|
16
|
+
|
|
17
|
+
const CONSTRUCTION_KINDS = new Set<string>(['plot'])
|
|
18
|
+
|
|
19
|
+
export class ConstructionManager extends BaseManager {
|
|
20
|
+
private readonly plot = new PlotManager(this.context)
|
|
21
|
+
|
|
22
|
+
getTarget(
|
|
23
|
+
entity: ServerContract.Types.entity_row,
|
|
24
|
+
cargo: ServerContract.Types.cargo_row[],
|
|
25
|
+
activeTask?: ServerContract.Types.task
|
|
26
|
+
): BuildableTarget | null {
|
|
27
|
+
const kind = entity.kind.toString()
|
|
28
|
+
if (kind === 'plot') {
|
|
29
|
+
return this.plot.buildableTarget(entity, cargo, activeTask)
|
|
30
|
+
}
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
eligibleSources(
|
|
35
|
+
target: BuildableTarget,
|
|
36
|
+
entities: ServerContract.Types.entity_info[],
|
|
37
|
+
cargo: ServerContract.Types.cargo_row[]
|
|
38
|
+
): SourceEntityRef[] {
|
|
39
|
+
return partitionSources(target, entities, cargo).eligible
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
unreachableSources(
|
|
43
|
+
target: BuildableTarget,
|
|
44
|
+
entities: ServerContract.Types.entity_info[],
|
|
45
|
+
cargo: ServerContract.Types.cargo_row[]
|
|
46
|
+
): SourceEntityRef[] {
|
|
47
|
+
return partitionSources(target, entities, cargo).unreachable
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
partitionSources(
|
|
51
|
+
target: BuildableTarget,
|
|
52
|
+
entities: ServerContract.Types.entity_info[],
|
|
53
|
+
cargo: ServerContract.Types.cargo_row[]
|
|
54
|
+
): {eligible: SourceEntityRef[]; unreachable: SourceEntityRef[]} {
|
|
55
|
+
return partitionSources(target, entities, cargo)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
eligibleFinalizers(
|
|
59
|
+
target: BuildableTarget,
|
|
60
|
+
entities: ServerContract.Types.entity_info[]
|
|
61
|
+
): FinalizerEntityRef[] {
|
|
62
|
+
const out: FinalizerEntityRef[] = []
|
|
63
|
+
for (const entity of entities) {
|
|
64
|
+
if (!entity.owner.equals(target.ownerName)) continue
|
|
65
|
+
if (entity.id.equals(target.entityId)) continue
|
|
66
|
+
if (!coordsEqual(entity.coordinates, target.coordinates)) continue
|
|
67
|
+
const speed = entity.crafter?.speed.toNumber()
|
|
68
|
+
if (speed === undefined) continue
|
|
69
|
+
out.push({
|
|
70
|
+
entityId: entity.id,
|
|
71
|
+
name: entity.id.toString(),
|
|
72
|
+
capability: 'crafter',
|
|
73
|
+
crafterSpeed: speed,
|
|
74
|
+
estimatedDuration: this.estimateFinalizeDuration(target, speed),
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
return out.sort((a, b) => a.estimatedDuration.value - b.estimatedDuration.value)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
inboundTransfersTo(
|
|
81
|
+
plotId: UInt64,
|
|
82
|
+
entities: ServerContract.Types.entity_info[],
|
|
83
|
+
now: Date
|
|
84
|
+
): InboundTransfer[] {
|
|
85
|
+
return this.inboundTransfersByTarget(entities, now).get(plotId.toString()) ?? []
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
inboundTransfersByTarget(
|
|
89
|
+
entities: ServerContract.Types.entity_info[],
|
|
90
|
+
now: Date
|
|
91
|
+
): Map<string, InboundTransfer[]> {
|
|
92
|
+
const buckets = new Map<string, Map<string, InboundTransfer>>()
|
|
93
|
+
const nowMs = now.getTime()
|
|
94
|
+
for (const entity of entities) {
|
|
95
|
+
const schedule = entity.schedule
|
|
96
|
+
if (!schedule) continue
|
|
97
|
+
const entityIdStr = entity.id.toString()
|
|
98
|
+
const sourceName = entity.entity_name || entityIdStr
|
|
99
|
+
const startedMs = schedule.started.toDate().getTime()
|
|
100
|
+
let cumulativeSec = 0
|
|
101
|
+
for (const task of schedule.tasks) {
|
|
102
|
+
cumulativeSec += task.duration.toNumber()
|
|
103
|
+
if (!isTransferTask(task)) continue
|
|
104
|
+
if (!task.entitytarget) continue
|
|
105
|
+
const targetIdStr = task.entitytarget.entity_id.toString()
|
|
106
|
+
const etaSeconds = Math.max(
|
|
107
|
+
0,
|
|
108
|
+
Math.round((startedMs + cumulativeSec * 1000 - nowMs) / 1000)
|
|
109
|
+
)
|
|
110
|
+
let perTarget = buckets.get(targetIdStr)
|
|
111
|
+
if (!perTarget) {
|
|
112
|
+
perTarget = new Map()
|
|
113
|
+
buckets.set(targetIdStr, perTarget)
|
|
114
|
+
}
|
|
115
|
+
for (const c of task.cargo) {
|
|
116
|
+
const itemId = c.item_id.toNumber()
|
|
117
|
+
const quantity = c.quantity.toNumber()
|
|
118
|
+
if (quantity === 0) continue
|
|
119
|
+
const key = `${entityIdStr}#${itemId}`
|
|
120
|
+
const existing = perTarget.get(key)
|
|
121
|
+
if (existing) {
|
|
122
|
+
existing.quantity += quantity
|
|
123
|
+
existing.etaSeconds = Math.min(existing.etaSeconds, etaSeconds)
|
|
124
|
+
} else {
|
|
125
|
+
perTarget.set(key, {
|
|
126
|
+
sourceEntityId: entity.id,
|
|
127
|
+
sourceEntityType: entity.type,
|
|
128
|
+
sourceName,
|
|
129
|
+
itemId,
|
|
130
|
+
quantity,
|
|
131
|
+
etaSeconds,
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const out = new Map<string, InboundTransfer[]>()
|
|
138
|
+
for (const [targetId, perTarget] of buckets) {
|
|
139
|
+
out.set(targetId, Array.from(perTarget.values()))
|
|
140
|
+
}
|
|
141
|
+
return out
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
reservationsFrom(
|
|
145
|
+
sourceEntityId: UInt64,
|
|
146
|
+
entities: ServerContract.Types.entity_info[]
|
|
147
|
+
): Reservation[] {
|
|
148
|
+
const source = entities.find((e) => e.id.equals(sourceEntityId))
|
|
149
|
+
if (!source) return []
|
|
150
|
+
return reservationsOf(source)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
estimateFinalizeDuration(target: BuildableTarget, crafterSpeed: number): UInt32 {
|
|
154
|
+
return calc_craft_duration(crafterSpeed, target.progress.massRequired)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static isConstructionKind(kind: string): boolean {
|
|
158
|
+
return CONSTRUCTION_KINDS.has(kind)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function coordsEqual(
|
|
163
|
+
a: ServerContract.Types.coordinates,
|
|
164
|
+
b: ServerContract.Types.coordinates
|
|
165
|
+
): boolean {
|
|
166
|
+
return a.x.equals(b.x) && a.y.equals(b.y)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function moduleKey(module: ServerContract.Types.module_entry): string {
|
|
170
|
+
const installed = module.installed
|
|
171
|
+
if (!installed) return `${module.type.toNumber()}:empty`
|
|
172
|
+
|
|
173
|
+
return `${module.type.toNumber()}:${installed.item_id.toNumber()}:${installed.stats.toString()}`
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function sourceStackKey(cargo: ServerContract.Types.cargo_row): string {
|
|
177
|
+
return `${cargo.item_id.toNumber()}#${cargo.stats.toString()}#${(cargo.modules ?? [])
|
|
178
|
+
.map(moduleKey)
|
|
179
|
+
.join(',')}`
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function matchRelevantCargo(
|
|
183
|
+
entity: ServerContract.Types.entity_info,
|
|
184
|
+
target: BuildableTarget,
|
|
185
|
+
cargo: ServerContract.Types.cargo_row[],
|
|
186
|
+
reservedByItem: Map<number, number>
|
|
187
|
+
): SourceCargoStack[] {
|
|
188
|
+
const needsByItemId = new Map(
|
|
189
|
+
target.progress.rows.filter((row) => row.missing > 0).map((row) => [row.itemId, row])
|
|
190
|
+
)
|
|
191
|
+
const remainingReserved = new Map(reservedByItem)
|
|
192
|
+
const out: SourceCargoStack[] = []
|
|
193
|
+
for (const c of cargo) {
|
|
194
|
+
if (!c.entity_id.equals(entity.id)) continue
|
|
195
|
+
const itemId = c.item_id.toNumber()
|
|
196
|
+
const need = needsByItemId.get(itemId)
|
|
197
|
+
if (!need) continue
|
|
198
|
+
const gross = c.quantity.toNumber()
|
|
199
|
+
if (gross === 0) continue
|
|
200
|
+
const reservedRemaining = remainingReserved.get(itemId) ?? 0
|
|
201
|
+
const reserved = Math.min(gross, reservedRemaining)
|
|
202
|
+
const available = gross - reserved
|
|
203
|
+
if (reserved > 0) {
|
|
204
|
+
remainingReserved.set(itemId, reservedRemaining - reserved)
|
|
205
|
+
}
|
|
206
|
+
if (available === 0) continue
|
|
207
|
+
out.push({
|
|
208
|
+
key: sourceStackKey(c),
|
|
209
|
+
rowId: c.id,
|
|
210
|
+
itemId,
|
|
211
|
+
item: getItem(itemId),
|
|
212
|
+
stats: c.stats,
|
|
213
|
+
modules: c.modules ?? [],
|
|
214
|
+
available,
|
|
215
|
+
plotNeeds: need.missing,
|
|
216
|
+
reserved,
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
return out
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function partitionSources(
|
|
223
|
+
target: BuildableTarget,
|
|
224
|
+
entities: ServerContract.Types.entity_info[],
|
|
225
|
+
cargo: ServerContract.Types.cargo_row[]
|
|
226
|
+
): {eligible: SourceEntityRef[]; unreachable: SourceEntityRef[]} {
|
|
227
|
+
const eligible: SourceEntityRef[] = []
|
|
228
|
+
const unreachable: SourceEntityRef[] = []
|
|
229
|
+
for (const entity of entities) {
|
|
230
|
+
if (!entity.owner.equals(target.ownerName)) continue
|
|
231
|
+
if (entity.id.equals(target.entityId)) continue
|
|
232
|
+
if (!coordsEqual(entity.coordinates, target.coordinates)) continue
|
|
233
|
+
const reserved = reservedByItemFor(entity)
|
|
234
|
+
const relevant = matchRelevantCargo(entity, target, cargo, reserved)
|
|
235
|
+
if (relevant.length === 0) continue
|
|
236
|
+
const loaderCount = entity.loaders?.quantity.toNumber() ?? 0
|
|
237
|
+
const loaderTotalMass = entity.loaders?.mass.toNumber() ?? 0
|
|
238
|
+
const ref: SourceEntityRef = {
|
|
239
|
+
entityId: entity.id,
|
|
240
|
+
name: entity.id.toString(),
|
|
241
|
+
hasLoaders: loaderCount > 0,
|
|
242
|
+
loaderCount,
|
|
243
|
+
loaderTotalMass,
|
|
244
|
+
relevantCargo: relevant,
|
|
245
|
+
}
|
|
246
|
+
if (ref.hasLoaders) eligible.push(ref)
|
|
247
|
+
else unreachable.push(ref)
|
|
248
|
+
}
|
|
249
|
+
return {eligible, unreachable}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isTransferTask(task: ServerContract.Types.task): boolean {
|
|
253
|
+
const type = task.type.toNumber()
|
|
254
|
+
return type === TaskType.LOAD || type === TaskType.UNLOAD
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function reservationsOf(source: ServerContract.Types.entity_info): Reservation[] {
|
|
258
|
+
if (!source.schedule) return []
|
|
259
|
+
const out = new Map<string, Reservation>()
|
|
260
|
+
for (const task of source.schedule.tasks) {
|
|
261
|
+
if (!isTransferTask(task)) continue
|
|
262
|
+
if (!task.entitytarget) continue
|
|
263
|
+
const targetType = task.entitytarget.entity_type
|
|
264
|
+
const targetId = task.entitytarget.entity_id
|
|
265
|
+
for (const c of task.cargo) {
|
|
266
|
+
const itemId = c.item_id.toNumber()
|
|
267
|
+
const quantity = c.quantity.toNumber()
|
|
268
|
+
if (quantity === 0) continue
|
|
269
|
+
const key = `${targetId.toString()}#${itemId}`
|
|
270
|
+
const existing = out.get(key)
|
|
271
|
+
if (existing) {
|
|
272
|
+
existing.quantity += quantity
|
|
273
|
+
} else {
|
|
274
|
+
out.set(key, {
|
|
275
|
+
targetEntityId: targetId,
|
|
276
|
+
targetEntityType: targetType,
|
|
277
|
+
itemId,
|
|
278
|
+
quantity,
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return Array.from(out.values())
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function reservedByItemFor(source: ServerContract.Types.entity_info): Map<number, number> {
|
|
287
|
+
const out = new Map<number, number>()
|
|
288
|
+
for (const r of reservationsOf(source)) {
|
|
289
|
+
out.set(r.itemId, (out.get(r.itemId) ?? 0) + r.quantity)
|
|
290
|
+
}
|
|
291
|
+
return out
|
|
292
|
+
}
|
package/src/managers/context.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {PlayersManager} from './players'
|
|
|
8
8
|
import {LocationsManager} from './locations'
|
|
9
9
|
import {EpochsManager} from './epochs'
|
|
10
10
|
import {ActionsManager} from './actions'
|
|
11
|
+
import {NftManager} from './nft'
|
|
11
12
|
import {SubscriptionsManager} from '../subscriptions/manager'
|
|
12
13
|
|
|
13
14
|
export class GameContext {
|
|
@@ -16,6 +17,7 @@ export class GameContext {
|
|
|
16
17
|
private _locations?: LocationsManager
|
|
17
18
|
private _epochs?: EpochsManager
|
|
18
19
|
private _actions?: ActionsManager
|
|
20
|
+
private _nft?: NftManager
|
|
19
21
|
private _subscriptions?: SubscriptionsManager
|
|
20
22
|
private _subscriptionsUrl?: string
|
|
21
23
|
|
|
@@ -63,6 +65,13 @@ export class GameContext {
|
|
|
63
65
|
return this._actions
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
get nft(): NftManager {
|
|
69
|
+
if (!this._nft) {
|
|
70
|
+
this._nft = new NftManager(this)
|
|
71
|
+
}
|
|
72
|
+
return this._nft
|
|
73
|
+
}
|
|
74
|
+
|
|
66
75
|
setSubscriptionsUrl(url: string) {
|
|
67
76
|
this._subscriptionsUrl = url
|
|
68
77
|
}
|
package/src/managers/entities.ts
CHANGED
|
@@ -1,99 +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'
|
|
3
|
+
import {Entity} from '../entities/entity'
|
|
4
|
+
import type {EntityTypeName} from '../data/kind-registry'
|
|
6
5
|
import type {ServerContract} from '../contracts'
|
|
7
6
|
|
|
8
|
-
export type
|
|
7
|
+
export type {EntityTypeName} from '../data/kind-registry'
|
|
9
8
|
|
|
10
9
|
export class EntitiesManager extends BaseManager {
|
|
11
|
-
async getEntity(
|
|
10
|
+
async getEntity(id: UInt64Type): Promise<Entity> {
|
|
12
11
|
const result = await this.server.readonly('getentity', {
|
|
13
|
-
entity_type: Name.from(type),
|
|
14
12
|
entity_id: id,
|
|
15
13
|
})
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
})
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
async getEntities(
|
|
21
25
|
owner: NameType | ServerContract.Types.player_row,
|
|
22
|
-
|
|
23
|
-
): Promise<
|
|
26
|
+
kind?: EntityTypeName
|
|
27
|
+
): Promise<Entity[]> {
|
|
24
28
|
const ownerName = this.resolveOwner(owner)
|
|
25
29
|
const result = await this.server.readonly('getentities', {
|
|
26
30
|
owner: ownerName,
|
|
27
|
-
entity_type:
|
|
31
|
+
entity_type: kind,
|
|
28
32
|
})
|
|
29
33
|
const entities = result as ServerContract.Types.entity_info[]
|
|
30
|
-
return entities.map((
|
|
34
|
+
return entities.map((e) => new Entity(e))
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
async getSummaries(
|
|
34
38
|
owner: NameType | ServerContract.Types.player_row,
|
|
35
|
-
|
|
39
|
+
kind?: EntityTypeName
|
|
36
40
|
): Promise<ServerContract.Types.entity_summary[]> {
|
|
37
41
|
const ownerName = this.resolveOwner(owner)
|
|
38
42
|
const result = await this.server.readonly('getsummaries', {
|
|
39
43
|
owner: ownerName,
|
|
40
|
-
entity_type:
|
|
44
|
+
entity_type: kind,
|
|
41
45
|
})
|
|
42
46
|
return result as ServerContract.Types.entity_summary[]
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
async getShip(id: UInt64Type): Promise<Ship> {
|
|
46
|
-
return (await this.getEntity('ship', id)) as Ship
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async getWarehouse(id: UInt64Type): Promise<Warehouse> {
|
|
50
|
-
return (await this.getEntity('warehouse', id)) as Warehouse
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async getContainer(id: UInt64Type): Promise<Container> {
|
|
54
|
-
return (await this.getEntity('container', id)) as Container
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async getShips(owner: NameType | ServerContract.Types.player_row): Promise<Ship[]> {
|
|
58
|
-
return (await this.getEntities(owner, 'ship')) as Ship[]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async getWarehouses(owner: NameType | ServerContract.Types.player_row): Promise<Warehouse[]> {
|
|
62
|
-
return (await this.getEntities(owner, 'warehouse')) as Warehouse[]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async getContainers(owner: NameType | ServerContract.Types.player_row): Promise<Container[]> {
|
|
66
|
-
return (await this.getEntities(owner, 'container')) as Container[]
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async getShipSummaries(
|
|
70
|
-
owner: NameType | ServerContract.Types.player_row
|
|
71
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
72
|
-
return this.getSummaries(owner, 'ship')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async getWarehouseSummaries(
|
|
76
|
-
owner: NameType | ServerContract.Types.player_row
|
|
77
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
78
|
-
return this.getSummaries(owner, 'warehouse')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async getContainerSummaries(
|
|
82
|
-
owner: NameType | ServerContract.Types.player_row
|
|
83
|
-
): Promise<ServerContract.Types.entity_summary[]> {
|
|
84
|
-
return this.getSummaries(owner, 'container')
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private wrapEntity(entity: ServerContract.Types.entity_info): Ship | Warehouse | Container {
|
|
88
|
-
if (entity.type.equals('ship')) {
|
|
89
|
-
return new Ship(entity)
|
|
90
|
-
} else if (entity.type.equals('warehouse')) {
|
|
91
|
-
return new Warehouse(entity)
|
|
92
|
-
} else {
|
|
93
|
-
return new Container(entity)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
49
|
private resolveOwner(owner: NameType | ServerContract.Types.player_row): Name {
|
|
98
50
|
if (typeof owner === 'object' && owner !== null && 'owner' in owner) {
|
|
99
51
|
return owner.owner
|
package/src/managers/epochs.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {UInt64, type UInt64Type} from '@wharfkit/antelope'
|
|
2
2
|
import {BaseManager} from './base'
|
|
3
3
|
import {type EpochInfo, getCurrentEpoch, getEpochInfo} from '../scheduling/epoch'
|
|
4
|
+
import type {ServerContract} from '../contracts'
|
|
4
5
|
|
|
5
6
|
export class EpochsManager extends BaseManager {
|
|
6
7
|
async getCurrentHeight(): Promise<UInt64> {
|
|
@@ -8,6 +9,11 @@ export class EpochsManager extends BaseManager {
|
|
|
8
9
|
return getCurrentEpoch(game)
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
async getFinalizedEpoch(reload = false): Promise<UInt64> {
|
|
13
|
+
const state = await this.getState(reload)
|
|
14
|
+
return state.currentEpoch
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
async getCurrent(): Promise<EpochInfo> {
|
|
12
18
|
const game = await this.getGame()
|
|
13
19
|
const epoch = await this.getCurrentHeight()
|
|
@@ -44,4 +50,38 @@ export class EpochsManager extends BaseManager {
|
|
|
44
50
|
const remaining = await this.getTimeRemaining()
|
|
45
51
|
return durationMs <= remaining
|
|
46
52
|
}
|
|
53
|
+
|
|
54
|
+
async getEpochRow(epoch: UInt64Type): Promise<ServerContract.Types.epoch_row | undefined> {
|
|
55
|
+
const target = UInt64.from(epoch)
|
|
56
|
+
return this.server.table('epoch').get(target)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getActiveEpochInfo(): Promise<ServerContract.Types.epoch_row | undefined> {
|
|
60
|
+
const rows = await this.server.table('epoch').all()
|
|
61
|
+
if (rows.length === 0) {
|
|
62
|
+
return undefined
|
|
63
|
+
}
|
|
64
|
+
return rows[rows.length - 1]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async getOracles(): Promise<ServerContract.Types.oracle_row[]> {
|
|
68
|
+
return this.server.table('oracles').all()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async getThreshold(): Promise<number> {
|
|
72
|
+
const cfg = await this.server.table('oraclecfg').get()
|
|
73
|
+
return cfg ? Number(cfg.threshold) : 0
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async getCommitsFor(epoch: UInt64Type): Promise<ServerContract.Types.commit_row[]> {
|
|
77
|
+
const target = UInt64.from(epoch)
|
|
78
|
+
const rows = await this.server.table('commit').all()
|
|
79
|
+
return rows.filter((r) => r.epoch.equals(target))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async getRevealsFor(epoch: UInt64Type): Promise<ServerContract.Types.reveal_row[]> {
|
|
83
|
+
const target = UInt64.from(epoch)
|
|
84
|
+
const rows = await this.server.table('reveal').all()
|
|
85
|
+
return rows.filter((r) => r.epoch.equals(target))
|
|
86
|
+
}
|
|
47
87
|
}
|
package/src/managers/index.ts
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
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'
|
|
8
8
|
export {EpochsManager} from './epochs'
|
|
9
9
|
export {ActionsManager} from './actions'
|
|
10
|
+
export {NftManager} from './nft'
|
|
11
|
+
export type {NftConfigForItem} from './nft'
|
|
12
|
+
export {PlotManager} from './plot'
|
|
13
|
+
export type {PlotProgress, PlotProgressInputRow} from './plot'
|
|
14
|
+
export {ConstructionManager} from './construction'
|
|
15
|
+
export type {
|
|
16
|
+
BuildableTarget,
|
|
17
|
+
BuildState,
|
|
18
|
+
SourceEntityRef,
|
|
19
|
+
SourceCargoStack,
|
|
20
|
+
FinalizerEntityRef,
|
|
21
|
+
FinalizerCapability,
|
|
22
|
+
InboundTransfer,
|
|
23
|
+
Reservation,
|
|
24
|
+
} from './construction-types'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type {UInt16Type} from '@wharfkit/antelope'
|
|
2
2
|
import {BaseManager} from './base'
|
|
3
|
-
import
|
|
3
|
+
import type {CoordinatesType, Distance} from '../types'
|
|
4
4
|
import {hasSystem} from '../utils/system'
|
|
5
5
|
import {findNearbyPlanets} from '../travel/travel'
|
|
6
6
|
import type {ServerContract} from '../contracts'
|
|
@@ -47,22 +47,4 @@ export class LocationsManager extends BaseManager {
|
|
|
47
47
|
reserve: overrideMap.get(s.index) ?? s.reserve,
|
|
48
48
|
}))
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
async getLocationEntity(
|
|
52
|
-
id: UInt64Type
|
|
53
|
-
): Promise<ServerContract.Types.location_row | undefined> {
|
|
54
|
-
const row = await this.server.table('location').get(UInt64.from(id))
|
|
55
|
-
return row ?? undefined
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async getLocationEntityAt(
|
|
59
|
-
coords: CoordinatesType
|
|
60
|
-
): Promise<ServerContract.Types.location_row | undefined> {
|
|
61
|
-
const id = coordsToLocationId(coords)
|
|
62
|
-
return this.getLocationEntity(id)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async getAllLocationEntities(): Promise<ServerContract.Types.location_row[]> {
|
|
66
|
-
return this.server.table('location').all()
|
|
67
|
-
}
|
|
68
50
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {UInt64, type UInt64Type} from '@wharfkit/antelope'
|
|
2
|
+
import {BaseManager} from './base'
|
|
3
|
+
import type {ServerContract} from '../contracts'
|
|
4
|
+
|
|
5
|
+
export interface NftConfigForItem {
|
|
6
|
+
templateId: number
|
|
7
|
+
schemaName: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class NftManager extends BaseManager {
|
|
11
|
+
private cache = new Map<string, NftConfigForItem | null>()
|
|
12
|
+
|
|
13
|
+
async getNftConfigForItem(itemId: UInt64Type): Promise<NftConfigForItem | undefined> {
|
|
14
|
+
const id = UInt64.from(itemId)
|
|
15
|
+
const key = id.toString()
|
|
16
|
+
if (this.cache.has(key)) {
|
|
17
|
+
return this.cache.get(key) ?? undefined
|
|
18
|
+
}
|
|
19
|
+
const row = (await this.server.table('nftconfig').get(id)) as
|
|
20
|
+
| ServerContract.Types.nftconfig_row
|
|
21
|
+
| undefined
|
|
22
|
+
const result: NftConfigForItem | null = row
|
|
23
|
+
? {templateId: Number(row.template_id), schemaName: String(row.schema_name)}
|
|
24
|
+
: null
|
|
25
|
+
this.cache.set(key, result)
|
|
26
|
+
return result ?? undefined
|
|
27
|
+
}
|
|
28
|
+
}
|