@shipload/sdk 0.7.1 → 2.0.0-rc10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/shipload.d.ts +2203 -288
- package/lib/shipload.js +8441 -2210
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +8160 -2167
- package/lib/shipload.m.js.map +1 -1
- package/package.json +7 -6
- package/src/capabilities/crafting.ts +26 -0
- package/src/capabilities/extraction.ts +36 -0
- package/src/capabilities/guards.ts +38 -0
- package/src/capabilities/hauling.ts +22 -0
- package/src/capabilities/index.ts +8 -0
- package/src/capabilities/loading.ts +8 -0
- package/src/capabilities/modules.ts +57 -0
- package/src/capabilities/movement.ts +29 -0
- package/src/capabilities/storage.ts +72 -0
- package/src/contracts/server.ts +1217 -254
- package/src/data/capabilities.ts +408 -0
- package/src/data/categories.ts +58 -0
- package/src/data/colors.ts +52 -0
- package/src/data/items.json +17 -0
- package/src/data/locations.ts +53 -0
- package/src/data/nebula-adjectives.json +211 -0
- package/src/data/nebula-nouns.json +151 -0
- package/src/data/recipes.ts +571 -0
- package/src/data/syllables.json +1790 -0
- package/src/data/tiers.ts +45 -0
- package/src/derivation/crafting.ts +197 -0
- package/src/derivation/index.ts +28 -0
- package/src/derivation/location-size.ts +15 -0
- package/src/derivation/resources.ts +142 -0
- package/src/derivation/stats.ts +146 -0
- package/src/derivation/stratum.ts +118 -0
- package/src/entities/cargo-utils.ts +84 -0
- package/src/entities/container.ts +106 -0
- package/src/entities/entity-inventory.ts +39 -0
- package/src/entities/gamestate.ts +152 -0
- package/src/entities/inventory-accessor.ts +42 -0
- package/src/entities/location.ts +60 -0
- package/src/entities/makers.ts +72 -0
- package/src/entities/player.ts +15 -0
- package/src/entities/ship-deploy.ts +263 -0
- package/src/entities/ship.ts +199 -0
- package/src/entities/warehouse.ts +91 -0
- package/src/errors.ts +46 -9
- package/src/index-module.ts +302 -7
- package/src/managers/actions.ts +197 -0
- package/src/managers/base.ts +25 -0
- package/src/managers/context.ts +95 -0
- package/src/managers/entities.ts +103 -0
- package/src/managers/epochs.ts +47 -0
- package/src/managers/index.ts +8 -0
- package/src/managers/locations.ts +39 -0
- package/src/managers/players.ts +13 -0
- package/src/market/items.ts +30 -0
- package/src/nft/description.ts +175 -0
- package/src/nft/deserializers.ts +81 -0
- package/src/nft/index.ts +2 -0
- package/src/resolution/resolve-item.ts +313 -0
- package/src/scheduling/accessor.ts +82 -0
- package/src/{epoch.ts → scheduling/epoch.ts} +1 -1
- package/src/scheduling/projection.ts +322 -0
- package/src/scheduling/schedule.ts +179 -0
- package/src/shipload.ts +36 -159
- package/src/travel/travel.ts +499 -0
- package/src/types/capabilities.ts +71 -0
- package/src/types/entity-traits.ts +69 -0
- package/src/types/entity.ts +39 -0
- package/src/types/index.ts +3 -0
- package/src/types.ts +113 -35
- package/src/{hash.ts → utils/hash.ts} +1 -1
- package/src/utils/system.ts +155 -0
- package/src/goods.ts +0 -124
- package/src/market.ts +0 -214
- package/src/rolls.ts +0 -8
- package/src/ship.ts +0 -36
- package/src/state.ts +0 -0
- package/src/syllables.ts +0 -1184
- package/src/system.ts +0 -37
- package/src/travel.ts +0 -259
package/src/index-module.ts
CHANGED
|
@@ -1,10 +1,305 @@
|
|
|
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
|
+
|
|
5
|
+
import {ServerContract} from './contracts'
|
|
6
|
+
|
|
7
|
+
export {Shipload} from './shipload'
|
|
8
|
+
export {Ship} from './entities/ship'
|
|
9
|
+
export type {ShipStateInput} from './entities/ship'
|
|
10
|
+
export {Warehouse} from './entities/warehouse'
|
|
11
|
+
export type {WarehouseStateInput} from './entities/warehouse'
|
|
12
|
+
export {Container} from './entities/container'
|
|
13
|
+
export type {ContainerStateInput} from './entities/container'
|
|
14
|
+
export {makeShip, makeWarehouse, makeContainer} from './entities/makers'
|
|
15
|
+
|
|
16
|
+
export type movement_stats = ServerContract.Types.movement_stats
|
|
17
|
+
export type energy_stats = ServerContract.Types.energy_stats
|
|
18
|
+
export type loader_stats = ServerContract.Types.loader_stats
|
|
19
|
+
export type schedule = ServerContract.Types.schedule
|
|
20
|
+
export type task = ServerContract.Types.task
|
|
21
|
+
export type cargo_item = ServerContract.Types.cargo_item
|
|
22
|
+
export type warehouse_row = ServerContract.Types.warehouse_row
|
|
23
|
+
export type container_row = ServerContract.Types.container_row
|
|
24
|
+
export type extractor_stats = ServerContract.Types.extractor_stats
|
|
25
|
+
|
|
26
|
+
export type location_static = ServerContract.Types.location_static
|
|
27
|
+
export type location_epoch = ServerContract.Types.location_epoch
|
|
28
|
+
export type location_derived = ServerContract.Types.location_derived
|
|
29
|
+
export type location_row = ServerContract.Types.location_row
|
|
30
|
+
export {Player} from './entities/player'
|
|
31
|
+
export type {PlayerStateInput} from './entities/player'
|
|
32
|
+
export {EntityInventory} from './entities/entity-inventory'
|
|
33
|
+
export {Location, toLocation} from './entities/location'
|
|
34
|
+
export {GameState} from './entities/gamestate'
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
EntitiesManager,
|
|
38
|
+
PlayersManager,
|
|
39
|
+
LocationsManager,
|
|
40
|
+
EpochsManager,
|
|
41
|
+
ActionsManager,
|
|
42
|
+
} from './managers'
|
|
43
|
+
export type {EntityType} from './managers'
|
|
44
|
+
export type {EntityRefInput} from './managers/actions'
|
|
45
|
+
|
|
46
|
+
export {getItem, getItems, itemIds} from './market/items'
|
|
47
|
+
export {getCurrentEpoch, getEpochInfo} from './scheduling/epoch'
|
|
48
|
+
export type {EpochInfo} from './scheduling/epoch'
|
|
49
|
+
export {
|
|
50
|
+
getSystemName,
|
|
51
|
+
hasSystem,
|
|
52
|
+
getLocationType,
|
|
53
|
+
isExtractableLocation,
|
|
54
|
+
deriveLocationStatic,
|
|
55
|
+
deriveLocationEpoch,
|
|
56
|
+
deriveLocation,
|
|
57
|
+
} from './utils/system'
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
deriveStratum,
|
|
61
|
+
deriveResourceStats,
|
|
62
|
+
deriveLocationSize,
|
|
63
|
+
getEligibleResources,
|
|
64
|
+
getResourceWeight,
|
|
65
|
+
getLocationCandidates,
|
|
66
|
+
getDepthThreshold,
|
|
67
|
+
getResourceTier,
|
|
68
|
+
depthScaleFactor,
|
|
69
|
+
DEPTH_THRESHOLD_T1,
|
|
70
|
+
DEPTH_THRESHOLD_T2,
|
|
71
|
+
DEPTH_THRESHOLD_T3,
|
|
72
|
+
DEPTH_THRESHOLD_T4,
|
|
73
|
+
DEPTH_THRESHOLD_T5,
|
|
74
|
+
LOCATION_MIN_DEPTH,
|
|
75
|
+
LOCATION_MAX_DEPTH,
|
|
76
|
+
PLANET_SUBTYPE_GAS_GIANT,
|
|
77
|
+
PLANET_SUBTYPE_ROCKY,
|
|
78
|
+
PLANET_SUBTYPE_TERRESTRIAL,
|
|
79
|
+
PLANET_SUBTYPE_ICY,
|
|
80
|
+
PLANET_SUBTYPE_OCEAN,
|
|
81
|
+
PLANET_SUBTYPE_INDUSTRIAL,
|
|
82
|
+
} from './derivation'
|
|
83
|
+
|
|
84
|
+
export type {StratumInfo, ResourceStats} from './derivation'
|
|
85
|
+
|
|
86
|
+
export {getStatDefinitions, getStatName, resolveStats} from './derivation'
|
|
87
|
+
export type {StatDefinition, NamedStats} from './derivation'
|
|
88
|
+
|
|
89
|
+
export {hash, hash512} from './utils/hash'
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
distanceBetweenCoordinates,
|
|
93
|
+
distanceBetweenPoints,
|
|
94
|
+
findNearbyPlanets,
|
|
95
|
+
lerp,
|
|
96
|
+
rotation,
|
|
97
|
+
calc_ship_mass,
|
|
98
|
+
calc_acceleration,
|
|
99
|
+
calc_flighttime,
|
|
100
|
+
calc_ship_flighttime,
|
|
101
|
+
calc_ship_acceleration,
|
|
102
|
+
calc_rechargetime,
|
|
103
|
+
calc_ship_rechargetime,
|
|
104
|
+
calc_loader_flighttime,
|
|
105
|
+
calc_loader_acceleration,
|
|
106
|
+
calc_energyusage,
|
|
107
|
+
calc_orbital_altitude,
|
|
108
|
+
calc_transfer_duration,
|
|
109
|
+
calculateTransferTime,
|
|
110
|
+
calculateLoadTimeBreakdown,
|
|
111
|
+
calculateRefuelingTime,
|
|
112
|
+
calculateFlightTime,
|
|
113
|
+
estimateTravelTime,
|
|
114
|
+
estimateDealTravelTime,
|
|
115
|
+
hasEnergyForDistance,
|
|
116
|
+
getFlightOrigin,
|
|
117
|
+
getDestinationLocation,
|
|
118
|
+
getPositionAt,
|
|
119
|
+
} from './travel/travel'
|
|
120
|
+
export type {
|
|
121
|
+
LoadTimeBreakdown,
|
|
122
|
+
EstimatedTravelTime,
|
|
123
|
+
EstimateTravelTimeOptions,
|
|
124
|
+
TransferEntity,
|
|
125
|
+
HasScheduleAndLocation,
|
|
126
|
+
} from './travel/travel'
|
|
127
|
+
|
|
128
|
+
export * as schedule from './scheduling/schedule'
|
|
129
|
+
export type {Scheduleable, ScheduleData} from './scheduling/schedule'
|
|
130
|
+
export {ScheduleAccessor, createScheduleAccessor} from './scheduling/accessor'
|
|
131
|
+
export {InventoryAccessor, createInventoryAccessor} from './entities/inventory-accessor'
|
|
132
|
+
export type {HasCargo} from './entities/inventory-accessor'
|
|
133
|
+
|
|
134
|
+
export * as cargoUtils from './entities/cargo-utils'
|
|
135
|
+
export type {CargoData} from './entities/cargo-utils'
|
|
136
|
+
|
|
137
|
+
export {projectEntity, projectEntityAt, createProjectedEntity} from './scheduling/projection'
|
|
138
|
+
export type {Projectable, ProjectedEntity} from './scheduling/projection'
|
|
139
|
+
|
|
140
|
+
export * from './types/capabilities'
|
|
141
|
+
export * from './types/entity'
|
|
142
|
+
export * from './capabilities'
|
|
143
|
+
|
|
144
|
+
export {
|
|
145
|
+
categoryColors,
|
|
146
|
+
tierColors,
|
|
147
|
+
categoryIcons,
|
|
148
|
+
componentIcon,
|
|
149
|
+
moduleIcon,
|
|
150
|
+
itemIcons,
|
|
151
|
+
} from './data/colors'
|
|
152
|
+
|
|
153
|
+
export {itemTier, itemOffset, itemCategory, isRelatedItem, isCraftedItem} from './data/tiers'
|
|
154
|
+
export type {CraftedItemCategory} from './data/tiers'
|
|
155
|
+
|
|
156
|
+
export {getCategoryInfo} from './data/categories'
|
|
157
|
+
export type {CategoryInfo} from './data/categories'
|
|
158
|
+
|
|
159
|
+
export {getPlanetSubtypes, getPlanetSubtype} from './data/locations'
|
|
160
|
+
export type {PlanetSubtypeInfo} from './data/locations'
|
|
161
|
+
|
|
162
|
+
export {
|
|
163
|
+
capabilityNames,
|
|
164
|
+
capabilityAttributes,
|
|
165
|
+
statMappings,
|
|
166
|
+
isInvertedAttribute,
|
|
167
|
+
getCapabilityAttributes,
|
|
168
|
+
getStatMappings,
|
|
169
|
+
getStatMappingsForStat,
|
|
170
|
+
getStatMappingsForCapability,
|
|
171
|
+
} from './data/capabilities'
|
|
172
|
+
export type {CapabilityAttribute, StatMapping} from './data/capabilities'
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
components,
|
|
176
|
+
entityRecipes,
|
|
177
|
+
moduleRecipes,
|
|
178
|
+
getComponentById,
|
|
179
|
+
getEntityRecipe,
|
|
180
|
+
getEntityRecipeByItemId,
|
|
181
|
+
getModuleRecipe,
|
|
182
|
+
getModuleRecipeByItemId,
|
|
183
|
+
getAllCraftableItems,
|
|
184
|
+
getComponentsForCategory,
|
|
185
|
+
getComponentsForStat,
|
|
186
|
+
ITEM_HULL_PLATES,
|
|
187
|
+
ITEM_CARGO_LINING,
|
|
188
|
+
ITEM_CONTAINER_T1_PACKED,
|
|
189
|
+
ITEM_THRUSTER_CORE,
|
|
190
|
+
ITEM_POWER_CELL,
|
|
191
|
+
ITEM_ENGINE_T1,
|
|
192
|
+
ITEM_GENERATOR_T1,
|
|
193
|
+
ITEM_SHIP_T1_PACKED,
|
|
194
|
+
ITEM_WAREHOUSE_T1_PACKED,
|
|
195
|
+
ITEM_DRILL_SHAFT,
|
|
196
|
+
ITEM_EXTRACTION_PROBE,
|
|
197
|
+
ITEM_CARGO_ARM,
|
|
198
|
+
ITEM_TOOL_BIT,
|
|
199
|
+
ITEM_REACTION_CHAMBER,
|
|
200
|
+
ITEM_EXTRACTOR_T1,
|
|
201
|
+
ITEM_LOADER_T1,
|
|
202
|
+
ITEM_MANUFACTURING_T1,
|
|
203
|
+
ITEM_STORAGE_T1,
|
|
204
|
+
ITEM_HULL_PLATES_T2,
|
|
205
|
+
ITEM_CARGO_LINING_T2,
|
|
206
|
+
ITEM_CONTAINER_T2_PACKED,
|
|
207
|
+
ITEM_FOCUSING_ARRAY,
|
|
208
|
+
} from './data/recipes'
|
|
209
|
+
export type {
|
|
210
|
+
ComponentDefinition,
|
|
211
|
+
ComponentStat,
|
|
212
|
+
RecipeInput,
|
|
213
|
+
EntityRecipe,
|
|
214
|
+
ModuleRecipe,
|
|
215
|
+
ModuleSlot,
|
|
216
|
+
CraftableItem,
|
|
217
|
+
} from './data/recipes'
|
|
218
|
+
|
|
219
|
+
export {
|
|
220
|
+
encodeStats,
|
|
221
|
+
decodeStat,
|
|
222
|
+
decodeStats,
|
|
223
|
+
decodeCraftedItemStats,
|
|
224
|
+
blendStacks,
|
|
225
|
+
computeComponentStats,
|
|
226
|
+
blendComponentStacks,
|
|
227
|
+
computeEntityStats,
|
|
228
|
+
blendCargoStacks,
|
|
229
|
+
blendCrossGroup,
|
|
230
|
+
categoryItemMass,
|
|
231
|
+
computeInputMass,
|
|
232
|
+
} from './derivation/crafting'
|
|
233
|
+
export type {StackInput, CategoryStacks} from './derivation/crafting'
|
|
234
|
+
|
|
235
|
+
export {computeContainerCapabilities, computeContainerT2Capabilities} from './entities/container'
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
computeShipHullCapabilities,
|
|
239
|
+
computeEngineCapabilities,
|
|
240
|
+
computeGeneratorCapabilities,
|
|
241
|
+
computeExtractorCapabilities,
|
|
242
|
+
computeHaulerCapabilities,
|
|
243
|
+
computeLoaderCapabilities,
|
|
244
|
+
computeManufacturingCapabilities,
|
|
245
|
+
computeWarehouseHullCapabilities,
|
|
246
|
+
computeStorageCapabilities,
|
|
247
|
+
computeShipCapabilities,
|
|
248
|
+
} from './entities/ship-deploy'
|
|
249
|
+
export type {ShipCapabilities} from './entities/ship-deploy'
|
|
250
|
+
|
|
251
|
+
export {resolveItem} from './resolution/resolve-item'
|
|
252
|
+
export type {
|
|
253
|
+
ResolvedItem,
|
|
254
|
+
ResolvedItemStat,
|
|
255
|
+
ResolvedAttributeGroup,
|
|
256
|
+
ResolvedModuleSlot,
|
|
257
|
+
ResolvedItemType,
|
|
258
|
+
} from './resolution/resolve-item'
|
|
259
|
+
|
|
260
|
+
export * as NFT from './nft'
|
|
261
|
+
export {
|
|
262
|
+
deserializeAsset,
|
|
263
|
+
deserializeResource,
|
|
264
|
+
deserializeComponent,
|
|
265
|
+
deserializeModule,
|
|
266
|
+
deserializeEntity,
|
|
267
|
+
readCommonBase,
|
|
268
|
+
} from './nft/deserializers'
|
|
269
|
+
export type {
|
|
270
|
+
NFTCargoItem,
|
|
271
|
+
NFTModuleSlot,
|
|
272
|
+
NFTInstalledModule,
|
|
273
|
+
NFTCommonBase,
|
|
274
|
+
} from './nft/deserializers'
|
|
275
|
+
|
|
276
|
+
export {
|
|
277
|
+
buildEntityDescription,
|
|
278
|
+
formatModuleLine,
|
|
279
|
+
entityDisplayName,
|
|
280
|
+
moduleDisplayName,
|
|
281
|
+
computeBaseHullmass,
|
|
282
|
+
computeBaseCapacityShip,
|
|
283
|
+
computeBaseCapacityWarehouse,
|
|
284
|
+
computeEngineThrust,
|
|
285
|
+
computeEngineDrain,
|
|
286
|
+
computeGeneratorCap,
|
|
287
|
+
computeGeneratorRech,
|
|
288
|
+
computeExtractorRate,
|
|
289
|
+
computeExtractorDrain,
|
|
290
|
+
computeExtractorDepth,
|
|
291
|
+
computeExtractorDrill,
|
|
292
|
+
computeLoaderMass,
|
|
293
|
+
computeLoaderThrust,
|
|
294
|
+
computeCrafterSpeed,
|
|
295
|
+
computeCrafterDrain,
|
|
296
|
+
} from './nft/description'
|
|
297
|
+
|
|
298
|
+
export {getEntitySlotLayout} from './data/recipes'
|
|
299
|
+
export {
|
|
300
|
+
ITEM_TYPE_RESOURCE,
|
|
301
|
+
ITEM_TYPE_COMPONENT,
|
|
302
|
+
ITEM_TYPE_MODULE,
|
|
303
|
+
ITEM_TYPE_ENTITY,
|
|
304
|
+
itemTypeCode,
|
|
305
|
+
} from './data/tiers'
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {Action, Int64, Name, NameType, UInt16, UInt32, UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
2
|
+
import {BaseManager} from './base'
|
|
3
|
+
import {CoordinatesType, EntityType, EntityTypeName} from '../types'
|
|
4
|
+
import {ServerContract} from '../contracts'
|
|
5
|
+
|
|
6
|
+
export type EntityRefInput = {
|
|
7
|
+
entityType: EntityTypeName
|
|
8
|
+
entityId: UInt64Type
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class ActionsManager extends BaseManager {
|
|
12
|
+
travel(shipId: UInt64Type, destination: CoordinatesType, recharge = true): Action {
|
|
13
|
+
const x = Int64.from(destination.x)
|
|
14
|
+
const y = Int64.from(destination.y)
|
|
15
|
+
|
|
16
|
+
return this.server.action('travel', {
|
|
17
|
+
entity_type: EntityType.SHIP,
|
|
18
|
+
id: UInt64.from(shipId),
|
|
19
|
+
x,
|
|
20
|
+
y,
|
|
21
|
+
recharge,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
grouptravel(entities: EntityRefInput[], destination: CoordinatesType, recharge = true): Action {
|
|
26
|
+
const entityRefs = entities.map((e) =>
|
|
27
|
+
ServerContract.Types.entity_ref.from({
|
|
28
|
+
entity_type: e.entityType,
|
|
29
|
+
entity_id: UInt64.from(e.entityId),
|
|
30
|
+
})
|
|
31
|
+
)
|
|
32
|
+
const x = Int64.from(destination.x)
|
|
33
|
+
const y = Int64.from(destination.y)
|
|
34
|
+
|
|
35
|
+
return this.server.action('grouptravel', {
|
|
36
|
+
entities: entityRefs,
|
|
37
|
+
x,
|
|
38
|
+
y,
|
|
39
|
+
recharge,
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
resolve(entityId: UInt64Type, entityType: EntityTypeName = EntityType.SHIP): Action {
|
|
44
|
+
return this.server.action('resolve', {
|
|
45
|
+
entity_type: entityType,
|
|
46
|
+
id: UInt64.from(entityId),
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
cancel(
|
|
51
|
+
entityId: UInt64Type,
|
|
52
|
+
count: UInt64Type,
|
|
53
|
+
entityType: EntityTypeName = EntityType.SHIP
|
|
54
|
+
): Action {
|
|
55
|
+
return this.server.action('cancel', {
|
|
56
|
+
entity_type: entityType,
|
|
57
|
+
id: UInt64.from(entityId),
|
|
58
|
+
count: UInt64.from(count),
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
recharge(shipId: UInt64Type): Action {
|
|
63
|
+
return this.server.action('recharge', {
|
|
64
|
+
entity_type: EntityType.SHIP,
|
|
65
|
+
id: UInt64.from(shipId),
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
transfer(
|
|
70
|
+
sourceType: EntityTypeName,
|
|
71
|
+
sourceId: UInt64Type,
|
|
72
|
+
destType: EntityTypeName,
|
|
73
|
+
destId: UInt64Type,
|
|
74
|
+
goodId: UInt64Type,
|
|
75
|
+
quantity: UInt64Type
|
|
76
|
+
): Action {
|
|
77
|
+
return this.server.action('transfer', {
|
|
78
|
+
source_type: sourceType,
|
|
79
|
+
source_id: UInt64.from(sourceId),
|
|
80
|
+
dest_type: destType,
|
|
81
|
+
dest_id: UInt64.from(destId),
|
|
82
|
+
item_id: UInt16.from(goodId),
|
|
83
|
+
quantity: UInt32.from(quantity),
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
foundCompany(account: NameType, name: string): Action {
|
|
88
|
+
return this.platform.action('foundcompany', {
|
|
89
|
+
account: Name.from(account),
|
|
90
|
+
name,
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
join(account: NameType): Action {
|
|
95
|
+
return this.server.action('join', {
|
|
96
|
+
account: Name.from(account),
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
extract(shipId: UInt64Type): Action {
|
|
101
|
+
return this.server.action('extract', {
|
|
102
|
+
ship_id: UInt64.from(shipId),
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
warp(shipId: UInt64Type, destination: CoordinatesType): Action {
|
|
107
|
+
const x = Int64.from(destination.x)
|
|
108
|
+
const y = Int64.from(destination.y)
|
|
109
|
+
|
|
110
|
+
return this.server.action('warp', {
|
|
111
|
+
entity_type: EntityType.SHIP,
|
|
112
|
+
id: UInt64.from(shipId),
|
|
113
|
+
x,
|
|
114
|
+
y,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
craft(
|
|
119
|
+
entityType: EntityTypeName,
|
|
120
|
+
entityId: UInt64Type,
|
|
121
|
+
recipeId: number,
|
|
122
|
+
quantity: number,
|
|
123
|
+
inputs: ServerContract.ActionParams.Type.cargo_item[]
|
|
124
|
+
): Action {
|
|
125
|
+
const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
|
|
126
|
+
return this.server.action('craft', {
|
|
127
|
+
entity_type: entityType,
|
|
128
|
+
id: UInt64.from(entityId),
|
|
129
|
+
recipe_id: UInt16.from(recipeId),
|
|
130
|
+
quantity: UInt32.from(quantity),
|
|
131
|
+
inputs: cargoInputs,
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
blend(
|
|
136
|
+
entityType: EntityTypeName,
|
|
137
|
+
entityId: UInt64Type,
|
|
138
|
+
inputs: ServerContract.ActionParams.Type.cargo_item[]
|
|
139
|
+
): Action {
|
|
140
|
+
const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
|
|
141
|
+
return this.server.action('blend', {
|
|
142
|
+
entity_type: entityType,
|
|
143
|
+
id: UInt64.from(entityId),
|
|
144
|
+
inputs: cargoInputs,
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
deploy(
|
|
149
|
+
entityType: EntityTypeName,
|
|
150
|
+
entityId: UInt64Type,
|
|
151
|
+
packedItemId: number,
|
|
152
|
+
seed: bigint,
|
|
153
|
+
entityName: string
|
|
154
|
+
): Action {
|
|
155
|
+
return this.server.action('deploy', {
|
|
156
|
+
entity_type: entityType,
|
|
157
|
+
id: UInt64.from(entityId),
|
|
158
|
+
packed_item_id: UInt16.from(packedItemId),
|
|
159
|
+
seed: UInt64.from(seed),
|
|
160
|
+
entity_name: entityName,
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
addmodule(
|
|
165
|
+
entityType: EntityTypeName,
|
|
166
|
+
entityId: UInt64Type,
|
|
167
|
+
moduleIndex: number,
|
|
168
|
+
moduleCargoId: UInt64Type,
|
|
169
|
+
targetCargoId: UInt64Type = UInt64.from(0)
|
|
170
|
+
): Action {
|
|
171
|
+
return this.server.action('addmodule', {
|
|
172
|
+
entity_type: entityType,
|
|
173
|
+
entity_id: UInt64.from(entityId),
|
|
174
|
+
module_index: moduleIndex,
|
|
175
|
+
module_cargo_id: UInt64.from(moduleCargoId),
|
|
176
|
+
target_cargo_id: UInt64.from(targetCargoId),
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
rmmodule(
|
|
181
|
+
entityType: EntityTypeName,
|
|
182
|
+
entityId: UInt64Type,
|
|
183
|
+
moduleIndex: number,
|
|
184
|
+
targetCargoId: UInt64Type = UInt64.from(0)
|
|
185
|
+
): Action {
|
|
186
|
+
return this.server.action('rmmodule', {
|
|
187
|
+
entity_type: entityType,
|
|
188
|
+
entity_id: UInt64.from(entityId),
|
|
189
|
+
module_index: moduleIndex,
|
|
190
|
+
target_cargo_id: UInt64.from(targetCargoId),
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
joinGame(account: NameType, companyName: string): Action[] {
|
|
195
|
+
return [this.foundCompany(account, companyName), this.join(account)]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {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,95 @@
|
|
|
1
|
+
import {APIClient} from '@wharfkit/antelope'
|
|
2
|
+
import {Contract} from '@wharfkit/contract'
|
|
3
|
+
import {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
|
+
|
|
12
|
+
export class GameContext {
|
|
13
|
+
private _entities?: EntitiesManager
|
|
14
|
+
private _players?: PlayersManager
|
|
15
|
+
private _locations?: LocationsManager
|
|
16
|
+
private _epochs?: EpochsManager
|
|
17
|
+
private _actions?: ActionsManager
|
|
18
|
+
|
|
19
|
+
private _gameCache?: PlatformContract.Types.game_row
|
|
20
|
+
private _stateCache?: GameState
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
public readonly client: APIClient,
|
|
24
|
+
public readonly server: Contract,
|
|
25
|
+
public readonly platform: Contract
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
get entities(): EntitiesManager {
|
|
29
|
+
if (!this._entities) {
|
|
30
|
+
this._entities = new EntitiesManager(this)
|
|
31
|
+
}
|
|
32
|
+
return this._entities
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get players(): PlayersManager {
|
|
36
|
+
if (!this._players) {
|
|
37
|
+
this._players = new PlayersManager(this)
|
|
38
|
+
}
|
|
39
|
+
return this._players
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get locations(): LocationsManager {
|
|
43
|
+
if (!this._locations) {
|
|
44
|
+
this._locations = new LocationsManager(this)
|
|
45
|
+
}
|
|
46
|
+
return this._locations
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get epochs(): EpochsManager {
|
|
50
|
+
if (!this._epochs) {
|
|
51
|
+
this._epochs = new EpochsManager(this)
|
|
52
|
+
}
|
|
53
|
+
return this._epochs
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get actions(): ActionsManager {
|
|
57
|
+
if (!this._actions) {
|
|
58
|
+
this._actions = new ActionsManager(this)
|
|
59
|
+
}
|
|
60
|
+
return this._actions
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async getGame(reload = false): Promise<PlatformContract.Types.game_row> {
|
|
64
|
+
if (!reload && this._gameCache) {
|
|
65
|
+
return this._gameCache
|
|
66
|
+
}
|
|
67
|
+
const game = await this.platform.table('games').get()
|
|
68
|
+
if (!game) {
|
|
69
|
+
throw new Error('Game not initialized')
|
|
70
|
+
}
|
|
71
|
+
this._gameCache = game
|
|
72
|
+
return game
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getState(reload = false): Promise<GameState> {
|
|
76
|
+
if (!reload && this._stateCache) {
|
|
77
|
+
return this._stateCache
|
|
78
|
+
}
|
|
79
|
+
const state = await this.server.table('state').get()
|
|
80
|
+
if (!state) {
|
|
81
|
+
throw new Error('Game state not initialized')
|
|
82
|
+
}
|
|
83
|
+
const game = this._gameCache
|
|
84
|
+
this._stateCache = GameState.from(state, game)
|
|
85
|
+
return this._stateCache
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
get cachedGame(): PlatformContract.Types.game_row | undefined {
|
|
89
|
+
return this._gameCache
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get cachedState(): GameState | undefined {
|
|
93
|
+
return this._stateCache
|
|
94
|
+
}
|
|
95
|
+
}
|