@shipload/sdk 2.0.0-rc1 → 2.0.0-rc3
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/README.md +349 -1
- package/lib/shipload.d.ts +809 -314
- package/lib/shipload.js +2745 -1740
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +2158 -1154
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -2
- package/src/capabilities/extraction.ts +30 -0
- package/src/capabilities/guards.ts +43 -0
- package/src/capabilities/index.ts +5 -0
- package/src/capabilities/loading.ts +8 -0
- package/src/capabilities/movement.ts +29 -0
- package/src/capabilities/storage.ts +67 -0
- package/src/contracts/server.ts +506 -183
- package/src/data/items.json +16 -0
- package/src/derivation/index.ts +25 -0
- package/src/derivation/location-size.ts +15 -0
- package/src/derivation/resources.ts +141 -0
- package/src/derivation/stratum.ts +116 -0
- package/src/entities/cargo-utils.ts +98 -3
- package/src/entities/container.ts +70 -0
- package/src/entities/entity-inventory.ts +13 -9
- package/src/entities/inventory-accessor.ts +46 -0
- package/src/entities/location.ts +31 -17
- package/src/entities/makers.ts +69 -0
- package/src/entities/player.ts +2 -1
- package/src/entities/ship.ts +93 -440
- package/src/entities/warehouse.ts +29 -145
- package/src/errors.ts +4 -4
- package/src/index-module.ts +62 -4
- package/src/managers/actions.ts +75 -31
- package/src/managers/entities.ts +22 -5
- package/src/managers/locations.ts +34 -15
- package/src/managers/trades.ts +7 -7
- package/src/market/items.ts +31 -0
- package/src/market/market.ts +12 -13
- package/src/scheduling/accessor.ts +82 -0
- package/src/scheduling/projection.ts +126 -54
- package/src/scheduling/schedule.ts +24 -0
- package/src/trading/collect.ts +25 -26
- package/src/trading/deal.ts +8 -9
- package/src/trading/trade.ts +9 -9
- package/src/travel/travel.ts +69 -8
- package/src/types/capabilities.ts +79 -0
- package/src/types/entity-traits.ts +70 -0
- package/src/types/entity.ts +36 -0
- package/src/types/index.ts +3 -0
- package/src/types.ts +92 -15
- package/src/utils/hash.ts +1 -1
- package/src/utils/system.ts +97 -4
- package/src/data/goods.json +0 -23
- package/src/market/goods.ts +0 -31
package/src/types.ts
CHANGED
|
@@ -1,15 +1,59 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Int64Type,
|
|
3
|
+
Name,
|
|
4
|
+
Struct,
|
|
5
|
+
UInt16,
|
|
6
|
+
UInt16Type,
|
|
7
|
+
UInt32,
|
|
8
|
+
UInt32Type,
|
|
9
|
+
UInt64,
|
|
10
|
+
} from '@wharfkit/antelope'
|
|
2
11
|
import {ServerContract} from './contracts'
|
|
3
12
|
|
|
4
13
|
export const PRECISION = 10000
|
|
5
14
|
|
|
6
|
-
|
|
15
|
+
// Ship constants
|
|
16
|
+
export const INITIAL_SHIP_GENERATOR_CAPACITY = 350
|
|
17
|
+
export const INITIAL_SHIP_DRAIN = 25
|
|
18
|
+
export const INITIAL_SHIP_ENERGY = 350
|
|
19
|
+
export const INITIAL_SHIP_HULLMASS = 100000
|
|
20
|
+
export const INITIAL_SHIP_CAPACITY = 500000
|
|
21
|
+
export const INITIAL_SHIP_Z = 800
|
|
22
|
+
export const INITIAL_SHIP_RECHARGE = 10
|
|
23
|
+
export const INITIAL_SHIP_THRUST = 250
|
|
24
|
+
|
|
25
|
+
// Loader constants
|
|
26
|
+
export const INITIAL_LOADER_MASS = 1000
|
|
27
|
+
export const INITIAL_LOADER_QUANTITY = 1
|
|
28
|
+
export const INITIAL_LOADER_THRUST = 1
|
|
29
|
+
|
|
30
|
+
// Warehouse constants
|
|
31
|
+
export const WAREHOUSE_Z = 500
|
|
32
|
+
export const INITIAL_WAREHOUSE_CAPACITY = 10000000
|
|
33
|
+
|
|
34
|
+
// Container constants
|
|
35
|
+
export const CONTAINER_Z = 300
|
|
36
|
+
export const INITIAL_CONTAINER_HULLMASS = 50000
|
|
37
|
+
export const INITIAL_CONTAINER_CAPACITY = 2000000
|
|
38
|
+
|
|
39
|
+
// Mechanics
|
|
40
|
+
export const TRAVEL_MAX_DURATION = 86400
|
|
41
|
+
|
|
42
|
+
// Altitude limits (for UI/calculations)
|
|
7
43
|
export const MIN_ORBITAL_ALTITUDE = 800
|
|
8
44
|
export const MAX_ORBITAL_ALTITUDE = 3000
|
|
9
45
|
|
|
46
|
+
// Legacy alias (deprecated, use INITIAL_SHIP_CAPACITY)
|
|
47
|
+
export const INITIAL_SHIP_MASS = 500000
|
|
48
|
+
|
|
49
|
+
// Extractor constants
|
|
50
|
+
export const INITIAL_EXTRACTOR_RATE = 700
|
|
51
|
+
export const INITIAL_EXTRACTOR_DRAIN = 2500
|
|
52
|
+
export const INITIAL_EXTRACTOR_EFFICIENCY = 5000
|
|
53
|
+
|
|
10
54
|
export interface ShipLike {
|
|
11
|
-
|
|
12
|
-
|
|
55
|
+
coordinates: ServerContract.Types.coordinates
|
|
56
|
+
hullmass: UInt32
|
|
13
57
|
energy: UInt16
|
|
14
58
|
engines: ServerContract.Types.movement_stats
|
|
15
59
|
generator: ServerContract.Types.energy_stats
|
|
@@ -18,15 +62,25 @@ export interface ShipLike {
|
|
|
18
62
|
}
|
|
19
63
|
|
|
20
64
|
export interface CargoMassInfo {
|
|
21
|
-
|
|
65
|
+
item_id: UInt16Type
|
|
22
66
|
quantity: UInt32Type
|
|
23
67
|
}
|
|
24
68
|
|
|
25
69
|
export enum TaskType {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
70
|
+
IDLE = 0,
|
|
71
|
+
TRAVEL = 1,
|
|
72
|
+
RECHARGE = 2,
|
|
73
|
+
LOAD = 3,
|
|
74
|
+
UNLOAD = 4,
|
|
75
|
+
EXTRACT = 5,
|
|
76
|
+
WARP = 6,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export enum LocationType {
|
|
80
|
+
EMPTY = 0,
|
|
81
|
+
PLANET = 1,
|
|
82
|
+
ASTEROID = 2,
|
|
83
|
+
NEBULA = 3,
|
|
30
84
|
}
|
|
31
85
|
|
|
32
86
|
export enum TaskCancelable {
|
|
@@ -38,6 +92,7 @@ export enum TaskCancelable {
|
|
|
38
92
|
export const EntityType = {
|
|
39
93
|
SHIP: Name.from('ship'),
|
|
40
94
|
WAREHOUSE: Name.from('warehouse'),
|
|
95
|
+
CONTAINER: Name.from('container'),
|
|
41
96
|
} as const
|
|
42
97
|
|
|
43
98
|
export type EntityTypeName = (typeof EntityType)[keyof typeof EntityType]
|
|
@@ -56,6 +111,19 @@ export class Coordinates extends ServerContract.Types.coordinates {
|
|
|
56
111
|
const coords = Coordinates.from(other)
|
|
57
112
|
return this.x.equals(coords.x) && this.y.equals(coords.y)
|
|
58
113
|
}
|
|
114
|
+
|
|
115
|
+
toLocationId(): UInt64 {
|
|
116
|
+
return coordsToLocationId(this)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function coordsToLocationId(coords: CoordinatesType): UInt64 {
|
|
121
|
+
const c = Coordinates.from(coords)
|
|
122
|
+
const mask = BigInt(0xffffffff)
|
|
123
|
+
const x = BigInt(c.x.toNumber()) & mask
|
|
124
|
+
const y = BigInt(c.y.toNumber()) & mask
|
|
125
|
+
const id = (x << BigInt(32)) | y
|
|
126
|
+
return UInt64.from(id)
|
|
59
127
|
}
|
|
60
128
|
|
|
61
129
|
export interface Distance {
|
|
@@ -64,8 +132,11 @@ export interface Distance {
|
|
|
64
132
|
distance: UInt16
|
|
65
133
|
}
|
|
66
134
|
|
|
67
|
-
|
|
68
|
-
export
|
|
135
|
+
export type ResourceCategory = 'metal' | 'gas' | 'mineral' | 'organic'
|
|
136
|
+
export type ResourceRarity = 'common' | 'uncommon' | 'rare' | 'epic' | 'legendary'
|
|
137
|
+
|
|
138
|
+
@Struct.type('item')
|
|
139
|
+
export class Item extends Struct {
|
|
69
140
|
@Struct.field(UInt16)
|
|
70
141
|
id!: UInt16
|
|
71
142
|
@Struct.field('string')
|
|
@@ -76,14 +147,20 @@ export class Good extends Struct {
|
|
|
76
147
|
base_price!: UInt32
|
|
77
148
|
@Struct.field(UInt32)
|
|
78
149
|
mass!: UInt32
|
|
150
|
+
@Struct.field('string')
|
|
151
|
+
category!: ResourceCategory
|
|
152
|
+
@Struct.field('string')
|
|
153
|
+
rarity!: ResourceRarity
|
|
154
|
+
@Struct.field('string')
|
|
155
|
+
color!: string
|
|
79
156
|
}
|
|
80
157
|
|
|
81
|
-
@Struct.type('
|
|
82
|
-
export class
|
|
158
|
+
@Struct.type('ItemPrice')
|
|
159
|
+
export class ItemPrice extends Struct {
|
|
83
160
|
@Struct.field(UInt16)
|
|
84
161
|
id!: UInt16
|
|
85
|
-
@Struct.field(
|
|
86
|
-
|
|
162
|
+
@Struct.field(Item)
|
|
163
|
+
item!: Item
|
|
87
164
|
@Struct.field(UInt32)
|
|
88
165
|
price!: UInt32
|
|
89
166
|
@Struct.field(UInt16)
|
package/src/utils/hash.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Bytes, Checksum256, Checksum256Type, Checksum512} from '@wharfkit/antelope'
|
|
2
2
|
|
|
3
|
-
export function hash(seed: Checksum256Type, string: string):
|
|
3
|
+
export function hash(seed: Checksum256Type, string: string): Checksum256 {
|
|
4
4
|
const bytes = Bytes.from(`${seed}${string}`, 'utf8')
|
|
5
5
|
return Checksum256.hash(bytes)
|
|
6
6
|
}
|
package/src/utils/system.ts
CHANGED
|
@@ -1,8 +1,36 @@
|
|
|
1
|
-
import {Checksum256, Checksum256Type} from '@wharfkit/antelope'
|
|
1
|
+
import {Checksum256, Checksum256Type, UInt8} from '@wharfkit/antelope'
|
|
2
2
|
import {hash512} from './hash'
|
|
3
|
-
import {CoordinatesType} from '../types'
|
|
3
|
+
import {Coordinates, CoordinatesType, LocationType} from '../types'
|
|
4
|
+
import {ServerContract} from '../contracts'
|
|
4
5
|
import syllables from '../data/syllables.json'
|
|
5
6
|
|
|
7
|
+
const LOCATION_EXISTS_THRESHOLD = 0x10
|
|
8
|
+
const LOCATION_ACTIVE_THRESHOLD = 0x80
|
|
9
|
+
|
|
10
|
+
export function getLocationType(
|
|
11
|
+
gameSeed: Checksum256Type,
|
|
12
|
+
coordinates: CoordinatesType
|
|
13
|
+
): LocationType {
|
|
14
|
+
const seed = Checksum256.from(gameSeed)
|
|
15
|
+
const str = ['system', coordinates.x, coordinates.y].join('-')
|
|
16
|
+
const hashResult = hash512(seed, str)
|
|
17
|
+
|
|
18
|
+
if (hashResult.array[0] >= LOCATION_EXISTS_THRESHOLD) {
|
|
19
|
+
return LocationType.EMPTY
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (hashResult.array[1] < 96) {
|
|
23
|
+
return LocationType.PLANET
|
|
24
|
+
} else if (hashResult.array[1] < 176) {
|
|
25
|
+
return LocationType.ASTEROID
|
|
26
|
+
}
|
|
27
|
+
return LocationType.NEBULA
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isExtractableLocation(locationType: LocationType): boolean {
|
|
31
|
+
return locationType !== LocationType.EMPTY
|
|
32
|
+
}
|
|
33
|
+
|
|
6
34
|
export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
|
|
7
35
|
const seed = Checksum256.from(gameSeed)
|
|
8
36
|
if (!hasSystem(seed, location)) {
|
|
@@ -21,7 +49,72 @@ export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesTy
|
|
|
21
49
|
}
|
|
22
50
|
|
|
23
51
|
export function hasSystem(gameSeed: Checksum256Type, coordinates: CoordinatesType): boolean {
|
|
52
|
+
return getLocationType(gameSeed, coordinates) !== LocationType.EMPTY
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function deriveLocationStatic(
|
|
56
|
+
gameSeed: Checksum256Type,
|
|
57
|
+
coordinates: CoordinatesType
|
|
58
|
+
): ServerContract.Types.location_static {
|
|
24
59
|
const seed = Checksum256.from(gameSeed)
|
|
25
|
-
const
|
|
26
|
-
|
|
60
|
+
const coords = Coordinates.from(coordinates)
|
|
61
|
+
const str = `system-${coords.x}-${coords.y}`
|
|
62
|
+
const hashResult = hash512(seed, str)
|
|
63
|
+
|
|
64
|
+
const loc = ServerContract.Types.location_static.from({
|
|
65
|
+
coords: coords,
|
|
66
|
+
type: LocationType.EMPTY,
|
|
67
|
+
subtype: 0,
|
|
68
|
+
seed0: 0,
|
|
69
|
+
seed1: 0,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
if (hashResult.array[0] >= LOCATION_EXISTS_THRESHOLD) {
|
|
73
|
+
return loc
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (hashResult.array[1] < 96) {
|
|
77
|
+
loc.type = UInt8.from(LocationType.PLANET)
|
|
78
|
+
} else if (hashResult.array[1] < 176) {
|
|
79
|
+
loc.type = UInt8.from(LocationType.ASTEROID)
|
|
80
|
+
} else {
|
|
81
|
+
loc.type = UInt8.from(LocationType.NEBULA)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
loc.subtype = UInt8.from(
|
|
85
|
+
Number(loc.type) === LocationType.PLANET
|
|
86
|
+
? hashResult.array[2] % 6
|
|
87
|
+
: hashResult.array[2]
|
|
88
|
+
)
|
|
89
|
+
loc.seed0 = UInt8.from(hashResult.array[3])
|
|
90
|
+
loc.seed1 = UInt8.from(hashResult.array[4])
|
|
91
|
+
|
|
92
|
+
return loc
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function deriveLocationEpoch(
|
|
96
|
+
epochSeed: Checksum256Type,
|
|
97
|
+
coordinates: CoordinatesType
|
|
98
|
+
): ServerContract.Types.location_epoch {
|
|
99
|
+
const seed = Checksum256.from(epochSeed)
|
|
100
|
+
const coords = Coordinates.from(coordinates)
|
|
101
|
+
const str = `system-epoch-${coords.x}-${coords.y}`
|
|
102
|
+
const hashResult = hash512(seed, str)
|
|
103
|
+
|
|
104
|
+
return ServerContract.Types.location_epoch.from({
|
|
105
|
+
active: hashResult.array[0] < LOCATION_ACTIVE_THRESHOLD,
|
|
106
|
+
seed0: hashResult.array[1],
|
|
107
|
+
seed1: hashResult.array[2],
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function deriveLocation(
|
|
112
|
+
gameSeed: Checksum256Type,
|
|
113
|
+
epochSeed: Checksum256Type,
|
|
114
|
+
coordinates: CoordinatesType
|
|
115
|
+
): ServerContract.Types.location_derived {
|
|
116
|
+
return ServerContract.Types.location_derived.from({
|
|
117
|
+
static_props: deriveLocationStatic(gameSeed, coordinates),
|
|
118
|
+
epoch_props: deriveLocationEpoch(epochSeed, coordinates),
|
|
119
|
+
})
|
|
27
120
|
}
|
package/src/data/goods.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"id": 1,
|
|
4
|
-
"name": "Hydrogen",
|
|
5
|
-
"description": "A lightweight fuel source essential for interstellar travel.",
|
|
6
|
-
"base_price": 50,
|
|
7
|
-
"mass": 15000
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"id": 2,
|
|
11
|
-
"name": "Iron",
|
|
12
|
-
"description": "A versatile metal used in construction and manufacturing.",
|
|
13
|
-
"base_price": 125,
|
|
14
|
-
"mass": 40000
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"id": 3,
|
|
18
|
-
"name": "Copper",
|
|
19
|
-
"description": "A conductive metal vital for electronics and wiring.",
|
|
20
|
-
"base_price": 200,
|
|
21
|
-
"mass": 60000
|
|
22
|
-
}
|
|
23
|
-
]
|
package/src/market/goods.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {UInt16, UInt16Type, UInt32} from '@wharfkit/antelope'
|
|
2
|
-
import {Good} from '../types'
|
|
3
|
-
import goodsData from '../data/goods.json'
|
|
4
|
-
|
|
5
|
-
const goods = goodsData as Array<{
|
|
6
|
-
id: number
|
|
7
|
-
name: string
|
|
8
|
-
description: string
|
|
9
|
-
base_price: number
|
|
10
|
-
mass: number
|
|
11
|
-
}>
|
|
12
|
-
|
|
13
|
-
export const goodIds = goods.map((g) => g.id)
|
|
14
|
-
|
|
15
|
-
export function getGood(goodId: UInt16Type): Good {
|
|
16
|
-
const good = goods.find((g) => UInt16.from(goodId).equals(g.id))
|
|
17
|
-
if (!good) {
|
|
18
|
-
throw new Error('Good does not exist')
|
|
19
|
-
}
|
|
20
|
-
return Good.from({
|
|
21
|
-
id: UInt16.from(good.id),
|
|
22
|
-
name: good.name,
|
|
23
|
-
description: good.description,
|
|
24
|
-
base_price: UInt32.from(good.base_price),
|
|
25
|
-
mass: UInt32.from(good.mass),
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function getGoods(): Good[] {
|
|
30
|
-
return goods.map((g) => getGood(g.id))
|
|
31
|
-
}
|