@shipload/sdk 0.7.0 → 1.0.0-beta1

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 (95) hide show
  1. package/lib/shipload.d.ts +2730 -287
  2. package/lib/shipload.js +10862 -2228
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +10434 -2170
  5. package/lib/shipload.m.js.map +1 -1
  6. package/package.json +11 -20
  7. package/src/capabilities/crafting.ts +22 -0
  8. package/src/capabilities/gathering.ts +36 -0
  9. package/src/capabilities/guards.ts +38 -0
  10. package/src/capabilities/hauling.ts +22 -0
  11. package/src/capabilities/index.ts +8 -0
  12. package/src/capabilities/loading.ts +8 -0
  13. package/src/capabilities/modules.ts +86 -0
  14. package/src/capabilities/movement.ts +29 -0
  15. package/src/capabilities/storage.ts +159 -0
  16. package/src/contracts/platform.ts +30 -30
  17. package/src/contracts/server.ts +1387 -283
  18. package/src/data/capabilities.ts +408 -0
  19. package/src/data/catalog.ts +135 -0
  20. package/src/data/categories.ts +55 -0
  21. package/src/data/colors.ts +84 -0
  22. package/src/data/entities.json +50 -0
  23. package/src/data/item-ids.ts +75 -0
  24. package/src/data/items.json +252 -0
  25. package/src/data/locations.ts +53 -0
  26. package/src/data/metadata.ts +208 -0
  27. package/src/data/nebula-adjectives.json +211 -0
  28. package/src/data/nebula-nouns.json +151 -0
  29. package/src/data/recipes-runtime.ts +65 -0
  30. package/src/data/recipes.json +878 -0
  31. package/src/data/syllables.json +1790 -0
  32. package/src/data/tiers.ts +45 -0
  33. package/src/derivation/crafting.ts +350 -0
  34. package/src/derivation/index.ts +32 -0
  35. package/src/derivation/location-size.ts +15 -0
  36. package/src/derivation/resources.ts +112 -0
  37. package/src/derivation/stats.ts +146 -0
  38. package/src/derivation/strata.ts +43 -0
  39. package/src/derivation/stratum.ts +134 -0
  40. package/src/derivation/tiers.ts +54 -0
  41. package/src/entities/cargo-utils.ts +84 -0
  42. package/src/entities/container.ts +108 -0
  43. package/src/entities/entity-inventory.ts +39 -0
  44. package/src/entities/gamestate.ts +152 -0
  45. package/src/entities/inventory-accessor.ts +42 -0
  46. package/src/entities/location.ts +60 -0
  47. package/src/entities/makers.ts +196 -0
  48. package/src/entities/player.ts +15 -0
  49. package/src/entities/ship-deploy.ts +258 -0
  50. package/src/entities/ship.ts +204 -0
  51. package/src/entities/warehouse.ts +119 -0
  52. package/src/errors.ts +100 -9
  53. package/src/format.ts +12 -0
  54. package/src/index-module.ts +317 -7
  55. package/src/managers/actions.ts +250 -0
  56. package/src/managers/base.ts +25 -0
  57. package/src/managers/context.ts +114 -0
  58. package/src/managers/entities.ts +103 -0
  59. package/src/managers/epochs.ts +47 -0
  60. package/src/managers/index.ts +9 -0
  61. package/src/managers/locations.ts +68 -0
  62. package/src/managers/players.ts +13 -0
  63. package/src/nft/description.ts +176 -0
  64. package/src/nft/deserializers.ts +83 -0
  65. package/src/nft/index.ts +2 -0
  66. package/src/resolution/describe-module.ts +166 -0
  67. package/src/resolution/display-name.ts +39 -0
  68. package/src/resolution/resolve-item.ts +358 -0
  69. package/src/scheduling/accessor.ts +82 -0
  70. package/src/{epoch.ts → scheduling/epoch.ts} +1 -1
  71. package/src/scheduling/projection.ts +463 -0
  72. package/src/scheduling/schedule.ts +179 -0
  73. package/src/shipload.ts +47 -160
  74. package/src/subscriptions/connection.ts +154 -0
  75. package/src/subscriptions/debug.ts +17 -0
  76. package/src/subscriptions/index.ts +5 -0
  77. package/src/subscriptions/manager.ts +240 -0
  78. package/src/subscriptions/mappers.ts +28 -0
  79. package/src/subscriptions/types.ts +143 -0
  80. package/src/travel/travel.ts +500 -0
  81. package/src/types/capabilities.ts +76 -0
  82. package/src/types/entity-traits.ts +69 -0
  83. package/src/types/entity.ts +39 -0
  84. package/src/types/index.ts +3 -0
  85. package/src/types.ts +140 -35
  86. package/src/{hash.ts → utils/hash.ts} +2 -2
  87. package/src/utils/system.ts +168 -0
  88. package/src/goods.ts +0 -124
  89. package/src/market.ts +0 -214
  90. package/src/rolls.ts +0 -8
  91. package/src/ship.ts +0 -36
  92. package/src/state.ts +0 -0
  93. package/src/syllables.ts +0 -1184
  94. package/src/system.ts +0 -36
  95. package/src/travel.ts +0 -259
@@ -1,10 +1,320 @@
1
1
  export * from './contracts'
2
- export * from './epoch'
3
2
  export * from './errors'
4
- export * from './goods'
5
- export * from './hash'
6
- export * from './system'
7
- export * from './market'
8
- export * from './ship'
9
- export * from './travel'
10
3
  export * from './types'
4
+ export * from './data/item-ids'
5
+ export * from './data/recipes-runtime'
6
+
7
+ // Direct namespace re-exports for flat `Types` access without going through ServerContract.
8
+ // Preserves both value and type sides through rollup-plugin-dts bundling.
9
+ export {Types as ServerTypes} from './contracts/server'
10
+ export {Types as PlatformTypes} from './contracts/platform'
11
+
12
+ import type {ServerContract} from './contracts'
13
+
14
+ export {Shipload} from './shipload'
15
+ export {Ship} from './entities/ship'
16
+ export type {ShipStateInput, PackedModuleInput} from './entities/ship'
17
+ export {Warehouse, computeWarehouseCapabilities} from './entities/warehouse'
18
+ export type {WarehouseStateInput} from './entities/warehouse'
19
+ export {Container} from './entities/container'
20
+ export type {ContainerStateInput} from './entities/container'
21
+ export {makeShip, makeWarehouse, makeContainer} from './entities/makers'
22
+
23
+ export type movement_stats = ServerContract.Types.movement_stats
24
+ export type energy_stats = ServerContract.Types.energy_stats
25
+ export type loader_stats = ServerContract.Types.loader_stats
26
+ export type schedule = ServerContract.Types.schedule
27
+ export type task = ServerContract.Types.task
28
+ export type cargo_item = ServerContract.Types.cargo_item
29
+ export type warehouse_row = ServerContract.Types.warehouse_row
30
+ export type container_row = ServerContract.Types.container_row
31
+ export type gatherer_stats = ServerContract.Types.gatherer_stats
32
+
33
+ export type location_static = ServerContract.Types.location_static
34
+ export type location_epoch = ServerContract.Types.location_epoch
35
+ export type location_derived = ServerContract.Types.location_derived
36
+ export type location_row = ServerContract.Types.location_row
37
+ export {Player} from './entities/player'
38
+ export type {PlayerStateInput} from './entities/player'
39
+ export {EntityInventory} from './entities/entity-inventory'
40
+ export {Location, toLocation} from './entities/location'
41
+ export {GameState} from './entities/gamestate'
42
+
43
+ export {
44
+ EntitiesManager,
45
+ PlayersManager,
46
+ LocationsManager,
47
+ EpochsManager,
48
+ ActionsManager,
49
+ } from './managers'
50
+ export type {EntityType, LocationStratum} from './managers'
51
+ export type {EntityRefInput} from './managers/actions'
52
+
53
+ export {
54
+ getItem,
55
+ getItems,
56
+ itemIds,
57
+ getResources,
58
+ getComponents,
59
+ getModules,
60
+ getEntityItems,
61
+ resolveItemCategory,
62
+ typeLabel,
63
+ categoryLabel,
64
+ categoryFromIndex,
65
+ categoryLabelFromIndex,
66
+ tierLabel,
67
+ } from './data/catalog'
68
+ export {getCurrentEpoch, getEpochInfo} from './scheduling/epoch'
69
+ export type {EpochInfo} from './scheduling/epoch'
70
+ export {
71
+ getSystemName,
72
+ hasSystem,
73
+ getLocationType,
74
+ getLocationTypeName,
75
+ isGatherableLocation,
76
+ deriveLocationStatic,
77
+ deriveLocationEpoch,
78
+ deriveLocation,
79
+ } from './utils/system'
80
+
81
+ export {
82
+ deriveStratum,
83
+ deriveStrata,
84
+ deriveResourceStats,
85
+ deriveLocationSize,
86
+ getEligibleResources,
87
+ getResourceWeight,
88
+ getLocationCandidates,
89
+ getDepthThreshold,
90
+ getResourceTier,
91
+ DEPTH_THRESHOLD_T1,
92
+ DEPTH_THRESHOLD_T2,
93
+ DEPTH_THRESHOLD_T3,
94
+ DEPTH_THRESHOLD_T4,
95
+ DEPTH_THRESHOLD_T5,
96
+ LOCATION_MIN_DEPTH,
97
+ LOCATION_MAX_DEPTH,
98
+ PLANET_SUBTYPE_GAS_GIANT,
99
+ PLANET_SUBTYPE_ROCKY,
100
+ PLANET_SUBTYPE_TERRESTRIAL,
101
+ PLANET_SUBTYPE_ICY,
102
+ PLANET_SUBTYPE_OCEAN,
103
+ PLANET_SUBTYPE_INDUSTRIAL,
104
+ } from './derivation'
105
+
106
+ export type {StratumInfo, ResourceStats, DerivedStratum} from './derivation'
107
+
108
+ export {RESERVE_TIERS, TIER_ROLL_MAX, rollTier, rollWithinTier} from './derivation'
109
+ export type {ReserveTier, TierRange} from './derivation'
110
+
111
+ export {getStatDefinitions, getStatName, resolveStats} from './derivation'
112
+ export type {StatDefinition, NamedStats} from './derivation'
113
+
114
+ export {hash, hash512} from './utils/hash'
115
+
116
+ export {
117
+ distanceBetweenCoordinates,
118
+ distanceBetweenPoints,
119
+ findNearbyPlanets,
120
+ lerp,
121
+ rotation,
122
+ calc_ship_mass,
123
+ calc_acceleration,
124
+ calc_flighttime,
125
+ calc_ship_flighttime,
126
+ calc_ship_acceleration,
127
+ calc_rechargetime,
128
+ calc_ship_rechargetime,
129
+ calc_loader_flighttime,
130
+ calc_loader_acceleration,
131
+ calc_energyusage,
132
+ calc_orbital_altitude,
133
+ calc_transfer_duration,
134
+ calculateTransferTime,
135
+ calculateLoadTimeBreakdown,
136
+ calculateRefuelingTime,
137
+ calculateFlightTime,
138
+ estimateTravelTime,
139
+ estimateDealTravelTime,
140
+ hasEnergyForDistance,
141
+ getFlightOrigin,
142
+ getDestinationLocation,
143
+ getPositionAt,
144
+ } from './travel/travel'
145
+ export type {
146
+ LoadTimeBreakdown,
147
+ EstimatedTravelTime,
148
+ EstimateTravelTimeOptions,
149
+ TransferEntity,
150
+ HasScheduleAndLocation,
151
+ } from './travel/travel'
152
+
153
+ export * as schedule from './scheduling/schedule'
154
+ export type {Scheduleable, ScheduleData} from './scheduling/schedule'
155
+ export {ScheduleAccessor, createScheduleAccessor} from './scheduling/accessor'
156
+ export {InventoryAccessor, createInventoryAccessor} from './entities/inventory-accessor'
157
+ export type {HasCargo} from './entities/inventory-accessor'
158
+
159
+ export * as cargoUtils from './entities/cargo-utils'
160
+ export type {CargoData} from './entities/cargo-utils'
161
+
162
+ export {
163
+ createProjectedEntity,
164
+ projectEntity,
165
+ projectEntityAt,
166
+ projectFromCurrentState,
167
+ projectFromCurrentStateAt,
168
+ validateSchedule,
169
+ } from './scheduling/projection'
170
+ export type {
171
+ Projectable,
172
+ ProjectableSnapshot,
173
+ ProjectedEntity,
174
+ ProjectionOptions,
175
+ } from './scheduling/projection'
176
+
177
+ export * from './types/capabilities'
178
+ export * from './types/entity'
179
+ export * from './capabilities'
180
+
181
+ export {
182
+ categoryColors,
183
+ tierColors,
184
+ tierLabels,
185
+ categoryIcons,
186
+ categoryIconShapes,
187
+ componentIcon,
188
+ moduleIcon,
189
+ itemAbbreviations,
190
+ } from './data/colors'
191
+ export type {CategoryIconShape} from './data/colors'
192
+
193
+ export {itemTier, itemOffset, itemCategory, isRelatedItem, isCraftedItem} from './data/tiers'
194
+ export type {CraftedItemCategory} from './data/tiers'
195
+
196
+ export {getCategoryInfo} from './data/categories'
197
+ export type {CategoryInfo} from './data/categories'
198
+
199
+ export {getPlanetSubtypes, getPlanetSubtype} from './data/locations'
200
+ export type {PlanetSubtypeInfo} from './data/locations'
201
+
202
+ export {
203
+ capabilityNames,
204
+ capabilityAttributes,
205
+ statMappings,
206
+ isInvertedAttribute,
207
+ getCapabilityAttributes,
208
+ getStatMappings,
209
+ getStatMappingsForStat,
210
+ getStatMappingsForCapability,
211
+ } from './data/capabilities'
212
+ export type {CapabilityAttribute, StatMapping} from './data/capabilities'
213
+
214
+ export {
215
+ encodeStats,
216
+ encodeGatheredCargoStats,
217
+ decodeStat,
218
+ decodeStats,
219
+ decodeCraftedItemStats,
220
+ blendStacks,
221
+ computeComponentStats,
222
+ blendComponentStacks,
223
+ computeEntityStats,
224
+ blendCargoStacks,
225
+ blendCrossGroup,
226
+ computeInputMass,
227
+ computeCraftedOutputStats,
228
+ } from './derivation/crafting'
229
+ export type {StackInput, CategoryStacks, RecipeSlotInput} from './derivation/crafting'
230
+
231
+ export {computeContainerCapabilities, computeContainerT2Capabilities} from './entities/container'
232
+
233
+ export {
234
+ computeShipHullCapabilities,
235
+ computeEngineCapabilities,
236
+ computeGeneratorCapabilities,
237
+ computeGathererCapabilities,
238
+ computeHaulerCapabilities,
239
+ computeLoaderCapabilities,
240
+ computeCrafterCapabilities,
241
+ computeWarehouseHullCapabilities,
242
+ computeStorageCapabilities,
243
+ computeShipCapabilities,
244
+ } from './entities/ship-deploy'
245
+ export type {ShipCapabilities} from './entities/ship-deploy'
246
+
247
+ export {resolveItem} from './resolution/resolve-item'
248
+ export type {
249
+ ResolvedItem,
250
+ ResolvedItemStat,
251
+ ResolvedAttributeGroup,
252
+ ResolvedModuleSlot,
253
+ ResolvedItemType,
254
+ } from './resolution/resolve-item'
255
+
256
+ export {
257
+ describeModule,
258
+ describeModuleForItem,
259
+ describeModuleForSlot,
260
+ renderDescription,
261
+ } from './resolution/describe-module'
262
+ export type {
263
+ TextSpan,
264
+ CapabilityInput,
265
+ ModuleDescription,
266
+ RenderDescriptionOptions,
267
+ } from './resolution/describe-module'
268
+
269
+ export * as NFT from './nft'
270
+ export {
271
+ deserializeAsset,
272
+ deserializeResource,
273
+ deserializeComponent,
274
+ deserializeModule,
275
+ deserializeEntity,
276
+ readCommonBase,
277
+ } from './nft/deserializers'
278
+ export type {
279
+ NFTCargoItem,
280
+ NFTModuleSlot,
281
+ NFTInstalledModule,
282
+ NFTCommonBase,
283
+ } from './nft/deserializers'
284
+
285
+ export {
286
+ buildEntityDescription,
287
+ formatModuleLine,
288
+ entityDisplayName,
289
+ moduleDisplayName,
290
+ computeBaseHullmass,
291
+ computeBaseCapacityShip,
292
+ computeBaseCapacityWarehouse,
293
+ computeEngineThrust,
294
+ computeEngineDrain,
295
+ computeGeneratorCap,
296
+ computeGeneratorRech,
297
+ computeGathererYield,
298
+ computeGathererDrain,
299
+ computeGathererDepth,
300
+ computeGathererSpeed,
301
+ computeLoaderMass,
302
+ computeLoaderThrust,
303
+ computeCrafterSpeed,
304
+ computeCrafterDrain,
305
+ } from './nft/description'
306
+
307
+ export {
308
+ ITEM_TYPE_RESOURCE,
309
+ ITEM_TYPE_COMPONENT,
310
+ ITEM_TYPE_MODULE,
311
+ ITEM_TYPE_ENTITY,
312
+ itemTypeCode,
313
+ } from './data/tiers'
314
+
315
+ export {formatMass, formatMassDelta} from './format'
316
+
317
+ export {displayName, describeItem} from './resolution/display-name'
318
+ export type {DescribeOptions} from './resolution/display-name'
319
+
320
+ export * from './subscriptions'
@@ -0,0 +1,250 @@
1
+ import {
2
+ type Action,
3
+ Int64,
4
+ Name,
5
+ type NameType,
6
+ UInt16,
7
+ type UInt16Type,
8
+ UInt32,
9
+ type UInt32Type,
10
+ UInt64,
11
+ type UInt64Type,
12
+ } from '@wharfkit/antelope'
13
+ import {BaseManager} from './base'
14
+ import {type CoordinatesType, EntityType, type EntityTypeName} from '../types'
15
+ import {ServerContract} from '../contracts'
16
+
17
+ export type EntityRefInput = {
18
+ entityType: EntityTypeName
19
+ entityId: UInt64Type
20
+ }
21
+
22
+ export class ActionsManager extends BaseManager {
23
+ travel(shipId: UInt64Type, destination: CoordinatesType, recharge = true): Action {
24
+ const x = Int64.from(destination.x)
25
+ const y = Int64.from(destination.y)
26
+
27
+ return this.server.action('travel', {
28
+ entity_type: EntityType.SHIP,
29
+ id: UInt64.from(shipId),
30
+ x,
31
+ y,
32
+ recharge,
33
+ })
34
+ }
35
+
36
+ grouptravel(entities: EntityRefInput[], destination: CoordinatesType, recharge = true): Action {
37
+ const entityRefs = entities.map((e) =>
38
+ ServerContract.Types.entity_ref.from({
39
+ entity_type: e.entityType,
40
+ entity_id: UInt64.from(e.entityId),
41
+ })
42
+ )
43
+ const x = Int64.from(destination.x)
44
+ const y = Int64.from(destination.y)
45
+
46
+ return this.server.action('grouptravel', {
47
+ entities: entityRefs,
48
+ x,
49
+ y,
50
+ recharge,
51
+ })
52
+ }
53
+
54
+ resolve(
55
+ entityId: UInt64Type,
56
+ entityType: EntityTypeName = EntityType.SHIP,
57
+ count?: UInt64Type
58
+ ): Action {
59
+ const params: ServerContract.ActionParams.resolve = {
60
+ entity_type: entityType,
61
+ id: UInt64.from(entityId),
62
+ }
63
+ if (count !== undefined) {
64
+ params.count = UInt64.from(count)
65
+ }
66
+ return this.server.action('resolve', params)
67
+ }
68
+
69
+ cancel(
70
+ entityId: UInt64Type,
71
+ count: UInt64Type,
72
+ entityType: EntityTypeName = EntityType.SHIP
73
+ ): Action {
74
+ return this.server.action('cancel', {
75
+ entity_type: entityType,
76
+ id: UInt64.from(entityId),
77
+ count: UInt64.from(count),
78
+ })
79
+ }
80
+
81
+ recharge(entityId: UInt64Type, entityType: EntityTypeName = EntityType.SHIP): Action {
82
+ return this.server.action('recharge', {
83
+ entity_type: entityType,
84
+ id: UInt64.from(entityId),
85
+ })
86
+ }
87
+
88
+ transfer(
89
+ sourceType: EntityTypeName,
90
+ sourceId: UInt64Type,
91
+ destType: EntityTypeName,
92
+ destId: UInt64Type,
93
+ itemId: UInt64Type,
94
+ stats: UInt64Type,
95
+ quantity: UInt64Type
96
+ ): 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),
105
+ })
106
+ }
107
+
108
+ foundCompany(account: NameType, name: string): Action {
109
+ return this.platform.action('foundcompany', {
110
+ account: Name.from(account),
111
+ name,
112
+ })
113
+ }
114
+
115
+ join(account: NameType): Action {
116
+ return this.server.action('join', {
117
+ account: Name.from(account),
118
+ })
119
+ }
120
+
121
+ gather(
122
+ source: EntityRefInput,
123
+ destination: EntityRefInput,
124
+ stratum: UInt16Type,
125
+ quantity: UInt32Type
126
+ ): 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
+ }),
136
+ stratum: UInt16.from(stratum),
137
+ quantity: UInt32.from(quantity),
138
+ })
139
+ }
140
+
141
+ warp(
142
+ entityId: UInt64Type,
143
+ destination: CoordinatesType,
144
+ entityType: EntityTypeName = EntityType.SHIP
145
+ ): Action {
146
+ const x = Int64.from(destination.x)
147
+ const y = Int64.from(destination.y)
148
+
149
+ return this.server.action('warp', {
150
+ entity_type: entityType,
151
+ id: UInt64.from(entityId),
152
+ x,
153
+ y,
154
+ })
155
+ }
156
+
157
+ craft(
158
+ entityType: EntityTypeName,
159
+ entityId: UInt64Type,
160
+ recipeId: number,
161
+ quantity: number,
162
+ inputs: ServerContract.ActionParams.Type.cargo_item[]
163
+ ): Action {
164
+ const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
165
+ return this.server.action('craft', {
166
+ entity_type: entityType,
167
+ id: UInt64.from(entityId),
168
+ recipe_id: UInt16.from(recipeId),
169
+ quantity: UInt32.from(quantity),
170
+ inputs: cargoInputs,
171
+ })
172
+ }
173
+
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))
180
+ return this.server.action('blend', {
181
+ entity_type: entityType,
182
+ id: UInt64.from(entityId),
183
+ inputs: cargoInputs,
184
+ })
185
+ }
186
+
187
+ deploy(
188
+ entityType: EntityTypeName,
189
+ entityId: UInt64Type,
190
+ packedItemId: number,
191
+ stats: bigint
192
+ ): Action {
193
+ return this.server.action('deploy', {
194
+ entity_type: entityType,
195
+ id: UInt64.from(entityId),
196
+ packed_item_id: UInt16.from(packedItemId),
197
+ stats: UInt64.from(stats),
198
+ })
199
+ }
200
+
201
+ addmodule(
202
+ entityType: EntityTypeName,
203
+ entityId: UInt64Type,
204
+ moduleIndex: number,
205
+ moduleCargoId: UInt64Type,
206
+ targetCargoId: UInt64Type = UInt64.from(0)
207
+ ): Action {
208
+ return this.server.action('addmodule', {
209
+ entity_type: entityType,
210
+ entity_id: UInt64.from(entityId),
211
+ module_index: moduleIndex,
212
+ module_cargo_id: UInt64.from(moduleCargoId),
213
+ target_cargo_id: UInt64.from(targetCargoId),
214
+ })
215
+ }
216
+
217
+ rmmodule(
218
+ entityType: EntityTypeName,
219
+ entityId: UInt64Type,
220
+ moduleIndex: number,
221
+ targetCargoId: UInt64Type = UInt64.from(0)
222
+ ): Action {
223
+ return this.server.action('rmmodule', {
224
+ entity_type: entityType,
225
+ entity_id: UInt64.from(entityId),
226
+ module_index: moduleIndex,
227
+ target_cargo_id: UInt64.from(targetCargoId),
228
+ })
229
+ }
230
+
231
+ wrap(
232
+ owner: NameType,
233
+ entityType: EntityTypeName,
234
+ entityId: UInt64Type,
235
+ cargoId: UInt64Type,
236
+ quantity: UInt64Type
237
+ ): Action {
238
+ return this.server.action('wrap', {
239
+ owner: Name.from(owner),
240
+ entity_type: entityType,
241
+ entity_id: UInt64.from(entityId),
242
+ cargo_id: UInt64.from(cargoId),
243
+ quantity: UInt64.from(quantity),
244
+ })
245
+ }
246
+
247
+ joinGame(account: NameType, companyName: string): Action[] {
248
+ return [this.foundCompany(account, companyName), this.join(account)]
249
+ }
250
+ }
@@ -0,0 +1,25 @@
1
+ import type {GameContext} from './context'
2
+
3
+ export abstract class BaseManager {
4
+ constructor(protected readonly context: GameContext) {}
5
+
6
+ protected get client() {
7
+ return this.context.client
8
+ }
9
+
10
+ protected get server() {
11
+ return this.context.server
12
+ }
13
+
14
+ protected get platform() {
15
+ return this.context.platform
16
+ }
17
+
18
+ protected async getGame() {
19
+ return this.context.getGame()
20
+ }
21
+
22
+ protected async getState() {
23
+ return this.context.getState()
24
+ }
25
+ }
@@ -0,0 +1,114 @@
1
+ import type {APIClient} from '@wharfkit/antelope'
2
+ import type {Contract} from '@wharfkit/contract'
3
+ import type {PlatformContract} from '../contracts'
4
+ import {GameState} from '../entities/gamestate'
5
+
6
+ import {EntitiesManager} from './entities'
7
+ import {PlayersManager} from './players'
8
+ import {LocationsManager} from './locations'
9
+ import {EpochsManager} from './epochs'
10
+ import {ActionsManager} from './actions'
11
+ import {SubscriptionsManager} from '../subscriptions/manager'
12
+
13
+ export class GameContext {
14
+ private _entities?: EntitiesManager
15
+ private _players?: PlayersManager
16
+ private _locations?: LocationsManager
17
+ private _epochs?: EpochsManager
18
+ private _actions?: ActionsManager
19
+ private _subscriptions?: SubscriptionsManager
20
+ private _subscriptionsUrl?: string
21
+
22
+ private _gameCache?: PlatformContract.Types.game_row
23
+ private _stateCache?: GameState
24
+
25
+ constructor(
26
+ public readonly client: APIClient,
27
+ public readonly server: Contract,
28
+ public readonly platform: Contract
29
+ ) {}
30
+
31
+ get entities(): EntitiesManager {
32
+ if (!this._entities) {
33
+ this._entities = new EntitiesManager(this)
34
+ }
35
+ return this._entities
36
+ }
37
+
38
+ get players(): PlayersManager {
39
+ if (!this._players) {
40
+ this._players = new PlayersManager(this)
41
+ }
42
+ return this._players
43
+ }
44
+
45
+ get locations(): LocationsManager {
46
+ if (!this._locations) {
47
+ this._locations = new LocationsManager(this)
48
+ }
49
+ return this._locations
50
+ }
51
+
52
+ get epochs(): EpochsManager {
53
+ if (!this._epochs) {
54
+ this._epochs = new EpochsManager(this)
55
+ }
56
+ return this._epochs
57
+ }
58
+
59
+ get actions(): ActionsManager {
60
+ if (!this._actions) {
61
+ this._actions = new ActionsManager(this)
62
+ }
63
+ return this._actions
64
+ }
65
+
66
+ setSubscriptionsUrl(url: string) {
67
+ this._subscriptionsUrl = url
68
+ }
69
+
70
+ get subscriptions(): SubscriptionsManager {
71
+ if (!this._subscriptions) {
72
+ if (!this._subscriptionsUrl) {
73
+ throw new Error(
74
+ 'subscriptions requires a subscriptionsUrl passed to Shipload constructor'
75
+ )
76
+ }
77
+ this._subscriptions = new SubscriptionsManager({url: this._subscriptionsUrl})
78
+ }
79
+ return this._subscriptions
80
+ }
81
+
82
+ async getGame(reload = false): Promise<PlatformContract.Types.game_row> {
83
+ if (!reload && this._gameCache) {
84
+ return this._gameCache
85
+ }
86
+ const game = await this.platform.table('games').get()
87
+ if (!game) {
88
+ throw new Error('Game not initialized')
89
+ }
90
+ this._gameCache = game
91
+ return game
92
+ }
93
+
94
+ async getState(reload = false): Promise<GameState> {
95
+ if (!reload && this._stateCache) {
96
+ return this._stateCache
97
+ }
98
+ const state = await this.server.table('state').get()
99
+ if (!state) {
100
+ throw new Error('Game state not initialized')
101
+ }
102
+ const game = this._gameCache
103
+ this._stateCache = GameState.from(state, game)
104
+ return this._stateCache
105
+ }
106
+
107
+ get cachedGame(): PlatformContract.Types.game_row | undefined {
108
+ return this._gameCache
109
+ }
110
+
111
+ get cachedState(): GameState | undefined {
112
+ return this._stateCache
113
+ }
114
+ }