@shipload/sdk 2.0.0-rc2 → 2.0.0-rc4
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 +319 -137
- package/lib/shipload.js +3253 -1812
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +2657 -1131
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/capabilities/extraction.ts +14 -21
- package/src/capabilities/storage.ts +2 -2
- package/src/contracts/server.ts +311 -120
- package/src/data/items.json +16 -0
- package/src/data/nebula-adjectives.json +211 -0
- package/src/data/nebula-nouns.json +151 -0
- package/src/data/syllables.json +1386 -780
- 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 +118 -0
- package/src/entities/cargo-utils.ts +8 -8
- package/src/entities/entity-inventory.ts +13 -9
- package/src/entities/inventory-accessor.ts +2 -2
- package/src/entities/location.ts +10 -10
- package/src/entities/ship.ts +10 -6
- package/src/entities/warehouse.ts +2 -2
- package/src/errors.ts +4 -4
- package/src/index-module.ts +31 -6
- package/src/managers/actions.ts +21 -9
- package/src/managers/locations.ts +7 -7
- package/src/managers/trades.ts +5 -5
- package/src/market/items.ts +31 -0
- package/src/market/market.ts +9 -9
- package/src/scheduling/projection.ts +7 -7
- package/src/trading/collect.ts +25 -25
- package/src/trading/deal.ts +8 -8
- package/src/trading/trade.ts +9 -9
- package/src/travel/travel.ts +6 -6
- package/src/types.ts +17 -7
- package/src/utils/system.ts +51 -52
- package/src/data/goods.json +0 -23
- package/src/market/goods.ts +0 -31
package/src/types.ts
CHANGED
|
@@ -62,7 +62,7 @@ export interface ShipLike {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export interface CargoMassInfo {
|
|
65
|
-
|
|
65
|
+
item_id: UInt16Type
|
|
66
66
|
quantity: UInt32Type
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -73,6 +73,7 @@ export enum TaskType {
|
|
|
73
73
|
LOAD = 3,
|
|
74
74
|
UNLOAD = 4,
|
|
75
75
|
EXTRACT = 5,
|
|
76
|
+
WARP = 6,
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
export enum LocationType {
|
|
@@ -131,8 +132,11 @@ export interface Distance {
|
|
|
131
132
|
distance: UInt16
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
|
|
135
|
-
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 {
|
|
136
140
|
@Struct.field(UInt16)
|
|
137
141
|
id!: UInt16
|
|
138
142
|
@Struct.field('string')
|
|
@@ -143,14 +147,20 @@ export class Good extends Struct {
|
|
|
143
147
|
base_price!: UInt32
|
|
144
148
|
@Struct.field(UInt32)
|
|
145
149
|
mass!: UInt32
|
|
150
|
+
@Struct.field('string')
|
|
151
|
+
category!: ResourceCategory
|
|
152
|
+
@Struct.field('string')
|
|
153
|
+
rarity!: ResourceRarity
|
|
154
|
+
@Struct.field('string')
|
|
155
|
+
color!: string
|
|
146
156
|
}
|
|
147
157
|
|
|
148
|
-
@Struct.type('
|
|
149
|
-
export class
|
|
158
|
+
@Struct.type('ItemPrice')
|
|
159
|
+
export class ItemPrice extends Struct {
|
|
150
160
|
@Struct.field(UInt16)
|
|
151
161
|
id!: UInt16
|
|
152
|
-
@Struct.field(
|
|
153
|
-
|
|
162
|
+
@Struct.field(Item)
|
|
163
|
+
item!: Item
|
|
154
164
|
@Struct.field(UInt32)
|
|
155
165
|
price!: UInt32
|
|
156
166
|
@Struct.field(UInt16)
|
package/src/utils/system.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {Checksum256, Checksum256Type, UInt8} from '@wharfkit/antelope'
|
|
1
|
+
import {Checksum256, Checksum256Type, Checksum512, UInt8} from '@wharfkit/antelope'
|
|
2
2
|
import {hash512} from './hash'
|
|
3
|
-
import {Coordinates, CoordinatesType, LocationType
|
|
3
|
+
import {Coordinates, CoordinatesType, LocationType} from '../types'
|
|
4
4
|
import {ServerContract} from '../contracts'
|
|
5
5
|
import syllables from '../data/syllables.json'
|
|
6
|
+
import nebulaAdjectives from '../data/nebula-adjectives.json'
|
|
7
|
+
import nebulaNouns from '../data/nebula-nouns.json'
|
|
6
8
|
|
|
7
9
|
const LOCATION_EXISTS_THRESHOLD = 0x10
|
|
8
10
|
const LOCATION_ACTIVE_THRESHOLD = 0x80
|
|
@@ -28,26 +30,58 @@ export function getLocationType(
|
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export function isExtractableLocation(locationType: LocationType): boolean {
|
|
31
|
-
return locationType
|
|
33
|
+
return locationType !== LocationType.EMPTY
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const hashResult = hash512(seed, seedStr)
|
|
41
|
-
const syllableCount = 1 + (hashResult.array[0] % 3)
|
|
36
|
+
function uint16(hash: Checksum512, offset: number): number {
|
|
37
|
+
return (hash.array[offset] << 8) | hash.array[offset + 1]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function generatePlanetName(hashResult: Checksum512): string {
|
|
41
|
+
const syllableCount = 2 + (hashResult.array[0] % 2)
|
|
42
42
|
const name: string[] = []
|
|
43
43
|
for (let i = 0; i < syllableCount; i++) {
|
|
44
|
-
const index = hashResult
|
|
44
|
+
const index = uint16(hashResult, 1 + i * 2) % syllables.length
|
|
45
45
|
const syllable = syllables[index]
|
|
46
46
|
name.push(i > 0 ? syllable.toLowerCase() : syllable)
|
|
47
47
|
}
|
|
48
48
|
return name.join('')
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function generateAsteroidName(hashResult: Checksum512): string {
|
|
52
|
+
const A = 65
|
|
53
|
+
const letter1 = String.fromCharCode(A + (hashResult.array[0] % 26))
|
|
54
|
+
const letter2 = String.fromCharCode(A + (hashResult.array[1] % 26))
|
|
55
|
+
const num = (uint16(hashResult, 2) % 9000) + 1000
|
|
56
|
+
return `${letter1}${letter2}-${num}`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function generateNebulaName(hashResult: Checksum512): string {
|
|
60
|
+
const adjIdx = uint16(hashResult, 0) % nebulaAdjectives.length
|
|
61
|
+
const nounIdx = uint16(hashResult, 2) % nebulaNouns.length
|
|
62
|
+
return `${nebulaAdjectives[adjIdx]} ${nebulaNouns[nounIdx]}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
|
|
66
|
+
const seed = Checksum256.from(gameSeed)
|
|
67
|
+
const locationType = getLocationType(seed, location)
|
|
68
|
+
if (locationType === LocationType.EMPTY) {
|
|
69
|
+
throw new Error("System doesn't exist at location")
|
|
70
|
+
}
|
|
71
|
+
const seedStr = `${location.x}-${location.y}-${locationType}-name`
|
|
72
|
+
const hashResult = hash512(seed, seedStr)
|
|
73
|
+
switch (locationType) {
|
|
74
|
+
case LocationType.PLANET:
|
|
75
|
+
return generatePlanetName(hashResult)
|
|
76
|
+
case LocationType.ASTEROID:
|
|
77
|
+
return generateAsteroidName(hashResult)
|
|
78
|
+
case LocationType.NEBULA:
|
|
79
|
+
return generateNebulaName(hashResult)
|
|
80
|
+
default:
|
|
81
|
+
return generatePlanetName(hashResult)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
51
85
|
export function hasSystem(gameSeed: Checksum256Type, coordinates: CoordinatesType): boolean {
|
|
52
86
|
return getLocationType(gameSeed, coordinates) !== LocationType.EMPTY
|
|
53
87
|
}
|
|
@@ -81,7 +115,11 @@ export function deriveLocationStatic(
|
|
|
81
115
|
loc.type = UInt8.from(LocationType.NEBULA)
|
|
82
116
|
}
|
|
83
117
|
|
|
84
|
-
loc.subtype = UInt8.from(
|
|
118
|
+
loc.subtype = UInt8.from(
|
|
119
|
+
Number(loc.type) === LocationType.PLANET
|
|
120
|
+
? hashResult.array[2] % 6
|
|
121
|
+
: hashResult.array[2]
|
|
122
|
+
)
|
|
85
123
|
loc.seed0 = UInt8.from(hashResult.array[3])
|
|
86
124
|
loc.seed1 = UInt8.from(hashResult.array[4])
|
|
87
125
|
|
|
@@ -114,42 +152,3 @@ export function deriveLocation(
|
|
|
114
152
|
epoch_props: deriveLocationEpoch(epochSeed, coordinates),
|
|
115
153
|
})
|
|
116
154
|
}
|
|
117
|
-
|
|
118
|
-
export function deriveLocationMixture(
|
|
119
|
-
location: ServerContract.Types.location_derived,
|
|
120
|
-
epochSeed: Checksum256Type
|
|
121
|
-
): ServerContract.Types.mixture_info {
|
|
122
|
-
const locationType = location.static_props.type.toNumber()
|
|
123
|
-
|
|
124
|
-
if (locationType === LocationType.NEBULA) {
|
|
125
|
-
return ServerContract.Types.mixture_info.from({
|
|
126
|
-
components: [{good_id: 1, purity: PRECISION}],
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (locationType === LocationType.ASTEROID) {
|
|
131
|
-
const seed = Checksum256.from(epochSeed)
|
|
132
|
-
const coords = location.static_props.coords
|
|
133
|
-
const str = `mixture-${coords.x}-${coords.y}`
|
|
134
|
-
const hashResult = hash512(seed, str)
|
|
135
|
-
|
|
136
|
-
const ironPrimary = location.static_props.subtype.toNumber() % 2 === 0
|
|
137
|
-
const purityRange = 0.3
|
|
138
|
-
const purityRoll = hashResult.array[0] / 255
|
|
139
|
-
const primaryPurity = 0.5 + purityRoll * purityRange
|
|
140
|
-
|
|
141
|
-
const primaryId = ironPrimary ? 26 : 29
|
|
142
|
-
const secondaryId = ironPrimary ? 29 : 26
|
|
143
|
-
const primaryAmt = Math.floor(primaryPurity * PRECISION)
|
|
144
|
-
const secondaryAmt = PRECISION - primaryAmt
|
|
145
|
-
|
|
146
|
-
return ServerContract.Types.mixture_info.from({
|
|
147
|
-
components: [
|
|
148
|
-
{good_id: primaryId, purity: primaryAmt},
|
|
149
|
-
{good_id: secondaryId, purity: secondaryAmt},
|
|
150
|
-
],
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return ServerContract.Types.mixture_info.from({components: []})
|
|
155
|
-
}
|
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": 26,
|
|
11
|
-
"name": "Iron",
|
|
12
|
-
"description": "A versatile metal used in construction and manufacturing.",
|
|
13
|
-
"base_price": 125,
|
|
14
|
-
"mass": 40000
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"id": 29,
|
|
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
|
-
}
|