@shipload/sdk 2.0.0-rc2 → 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/lib/shipload.d.ts +271 -137
- package/lib/shipload.js +1375 -1022
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +780 -342
- 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 +239 -120
- 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 +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 +7 -42
- 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,6 +1,6 @@
|
|
|
1
1
|
import {Checksum256, Checksum256Type, 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
6
|
|
|
@@ -28,7 +28,7 @@ export function getLocationType(
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export function isExtractableLocation(locationType: LocationType): boolean {
|
|
31
|
-
return locationType
|
|
31
|
+
return locationType !== LocationType.EMPTY
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
|
|
@@ -81,7 +81,11 @@ export function deriveLocationStatic(
|
|
|
81
81
|
loc.type = UInt8.from(LocationType.NEBULA)
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
loc.subtype = UInt8.from(
|
|
84
|
+
loc.subtype = UInt8.from(
|
|
85
|
+
Number(loc.type) === LocationType.PLANET
|
|
86
|
+
? hashResult.array[2] % 6
|
|
87
|
+
: hashResult.array[2]
|
|
88
|
+
)
|
|
85
89
|
loc.seed0 = UInt8.from(hashResult.array[3])
|
|
86
90
|
loc.seed1 = UInt8.from(hashResult.array[4])
|
|
87
91
|
|
|
@@ -114,42 +118,3 @@ export function deriveLocation(
|
|
|
114
118
|
epoch_props: deriveLocationEpoch(epochSeed, coordinates),
|
|
115
119
|
})
|
|
116
120
|
}
|
|
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
|
-
}
|