@shipload/sdk 1.0.0-next.2 → 1.0.0-next.20

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 (85) hide show
  1. package/lib/shipload.d.ts +1709 -1044
  2. package/lib/shipload.js +6762 -4658
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +6653 -4614
  5. package/lib/shipload.m.js.map +1 -1
  6. package/lib/testing.d.ts +833 -0
  7. package/lib/testing.js +3647 -0
  8. package/lib/testing.js.map +1 -0
  9. package/lib/testing.m.js +3641 -0
  10. package/lib/testing.m.js.map +1 -0
  11. package/package.json +15 -2
  12. package/src/capabilities/gathering.ts +17 -7
  13. package/src/capabilities/modules.ts +9 -0
  14. package/src/capabilities/storage.ts +1 -1
  15. package/src/contracts/platform.ts +211 -3
  16. package/src/contracts/server.ts +723 -438
  17. package/src/data/capabilities.ts +9 -329
  18. package/src/data/capability-formulas.ts +76 -0
  19. package/src/data/catalog.ts +0 -5
  20. package/src/data/colors.ts +14 -28
  21. package/src/data/entities.json +46 -10
  22. package/src/data/item-ids.ts +17 -13
  23. package/src/data/items.json +308 -37
  24. package/src/data/kind-registry.json +85 -0
  25. package/src/data/kind-registry.ts +150 -0
  26. package/src/data/metadata.ts +99 -24
  27. package/src/data/recipes-runtime.ts +3 -23
  28. package/src/data/recipes.json +265 -96
  29. package/src/derivation/build-methods.ts +45 -0
  30. package/src/derivation/capabilities.ts +414 -0
  31. package/src/derivation/capability-mappings.ts +117 -0
  32. package/src/derivation/crafting.ts +23 -24
  33. package/src/derivation/index.ts +8 -2
  34. package/src/derivation/reserve-regen.ts +34 -0
  35. package/src/derivation/resources.ts +125 -38
  36. package/src/derivation/stats.ts +1 -2
  37. package/src/derivation/stratum.ts +15 -19
  38. package/src/derivation/tiers.ts +28 -7
  39. package/src/entities/entity.ts +98 -0
  40. package/src/entities/gamestate.ts +3 -28
  41. package/src/entities/makers.ts +75 -129
  42. package/src/entities/slot-multiplier.ts +37 -0
  43. package/src/errors.ts +10 -15
  44. package/src/format.ts +26 -4
  45. package/src/index-module.ts +149 -40
  46. package/src/managers/actions.ts +184 -82
  47. package/src/managers/base.ts +2 -2
  48. package/src/managers/construction-types.ts +47 -0
  49. package/src/managers/construction.ts +147 -0
  50. package/src/managers/context.ts +9 -0
  51. package/src/managers/entities.ts +18 -66
  52. package/src/managers/epochs.ts +40 -0
  53. package/src/managers/index.ts +14 -1
  54. package/src/managers/locations.ts +2 -20
  55. package/src/managers/nft.ts +28 -0
  56. package/src/managers/plot.ts +123 -0
  57. package/src/nft/atomicassets.ts +231 -0
  58. package/src/nft/atomicdata.ts +130 -0
  59. package/src/nft/buildImmutableData.ts +319 -0
  60. package/src/nft/description.ts +45 -13
  61. package/src/nft/index.ts +3 -0
  62. package/src/resolution/describe-module.ts +5 -8
  63. package/src/resolution/display-name.ts +38 -10
  64. package/src/resolution/resolve-item.ts +20 -12
  65. package/src/scheduling/accessor.ts +4 -0
  66. package/src/scheduling/projection.ts +79 -27
  67. package/src/scheduling/schedule.ts +15 -1
  68. package/src/scheduling/task-cargo.ts +46 -0
  69. package/src/shipload.ts +5 -0
  70. package/src/subscriptions/manager.ts +40 -6
  71. package/src/subscriptions/mappers.ts +3 -8
  72. package/src/subscriptions/types.ts +3 -2
  73. package/src/testing/catalog-hash.ts +19 -0
  74. package/src/testing/index.ts +2 -0
  75. package/src/testing/projection-parity.ts +143 -0
  76. package/src/travel/travel.ts +61 -2
  77. package/src/types/index.ts +0 -1
  78. package/src/types.ts +17 -12
  79. package/src/utils/cargo.ts +27 -0
  80. package/src/utils/system.ts +25 -24
  81. package/src/entities/container.ts +0 -108
  82. package/src/entities/ship-deploy.ts +0 -258
  83. package/src/entities/ship.ts +0 -204
  84. package/src/entities/warehouse.ts +0 -119
  85. package/src/types/entity-traits.ts +0 -69
@@ -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
- }
@@ -1,69 +0,0 @@
1
- import {Name} from '@wharfkit/antelope'
2
-
3
- export const ENTITY_SHIP = Name.from('ship')
4
- export const ENTITY_WAREHOUSE = Name.from('warehouse')
5
- export const ENTITY_CONTAINER = Name.from('container')
6
-
7
- export type EntityTypeName = 'ship' | 'warehouse' | 'container'
8
-
9
- export interface EntityTraits {
10
- typeName: Name
11
- isMovable: boolean
12
- hasEnergy: boolean
13
- hasLoaders: boolean
14
- notFoundError: string
15
- }
16
-
17
- export const shipTraits: EntityTraits = {
18
- typeName: ENTITY_SHIP,
19
- isMovable: true,
20
- hasEnergy: true,
21
- hasLoaders: true,
22
-
23
- notFoundError: 'ship not found',
24
- }
25
-
26
- export const warehouseTraits: EntityTraits = {
27
- typeName: ENTITY_WAREHOUSE,
28
- isMovable: false,
29
- hasEnergy: false,
30
- hasLoaders: true,
31
-
32
- notFoundError: 'warehouse not found',
33
- }
34
-
35
- export const containerTraits: EntityTraits = {
36
- typeName: ENTITY_CONTAINER,
37
- isMovable: true,
38
- hasEnergy: false,
39
- hasLoaders: false,
40
-
41
- notFoundError: 'container not found',
42
- }
43
-
44
- export function getEntityTraits(entityType: Name | EntityTypeName): EntityTraits {
45
- const typeName = typeof entityType === 'string' ? entityType : entityType.toString()
46
-
47
- switch (typeName) {
48
- case 'ship':
49
- return shipTraits
50
- case 'warehouse':
51
- return warehouseTraits
52
- case 'container':
53
- return containerTraits
54
- default:
55
- throw new Error(`Unknown entity type: ${typeName}`)
56
- }
57
- }
58
-
59
- export function isShip(entity: {type?: Name}): boolean {
60
- return entity.type?.equals(ENTITY_SHIP) ?? false
61
- }
62
-
63
- export function isWarehouse(entity: {type?: Name}): boolean {
64
- return entity.type?.equals(ENTITY_WAREHOUSE) ?? false
65
- }
66
-
67
- export function isContainer(entity: {type?: Name}): boolean {
68
- return entity.type?.equals(ENTITY_CONTAINER) ?? false
69
- }