@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.
Files changed (85) hide show
  1. package/lib/shipload.d.ts +1731 -1044
  2. package/lib/shipload.js +6758 -4523
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +6649 -4479
  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 +151 -40
  46. package/src/managers/actions.ts +184 -82
  47. package/src/managers/base.ts +2 -2
  48. package/src/managers/construction-types.ts +68 -0
  49. package/src/managers/construction.ts +292 -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 +16 -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,8 +1,12 @@
1
1
  import {
2
- type Action,
2
+ Action,
3
+ Checksum256,
4
+ type Checksum256Type,
3
5
  Int64,
4
6
  Name,
5
7
  type NameType,
8
+ UInt8,
9
+ type UInt8Type,
6
10
  UInt16,
7
11
  type UInt16Type,
8
12
  UInt32,
@@ -11,11 +15,11 @@ import {
11
15
  type UInt64Type,
12
16
  } from '@wharfkit/antelope'
13
17
  import {BaseManager} from './base'
14
- import {type CoordinatesType, EntityType, type EntityTypeName} from '../types'
18
+ import type {CoordinatesType} from '../types'
15
19
  import {ServerContract} from '../contracts'
16
20
 
17
21
  export type EntityRefInput = {
18
- entityType: EntityTypeName
22
+ entityType: NameType
19
23
  entityId: UInt64Type
20
24
  }
21
25
 
@@ -25,7 +29,6 @@ export class ActionsManager extends BaseManager {
25
29
  const y = Int64.from(destination.y)
26
30
 
27
31
  return this.server.action('travel', {
28
- entity_type: EntityType.SHIP,
29
32
  id: UInt64.from(shipId),
30
33
  x,
31
34
  y,
@@ -51,13 +54,8 @@ export class ActionsManager extends BaseManager {
51
54
  })
52
55
  }
53
56
 
54
- resolve(
55
- entityId: UInt64Type,
56
- entityType: EntityTypeName = EntityType.SHIP,
57
- count?: UInt64Type
58
- ): Action {
57
+ resolve(entityId: UInt64Type, count?: UInt64Type): Action {
59
58
  const params: ServerContract.ActionParams.resolve = {
60
- entity_type: entityType,
61
59
  id: UInt64.from(entityId),
62
60
  }
63
61
  if (count !== undefined) {
@@ -66,42 +64,34 @@ export class ActionsManager extends BaseManager {
66
64
  return this.server.action('resolve', params)
67
65
  }
68
66
 
69
- cancel(
70
- entityId: UInt64Type,
71
- count: UInt64Type,
72
- entityType: EntityTypeName = EntityType.SHIP
73
- ): Action {
67
+ cancel(entityId: UInt64Type, count: UInt64Type): Action {
74
68
  return this.server.action('cancel', {
75
- entity_type: entityType,
76
69
  id: UInt64.from(entityId),
77
70
  count: UInt64.from(count),
78
71
  })
79
72
  }
80
73
 
81
- recharge(entityId: UInt64Type, entityType: EntityTypeName = EntityType.SHIP): Action {
74
+ recharge(entityId: UInt64Type): Action {
82
75
  return this.server.action('recharge', {
83
- entity_type: entityType,
84
76
  id: UInt64.from(entityId),
85
77
  })
86
78
  }
87
79
 
80
+ refrshentity(entityId: UInt64Type): Action {
81
+ return this.server.action('refrshentity', {
82
+ entity_id: UInt64.from(entityId),
83
+ })
84
+ }
85
+
88
86
  transfer(
89
- sourceType: EntityTypeName,
90
87
  sourceId: UInt64Type,
91
- destType: EntityTypeName,
92
88
  destId: UInt64Type,
93
- itemId: UInt64Type,
94
- stats: UInt64Type,
95
- quantity: UInt64Type
89
+ items: ServerContract.ActionParams.Type.cargo_item[]
96
90
  ): Action {
97
91
  return this.server.action('transfer', {
98
- source_type: sourceType,
99
92
  source_id: UInt64.from(sourceId),
100
- dest_type: destType,
101
93
  dest_id: UInt64.from(destId),
102
- item_id: UInt16.from(itemId),
103
- stats: UInt64.from(stats),
104
- quantity: UInt32.from(quantity),
94
+ items,
105
95
  })
106
96
  }
107
97
 
@@ -119,35 +109,24 @@ export class ActionsManager extends BaseManager {
119
109
  }
120
110
 
121
111
  gather(
122
- source: EntityRefInput,
123
- destination: EntityRefInput,
112
+ sourceId: UInt64Type,
113
+ destinationId: UInt64Type,
124
114
  stratum: UInt16Type,
125
115
  quantity: UInt32Type
126
116
  ): Action {
127
117
  return this.server.action('gather', {
128
- source: ServerContract.Types.entity_ref.from({
129
- entity_type: source.entityType,
130
- entity_id: UInt64.from(source.entityId),
131
- }),
132
- destination: ServerContract.Types.entity_ref.from({
133
- entity_type: destination.entityType,
134
- entity_id: UInt64.from(destination.entityId),
135
- }),
118
+ source_id: UInt64.from(sourceId),
119
+ destination_id: UInt64.from(destinationId),
136
120
  stratum: UInt16.from(stratum),
137
121
  quantity: UInt32.from(quantity),
138
122
  })
139
123
  }
140
124
 
141
- warp(
142
- entityId: UInt64Type,
143
- destination: CoordinatesType,
144
- entityType: EntityTypeName = EntityType.SHIP
145
- ): Action {
125
+ warp(entityId: UInt64Type, destination: CoordinatesType): Action {
146
126
  const x = Int64.from(destination.x)
147
127
  const y = Int64.from(destination.y)
148
128
 
149
129
  return this.server.action('warp', {
150
- entity_type: entityType,
151
130
  id: UInt64.from(entityId),
152
131
  x,
153
132
  y,
@@ -155,96 +134,219 @@ export class ActionsManager extends BaseManager {
155
134
  }
156
135
 
157
136
  craft(
158
- entityType: EntityTypeName,
159
137
  entityId: UInt64Type,
160
138
  recipeId: number,
161
139
  quantity: number,
162
140
  inputs: ServerContract.ActionParams.Type.cargo_item[]
163
141
  ): Action {
164
- const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
165
142
  return this.server.action('craft', {
166
- entity_type: entityType,
167
143
  id: UInt64.from(entityId),
168
144
  recipe_id: UInt16.from(recipeId),
169
145
  quantity: UInt32.from(quantity),
170
- inputs: cargoInputs,
146
+ inputs,
171
147
  })
172
148
  }
173
149
 
174
- blend(
175
- entityType: EntityTypeName,
176
- entityId: UInt64Type,
177
- inputs: ServerContract.ActionParams.Type.cargo_item[]
178
- ): Action {
179
- const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
150
+ blend(entityId: UInt64Type, inputs: ServerContract.ActionParams.Type.cargo_item[]): Action {
180
151
  return this.server.action('blend', {
181
- entity_type: entityType,
182
152
  id: UInt64.from(entityId),
183
- inputs: cargoInputs,
153
+ inputs,
184
154
  })
185
155
  }
186
156
 
187
- deploy(
188
- entityType: EntityTypeName,
189
- entityId: UInt64Type,
190
- packedItemId: number,
191
- stats: bigint
192
- ): Action {
157
+ deploy(entityId: UInt64Type, ref: ServerContract.ActionParams.Type.cargo_ref): Action {
193
158
  return this.server.action('deploy', {
194
- entity_type: entityType,
195
159
  id: UInt64.from(entityId),
196
- packed_item_id: UInt16.from(packedItemId),
197
- stats: UInt64.from(stats),
160
+ ref,
161
+ })
162
+ }
163
+
164
+ claimplot(
165
+ entityId: UInt64Type,
166
+ targetItemId: UInt16Type,
167
+ coords: ServerContract.ActionParams.Type.coordinates
168
+ ): Action {
169
+ return this.server.action('claimplot', {
170
+ builder_id: UInt64.from(entityId),
171
+ target_item_id: UInt16.from(targetItemId),
172
+ coords,
173
+ })
174
+ }
175
+
176
+ buildplot(entityId: UInt64Type, plotId: UInt64Type): Action {
177
+ return this.server.action('buildplot', {
178
+ builder_id: UInt64.from(entityId),
179
+ plot_id: UInt64.from(plotId),
198
180
  })
199
181
  }
200
182
 
201
183
  addmodule(
202
- entityType: EntityTypeName,
203
184
  entityId: UInt64Type,
204
185
  moduleIndex: number,
205
- moduleCargoId: UInt64Type,
206
- targetCargoId: UInt64Type = UInt64.from(0)
186
+ moduleRef: ServerContract.ActionParams.Type.cargo_ref,
187
+ targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
207
188
  ): Action {
208
189
  return this.server.action('addmodule', {
209
- entity_type: entityType,
210
190
  entity_id: UInt64.from(entityId),
211
191
  module_index: moduleIndex,
212
- module_cargo_id: UInt64.from(moduleCargoId),
213
- target_cargo_id: UInt64.from(targetCargoId),
192
+ module_ref: moduleRef,
193
+ target_ref: targetRef ?? undefined,
214
194
  })
215
195
  }
216
196
 
217
197
  rmmodule(
218
- entityType: EntityTypeName,
219
198
  entityId: UInt64Type,
220
199
  moduleIndex: number,
221
- targetCargoId: UInt64Type = UInt64.from(0)
200
+ targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
222
201
  ): Action {
223
202
  return this.server.action('rmmodule', {
224
- entity_type: entityType,
225
203
  entity_id: UInt64.from(entityId),
226
204
  module_index: moduleIndex,
227
- target_cargo_id: UInt64.from(targetCargoId),
205
+ target_ref: targetRef ?? undefined,
228
206
  })
229
207
  }
230
208
 
231
- wrap(
209
+ async wrap(
232
210
  owner: NameType,
233
- entityType: EntityTypeName,
234
211
  entityId: UInt64Type,
212
+ nexusId: UInt64Type,
235
213
  cargoId: UInt64Type,
236
214
  quantity: UInt64Type
237
- ): Action {
238
- return this.server.action('wrap', {
215
+ ): Promise<Action[]> {
216
+ return [
217
+ this.platform.action('wrapcargo', {
218
+ game: this.server.account,
219
+ owner: Name.from(owner),
220
+ entity_id: UInt64.from(entityId),
221
+ nexus_id: UInt64.from(nexusId),
222
+ cargo_id: UInt64.from(cargoId),
223
+ quantity: UInt64.from(quantity),
224
+ }),
225
+ ]
226
+ }
227
+
228
+ undeploy(hostId: UInt64Type, targetId: UInt64Type): Action {
229
+ return this.server.action('undeploy', {
230
+ host_id: UInt64.from(hostId),
231
+ target_id: UInt64.from(targetId),
232
+ })
233
+ }
234
+
235
+ async wrapEntity(
236
+ owner: NameType,
237
+ entityId: UInt64Type,
238
+ nexusId: UInt64Type
239
+ ): Promise<Action[]> {
240
+ return [
241
+ this.platform.action('wrapentity', {
242
+ game: this.server.account,
243
+ owner: Name.from(owner),
244
+ entity_id: UInt64.from(entityId),
245
+ nexus_id: UInt64.from(nexusId),
246
+ }),
247
+ ]
248
+ }
249
+
250
+ placecargo(owner: NameType, hostId: UInt64Type, assetId: UInt64Type): Action {
251
+ return this.server.action('placecargo', {
252
+ owner: Name.from(owner),
253
+ host_id: UInt64.from(hostId),
254
+ asset_id: UInt64.from(assetId),
255
+ })
256
+ }
257
+
258
+ placeentity(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action {
259
+ return this.server.action('placeentity', {
239
260
  owner: Name.from(owner),
240
- entity_type: entityType,
261
+ asset_id: UInt64.from(assetId),
262
+ target_nexus_id: UInt64.from(targetNexusId),
263
+ })
264
+ }
265
+
266
+ transferForUnwrap(owner: NameType, assetId: UInt64Type): Action {
267
+ return Action.from({
268
+ account: 'atomicassets',
269
+ name: 'transfer',
270
+ authorization: [{actor: Name.from(owner), permission: 'active'}],
271
+ data: {
272
+ from: Name.from(owner),
273
+ to: this.platform.account,
274
+ asset_ids: [UInt64.from(assetId)],
275
+ memo: 'unwrap',
276
+ },
277
+ })
278
+ }
279
+
280
+ // Two top-level actions the wallet signs to unwrap an NFT into a host's cargo.
281
+ unwrapCargoTx(owner: NameType, assetId: UInt64Type, hostId: UInt64Type): Action[] {
282
+ return [this.transferForUnwrap(owner, assetId), this.placecargo(owner, hostId, assetId)]
283
+ }
284
+
285
+ // Two top-level actions the wallet signs to place an entity NFT at a nexus.
286
+ unwrapEntityTx(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action[] {
287
+ return [
288
+ this.transferForUnwrap(owner, assetId),
289
+ this.placeentity(owner, assetId, targetNexusId),
290
+ ]
291
+ }
292
+
293
+ setRamPayer(newPayer: NameType, assetId: UInt64Type): Action {
294
+ return Action.from({
295
+ account: 'atomicassets',
296
+ name: 'setrampayer',
297
+ authorization: [{actor: Name.from(newPayer), permission: 'active'}],
298
+ data: {new_payer: Name.from(newPayer), asset_id: UInt64.from(assetId)},
299
+ })
300
+ }
301
+
302
+ demolish(entityId: UInt64Type): Action {
303
+ return this.server.action('demolish', {
241
304
  entity_id: UInt64.from(entityId),
242
- cargo_id: UInt64.from(cargoId),
243
- quantity: UInt64.from(quantity),
244
305
  })
245
306
  }
246
307
 
247
308
  joinGame(account: NameType, companyName: string): Action[] {
248
309
  return [this.foundCompany(account, companyName), this.join(account)]
249
310
  }
311
+
312
+ commit(oracleId: NameType, epoch: UInt64Type, commit: Checksum256Type): Action {
313
+ return this.server.action('commit', {
314
+ oracle_id: Name.from(oracleId),
315
+ epoch: UInt64.from(epoch),
316
+ commit: Checksum256.from(commit),
317
+ })
318
+ }
319
+
320
+ reveal(oracleId: NameType, epoch: UInt64Type, reveal: Checksum256Type): Action {
321
+ return this.server.action('reveal', {
322
+ oracle_id: Name.from(oracleId),
323
+ epoch: UInt64.from(epoch),
324
+ reveal: Checksum256.from(reveal),
325
+ })
326
+ }
327
+
328
+ addoracle(oracleId: NameType): Action {
329
+ return this.server.action('addoracle', {
330
+ oracle_id: Name.from(oracleId),
331
+ })
332
+ }
333
+
334
+ removeoracle(oracleId: NameType): Action {
335
+ return this.server.action('removeoracle', {
336
+ oracle_id: Name.from(oracleId),
337
+ })
338
+ }
339
+
340
+ setthreshold(threshold: UInt8Type): Action {
341
+ return this.server.action('setthreshold', {
342
+ threshold: UInt8.from(threshold),
343
+ })
344
+ }
345
+
346
+ cleanrsvp(epoch: UInt64Type, maxRows: UInt64Type): Action {
347
+ return this.server.action('cleanrsvp', {
348
+ epoch: UInt64.from(epoch),
349
+ max_rows: UInt64.from(maxRows),
350
+ })
351
+ }
250
352
  }
@@ -19,7 +19,7 @@ export abstract class BaseManager {
19
19
  return this.context.getGame()
20
20
  }
21
21
 
22
- protected async getState() {
23
- return this.context.getState()
22
+ protected async getState(reload = false) {
23
+ return this.context.getState(reload)
24
24
  }
25
25
  }
@@ -0,0 +1,68 @@
1
+ import type {Name, UInt32, UInt64} from '@wharfkit/antelope'
2
+ import type {ServerContract} from '../contracts'
3
+ import type {Item} from '../types'
4
+ import type {Recipe} from '../data/recipes-runtime'
5
+ import type {PlotProgress} from './plot'
6
+
7
+ export type BuildState = 'initializing' | 'accepting' | 'ready' | 'finalizing'
8
+
9
+ export type FinalizerCapability = 'crafter'
10
+
11
+ export interface BuildableTarget {
12
+ entityId: UInt64
13
+ ownerName: Name
14
+ coordinates: ServerContract.Types.coordinates
15
+ targetItemId: number
16
+ targetItem: Item
17
+ state: BuildState
18
+ recipe: Recipe
19
+ progress: PlotProgress
20
+ finalizeAction: Name
21
+ finalizerCapability: FinalizerCapability
22
+ activeTask?: ServerContract.Types.task
23
+ }
24
+
25
+ export interface SourceEntityRef {
26
+ entityId: UInt64
27
+ name: string
28
+ hasLoaders: boolean
29
+ loaderCount: number
30
+ loaderTotalMass: number
31
+ relevantCargo: SourceCargoStack[]
32
+ }
33
+
34
+ export interface SourceCargoStack {
35
+ key: string
36
+ rowId: UInt64
37
+ itemId: number
38
+ item: Item
39
+ stats: UInt64
40
+ modules: ServerContract.Types.module_entry[]
41
+ available: number
42
+ plotNeeds: number
43
+ reserved: number
44
+ }
45
+
46
+ export interface FinalizerEntityRef {
47
+ entityId: UInt64
48
+ name: string
49
+ capability: FinalizerCapability
50
+ crafterSpeed: number
51
+ estimatedDuration: UInt32
52
+ }
53
+
54
+ export interface InboundTransfer {
55
+ sourceEntityId: UInt64
56
+ sourceEntityType: Name
57
+ sourceName: string
58
+ itemId: number
59
+ quantity: number
60
+ etaSeconds: number
61
+ }
62
+
63
+ export interface Reservation {
64
+ targetEntityId: UInt64
65
+ targetEntityType: Name
66
+ itemId: number
67
+ quantity: number
68
+ }