@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/entities/location.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Checksum256, Checksum256Type, UInt16, UInt16Type, UInt64} from '@wharfkit/antelope'
|
|
2
2
|
import {ServerContract} from '../contracts'
|
|
3
|
-
import {Coordinates, CoordinatesType, Distance,
|
|
4
|
-
import {hasSystem} from '../utils/system'
|
|
3
|
+
import {Coordinates, CoordinatesType, Distance, ItemPrice, LocationType} from '../types'
|
|
4
|
+
import {getLocationType, hasSystem, isExtractableLocation} from '../utils/system'
|
|
5
5
|
import {findNearbyPlanets} from '../travel/travel'
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -10,10 +10,10 @@ import {findNearbyPlanets} from '../travel/travel'
|
|
|
10
10
|
*/
|
|
11
11
|
export class Location {
|
|
12
12
|
readonly coordinates: Coordinates
|
|
13
|
-
private _marketPrices?:
|
|
13
|
+
private _marketPrices?: ItemPrice[]
|
|
14
14
|
private _gameSeed?: Checksum256
|
|
15
15
|
private _hasSystem?: boolean
|
|
16
|
-
private _locationRows?: ServerContract.Types.
|
|
16
|
+
private _locationRows?: ServerContract.Types.supply_row[]
|
|
17
17
|
private _epoch?: UInt64
|
|
18
18
|
|
|
19
19
|
constructor(coordinates: CoordinatesType) {
|
|
@@ -28,7 +28,7 @@ export class Location {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Check if this location has a system (planet)
|
|
31
|
+
* Check if this location has a system (planet, asteroid, or nebula)
|
|
32
32
|
*/
|
|
33
33
|
hasSystemAt(gameSeed: Checksum256Type): boolean {
|
|
34
34
|
const seed = Checksum256.from(gameSeed)
|
|
@@ -39,24 +39,38 @@ export class Location {
|
|
|
39
39
|
return this._hasSystem
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Get the location type (EMPTY, PLANET, ASTEROID, or NEBULA)
|
|
44
|
+
*/
|
|
45
|
+
getLocationTypeAt(gameSeed: Checksum256Type): LocationType {
|
|
46
|
+
return getLocationType(gameSeed, this.coordinates)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Check if this location is extractable (asteroid or nebula)
|
|
51
|
+
*/
|
|
52
|
+
isExtractableAt(gameSeed: Checksum256Type): boolean {
|
|
53
|
+
return isExtractableLocation(this.getLocationTypeAt(gameSeed))
|
|
54
|
+
}
|
|
55
|
+
|
|
42
56
|
/**
|
|
43
57
|
* Set cached market prices for this location
|
|
44
58
|
*/
|
|
45
|
-
setMarketPrices(prices:
|
|
59
|
+
setMarketPrices(prices: ItemPrice[]): void {
|
|
46
60
|
this._marketPrices = prices
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
/**
|
|
50
64
|
* Get cached market prices (returns undefined if not cached)
|
|
51
65
|
*/
|
|
52
|
-
get marketPrices():
|
|
66
|
+
get marketPrices(): ItemPrice[] | undefined {
|
|
53
67
|
return this._marketPrices
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
/**
|
|
57
71
|
* Get price for a specific good (from cache)
|
|
58
72
|
*/
|
|
59
|
-
getPrice(goodId: UInt16Type):
|
|
73
|
+
getPrice(goodId: UInt16Type): ItemPrice | undefined {
|
|
60
74
|
if (!this._marketPrices) return undefined
|
|
61
75
|
return this._marketPrices.find((p) => p.id.equals(goodId))
|
|
62
76
|
}
|
|
@@ -79,7 +93,7 @@ export class Location {
|
|
|
79
93
|
/**
|
|
80
94
|
* Set location rows (supply data) for this location
|
|
81
95
|
*/
|
|
82
|
-
setLocationRows(rows: ServerContract.Types.
|
|
96
|
+
setLocationRows(rows: ServerContract.Types.supply_row[], epoch: UInt64): void {
|
|
83
97
|
this._locationRows = rows
|
|
84
98
|
this._epoch = epoch
|
|
85
99
|
}
|
|
@@ -87,7 +101,7 @@ export class Location {
|
|
|
87
101
|
/**
|
|
88
102
|
* Get cached location rows (supply data)
|
|
89
103
|
*/
|
|
90
|
-
get locationRows(): ServerContract.Types.
|
|
104
|
+
get locationRows(): ServerContract.Types.supply_row[] | undefined {
|
|
91
105
|
return this._locationRows
|
|
92
106
|
}
|
|
93
107
|
|
|
@@ -98,7 +112,7 @@ export class Location {
|
|
|
98
112
|
getSupply(goodId: UInt16Type): UInt16 | undefined {
|
|
99
113
|
if (!this._locationRows) return undefined
|
|
100
114
|
const row = this._locationRows.find(
|
|
101
|
-
(r) => r.
|
|
115
|
+
(r) => r.item_id.equals(goodId) && this._epoch && r.epoch.equals(this._epoch)
|
|
102
116
|
)
|
|
103
117
|
return row ? row.supply : undefined
|
|
104
118
|
}
|
|
@@ -107,7 +121,7 @@ export class Location {
|
|
|
107
121
|
* Get all available goods at this location (goods with supply > 0)
|
|
108
122
|
* Returns undefined if location rows not cached
|
|
109
123
|
*/
|
|
110
|
-
get availableGoods(): ServerContract.Types.
|
|
124
|
+
get availableGoods(): ServerContract.Types.supply_row[] | undefined {
|
|
111
125
|
if (!this._locationRows) return undefined
|
|
112
126
|
return this._locationRows.filter(
|
|
113
127
|
(r) => this._epoch && r.epoch.equals(this._epoch) && r.supply.gt(UInt16.from(0))
|
|
@@ -185,9 +199,9 @@ export class Location {
|
|
|
185
199
|
: UInt16.from(0)
|
|
186
200
|
: currentSupply.adding(quantityDelta)
|
|
187
201
|
|
|
188
|
-
return
|
|
202
|
+
return ItemPrice.from({
|
|
189
203
|
id: price.id,
|
|
190
|
-
|
|
204
|
+
item: price.item,
|
|
191
205
|
price: price.price,
|
|
192
206
|
supply: newSupply,
|
|
193
207
|
})
|
|
@@ -199,7 +213,7 @@ export class Location {
|
|
|
199
213
|
// Copy location rows if cached
|
|
200
214
|
if (this._locationRows && this._epoch) {
|
|
201
215
|
newLocation._locationRows = this._locationRows.map((row) => {
|
|
202
|
-
if (row.
|
|
216
|
+
if (row.item_id.equals(goodId) && row.epoch.equals(this._epoch!)) {
|
|
203
217
|
const currentSupply = UInt16.from(row.supply)
|
|
204
218
|
const delta = UInt16.from(Math.abs(quantityDelta))
|
|
205
219
|
const newSupply =
|
|
@@ -209,11 +223,11 @@ export class Location {
|
|
|
209
223
|
: UInt16.from(0)
|
|
210
224
|
: currentSupply.adding(quantityDelta)
|
|
211
225
|
|
|
212
|
-
return ServerContract.Types.
|
|
226
|
+
return ServerContract.Types.supply_row.from({
|
|
213
227
|
id: row.id,
|
|
214
228
|
coordinates: row.coordinates,
|
|
215
229
|
epoch: row.epoch,
|
|
216
|
-
|
|
230
|
+
item_id: row.item_id,
|
|
217
231
|
supply: newSupply,
|
|
218
232
|
})
|
|
219
233
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {Name, UInt16, UInt32, UInt64} from '@wharfkit/antelope'
|
|
2
|
+
import {ServerContract} from '../contracts'
|
|
3
|
+
import {Ship, ShipStateInput} from './ship'
|
|
4
|
+
import {Warehouse, WarehouseStateInput} from './warehouse'
|
|
5
|
+
import {Container, ContainerStateInput} from './container'
|
|
6
|
+
|
|
7
|
+
export function makeShip(state: ShipStateInput): Ship {
|
|
8
|
+
const entityInfo = ServerContract.Types.entity_info.from({
|
|
9
|
+
type: Name.from('ship'),
|
|
10
|
+
id: UInt64.from(state.id),
|
|
11
|
+
owner: Name.from(state.owner),
|
|
12
|
+
entity_name: state.name,
|
|
13
|
+
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
14
|
+
hullmass: UInt32.from(state.hullmass),
|
|
15
|
+
capacity: UInt32.from(state.capacity),
|
|
16
|
+
energy: UInt16.from(state.energy),
|
|
17
|
+
cargomass: UInt32.from(0),
|
|
18
|
+
cargo: state.cargo || [],
|
|
19
|
+
is_idle: !state.schedule,
|
|
20
|
+
current_task_elapsed: UInt32.from(0),
|
|
21
|
+
current_task_remaining: UInt32.from(0),
|
|
22
|
+
pending_tasks: [],
|
|
23
|
+
engines: state.engines,
|
|
24
|
+
generator: state.generator,
|
|
25
|
+
loaders: state.loaders,
|
|
26
|
+
schedule: state.schedule,
|
|
27
|
+
})
|
|
28
|
+
return new Ship(entityInfo)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function makeWarehouse(state: WarehouseStateInput): Warehouse {
|
|
32
|
+
const entityInfo = ServerContract.Types.entity_info.from({
|
|
33
|
+
type: Name.from('warehouse'),
|
|
34
|
+
id: UInt64.from(state.id),
|
|
35
|
+
owner: Name.from(state.owner),
|
|
36
|
+
entity_name: state.name,
|
|
37
|
+
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
38
|
+
capacity: UInt32.from(state.capacity),
|
|
39
|
+
cargomass: UInt32.from(0),
|
|
40
|
+
cargo: state.cargo || [],
|
|
41
|
+
loaders: state.loaders,
|
|
42
|
+
is_idle: !state.schedule,
|
|
43
|
+
current_task_elapsed: UInt32.from(0),
|
|
44
|
+
current_task_remaining: UInt32.from(0),
|
|
45
|
+
pending_tasks: [],
|
|
46
|
+
schedule: state.schedule,
|
|
47
|
+
})
|
|
48
|
+
return new Warehouse(entityInfo)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function makeContainer(state: ContainerStateInput): Container {
|
|
52
|
+
const entityInfo = ServerContract.Types.entity_info.from({
|
|
53
|
+
type: Name.from('container'),
|
|
54
|
+
id: UInt64.from(state.id),
|
|
55
|
+
owner: Name.from(state.owner),
|
|
56
|
+
entity_name: state.name,
|
|
57
|
+
coordinates: ServerContract.Types.coordinates.from(state.coordinates),
|
|
58
|
+
hullmass: UInt32.from(state.hullmass),
|
|
59
|
+
capacity: UInt32.from(state.capacity),
|
|
60
|
+
cargomass: UInt32.from(state.cargomass || 0),
|
|
61
|
+
cargo: [],
|
|
62
|
+
is_idle: !state.schedule,
|
|
63
|
+
current_task_elapsed: UInt32.from(0),
|
|
64
|
+
current_task_remaining: UInt32.from(0),
|
|
65
|
+
pending_tasks: [],
|
|
66
|
+
schedule: state.schedule,
|
|
67
|
+
})
|
|
68
|
+
return new Container(entityInfo)
|
|
69
|
+
}
|
package/src/entities/player.ts
CHANGED
|
@@ -37,7 +37,8 @@ export class Player extends ServerContract.Types.player_row {
|
|
|
37
37
|
}
|
|
38
38
|
// Constants for game rules (match smart contract)
|
|
39
39
|
private static readonly MAX_LOAN = 1000000
|
|
40
|
-
|
|
40
|
+
// Contract formula: 2500 * pow(5, sequence - 1) = 500 * pow(5, sequence)
|
|
41
|
+
private static readonly BASE_SHIP_COST = 500
|
|
41
42
|
private static readonly SHIP_COST_MULTIPLIER = 5
|
|
42
43
|
|
|
43
44
|
// Optional ship count for nextShipCost calculation
|