@shipload/sdk 1.0.0-next.6 → 1.0.0-next.60

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 (155) hide show
  1. package/lib/scan.d.ts +52 -0
  2. package/lib/scan.js +162 -0
  3. package/lib/scan.js.map +1 -0
  4. package/lib/scan.m.js +152 -0
  5. package/lib/scan.m.js.map +1 -0
  6. package/lib/shipload.d.ts +3589 -1363
  7. package/lib/shipload.js +15700 -5454
  8. package/lib/shipload.js.map +1 -1
  9. package/lib/shipload.m.js +15423 -5402
  10. package/lib/shipload.m.js.map +1 -1
  11. package/lib/testing.d.ts +1173 -0
  12. package/lib/testing.js +4947 -0
  13. package/lib/testing.js.map +1 -0
  14. package/lib/testing.m.js +4941 -0
  15. package/lib/testing.m.js.map +1 -0
  16. package/package.json +20 -2
  17. package/src/capabilities/craftable.test.ts +82 -0
  18. package/src/capabilities/craftable.ts +82 -0
  19. package/src/capabilities/crafting.test.ts +35 -0
  20. package/src/capabilities/crafting.ts +34 -7
  21. package/src/capabilities/gathering.test.ts +29 -0
  22. package/src/capabilities/gathering.ts +37 -19
  23. package/src/capabilities/hauling.ts +0 -5
  24. package/src/capabilities/index.ts +0 -1
  25. package/src/capabilities/modules.ts +42 -0
  26. package/src/capabilities/movement.ts +1 -1
  27. package/src/capabilities/storage.ts +16 -1
  28. package/src/contracts/platform.ts +231 -3
  29. package/src/contracts/server.ts +1518 -501
  30. package/src/coordinates/address.ts +88 -0
  31. package/src/coordinates/constants.test.ts +15 -0
  32. package/src/coordinates/constants.ts +23 -0
  33. package/src/coordinates/index.ts +15 -0
  34. package/src/coordinates/memo.test.ts +47 -0
  35. package/src/coordinates/memo.ts +20 -0
  36. package/src/coordinates/permutation.ts +77 -0
  37. package/src/coordinates/regions.ts +48 -0
  38. package/src/coordinates/sectors.ts +115 -0
  39. package/src/data/capabilities.ts +49 -18
  40. package/src/data/capability-formulas.ts +26 -14
  41. package/src/data/catalog.ts +0 -5
  42. package/src/data/colors.ts +13 -47
  43. package/src/data/entities.json +379 -14
  44. package/src/data/item-ids.ts +48 -12
  45. package/src/data/items.json +301 -74
  46. package/src/data/kind-registry.json +195 -0
  47. package/src/data/kind-registry.ts +182 -0
  48. package/src/data/metadata.ts +277 -48
  49. package/src/data/recipes-runtime.ts +6 -23
  50. package/src/data/recipes.json +2074 -173
  51. package/src/derivation/build-methods.test.ts +13 -0
  52. package/src/derivation/build-methods.ts +48 -0
  53. package/src/derivation/capabilities.test.ts +348 -0
  54. package/src/derivation/capabilities.ts +692 -0
  55. package/src/derivation/capability-mappings.ts +60 -16
  56. package/src/derivation/crafting.test.ts +17 -0
  57. package/src/derivation/crafting.ts +56 -33
  58. package/src/derivation/index.ts +27 -2
  59. package/src/derivation/recipe-usage.test.ts +88 -0
  60. package/src/derivation/recipe-usage.ts +141 -0
  61. package/src/derivation/reserve-regen.ts +34 -0
  62. package/src/derivation/resources.ts +9 -1
  63. package/src/derivation/rollups.test.ts +55 -0
  64. package/src/derivation/rollups.ts +72 -0
  65. package/src/derivation/stars.test.ts +67 -0
  66. package/src/derivation/stars.ts +25 -0
  67. package/src/derivation/stat-scaling.ts +12 -0
  68. package/src/derivation/stats.ts +6 -6
  69. package/src/derivation/stratum.ts +26 -22
  70. package/src/derivation/tiers.ts +40 -7
  71. package/src/derivation/upgrades.ts +14 -0
  72. package/src/derivation/wormhole.ts +154 -0
  73. package/src/entities/entity.ts +102 -0
  74. package/src/entities/gamestate.ts +3 -28
  75. package/src/entities/makers.ts +141 -135
  76. package/src/entities/slot-multiplier.ts +43 -0
  77. package/src/errors.ts +12 -16
  78. package/src/format.ts +26 -4
  79. package/src/index-module.ts +333 -35
  80. package/src/managers/actions.ts +668 -103
  81. package/src/managers/base.ts +6 -2
  82. package/src/managers/cluster.test.ts +39 -0
  83. package/src/managers/cluster.ts +53 -0
  84. package/src/managers/construction-types.ts +80 -0
  85. package/src/managers/construction.ts +443 -0
  86. package/src/managers/context.ts +29 -1
  87. package/src/managers/coordinates.ts +14 -0
  88. package/src/managers/entities.ts +27 -66
  89. package/src/managers/epochs.ts +40 -0
  90. package/src/managers/index.ts +20 -1
  91. package/src/managers/locations.ts +25 -29
  92. package/src/managers/nft.test.ts +14 -0
  93. package/src/managers/nft.ts +70 -0
  94. package/src/managers/players.ts +25 -0
  95. package/src/managers/plot.ts +122 -0
  96. package/src/nft/atomicassets.abi.json +1342 -0
  97. package/src/nft/atomicassets.ts +237 -0
  98. package/src/nft/atomicdata.ts +130 -0
  99. package/src/nft/buildImmutableData.ts +385 -0
  100. package/src/nft/description.ts +225 -52
  101. package/src/nft/index.ts +3 -0
  102. package/src/planner/index.ts +242 -0
  103. package/src/planner/planner.test.ts +334 -0
  104. package/src/resolution/describe-module.ts +43 -25
  105. package/src/resolution/display-name.ts +38 -10
  106. package/src/resolution/resolve-item.test.ts +48 -0
  107. package/src/resolution/resolve-item.ts +112 -58
  108. package/src/scan/index.ts +244 -0
  109. package/src/scan/scan-wasm.base64.ts +2 -0
  110. package/src/scheduling/accessor.ts +65 -23
  111. package/src/scheduling/availability.test.ts +204 -0
  112. package/src/scheduling/availability.ts +211 -0
  113. package/src/scheduling/cancel.test.ts +542 -0
  114. package/src/scheduling/cancel.ts +254 -0
  115. package/src/scheduling/cluster-stock.test.ts +31 -0
  116. package/src/scheduling/cluster-stock.ts +15 -0
  117. package/src/scheduling/energy.ts +47 -0
  118. package/src/scheduling/idle-resolve.ts +45 -0
  119. package/src/scheduling/jobs.ts +71 -0
  120. package/src/scheduling/lane-core.ts +128 -0
  121. package/src/scheduling/lanes.test.ts +250 -0
  122. package/src/scheduling/lanes.ts +227 -0
  123. package/src/scheduling/projection.ts +257 -133
  124. package/src/scheduling/schedule.test.ts +119 -0
  125. package/src/scheduling/schedule.ts +257 -117
  126. package/src/scheduling/task-cargo.test.ts +44 -0
  127. package/src/scheduling/task-cargo.ts +46 -0
  128. package/src/scheduling/unwrap.test.ts +86 -0
  129. package/src/scheduling/unwrap.ts +190 -0
  130. package/src/shipload.ts +26 -1
  131. package/src/subscriptions/manager.cluster.test.ts +51 -0
  132. package/src/subscriptions/manager.ts +245 -172
  133. package/src/subscriptions/mappers.ts +5 -8
  134. package/src/subscriptions/types.ts +28 -3
  135. package/src/testing/catalog-hash.ts +19 -0
  136. package/src/testing/index.ts +2 -0
  137. package/src/testing/projection-parity.ts +167 -0
  138. package/src/travel/reach.ts +21 -0
  139. package/src/travel/route-planner.ts +288 -0
  140. package/src/travel/route-simulator.ts +170 -0
  141. package/src/travel/travel.ts +188 -122
  142. package/src/types/capabilities.ts +37 -8
  143. package/src/types/entity.ts +3 -3
  144. package/src/types/index.ts +0 -1
  145. package/src/types.ts +51 -16
  146. package/src/utils/cargo.test.ts +14 -0
  147. package/src/utils/cargo.ts +29 -0
  148. package/src/utils/display-name.ts +70 -0
  149. package/src/utils/system.ts +15 -16
  150. package/src/capabilities/loading.ts +0 -8
  151. package/src/entities/container.ts +0 -123
  152. package/src/entities/ship-deploy.ts +0 -295
  153. package/src/entities/ship.ts +0 -221
  154. package/src/entities/warehouse.ts +0 -127
  155. package/src/types/entity-traits.ts +0 -69
@@ -1,8 +1,14 @@
1
1
  import {
2
- type Action,
2
+ Action,
3
+ Bytes,
4
+ Checksum256,
5
+ type Checksum256Type,
3
6
  Int64,
7
+ type Int64Type,
4
8
  Name,
5
9
  type NameType,
10
+ UInt8,
11
+ type UInt8Type,
6
12
  UInt16,
7
13
  type UInt16Type,
8
14
  UInt32,
@@ -11,21 +17,158 @@ import {
11
17
  type UInt64Type,
12
18
  } from '@wharfkit/antelope'
13
19
  import {BaseManager} from './base'
14
- import {type CoordinatesType, EntityType, type EntityTypeName} from '../types'
20
+ import {Coordinates, PRECISION, type ClusterSlotType, type CoordinatesType} from '../types'
15
21
  import {ServerContract} from '../contracts'
22
+ import {ATOMICASSETS_ABI, SHIPLOAD_COLLECTION} from '../nft/atomicassets'
23
+ import {getItem} from '../data/catalog'
24
+
25
+ const CHARGE_K = 1n
26
+ const ENERGY_DIVISOR = 1_000_000n
27
+ const UINT32_MAX = 4_294_967_295
28
+ const UINT32_MAX_BIGINT = 4_294_967_295n
29
+ const UINT32_MOD = 4_294_967_296n
30
+ const UINT64_MAX = 18_446_744_073_709_551_615n
31
+ const PRECISION_BIGINT = BigInt(PRECISION)
32
+
33
+ export type LaunchNumericInput =
34
+ | number
35
+ | bigint
36
+ | string
37
+ | {toNumber(): number}
38
+ | {toString(): string}
39
+
40
+ export interface LaunchStatsInput {
41
+ charge_rate?: LaunchNumericInput
42
+ chargeRate?: LaunchNumericInput
43
+ velocity: LaunchNumericInput
44
+ drain: LaunchNumericInput
45
+ }
46
+
47
+ export interface LaunchQuoteLauncher {
48
+ coordinates: CoordinatesType
49
+ launcher: LaunchStatsInput
50
+ generator?: {capacity: LaunchNumericInput}
51
+ }
52
+
53
+ export interface LaunchQuoteCatcher {
54
+ coordinates: CoordinatesType
55
+ }
56
+
57
+ export interface LaunchQuote {
58
+ chargeTime: number
59
+ flightTime: number
60
+ arrival: Date
61
+ energyCost: number
62
+ maxReach: bigint
63
+ }
64
+
65
+ function toNumber(value: LaunchNumericInput): number {
66
+ if (typeof value === 'number') return Math.trunc(value)
67
+ if (typeof value === 'bigint') return Number(value)
68
+ if (typeof value === 'string') return Number(value)
69
+ if ('toNumber' in value && typeof value.toNumber === 'function') return value.toNumber()
70
+ return Number(value.toString())
71
+ }
72
+
73
+ function requiredNumber(value: LaunchNumericInput | undefined, label: string): number {
74
+ if (value === undefined) throw new Error(`launch quote requires ${label}`)
75
+ return toNumber(value)
76
+ }
77
+
78
+ function toBigInt(value: LaunchNumericInput | undefined): bigint {
79
+ if (value === undefined) return 0n
80
+ if (typeof value === 'bigint') return value
81
+ if (typeof value === 'number') return BigInt(Math.trunc(value))
82
+ if (typeof value === 'string') return BigInt(value)
83
+ return BigInt(value.toString())
84
+ }
85
+
86
+ function saturatingMul(lhs: bigint, rhs: bigint): bigint {
87
+ if (lhs !== 0n && rhs > UINT64_MAX / lhs) {
88
+ return UINT64_MAX
89
+ }
90
+ return lhs * rhs
91
+ }
92
+
93
+ function clampLaunchResult(value: bigint): number {
94
+ if (value < 1n) return 1
95
+ if (value > UINT32_MAX_BIGINT) return UINT32_MAX
96
+ return Number(value)
97
+ }
98
+
99
+ function toUint32(value: bigint): bigint {
100
+ return value % UINT32_MOD
101
+ }
102
+
103
+ function calcDistance(origin: CoordinatesType, destination: CoordinatesType): bigint {
104
+ const a = Coordinates.from(origin)
105
+ const b = Coordinates.from(destination)
106
+ const dx = toNumber(a.x) - toNumber(b.x)
107
+ const dy = toNumber(a.y) - toNumber(b.y)
108
+ return BigInt(Math.trunc(Math.sqrt(dx * dx + dy * dy) * PRECISION))
109
+ }
110
+
111
+ function calcCargoItemMassUint32(item: ServerContract.ActionParams.Type.cargo_item): bigint {
112
+ let mass = toUint32(BigInt(getItem(item.item_id).mass) * toUint32(toBigInt(item.quantity)))
113
+
114
+ for (const mod of item.modules) {
115
+ if (mod.installed) {
116
+ mass = toUint32(mass + BigInt(getItem(mod.installed.item_id).mass))
117
+ }
118
+ }
119
+
120
+ return mass
121
+ }
122
+
123
+ function calcPayloadMass(items: ServerContract.ActionParams.Type.cargo_item[]): bigint {
124
+ let mass = 0n
125
+ for (const item of items) {
126
+ mass = toUint32(mass + calcCargoItemMassUint32(item))
127
+ }
128
+ return mass
129
+ }
130
+
131
+ function calcChargeTime(chargeRate: number, mass: bigint): number {
132
+ const rate = BigInt(chargeRate || 1)
133
+ return clampLaunchResult((mass * CHARGE_K) / rate)
134
+ }
135
+
136
+ function calcFlightTime(velocity: number, distance: bigint): number {
137
+ const v = BigInt(velocity || 1)
138
+ return clampLaunchResult(distance / (v * PRECISION_BIGINT))
139
+ }
140
+
141
+ function calcLaunchEnergy(drain: number, mass: bigint, distance: bigint): number {
142
+ const e =
143
+ saturatingMul(saturatingMul(mass, distance / PRECISION_BIGINT), BigInt(drain)) /
144
+ ENERGY_DIVISOR
145
+ return clampLaunchResult(e)
146
+ }
147
+
148
+ function calcMaxReach(energyBudget: bigint, mass: bigint, drain: number): bigint {
149
+ if (energyBudget < 1n) return 0n
150
+ if (energyBudget >= UINT32_MAX_BIGINT || mass === 0n || drain === 0) return UINT64_MAX
151
+
152
+ const numerator = (energyBudget + 1n) * ENERGY_DIVISOR - 1n
153
+ const denominator = mass * BigInt(drain)
154
+ const distanceUnits = numerator / denominator
155
+ const maxDistance = distanceUnits * PRECISION_BIGINT + (PRECISION_BIGINT - 1n)
156
+ return maxDistance > UINT64_MAX ? UINT64_MAX : maxDistance
157
+ }
16
158
 
17
159
  export type EntityRefInput = {
18
160
  entityType: NameType
19
161
  entityId: UInt64Type
20
162
  }
21
163
 
164
+ export type WaypointInput = {x: Int64Type; y: Int64Type}
165
+
22
166
  export class ActionsManager extends BaseManager {
23
167
  travel(shipId: UInt64Type, destination: CoordinatesType, recharge = true): Action {
24
168
  const x = Int64.from(destination.x)
25
169
  const y = Int64.from(destination.y)
26
170
 
27
171
  return this.server.action('travel', {
28
- entity_type: EntityType.SHIP,
29
172
  id: UInt64.from(shipId),
30
173
  x,
31
174
  y,
@@ -33,13 +176,17 @@ export class ActionsManager extends BaseManager {
33
176
  })
34
177
  }
35
178
 
36
- grouptravel(entities: EntityRefInput[], destination: CoordinatesType, recharge = true): Action {
37
- const entityRefs = entities.map((e) =>
179
+ private entityRefs(entities: EntityRefInput[]) {
180
+ return entities.map((e) =>
38
181
  ServerContract.Types.entity_ref.from({
39
182
  entity_type: e.entityType,
40
183
  entity_id: UInt64.from(e.entityId),
41
184
  })
42
185
  )
186
+ }
187
+
188
+ grouptravel(entities: EntityRefInput[], destination: CoordinatesType, recharge = true): Action {
189
+ const entityRefs = this.entityRefs(entities)
43
190
  const x = Int64.from(destination.x)
44
191
  const y = Int64.from(destination.y)
45
192
 
@@ -51,13 +198,58 @@ export class ActionsManager extends BaseManager {
51
198
  })
52
199
  }
53
200
 
54
- resolve(
55
- entityId: UInt64Type,
56
- entityType: EntityTypeName = EntityType.SHIP,
57
- count?: UInt64Type
201
+ travelplan(entities: EntityRefInput[], waypoints: WaypointInput[], recharge = true): Action {
202
+ const entityRefs = this.entityRefs(entities)
203
+ const wps = waypoints.map((w) =>
204
+ ServerContract.Types.route_waypoint.from({x: Int64.from(w.x), y: Int64.from(w.y)})
205
+ )
206
+ return this.server.action('travelplan', {
207
+ entities: entityRefs,
208
+ waypoints: wps,
209
+ recharge,
210
+ })
211
+ }
212
+
213
+ transit(shipId: UInt64Type, entrance: CoordinatesType, exit: CoordinatesType): Action {
214
+ return this.server.action('transit', {
215
+ id: UInt64.from(shipId),
216
+ ax: Int64.from(entrance.x),
217
+ ay: Int64.from(entrance.y),
218
+ bx: Int64.from(exit.x),
219
+ by: Int64.from(exit.y),
220
+ })
221
+ }
222
+
223
+ grouptransit(
224
+ entities: EntityRefInput[],
225
+ entrance: CoordinatesType,
226
+ exit: CoordinatesType
58
227
  ): Action {
228
+ const entityRefs = this.entityRefs(entities)
229
+ return this.server.action('grouptransit', {
230
+ entities: entityRefs,
231
+ ax: Int64.from(entrance.x),
232
+ ay: Int64.from(entrance.y),
233
+ bx: Int64.from(exit.x),
234
+ by: Int64.from(exit.y),
235
+ })
236
+ }
237
+
238
+ getwormhole(x: Int64Type, y: Int64Type): Action {
239
+ return this.server.action('getwormhole', {x: Int64.from(x), y: Int64.from(y)})
240
+ }
241
+
242
+ getdistance(origin: CoordinatesType, destination: CoordinatesType): Action {
243
+ return this.server.action('getdistance', {
244
+ ax: Int64.from(origin.x),
245
+ ay: Int64.from(origin.y),
246
+ bx: Int64.from(destination.x),
247
+ by: Int64.from(destination.y),
248
+ })
249
+ }
250
+
251
+ resolve(entityId: UInt64Type, count?: UInt64Type): Action {
59
252
  const params: ServerContract.ActionParams.resolve = {
60
- entity_type: entityType,
61
253
  id: UInt64.from(entityId),
62
254
  }
63
255
  if (count !== undefined) {
@@ -66,45 +258,117 @@ export class ActionsManager extends BaseManager {
66
258
  return this.server.action('resolve', params)
67
259
  }
68
260
 
69
- cancel(
70
- entityId: UInt64Type,
71
- count: UInt64Type,
72
- entityType: EntityTypeName = EntityType.SHIP
73
- ): Action {
261
+ resolveall(owner: NameType): Action {
262
+ return this.server.action('resolveall', {
263
+ owner: Name.from(owner),
264
+ })
265
+ }
266
+
267
+ cancel(entityId: UInt64Type, laneKey: number, count: UInt64Type): Action {
74
268
  return this.server.action('cancel', {
75
- entity_type: entityType,
76
269
  id: UInt64.from(entityId),
270
+ lane_key: UInt8.from(laneKey),
77
271
  count: UInt64.from(count),
78
272
  })
79
273
  }
80
274
 
81
- recharge(entityId: UInt64Type, entityType: EntityTypeName = EntityType.SHIP): Action {
275
+ recharge(entityId: UInt64Type): Action {
82
276
  return this.server.action('recharge', {
83
- entity_type: entityType,
84
277
  id: UInt64.from(entityId),
85
278
  })
86
279
  }
87
280
 
88
- transfer(
89
- sourceType: EntityTypeName,
90
- sourceId: UInt64Type,
91
- destType: EntityTypeName,
92
- destId: UInt64Type,
93
- itemId: UInt64Type,
94
- stats: UInt64Type,
95
- quantity: UInt64Type
281
+ rename(entityId: UInt64Type, name: string): Action {
282
+ return this.server.action('rename', {
283
+ id: UInt64.from(entityId),
284
+ name,
285
+ })
286
+ }
287
+
288
+ refrshentity(entityId: UInt64Type): Action {
289
+ return this.server.action('refrshentity', {
290
+ entity_id: UInt64.from(entityId),
291
+ })
292
+ }
293
+
294
+ load(
295
+ id: UInt64Type,
296
+ fromId: UInt64Type,
297
+ items: ServerContract.ActionParams.Type.cargo_item[]
96
298
  ): Action {
97
- return this.server.action('transfer', {
98
- source_type: sourceType,
99
- source_id: UInt64.from(sourceId),
100
- dest_type: destType,
101
- dest_id: UInt64.from(destId),
102
- item_id: UInt16.from(itemId),
103
- stats: UInt64.from(stats),
104
- quantity: UInt32.from(quantity),
299
+ return this.server.action('load', {
300
+ id: UInt64.from(id),
301
+ from_id: UInt64.from(fromId),
302
+ items,
303
+ })
304
+ }
305
+
306
+ unload(
307
+ id: UInt64Type,
308
+ toId: UInt64Type,
309
+ items: ServerContract.ActionParams.Type.cargo_item[]
310
+ ): Action {
311
+ return this.server.action('unload', {
312
+ id: UInt64.from(id),
313
+ to_id: UInt64.from(toId),
314
+ items,
315
+ })
316
+ }
317
+
318
+ shuttle(
319
+ carrierId: UInt64Type,
320
+ fromId: UInt64Type,
321
+ toId: UInt64Type,
322
+ items: ServerContract.ActionParams.Type.cargo_item[]
323
+ ): Action {
324
+ return this.server.action('shuttle', {
325
+ carrier: UInt64.from(carrierId),
326
+ from_id: UInt64.from(fromId),
327
+ to_id: UInt64.from(toId),
328
+ items,
105
329
  })
106
330
  }
107
331
 
332
+ launch(
333
+ launcherId: UInt64Type,
334
+ catcherId: UInt64Type,
335
+ items: ServerContract.ActionParams.Type.cargo_item[]
336
+ ): Action {
337
+ return this.server.action('launch', {
338
+ launcher_id: UInt64.from(launcherId),
339
+ catcher_id: UInt64.from(catcherId),
340
+ items,
341
+ })
342
+ }
343
+
344
+ getLaunchQuote(
345
+ launcher: LaunchQuoteLauncher,
346
+ catcher: LaunchQuoteCatcher,
347
+ items: ServerContract.ActionParams.Type.cargo_item[],
348
+ start = new Date()
349
+ ): LaunchQuote {
350
+ const chargeRate = requiredNumber(
351
+ launcher.launcher.charge_rate ?? launcher.launcher.chargeRate,
352
+ 'launcher charge rate'
353
+ )
354
+ const velocity = requiredNumber(launcher.launcher.velocity, 'launcher velocity')
355
+ const drain = requiredNumber(launcher.launcher.drain, 'launcher drain')
356
+ const mass = calcPayloadMass(items)
357
+ const distance = calcDistance(launcher.coordinates, catcher.coordinates)
358
+ const chargeTime = calcChargeTime(chargeRate, mass)
359
+ const flightTime = calcFlightTime(velocity, distance)
360
+ const energyCost = calcLaunchEnergy(drain, mass, distance)
361
+ const maxReach = calcMaxReach(toBigInt(launcher.generator?.capacity), mass, drain)
362
+
363
+ return {
364
+ chargeTime,
365
+ flightTime,
366
+ arrival: new Date(start.getTime() + (chargeTime + flightTime) * 1000),
367
+ energyCost,
368
+ maxReach,
369
+ }
370
+ }
371
+
108
372
  foundCompany(account: NameType, name: string): Action {
109
373
  return this.platform.action('foundcompany', {
110
374
  account: Name.from(account),
@@ -119,35 +383,47 @@ export class ActionsManager extends BaseManager {
119
383
  }
120
384
 
121
385
  gather(
122
- source: EntityRefInput,
123
- destination: EntityRefInput,
386
+ sourceId: UInt64Type,
387
+ destinationId: UInt64Type,
124
388
  stratum: UInt16Type,
125
- quantity: UInt32Type
389
+ quantity: UInt32Type,
390
+ slot?: UInt8Type
126
391
  ): Action {
127
- 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
- }),
392
+ const params: ServerContract.ActionParams.gather = {
393
+ source_id: UInt64.from(sourceId),
394
+ destination_id: UInt64.from(destinationId),
136
395
  stratum: UInt16.from(stratum),
137
396
  quantity: UInt32.from(quantity),
138
- })
397
+ }
398
+ if (slot !== undefined) {
399
+ params.slot = UInt8.from(slot)
400
+ }
401
+ return this.server.action('gather', params)
139
402
  }
140
403
 
141
- warp(
142
- entityId: UInt64Type,
143
- destination: CoordinatesType,
144
- entityType: EntityTypeName = EntityType.SHIP
404
+ gatherplan(
405
+ sourceId: UInt64Type,
406
+ destinationId: UInt64Type,
407
+ stratum: UInt16Type,
408
+ quantity: UInt32Type,
409
+ recharge = true,
410
+ slots: number[] = []
145
411
  ): Action {
412
+ return this.server.action('gatherplan', {
413
+ source_id: UInt64.from(sourceId),
414
+ destination_id: UInt64.from(destinationId),
415
+ stratum: UInt16.from(stratum),
416
+ quantity: UInt32.from(quantity),
417
+ recharge,
418
+ slots: Bytes.from(slots),
419
+ })
420
+ }
421
+
422
+ warp(entityId: UInt64Type, destination: CoordinatesType): Action {
146
423
  const x = Int64.from(destination.x)
147
424
  const y = Int64.from(destination.y)
148
425
 
149
426
  return this.server.action('warp', {
150
- entity_type: entityType,
151
427
  id: UInt64.from(entityId),
152
428
  x,
153
429
  y,
@@ -155,119 +431,408 @@ export class ActionsManager extends BaseManager {
155
431
  }
156
432
 
157
433
  craft(
158
- entityType: EntityTypeName,
159
434
  entityId: UInt64Type,
160
435
  recipeId: number,
161
436
  quantity: number,
162
- inputs: ServerContract.ActionParams.Type.cargo_item[]
437
+ inputs: ServerContract.ActionParams.Type.cargo_item[],
438
+ target?: UInt64Type,
439
+ slot?: UInt8Type
163
440
  ): Action {
164
- const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
165
- return this.server.action('craft', {
166
- entity_type: entityType,
441
+ const params: ServerContract.ActionParams.craft = {
167
442
  id: UInt64.from(entityId),
168
443
  recipe_id: UInt16.from(recipeId),
169
444
  quantity: UInt32.from(quantity),
170
- inputs: cargoInputs,
171
- })
445
+ inputs,
446
+ }
447
+ if (target !== undefined) {
448
+ params.target = UInt64.from(target)
449
+ }
450
+ if (slot !== undefined) {
451
+ params.slot = UInt8.from(slot)
452
+ }
453
+ return this.server.action('craft', params)
172
454
  }
173
455
 
174
- blend(
175
- entityType: EntityTypeName,
176
- entityId: UInt64Type,
456
+ craftjob(
457
+ shipId: UInt64Type,
458
+ workshopId: UInt64Type,
459
+ slot: UInt8Type,
460
+ recipeId: UInt16Type,
461
+ quantity: UInt32Type,
177
462
  inputs: ServerContract.ActionParams.Type.cargo_item[]
178
463
  ): Action {
179
- const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
464
+ const params: ServerContract.ActionParams.craftjob = {
465
+ ship_id: UInt64.from(shipId),
466
+ workshop_id: UInt64.from(workshopId),
467
+ slot: UInt8.from(slot),
468
+ recipe_id: UInt16.from(recipeId),
469
+ quantity: UInt32.from(quantity),
470
+ inputs,
471
+ }
472
+ return this.server.action('craftjob', params)
473
+ }
474
+
475
+ clustercraft(
476
+ entityId: UInt64Type,
477
+ recipeId: number,
478
+ quantity: number,
479
+ sources: ServerContract.ActionParams.Type.cluster_source[],
480
+ target?: UInt64Type,
481
+ slot?: UInt8Type
482
+ ): Action {
483
+ const params: ServerContract.ActionParams.clustercraft = {
484
+ id: UInt64.from(entityId),
485
+ recipe_id: UInt16.from(recipeId),
486
+ quantity: UInt32.from(quantity),
487
+ sources,
488
+ }
489
+ if (target !== undefined) {
490
+ params.target = UInt64.from(target)
491
+ }
492
+ if (slot !== undefined) {
493
+ params.slot = UInt8.from(slot)
494
+ }
495
+ return this.server.action('clustercraft', params)
496
+ }
497
+
498
+ claimjob(jobId: UInt64Type, shipId: UInt64Type): Action {
499
+ const params: ServerContract.ActionParams.claimjob = {
500
+ job_id: UInt64.from(jobId),
501
+ ship_id: UInt64.from(shipId),
502
+ }
503
+ return this.server.action('claimjob', params)
504
+ }
505
+
506
+ canceljob(jobId: UInt64Type, shipId: UInt64Type): Action {
507
+ const params: ServerContract.ActionParams.canceljob = {
508
+ job_id: UInt64.from(jobId),
509
+ ship_id: UInt64.from(shipId),
510
+ }
511
+ return this.server.action('canceljob', params)
512
+ }
513
+
514
+ setsocket(workshopId: UInt64Type, slot: UInt8Type, open: boolean): Action {
515
+ const params: ServerContract.ActionParams.setsocket = {
516
+ workshop_id: UInt64.from(workshopId),
517
+ slot: UInt8.from(slot),
518
+ open,
519
+ }
520
+ return this.server.action('setsocket', params)
521
+ }
522
+
523
+ blend(entityId: UInt64Type, inputs: ServerContract.ActionParams.Type.cargo_item[]): Action {
180
524
  return this.server.action('blend', {
181
- entity_type: entityType,
182
525
  id: UInt64.from(entityId),
183
- inputs: cargoInputs,
526
+ inputs,
184
527
  })
185
528
  }
186
529
 
187
530
  deploy(
188
- entityType: EntityTypeName,
189
531
  entityId: UInt64Type,
190
- packedItemId: number,
191
- stats: bigint
532
+ ref: ServerContract.ActionParams.Type.cargo_ref,
533
+ slot?: ClusterSlotType
192
534
  ): Action {
193
535
  return this.server.action('deploy', {
194
- entity_type: entityType,
195
536
  id: UInt64.from(entityId),
196
- packed_item_id: UInt16.from(packedItemId),
197
- stats: UInt64.from(stats),
537
+ ref,
538
+ slot: slot ? {hub: UInt64.from(slot.hub), gx: slot.gx, gy: slot.gy} : undefined,
539
+ })
540
+ }
541
+
542
+ upgrade(
543
+ builderId: UInt64Type,
544
+ targetId: UInt64Type,
545
+ targetItemId: UInt16Type,
546
+ inputs: ServerContract.ActionParams.Type.cargo_item[],
547
+ slot?: UInt8Type
548
+ ): Action {
549
+ const params: ServerContract.ActionParams.upgrade = {
550
+ builder_id: UInt64.from(builderId),
551
+ target_id: UInt64.from(targetId),
552
+ target_item_id: UInt16.from(targetItemId),
553
+ inputs,
554
+ }
555
+ if (slot !== undefined) {
556
+ params.slot = UInt8.from(slot)
557
+ }
558
+ return this.server.action('upgrade', params)
559
+ }
560
+
561
+ claimplot(entityId: UInt64Type, targetItemId: UInt16Type, slot: ClusterSlotType): Action {
562
+ return this.server.action('claimplot', {
563
+ builder_id: UInt64.from(entityId),
564
+ target_item_id: UInt16.from(targetItemId),
565
+ slot: {hub: UInt64.from(slot.hub), gx: slot.gx, gy: slot.gy},
566
+ })
567
+ }
568
+
569
+ movetile(
570
+ hubId: UInt64Type,
571
+ fromGx: number,
572
+ fromGy: number,
573
+ toGx: number,
574
+ toGy: number
575
+ ): Action {
576
+ return this.server.action('movetile', {
577
+ hub_id: UInt64.from(hubId),
578
+ from_gx: fromGx,
579
+ from_gy: fromGy,
580
+ to_gx: toGx,
581
+ to_gy: toGy,
582
+ })
583
+ }
584
+
585
+ swaptile(hubId: UInt64Type, aGx: number, aGy: number, bGx: number, bGy: number): Action {
586
+ return this.server.action('swaptile', {
587
+ hub_id: UInt64.from(hubId),
588
+ a_gx: aGx,
589
+ a_gy: aGy,
590
+ b_gx: bGx,
591
+ b_gy: bGy,
592
+ })
593
+ }
594
+
595
+ buildplot(entityId: UInt64Type, plotId: UInt64Type): Action {
596
+ return this.server.action('buildplot', {
597
+ builder_id: UInt64.from(entityId),
598
+ plot_id: UInt64.from(plotId),
198
599
  })
199
600
  }
200
601
 
201
602
  addmodule(
202
- entityType: EntityTypeName,
203
603
  entityId: UInt64Type,
204
604
  moduleIndex: number,
205
- moduleCargoId: UInt64Type,
206
- targetCargoId: UInt64Type = UInt64.from(0)
605
+ moduleRef: ServerContract.ActionParams.Type.cargo_ref,
606
+ targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
207
607
  ): Action {
208
608
  return this.server.action('addmodule', {
209
- entity_type: entityType,
210
609
  entity_id: UInt64.from(entityId),
211
610
  module_index: moduleIndex,
212
- module_cargo_id: UInt64.from(moduleCargoId),
213
- target_cargo_id: UInt64.from(targetCargoId),
611
+ module_ref: moduleRef,
612
+ target_ref: targetRef ?? undefined,
214
613
  })
215
614
  }
216
615
 
217
616
  rmmodule(
218
- entityType: EntityTypeName,
219
617
  entityId: UInt64Type,
220
618
  moduleIndex: number,
221
- targetCargoId: UInt64Type = UInt64.from(0)
619
+ targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
222
620
  ): Action {
223
621
  return this.server.action('rmmodule', {
224
- entity_type: entityType,
225
622
  entity_id: UInt64.from(entityId),
226
623
  module_index: moduleIndex,
227
- target_cargo_id: UInt64.from(targetCargoId),
624
+ target_ref: targetRef ?? undefined,
228
625
  })
229
626
  }
230
627
 
231
- wrap(
232
- owner: NameType,
233
- entityType: EntityTypeName,
628
+ swapmodule(
234
629
  entityId: UInt64Type,
235
- cargoId: UInt64Type,
236
- quantity: UInt64Type
630
+ moduleIndex: number,
631
+ moduleRef: ServerContract.ActionParams.Type.cargo_ref
237
632
  ): Action {
238
- return this.server.action('wrap', {
239
- owner: Name.from(owner),
240
- entity_type: entityType,
633
+ return this.server.action('swapmodule', {
241
634
  entity_id: UInt64.from(entityId),
242
- cargo_id: UInt64.from(cargoId),
243
- quantity: UInt64.from(quantity),
635
+ module_index: moduleIndex,
636
+ module_ref: moduleRef,
244
637
  })
245
638
  }
246
639
 
247
- undeploy(host: EntityRefInput, target: EntityRefInput): Action {
640
+ async wrap(
641
+ owner: NameType,
642
+ entityId: UInt64Type,
643
+ nexusId: UInt64Type,
644
+ cargoId: UInt64Type,
645
+ quantity: UInt64Type,
646
+ opts: {claimRam?: boolean} = {}
647
+ ): Promise<Action[]> {
648
+ const actions: Action[] = [
649
+ this.platform.action('wrapcargo', {
650
+ game: this.server.account,
651
+ owner: Name.from(owner),
652
+ entity_id: UInt64.from(entityId),
653
+ nexus_id: UInt64.from(nexusId),
654
+ cargo_id: UInt64.from(cargoId),
655
+ quantity: UInt64.from(quantity),
656
+ }),
657
+ ]
658
+ const claimRam =
659
+ opts.claimRam ?? (this.atomicAssetsAccount ?? 'atomicassets') !== 'atomicassets'
660
+ if (claimRam) {
661
+ actions.push(this.setLastPayer(owner, SHIPLOAD_COLLECTION))
662
+ }
663
+ return actions
664
+ }
665
+
666
+ undeploy(hostId: UInt64Type, targetId: UInt64Type): Action {
248
667
  return this.server.action('undeploy', {
249
- host_type: Name.from(host.entityType),
250
- host_id: UInt64.from(host.entityId),
251
- target_type: Name.from(target.entityType),
252
- target_id: UInt64.from(target.entityId),
668
+ host_id: UInt64.from(hostId),
669
+ target_id: UInt64.from(targetId),
253
670
  })
254
671
  }
255
672
 
256
- wrapEntity(entity: EntityRefInput): Action {
257
- return this.server.action('wrapentity', {
258
- entity_type: Name.from(entity.entityType),
259
- entity_id: UInt64.from(entity.entityId),
673
+ claimStarter(owner: NameType): Action {
674
+ return this.server.action('claimstarter', {
675
+ owner: Name.from(owner),
260
676
  })
261
677
  }
262
678
 
263
- demolish(entity: EntityRefInput): Action {
679
+ async wrapEntity(
680
+ owner: NameType,
681
+ entityId: UInt64Type,
682
+ nexusId: UInt64Type,
683
+ opts: {claimRam?: boolean} = {}
684
+ ): Promise<Action[]> {
685
+ const actions: Action[] = [
686
+ this.platform.action('wrapentity', {
687
+ game: this.server.account,
688
+ owner: Name.from(owner),
689
+ entity_id: UInt64.from(entityId),
690
+ nexus_id: UInt64.from(nexusId),
691
+ }),
692
+ ]
693
+ const claimRam =
694
+ opts.claimRam ?? (this.atomicAssetsAccount ?? 'atomicassets') !== 'atomicassets'
695
+ if (claimRam) {
696
+ actions.push(this.setLastPayer(owner, SHIPLOAD_COLLECTION))
697
+ }
698
+ return actions
699
+ }
700
+
701
+ placecargo(owner: NameType, hostId: UInt64Type, assetId: UInt64Type): Action {
702
+ return this.server.action('placecargo', {
703
+ owner: Name.from(owner),
704
+ host_id: UInt64.from(hostId),
705
+ asset_id: UInt64.from(assetId),
706
+ })
707
+ }
708
+
709
+ placeentity(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action {
710
+ return this.server.action('placeentity', {
711
+ owner: Name.from(owner),
712
+ asset_id: UInt64.from(assetId),
713
+ target_nexus_id: UInt64.from(targetNexusId),
714
+ })
715
+ }
716
+
717
+ transferForUnwrap(owner: NameType, assetId: UInt64Type): Action {
718
+ return Action.from(
719
+ {
720
+ account: this.atomicAssetsAccount,
721
+ name: 'transfer',
722
+ authorization: [{actor: Name.from(owner), permission: 'active'}],
723
+ data: {
724
+ from: Name.from(owner),
725
+ to: this.platform.account,
726
+ asset_ids: [UInt64.from(assetId)],
727
+ memo: 'unwrap',
728
+ },
729
+ },
730
+ ATOMICASSETS_ABI
731
+ )
732
+ }
733
+
734
+ sendAsset(owner: NameType, recipient: NameType, assetId: UInt64Type, memo = ''): Action {
735
+ return Action.from(
736
+ {
737
+ account: this.atomicAssetsAccount,
738
+ name: 'transfer',
739
+ authorization: [{actor: Name.from(owner), permission: 'active'}],
740
+ data: {
741
+ from: Name.from(owner),
742
+ to: Name.from(recipient),
743
+ asset_ids: [UInt64.from(assetId)],
744
+ memo,
745
+ },
746
+ },
747
+ ATOMICASSETS_ABI
748
+ )
749
+ }
750
+
751
+ // Two top-level actions the wallet signs to unwrap an NFT into a host's cargo.
752
+ unwrapCargoTx(owner: NameType, assetId: UInt64Type, hostId: UInt64Type): Action[] {
753
+ return [this.transferForUnwrap(owner, assetId), this.placecargo(owner, hostId, assetId)]
754
+ }
755
+
756
+ // Two top-level actions the wallet signs to place an entity NFT at a nexus.
757
+ unwrapEntityTx(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action[] {
758
+ return [
759
+ this.transferForUnwrap(owner, assetId),
760
+ this.placeentity(owner, assetId, targetNexusId),
761
+ ]
762
+ }
763
+
764
+ setRamPayer(newPayer: NameType, assetId: UInt64Type): Action {
765
+ return Action.from(
766
+ {
767
+ account: this.atomicAssetsAccount,
768
+ name: 'setrampayer',
769
+ authorization: [{actor: Name.from(newPayer), permission: 'active'}],
770
+ data: {new_payer: Name.from(newPayer), asset_id: UInt64.from(assetId)},
771
+ },
772
+ ATOMICASSETS_ABI
773
+ )
774
+ }
775
+
776
+ setLastPayer(owner: NameType, collectionName: NameType): Action {
777
+ return Action.from(
778
+ {
779
+ account: this.atomicAssetsAccount,
780
+ name: 'setlastpayer',
781
+ authorization: [{actor: Name.from(owner), permission: 'active'}],
782
+ data: {owner: Name.from(owner), collection_name: Name.from(collectionName)},
783
+ },
784
+ ATOMICASSETS_ABI
785
+ )
786
+ }
787
+
788
+ demolish(entityId: UInt64Type): Action {
264
789
  return this.server.action('demolish', {
265
- entity_type: Name.from(entity.entityType),
266
- entity_id: UInt64.from(entity.entityId),
790
+ entity_id: UInt64.from(entityId),
267
791
  })
268
792
  }
269
793
 
270
794
  joinGame(account: NameType, companyName: string): Action[] {
271
795
  return [this.foundCompany(account, companyName), this.join(account)]
272
796
  }
797
+
798
+ commit(oracleId: NameType, epoch: UInt64Type, commit: Checksum256Type): Action {
799
+ return this.server.action('commit', {
800
+ oracle_id: Name.from(oracleId),
801
+ epoch: UInt64.from(epoch),
802
+ commit: Checksum256.from(commit),
803
+ })
804
+ }
805
+
806
+ reveal(oracleId: NameType, epoch: UInt64Type, reveal: Checksum256Type): Action {
807
+ return this.server.action('reveal', {
808
+ oracle_id: Name.from(oracleId),
809
+ epoch: UInt64.from(epoch),
810
+ reveal: Checksum256.from(reveal),
811
+ })
812
+ }
813
+
814
+ addoracle(oracleId: NameType): Action {
815
+ return this.server.action('addoracle', {
816
+ oracle_id: Name.from(oracleId),
817
+ })
818
+ }
819
+
820
+ removeoracle(oracleId: NameType): Action {
821
+ return this.server.action('removeoracle', {
822
+ oracle_id: Name.from(oracleId),
823
+ })
824
+ }
825
+
826
+ setthreshold(threshold: UInt8Type): Action {
827
+ return this.server.action('setthreshold', {
828
+ threshold: UInt8.from(threshold),
829
+ })
830
+ }
831
+
832
+ cleanrsvp(epoch: UInt64Type, maxRows: UInt64Type): Action {
833
+ return this.server.action('cleanrsvp', {
834
+ epoch: UInt64.from(epoch),
835
+ max_rows: UInt64.from(maxRows),
836
+ })
837
+ }
273
838
  }