@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
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {Name, NameType, UInt64Type} from '@wharfkit/antelope'
|
|
2
|
+
import {BaseManager} from './base'
|
|
3
|
+
import {Ship} from '../entities/ship'
|
|
4
|
+
import {Warehouse} from '../entities/warehouse'
|
|
5
|
+
import {Container} from '../entities/container'
|
|
6
|
+
import {ServerContract} from '../contracts'
|
|
7
|
+
|
|
8
|
+
export type EntityType = 'ship' | 'warehouse' | 'container' | 'location'
|
|
9
|
+
|
|
10
|
+
export class EntitiesManager extends BaseManager {
|
|
11
|
+
async getEntity(type: EntityType, id: UInt64Type): Promise<Ship | Warehouse | Container> {
|
|
12
|
+
const result = await this.server.readonly('getentity', {
|
|
13
|
+
entity_type: Name.from(type),
|
|
14
|
+
entity_id: id,
|
|
15
|
+
})
|
|
16
|
+
const entityInfo = result as ServerContract.Types.entity_info
|
|
17
|
+
return this.wrapEntity(entityInfo)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getEntities(
|
|
21
|
+
owner: NameType | ServerContract.Types.player_row,
|
|
22
|
+
type?: EntityType
|
|
23
|
+
): Promise<(Ship | Warehouse | Container)[]> {
|
|
24
|
+
const ownerName = this.resolveOwner(owner)
|
|
25
|
+
const result = await this.server.readonly('getentities', {
|
|
26
|
+
owner: ownerName,
|
|
27
|
+
entity_type: type ? Name.from(type) : null,
|
|
28
|
+
})
|
|
29
|
+
const entities = result as ServerContract.Types.entity_info[]
|
|
30
|
+
return entities.map((entity) => this.wrapEntity(entity))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getSummaries(
|
|
34
|
+
owner: NameType | ServerContract.Types.player_row,
|
|
35
|
+
type?: EntityType
|
|
36
|
+
): Promise<ServerContract.Types.entity_summary[]> {
|
|
37
|
+
const ownerName = this.resolveOwner(owner)
|
|
38
|
+
const result = await this.server.readonly('getsummaries', {
|
|
39
|
+
owner: ownerName,
|
|
40
|
+
entity_type: type ? Name.from(type) : null,
|
|
41
|
+
})
|
|
42
|
+
return result as ServerContract.Types.entity_summary[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async getShip(id: UInt64Type): Promise<Ship> {
|
|
46
|
+
return (await this.getEntity('ship', id)) as Ship
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async getWarehouse(id: UInt64Type): Promise<Warehouse> {
|
|
50
|
+
return (await this.getEntity('warehouse', id)) as Warehouse
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async getContainer(id: UInt64Type): Promise<Container> {
|
|
54
|
+
return (await this.getEntity('container', id)) as Container
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async getShips(owner: NameType | ServerContract.Types.player_row): Promise<Ship[]> {
|
|
58
|
+
return (await this.getEntities(owner, 'ship')) as Ship[]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getWarehouses(owner: NameType | ServerContract.Types.player_row): Promise<Warehouse[]> {
|
|
62
|
+
return (await this.getEntities(owner, 'warehouse')) as Warehouse[]
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getContainers(owner: NameType | ServerContract.Types.player_row): Promise<Container[]> {
|
|
66
|
+
return (await this.getEntities(owner, 'container')) as Container[]
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getShipSummaries(
|
|
70
|
+
owner: NameType | ServerContract.Types.player_row
|
|
71
|
+
): Promise<ServerContract.Types.entity_summary[]> {
|
|
72
|
+
return this.getSummaries(owner, 'ship')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getWarehouseSummaries(
|
|
76
|
+
owner: NameType | ServerContract.Types.player_row
|
|
77
|
+
): Promise<ServerContract.Types.entity_summary[]> {
|
|
78
|
+
return this.getSummaries(owner, 'warehouse')
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async getContainerSummaries(
|
|
82
|
+
owner: NameType | ServerContract.Types.player_row
|
|
83
|
+
): Promise<ServerContract.Types.entity_summary[]> {
|
|
84
|
+
return this.getSummaries(owner, 'container')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private wrapEntity(entity: ServerContract.Types.entity_info): Ship | Warehouse | Container {
|
|
88
|
+
if (entity.type.equals('ship')) {
|
|
89
|
+
return new Ship(entity)
|
|
90
|
+
} else if (entity.type.equals('warehouse')) {
|
|
91
|
+
return new Warehouse(entity)
|
|
92
|
+
} else {
|
|
93
|
+
return new Container(entity)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private resolveOwner(owner: NameType | ServerContract.Types.player_row): Name {
|
|
98
|
+
if (typeof owner === 'object' && owner !== null && 'owner' in owner) {
|
|
99
|
+
return owner.owner
|
|
100
|
+
}
|
|
101
|
+
return Name.from(owner)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
2
|
+
import {BaseManager} from './base'
|
|
3
|
+
import {EpochInfo, getCurrentEpoch, getEpochInfo} from '../scheduling/epoch'
|
|
4
|
+
|
|
5
|
+
export class EpochsManager extends BaseManager {
|
|
6
|
+
async getCurrentHeight(): Promise<UInt64> {
|
|
7
|
+
const game = await this.getGame()
|
|
8
|
+
return getCurrentEpoch(game)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async getCurrent(): Promise<EpochInfo> {
|
|
12
|
+
const game = await this.getGame()
|
|
13
|
+
const epoch = await this.getCurrentHeight()
|
|
14
|
+
return getEpochInfo(game, epoch)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getByHeight(height: UInt64Type): Promise<EpochInfo> {
|
|
18
|
+
const game = await this.getGame()
|
|
19
|
+
return getEpochInfo(game, UInt64.from(height))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getTimeRemaining(): Promise<number> {
|
|
23
|
+
const epochInfo = await this.getCurrent()
|
|
24
|
+
const now = Date.now()
|
|
25
|
+
const endTime = epochInfo.end.getTime()
|
|
26
|
+
return Math.max(0, endTime - now)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getProgress(): Promise<number> {
|
|
30
|
+
const epochInfo = await this.getCurrent()
|
|
31
|
+
const now = Date.now()
|
|
32
|
+
const startTime = epochInfo.start.getTime()
|
|
33
|
+
const endTime = epochInfo.end.getTime()
|
|
34
|
+
const duration = endTime - startTime
|
|
35
|
+
const elapsed = now - startTime
|
|
36
|
+
|
|
37
|
+
if (elapsed <= 0) return 0
|
|
38
|
+
if (elapsed >= duration) return 1
|
|
39
|
+
|
|
40
|
+
return elapsed / duration
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async fitsInCurrentEpoch(durationMs: number): Promise<boolean> {
|
|
44
|
+
const remaining = await this.getTimeRemaining()
|
|
45
|
+
return durationMs <= remaining
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export {GameContext} from './context'
|
|
2
|
+
export {BaseManager} from './base'
|
|
3
|
+
export {EntitiesManager} from './entities'
|
|
4
|
+
export type {EntityType} from './entities'
|
|
5
|
+
export {PlayersManager} from './players'
|
|
6
|
+
export {LocationsManager} from './locations'
|
|
7
|
+
export {EpochsManager} from './epochs'
|
|
8
|
+
export {ActionsManager} from './actions'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {UInt16Type, UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
2
|
+
import {BaseManager} from './base'
|
|
3
|
+
import {CoordinatesType, coordsToLocationId, Distance} from '../types'
|
|
4
|
+
import {hasSystem} from '../utils/system'
|
|
5
|
+
import {findNearbyPlanets} from '../travel/travel'
|
|
6
|
+
import {ServerContract} from '../contracts'
|
|
7
|
+
|
|
8
|
+
export class LocationsManager extends BaseManager {
|
|
9
|
+
async hasSystem(location: CoordinatesType): Promise<boolean> {
|
|
10
|
+
const game = await this.getGame()
|
|
11
|
+
return hasSystem(game.config.seed, location)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async findNearbyPlanets(
|
|
15
|
+
origin: CoordinatesType,
|
|
16
|
+
maxDistance: UInt16Type = 20
|
|
17
|
+
): Promise<Distance[]> {
|
|
18
|
+
const game = await this.getGame()
|
|
19
|
+
return findNearbyPlanets(game.config.seed, origin, maxDistance)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getLocationEntity(
|
|
23
|
+
id: UInt64Type
|
|
24
|
+
): Promise<ServerContract.Types.location_row | undefined> {
|
|
25
|
+
const row = await this.server.table('location').get(UInt64.from(id))
|
|
26
|
+
return row ?? undefined
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getLocationEntityAt(
|
|
30
|
+
coords: CoordinatesType
|
|
31
|
+
): Promise<ServerContract.Types.location_row | undefined> {
|
|
32
|
+
const id = coordsToLocationId(coords)
|
|
33
|
+
return this.getLocationEntity(id)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getAllLocationEntities(): Promise<ServerContract.Types.location_row[]> {
|
|
37
|
+
return this.server.table('location').all()
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {Name, NameType} from '@wharfkit/antelope'
|
|
2
|
+
import {BaseManager} from './base'
|
|
3
|
+
import {Player} from '../entities/player'
|
|
4
|
+
|
|
5
|
+
export class PlayersManager extends BaseManager {
|
|
6
|
+
async getPlayer(account: NameType): Promise<Player | undefined> {
|
|
7
|
+
const playerRow = await this.server.table('player').get(Name.from(account))
|
|
8
|
+
if (!playerRow) {
|
|
9
|
+
return undefined
|
|
10
|
+
}
|
|
11
|
+
return new Player(playerRow)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {UInt16, UInt16Type} from '@wharfkit/antelope'
|
|
2
|
+
import {Item} from '../types'
|
|
3
|
+
import itemsData from '../data/items.json'
|
|
4
|
+
|
|
5
|
+
const items: Item[] = itemsData.map((g) =>
|
|
6
|
+
Item.from({
|
|
7
|
+
id: g.id,
|
|
8
|
+
name: g.name,
|
|
9
|
+
description: g.description,
|
|
10
|
+
mass: g.mass,
|
|
11
|
+
category: g.category,
|
|
12
|
+
tier: g.tier,
|
|
13
|
+
color: g.color,
|
|
14
|
+
})
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
export const itemIds = items.map((i) => i.id)
|
|
18
|
+
|
|
19
|
+
export function getItem(itemId: UInt16Type): Item {
|
|
20
|
+
const id = UInt16.from(itemId)
|
|
21
|
+
const item = items.find((i) => i.id.equals(id))
|
|
22
|
+
if (!item) {
|
|
23
|
+
throw new Error(`Item with id ${id} not found`)
|
|
24
|
+
}
|
|
25
|
+
return item
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getItems(): Item[] {
|
|
29
|
+
return items
|
|
30
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getModuleCapabilityType,
|
|
3
|
+
ITEM_ENGINE_T1,
|
|
4
|
+
ITEM_EXTRACTOR_T1,
|
|
5
|
+
ITEM_GENERATOR_T1,
|
|
6
|
+
ITEM_LOADER_T1,
|
|
7
|
+
ITEM_MANUFACTURING_T1,
|
|
8
|
+
ITEM_STORAGE_T1,
|
|
9
|
+
MODULE_CRAFTER,
|
|
10
|
+
MODULE_ENGINE,
|
|
11
|
+
MODULE_EXTRACTOR,
|
|
12
|
+
MODULE_GENERATOR,
|
|
13
|
+
MODULE_LOADER,
|
|
14
|
+
MODULE_STORAGE,
|
|
15
|
+
} from '../capabilities/modules'
|
|
16
|
+
import {
|
|
17
|
+
ITEM_CONTAINER_T1_PACKED,
|
|
18
|
+
ITEM_CONTAINER_T2_PACKED,
|
|
19
|
+
ITEM_SHIP_T1_PACKED,
|
|
20
|
+
ITEM_WAREHOUSE_T1_PACKED,
|
|
21
|
+
} from '../data/recipes'
|
|
22
|
+
import {decodeStat} from '../derivation/crafting'
|
|
23
|
+
|
|
24
|
+
function idiv(a: number, b: number): number {
|
|
25
|
+
return Math.floor(a / b)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function computeBaseHullmass(seed: bigint): number {
|
|
29
|
+
const density = decodeStat(seed, 1)
|
|
30
|
+
return 25000 + 75 * density
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function computeBaseCapacityShip(seed: bigint): number {
|
|
34
|
+
const s = decodeStat(seed, 0) + decodeStat(seed, 2) + decodeStat(seed, 3)
|
|
35
|
+
return Math.floor(1_000_000 * Math.pow(10, s / 2997))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function computeBaseCapacityWarehouse(seed: bigint): number {
|
|
39
|
+
const s = decodeStat(seed, 0) + decodeStat(seed, 2) + decodeStat(seed, 3)
|
|
40
|
+
return Math.floor(20_000_000 * Math.pow(10, s / 2997))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const computeEngineThrust = (vol: number): number => 400 + idiv(vol * 3, 4)
|
|
44
|
+
export const computeEngineDrain = (thm: number): number => Math.max(30, 50 - idiv(thm, 70))
|
|
45
|
+
export const computeGeneratorCap = (res: number): number => 300 + idiv(res, 6)
|
|
46
|
+
export const computeGeneratorRech = (clr: number): number => 5 + idiv(clr * 15, 1000)
|
|
47
|
+
export const computeExtractorRate = (str: number): number => 200 + str
|
|
48
|
+
export const computeExtractorDrain = (con: number): number => Math.max(10, 50 - idiv(con, 20))
|
|
49
|
+
export const computeExtractorDepth = (tol: number): number => 200 + idiv(tol * 3, 2)
|
|
50
|
+
export const computeExtractorDrill = (ref: number): number => 100 + idiv(ref * 4, 5)
|
|
51
|
+
export const computeLoaderMass = (duc: number): number => Math.max(200, 2000 - duc * 2)
|
|
52
|
+
export const computeLoaderThrust = (pla: number): number => 1 + idiv(pla, 500)
|
|
53
|
+
export const computeCrafterSpeed = (rea: number): number => 100 + idiv(rea * 4, 5)
|
|
54
|
+
export const computeCrafterDrain = (clr: number): number => Math.max(5, 30 - idiv(clr, 33))
|
|
55
|
+
|
|
56
|
+
export function entityDisplayName(itemId: number): string {
|
|
57
|
+
switch (itemId) {
|
|
58
|
+
case ITEM_SHIP_T1_PACKED:
|
|
59
|
+
return 'Ship T1'
|
|
60
|
+
case ITEM_WAREHOUSE_T1_PACKED:
|
|
61
|
+
return 'Warehouse T1'
|
|
62
|
+
case ITEM_CONTAINER_T1_PACKED:
|
|
63
|
+
return 'Container T1'
|
|
64
|
+
case ITEM_CONTAINER_T2_PACKED:
|
|
65
|
+
return 'Container T2'
|
|
66
|
+
default:
|
|
67
|
+
return 'Entity'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function moduleDisplayName(itemId: number): string {
|
|
72
|
+
switch (itemId) {
|
|
73
|
+
case ITEM_ENGINE_T1:
|
|
74
|
+
return 'Engine T1'
|
|
75
|
+
case ITEM_GENERATOR_T1:
|
|
76
|
+
return 'Generator T1'
|
|
77
|
+
case ITEM_EXTRACTOR_T1:
|
|
78
|
+
return 'Extractor T1'
|
|
79
|
+
case ITEM_LOADER_T1:
|
|
80
|
+
return 'Loader T1'
|
|
81
|
+
case ITEM_MANUFACTURING_T1:
|
|
82
|
+
return 'Manufacturing T1'
|
|
83
|
+
case ITEM_STORAGE_T1:
|
|
84
|
+
return 'Storage T1'
|
|
85
|
+
default:
|
|
86
|
+
return 'Module'
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function formatModuleLine(slot: number, itemId: number, seed: bigint): string {
|
|
91
|
+
let out = `Slot ${slot} - `
|
|
92
|
+
if (itemId === 0) {
|
|
93
|
+
out += '(empty)'
|
|
94
|
+
return out
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
out += moduleDisplayName(itemId)
|
|
98
|
+
const subtype = getModuleCapabilityType(itemId)
|
|
99
|
+
|
|
100
|
+
switch (subtype) {
|
|
101
|
+
case MODULE_ENGINE: {
|
|
102
|
+
const vol = decodeStat(seed, 0)
|
|
103
|
+
const thm = decodeStat(seed, 1)
|
|
104
|
+
out += ` Thrust ${computeEngineThrust(vol)} Drain ${computeEngineDrain(thm)}`
|
|
105
|
+
break
|
|
106
|
+
}
|
|
107
|
+
case MODULE_GENERATOR: {
|
|
108
|
+
const res = decodeStat(seed, 0)
|
|
109
|
+
const clr = decodeStat(seed, 1)
|
|
110
|
+
out += ` Capacity ${computeGeneratorCap(res)} Recharge ${computeGeneratorRech(clr)}`
|
|
111
|
+
break
|
|
112
|
+
}
|
|
113
|
+
case MODULE_EXTRACTOR: {
|
|
114
|
+
const str = decodeStat(seed, 0)
|
|
115
|
+
const tol = decodeStat(seed, 1)
|
|
116
|
+
const con = decodeStat(seed, 3)
|
|
117
|
+
const ref = decodeStat(seed, 4)
|
|
118
|
+
out += ` Rate ${computeExtractorRate(str)} Depth ${computeExtractorDepth(
|
|
119
|
+
tol
|
|
120
|
+
)} Drill ${computeExtractorDrill(ref)} Drain ${computeExtractorDrain(con)}`
|
|
121
|
+
break
|
|
122
|
+
}
|
|
123
|
+
case MODULE_LOADER: {
|
|
124
|
+
const duc = decodeStat(seed, 0)
|
|
125
|
+
const pla = decodeStat(seed, 1)
|
|
126
|
+
out += ` Mass ${computeLoaderMass(duc)} Thrust ${computeLoaderThrust(pla)}`
|
|
127
|
+
break
|
|
128
|
+
}
|
|
129
|
+
case MODULE_CRAFTER: {
|
|
130
|
+
const rea = decodeStat(seed, 0)
|
|
131
|
+
const clr = decodeStat(seed, 1)
|
|
132
|
+
out += ` Speed ${computeCrafterSpeed(rea)} Drain ${computeCrafterDrain(clr)}`
|
|
133
|
+
break
|
|
134
|
+
}
|
|
135
|
+
case MODULE_STORAGE: {
|
|
136
|
+
const str = decodeStat(seed, 0)
|
|
137
|
+
const duc = decodeStat(seed, 1)
|
|
138
|
+
const pur = decodeStat(seed, 2)
|
|
139
|
+
const sum = str + duc + pur
|
|
140
|
+
const pct = 10 + idiv(sum * 10, 2997)
|
|
141
|
+
out += ` +${pct}% capacity`
|
|
142
|
+
break
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return out
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function buildEntityDescription(
|
|
149
|
+
itemId: number,
|
|
150
|
+
hullSeed: bigint,
|
|
151
|
+
moduleItems: number[],
|
|
152
|
+
moduleSeeds: bigint[]
|
|
153
|
+
): string {
|
|
154
|
+
const hullMass = computeBaseHullmass(hullSeed)
|
|
155
|
+
let baseCapacity = 0
|
|
156
|
+
if (itemId === ITEM_SHIP_T1_PACKED) {
|
|
157
|
+
baseCapacity = computeBaseCapacityShip(hullSeed)
|
|
158
|
+
} else if (itemId === ITEM_WAREHOUSE_T1_PACKED) {
|
|
159
|
+
baseCapacity = computeBaseCapacityWarehouse(hullSeed)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let out = entityDisplayName(itemId)
|
|
163
|
+
out += ` - Hull ${hullMass} mass`
|
|
164
|
+
if (baseCapacity > 0) {
|
|
165
|
+
out += ` * ${baseCapacity} capacity`
|
|
166
|
+
}
|
|
167
|
+
out += '\n\n'
|
|
168
|
+
|
|
169
|
+
for (let i = 0; i < moduleItems.length; i++) {
|
|
170
|
+
out += formatModuleLine(i, moduleItems[i], moduleSeeds[i] ?? 0n)
|
|
171
|
+
out += '\n'
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return out
|
|
175
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {getEntitySlotLayout} from '../data/recipes'
|
|
2
|
+
import {
|
|
3
|
+
ITEM_TYPE_COMPONENT,
|
|
4
|
+
ITEM_TYPE_ENTITY,
|
|
5
|
+
ITEM_TYPE_MODULE,
|
|
6
|
+
ITEM_TYPE_RESOURCE,
|
|
7
|
+
itemTypeCode,
|
|
8
|
+
} from '../data/tiers'
|
|
9
|
+
|
|
10
|
+
export interface NFTInstalledModule {
|
|
11
|
+
item_id: number
|
|
12
|
+
seed: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NFTModuleSlot {
|
|
16
|
+
type: number
|
|
17
|
+
installed?: NFTInstalledModule
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface NFTCargoItem {
|
|
21
|
+
item_id: number
|
|
22
|
+
quantity: number
|
|
23
|
+
seed: string
|
|
24
|
+
modules?: NFTModuleSlot[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface NFTCommonBase {
|
|
28
|
+
quantity: number
|
|
29
|
+
seed: string
|
|
30
|
+
origin_x: string
|
|
31
|
+
origin_y: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function readCommonBase(data: Record<string, any>): NFTCommonBase {
|
|
35
|
+
return {
|
|
36
|
+
quantity: Number(data.quantity),
|
|
37
|
+
seed: String(data.seed),
|
|
38
|
+
origin_x: String(data.origin_x),
|
|
39
|
+
origin_y: String(data.origin_y),
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function deserializeScalar(data: Record<string, any>, itemId: number): NFTCargoItem {
|
|
44
|
+
const base = readCommonBase(data)
|
|
45
|
+
return {item_id: itemId, quantity: base.quantity, seed: base.seed}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const deserializeResource = deserializeScalar
|
|
49
|
+
export const deserializeComponent = deserializeScalar
|
|
50
|
+
export const deserializeModule = deserializeScalar
|
|
51
|
+
|
|
52
|
+
export function deserializeEntity(data: Record<string, any>, itemId: number): NFTCargoItem {
|
|
53
|
+
const base = readCommonBase(data)
|
|
54
|
+
const moduleItems: number[] = (data.module_items ?? []).map((v: any) => Number(v))
|
|
55
|
+
const moduleSeeds: string[] = (data.module_seeds ?? []).map((v: any) => String(v))
|
|
56
|
+
const layout = getEntitySlotLayout(itemId)
|
|
57
|
+
|
|
58
|
+
const modules: NFTModuleSlot[] = layout.map((slot, i) => ({
|
|
59
|
+
type: slot.type,
|
|
60
|
+
installed:
|
|
61
|
+
moduleItems[i] && moduleItems[i] !== 0
|
|
62
|
+
? {item_id: moduleItems[i], seed: moduleSeeds[i]}
|
|
63
|
+
: undefined,
|
|
64
|
+
}))
|
|
65
|
+
|
|
66
|
+
return {item_id: itemId, quantity: base.quantity, seed: base.seed, modules}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function deserializeAsset(data: Record<string, any>, itemId: number): NFTCargoItem {
|
|
70
|
+
const type = itemTypeCode(itemId)
|
|
71
|
+
switch (type) {
|
|
72
|
+
case ITEM_TYPE_RESOURCE:
|
|
73
|
+
case ITEM_TYPE_COMPONENT:
|
|
74
|
+
case ITEM_TYPE_MODULE:
|
|
75
|
+
return deserializeScalar(data, itemId)
|
|
76
|
+
case ITEM_TYPE_ENTITY:
|
|
77
|
+
return deserializeEntity(data, itemId)
|
|
78
|
+
default:
|
|
79
|
+
throw new Error(`unknown item type ${type} for item ${itemId}`)
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/nft/index.ts
ADDED