@shipload/sdk 1.0.0-next.3 → 1.0.0-next.31
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 +1849 -961
- package/lib/shipload.js +9089 -4854
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +8958 -4805
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +856 -0
- package/lib/testing.js +3739 -0
- package/lib/testing.js.map +1 -0
- package/lib/testing.m.js +3733 -0
- package/lib/testing.m.js.map +1 -0
- package/package.json +15 -2
- package/src/capabilities/craftable.ts +51 -0
- package/src/capabilities/crafting.test.ts +7 -0
- package/src/capabilities/crafting.ts +3 -3
- package/src/capabilities/gathering.ts +17 -7
- package/src/capabilities/index.ts +0 -1
- package/src/capabilities/modules.ts +6 -0
- package/src/capabilities/storage.ts +16 -1
- package/src/contracts/platform.ts +231 -3
- package/src/contracts/server.ts +816 -471
- package/src/data/capabilities.ts +14 -329
- package/src/data/capability-formulas.ts +76 -0
- package/src/data/catalog.ts +0 -5
- package/src/data/colors.ts +14 -47
- package/src/data/entities.json +46 -10
- package/src/data/item-ids.ts +15 -12
- package/src/data/items.json +302 -38
- package/src/data/kind-registry.json +85 -0
- package/src/data/kind-registry.ts +150 -0
- package/src/data/metadata.ts +100 -31
- package/src/data/recipes-runtime.ts +3 -23
- package/src/data/recipes.json +250 -113
- package/src/derivation/build-methods.ts +45 -0
- package/src/derivation/capabilities.ts +415 -0
- package/src/derivation/capability-mappings.ts +117 -0
- package/src/derivation/crafting.ts +23 -24
- package/src/derivation/index.ts +17 -2
- package/src/derivation/reserve-regen.ts +34 -0
- package/src/derivation/resources.ts +125 -38
- package/src/derivation/stars.test.ts +51 -0
- package/src/derivation/stars.ts +15 -0
- package/src/derivation/stats.ts +6 -6
- 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 +91 -136
- package/src/entities/slot-multiplier.ts +39 -0
- package/src/errors.ts +10 -15
- package/src/format.ts +26 -4
- package/src/index-module.ts +189 -47
- package/src/managers/actions.ts +252 -83
- package/src/managers/base.ts +6 -2
- package/src/managers/construction-types.ts +79 -0
- package/src/managers/construction.ts +396 -0
- package/src/managers/context.ts +11 -1
- package/src/managers/entities.ts +18 -66
- package/src/managers/epochs.ts +40 -0
- package/src/managers/index.ts +17 -1
- package/src/managers/locations.ts +25 -29
- package/src/managers/nft.ts +28 -0
- package/src/managers/plot.ts +127 -0
- package/src/nft/atomicassets.abi.json +1342 -0
- package/src/nft/atomicassets.ts +237 -0
- package/src/nft/atomicdata.ts +130 -0
- package/src/nft/buildImmutableData.ts +321 -0
- package/src/nft/description.ts +37 -15
- 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 +22 -20
- package/src/scheduling/accessor.ts +68 -22
- package/src/scheduling/availability.ts +108 -0
- package/src/scheduling/energy.ts +48 -0
- package/src/scheduling/lane-core.ts +130 -0
- package/src/scheduling/lanes.ts +60 -0
- package/src/scheduling/projection.ts +121 -94
- package/src/scheduling/schedule.ts +237 -103
- package/src/scheduling/task-cargo.ts +46 -0
- package/src/shipload.ts +16 -1
- 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 +90 -13
- package/src/types/capabilities.ts +1 -0
- package/src/types/index.ts +0 -1
- package/src/types.ts +19 -12
- package/src/utils/cargo.ts +27 -0
- package/src/utils/display-name.ts +70 -0
- package/src/utils/system.ts +25 -24
- package/src/capabilities/loading.ts +0 -8
- 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
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {BlockTimestamp, 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'
|
|
7
|
-
import {type DerivedStratum, deriveStrata} from '../derivation'
|
|
7
|
+
import {type DerivedStratum, deriveStrata, getEffectiveReserve} from '../derivation'
|
|
8
8
|
|
|
9
9
|
export interface LocationStratum extends DerivedStratum {
|
|
10
10
|
reserveMax: number
|
|
@@ -24,7 +24,10 @@ export class LocationsManager extends BaseManager {
|
|
|
24
24
|
return findNearbyPlanets(game.config.seed, origin, maxDistance)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
async getStrata(
|
|
27
|
+
async getStrata(
|
|
28
|
+
coords: CoordinatesType,
|
|
29
|
+
now: BlockTimestamp = BlockTimestamp.fromMilliseconds(Date.now())
|
|
30
|
+
): Promise<LocationStratum[]> {
|
|
28
31
|
const game = await this.getGame()
|
|
29
32
|
const state = await this.getState()
|
|
30
33
|
|
|
@@ -36,33 +39,26 @@ export class LocationsManager extends BaseManager {
|
|
|
36
39
|
y: coords.y,
|
|
37
40
|
})) as ServerContract.Types.stratum_remaining[]
|
|
38
41
|
|
|
39
|
-
const
|
|
42
|
+
const epochSeconds = Number(game.config.epochtime)
|
|
43
|
+
const overrideMap = new Map<number, ServerContract.Types.stratum_remaining>()
|
|
40
44
|
for (const o of overrides) {
|
|
41
|
-
overrideMap.set(Number(o.stratum),
|
|
45
|
+
overrideMap.set(Number(o.stratum), o)
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
return derived.map((s) =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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()
|
|
48
|
+
return derived.map((s) => {
|
|
49
|
+
const override = overrideMap.get(s.index)
|
|
50
|
+
const reserve = override
|
|
51
|
+
? getEffectiveReserve(
|
|
52
|
+
{
|
|
53
|
+
remaining: override.remaining,
|
|
54
|
+
max_reserve: s.reserve,
|
|
55
|
+
last_block: override.last_block,
|
|
56
|
+
},
|
|
57
|
+
now,
|
|
58
|
+
epochSeconds
|
|
59
|
+
)
|
|
60
|
+
: s.reserve
|
|
61
|
+
return {...s, reserveMax: s.reserve, reserve}
|
|
62
|
+
})
|
|
67
63
|
}
|
|
68
64
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {Name} from '@wharfkit/antelope'
|
|
2
|
+
import {getItem} from '../data/catalog'
|
|
3
|
+
import {getRecipe} from '../data/recipes-runtime'
|
|
4
|
+
import {computeInputMass} from '../derivation/crafting'
|
|
5
|
+
import {calc_craft_duration} from '../capabilities/crafting'
|
|
6
|
+
import {TaskType} from '../types'
|
|
7
|
+
import {BaseManager} from './base'
|
|
8
|
+
import type {ServerContract} from '../contracts'
|
|
9
|
+
import type {BuildableTarget, ScheduledBuild} from './construction-types'
|
|
10
|
+
|
|
11
|
+
export interface PlotProgressInputRow {
|
|
12
|
+
itemId: number
|
|
13
|
+
required: number
|
|
14
|
+
provided: number
|
|
15
|
+
missing: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PlotProgress {
|
|
19
|
+
targetItemId: number
|
|
20
|
+
rows: PlotProgressInputRow[]
|
|
21
|
+
massProvided: number
|
|
22
|
+
massRequired: number
|
|
23
|
+
isComplete: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class PlotManager extends BaseManager {
|
|
27
|
+
progress(
|
|
28
|
+
plot: ServerContract.Types.entity_row,
|
|
29
|
+
cargo: ServerContract.Types.cargo_row[]
|
|
30
|
+
): PlotProgress {
|
|
31
|
+
const targetItemId = Number(plot.item_id.toString())
|
|
32
|
+
const recipe = getRecipe(targetItemId)
|
|
33
|
+
if (!recipe) {
|
|
34
|
+
throw new Error(`No recipe found for item ${targetItemId}`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const plotId = plot.id.toString()
|
|
38
|
+
const plotCargo = cargo.filter((c) => c.entity_id.toString() === plotId)
|
|
39
|
+
|
|
40
|
+
const quantityByItemId = new Map<number, number>()
|
|
41
|
+
for (const c of plotCargo) {
|
|
42
|
+
const id = c.item_id.toNumber()
|
|
43
|
+
quantityByItemId.set(
|
|
44
|
+
id,
|
|
45
|
+
(quantityByItemId.get(id) ?? 0) + Number(c.quantity.toString())
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const rows: PlotProgressInputRow[] = recipe.inputs.map((input) => {
|
|
50
|
+
const itemId = input.itemId
|
|
51
|
+
const required = input.quantity
|
|
52
|
+
const provided = quantityByItemId.get(itemId) ?? 0
|
|
53
|
+
const missing = Math.max(0, required - provided)
|
|
54
|
+
return {itemId, required, provided, missing}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const massRequired = computeInputMass(targetItemId)
|
|
58
|
+
const massProvided = rows.reduce((sum, r) => {
|
|
59
|
+
const item = getItem(r.itemId)
|
|
60
|
+
return sum + item.mass * r.provided
|
|
61
|
+
}, 0)
|
|
62
|
+
const isComplete = rows.every((r) => r.missing === 0)
|
|
63
|
+
|
|
64
|
+
return {targetItemId, rows, massProvided, massRequired, isComplete}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
buildableTarget(
|
|
68
|
+
plot: ServerContract.Types.entity_row,
|
|
69
|
+
cargo: ServerContract.Types.cargo_row[],
|
|
70
|
+
activeTask?: ServerContract.Types.task,
|
|
71
|
+
scheduledBuild?: ScheduledBuild
|
|
72
|
+
): BuildableTarget {
|
|
73
|
+
const progress = this.progress(plot, cargo)
|
|
74
|
+
const targetItemId = Number(plot.item_id.toString())
|
|
75
|
+
const targetItem = getItem(targetItemId)
|
|
76
|
+
const recipe = getRecipe(targetItemId)
|
|
77
|
+
if (!recipe) {
|
|
78
|
+
throw new Error(`Plot target item ${targetItemId} has no recipe`)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let state: BuildableTarget['state']
|
|
82
|
+
const taskType = activeTask?.type.toNumber()
|
|
83
|
+
if (scheduledBuild?.hasStarted) {
|
|
84
|
+
state = 'finalizing'
|
|
85
|
+
} else if (scheduledBuild) {
|
|
86
|
+
state = 'scheduled'
|
|
87
|
+
} else if (taskType === TaskType.CLAIMPLOT) {
|
|
88
|
+
state = 'initializing'
|
|
89
|
+
} else if (progress.isComplete) {
|
|
90
|
+
state = 'ready'
|
|
91
|
+
} else {
|
|
92
|
+
state = 'accepting'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
entityId: plot.id,
|
|
97
|
+
ownerName: plot.owner,
|
|
98
|
+
coordinates: plot.coordinates,
|
|
99
|
+
targetItemId,
|
|
100
|
+
targetItem,
|
|
101
|
+
state,
|
|
102
|
+
recipe,
|
|
103
|
+
progress,
|
|
104
|
+
finalizeAction: Name.from('buildplot'),
|
|
105
|
+
finalizerCapability: 'crafter',
|
|
106
|
+
activeTask,
|
|
107
|
+
scheduledBuild,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
canBuild(
|
|
112
|
+
plot: ServerContract.Types.entity_row,
|
|
113
|
+
cargo: ServerContract.Types.cargo_row[]
|
|
114
|
+
): boolean {
|
|
115
|
+
return this.progress(plot, cargo).isComplete
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
timeToComplete(
|
|
119
|
+
plot: ServerContract.Types.entity_info,
|
|
120
|
+
crafter: ServerContract.Types.crafter_stats
|
|
121
|
+
): number {
|
|
122
|
+
const capacity = Number(plot.capacity?.toString() ?? '0')
|
|
123
|
+
const speed = Number(crafter.speed.toString())
|
|
124
|
+
if (speed === 0) return 0
|
|
125
|
+
return calc_craft_duration(speed, capacity).toNumber()
|
|
126
|
+
}
|
|
127
|
+
}
|