@shipload/sdk 0.7.1 → 2.0.0-rc2
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 +2016 -230
- package/lib/shipload.js +5733 -2094
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +5425 -2012
- package/lib/shipload.m.js.map +1 -1
- package/package.json +5 -5
- package/src/capabilities/extraction.ts +37 -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 +788 -202
- package/src/data/goods.json +23 -0
- package/src/data/syllables.json +1184 -0
- package/src/entities/cargo-utils.ts +142 -0
- package/src/entities/container.ts +70 -0
- package/src/entities/entity-inventory.ts +39 -0
- package/src/entities/gamestate.ts +152 -0
- package/src/entities/inventory-accessor.ts +46 -0
- package/src/entities/location.ts +255 -0
- package/src/entities/makers.ts +69 -0
- package/src/entities/player.ts +288 -0
- package/src/entities/ship.ts +208 -0
- package/src/entities/warehouse.ts +89 -0
- package/src/errors.ts +46 -9
- package/src/index-module.ts +152 -7
- package/src/managers/actions.ts +200 -0
- package/src/managers/base.ts +25 -0
- package/src/managers/context.ts +104 -0
- package/src/managers/entities.ts +103 -0
- package/src/managers/epochs.ts +47 -0
- package/src/managers/index.ts +9 -0
- package/src/managers/locations.ts +122 -0
- package/src/managers/players.ts +13 -0
- package/src/managers/trades.ts +119 -0
- package/src/market/goods.ts +31 -0
- package/src/{market.ts → market/market.ts} +31 -37
- package/src/{rolls.ts → market/rolls.ts} +3 -3
- package/src/scheduling/accessor.ts +82 -0
- package/src/{epoch.ts → scheduling/epoch.ts} +1 -1
- package/src/scheduling/projection.ts +290 -0
- package/src/scheduling/schedule.ts +179 -0
- package/src/shipload.ts +39 -157
- package/src/trading/collect.ts +938 -0
- package/src/trading/deal.ts +207 -0
- package/src/trading/trade.ts +203 -0
- package/src/travel/travel.ts +486 -0
- 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 +127 -25
- package/src/{hash.ts → utils/hash.ts} +1 -1
- package/src/utils/system.ts +155 -0
- package/src/goods.ts +0 -124
- 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
package/src/shipload.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
APIClient,
|
|
3
|
-
Bytes,
|
|
4
|
-
Checksum256,
|
|
5
|
-
Name,
|
|
6
|
-
NameType,
|
|
7
|
-
Serializer,
|
|
8
|
-
UInt16Type,
|
|
9
|
-
UInt64,
|
|
10
|
-
UInt64Type,
|
|
11
|
-
} from '@wharfkit/antelope'
|
|
12
|
-
import {Coordinates, Distance, GoodPrice} from './types'
|
|
13
|
-
import {marketprice, marketprices} from './market'
|
|
1
|
+
import {APIClient} from '@wharfkit/antelope'
|
|
14
2
|
import {PlatformContract, ServerContract} from './contracts'
|
|
15
|
-
import {ERROR_SYSTEM_NOT_INITIALIZED} from './errors'
|
|
16
3
|
import {ChainDefinition} from '@wharfkit/session'
|
|
17
4
|
import ContractKit, {Contract} from '@wharfkit/contract'
|
|
18
|
-
import {findNearbyPlanets, travelplan} from './travel'
|
|
19
5
|
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
6
|
+
import {GameContext} from './managers/context'
|
|
7
|
+
import {EntitiesManager} from './managers/entities'
|
|
8
|
+
import {PlayersManager} from './managers/players'
|
|
9
|
+
import {LocationsManager} from './managers/locations'
|
|
10
|
+
import {TradesManager} from './managers/trades'
|
|
11
|
+
import {EpochsManager} from './managers/epochs'
|
|
12
|
+
import {ActionsManager} from './managers/actions'
|
|
13
|
+
import {GameState} from './entities/gamestate'
|
|
23
14
|
|
|
24
15
|
interface ShiploadOptions {
|
|
25
16
|
platformContractName?: string
|
|
@@ -33,22 +24,21 @@ interface ShiploadConstructorOptions extends ShiploadOptions {
|
|
|
33
24
|
}
|
|
34
25
|
|
|
35
26
|
export class Shipload {
|
|
36
|
-
|
|
37
|
-
public server: Contract
|
|
38
|
-
public platform: Contract
|
|
39
|
-
public game: PlatformContract.Types.game_row | undefined
|
|
27
|
+
private readonly _context: GameContext
|
|
40
28
|
|
|
41
29
|
constructor(chain: ChainDefinition, constructorOptions?: ShiploadConstructorOptions) {
|
|
42
30
|
const {client, platformContract, serverContract} = constructorOptions || {}
|
|
43
|
-
|
|
31
|
+
const apiClient = client || new APIClient({url: chain.url})
|
|
44
32
|
|
|
45
|
-
|
|
33
|
+
const platform = platformContract
|
|
46
34
|
? platformContract
|
|
47
|
-
: new PlatformContract.Contract({client:
|
|
35
|
+
: new PlatformContract.Contract({client: apiClient})
|
|
48
36
|
|
|
49
|
-
|
|
37
|
+
const server = serverContract
|
|
50
38
|
? serverContract
|
|
51
|
-
: new ServerContract.Contract({client:
|
|
39
|
+
: new ServerContract.Contract({client: apiClient})
|
|
40
|
+
|
|
41
|
+
this._context = new GameContext(apiClient, server, platform)
|
|
52
42
|
}
|
|
53
43
|
|
|
54
44
|
static async load(
|
|
@@ -80,155 +70,47 @@ export class Shipload {
|
|
|
80
70
|
})
|
|
81
71
|
}
|
|
82
72
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return this.game
|
|
86
|
-
}
|
|
87
|
-
const game = await this.platform.table('games').get()
|
|
88
|
-
if (!game) {
|
|
89
|
-
throw new Error(ERROR_SYSTEM_NOT_INITIALIZED)
|
|
90
|
-
}
|
|
91
|
-
this.game = game
|
|
92
|
-
return game
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async getState(): Promise<ServerContract.Types.state_row> {
|
|
96
|
-
const state = await this.server.table('state').get()
|
|
97
|
-
if (!state) {
|
|
98
|
-
throw new Error(ERROR_SYSTEM_NOT_INITIALIZED)
|
|
99
|
-
}
|
|
100
|
-
return state
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async getShip(ship_id: UInt64Type): Promise<Ship> {
|
|
104
|
-
const ship = await this.server.table('ship').get(UInt64.from(ship_id))
|
|
105
|
-
if (!ship) {
|
|
106
|
-
throw new Error('No ship found')
|
|
107
|
-
}
|
|
108
|
-
return new Ship(ship)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async getShips(player: NameType | ServerContract.Types.player_row): Promise<Ship[]> {
|
|
112
|
-
let account: Name
|
|
113
|
-
if (player instanceof ServerContract.Types.player_row) {
|
|
114
|
-
account = player.owner
|
|
115
|
-
} else {
|
|
116
|
-
account = Name.from(player)
|
|
117
|
-
}
|
|
118
|
-
const from = Serializer.decode({
|
|
119
|
-
data:
|
|
120
|
-
Serializer.encode({object: UInt64.from(UInt64.min)}).hexString +
|
|
121
|
-
Serializer.encode({object: Name.from(account)}).hexString,
|
|
122
|
-
type: 'uint128',
|
|
123
|
-
})
|
|
124
|
-
const to = Serializer.decode({
|
|
125
|
-
data:
|
|
126
|
-
Serializer.encode({object: UInt64.from(UInt64.max)}).hexString +
|
|
127
|
-
Serializer.encode({object: Name.from(account)}).hexString,
|
|
128
|
-
type: 'uint128',
|
|
129
|
-
})
|
|
130
|
-
const ships = await this.server
|
|
131
|
-
.table('ship')
|
|
132
|
-
.query({
|
|
133
|
-
key_type: 'i128',
|
|
134
|
-
index_position: 'secondary',
|
|
135
|
-
from,
|
|
136
|
-
to,
|
|
137
|
-
})
|
|
138
|
-
.all()
|
|
139
|
-
return ships.map((ship) => new Ship(ship))
|
|
73
|
+
get client(): APIClient {
|
|
74
|
+
return this._context.client
|
|
140
75
|
}
|
|
141
76
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
good_id: number
|
|
145
|
-
): Promise<GoodPrice> {
|
|
146
|
-
const game = await this.getGame()
|
|
147
|
-
const state = await this.getState()
|
|
148
|
-
return marketprice(location, good_id, game.config.seed, state)
|
|
77
|
+
get server(): Contract {
|
|
78
|
+
return this._context.server
|
|
149
79
|
}
|
|
150
80
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
): Promise<GoodPrice[]> {
|
|
154
|
-
const game = await this.getGame()
|
|
155
|
-
const state = await this.getState()
|
|
156
|
-
return marketprices(location, game.config.seed, state)
|
|
81
|
+
get platform(): Contract {
|
|
82
|
+
return this._context.platform
|
|
157
83
|
}
|
|
158
84
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return hasSystem(game.config.seed, location)
|
|
85
|
+
get entities(): EntitiesManager {
|
|
86
|
+
return this._context.entities
|
|
162
87
|
}
|
|
163
88
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
maxDistance: UInt16Type = 20
|
|
167
|
-
): Promise<Distance[]> {
|
|
168
|
-
const game = await this.getGame()
|
|
169
|
-
return findNearbyPlanets(game.config.seed, origin, maxDistance)
|
|
89
|
+
get players(): PlayersManager {
|
|
90
|
+
return this._context.players
|
|
170
91
|
}
|
|
171
92
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
origin: ServerContract.ActionParams.Type.coordinates,
|
|
175
|
-
destination: ServerContract.ActionParams.Type.coordinates,
|
|
176
|
-
recharge = false
|
|
177
|
-
): Promise<ServerContract.Types.travel_plan> {
|
|
178
|
-
const game = await this.getGame()
|
|
179
|
-
const cargos = await this.server.table('cargo').all({
|
|
180
|
-
from: ship.id,
|
|
181
|
-
to: ship.id,
|
|
182
|
-
index_position: 'secondary',
|
|
183
|
-
})
|
|
184
|
-
return travelplan(game, ship, cargos, origin, destination, recharge)
|
|
93
|
+
get locations(): LocationsManager {
|
|
94
|
+
return this._context.locations
|
|
185
95
|
}
|
|
186
96
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
): Promise<ServerContract.Types.cargo_row[]> {
|
|
190
|
-
let shipId: UInt64
|
|
191
|
-
if (ship instanceof ServerContract.Types.ship_row) {
|
|
192
|
-
shipId = UInt64.from(ship.id)
|
|
193
|
-
} else {
|
|
194
|
-
shipId = UInt64.from(ship)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const cargoItems = await this.server
|
|
198
|
-
.table('cargo')
|
|
199
|
-
.query({
|
|
200
|
-
key_type: 'i64',
|
|
201
|
-
index_position: 'secondary',
|
|
202
|
-
from: shipId,
|
|
203
|
-
to: shipId,
|
|
204
|
-
})
|
|
205
|
-
.all()
|
|
206
|
-
|
|
207
|
-
return cargoItems
|
|
97
|
+
get trades(): TradesManager {
|
|
98
|
+
return this._context.trades
|
|
208
99
|
}
|
|
209
100
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
return getCurrentEpoch(game)
|
|
101
|
+
get epochs(): EpochsManager {
|
|
102
|
+
return this._context.epochs
|
|
213
103
|
}
|
|
214
104
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const epoch = await this.getCurrentEpochHeight()
|
|
218
|
-
return getEpochInfo(game, epoch)
|
|
105
|
+
get actions(): ActionsManager {
|
|
106
|
+
return this._context.actions
|
|
219
107
|
}
|
|
220
108
|
|
|
221
|
-
async
|
|
222
|
-
|
|
223
|
-
return getEpochInfo(game, UInt64.from(height))
|
|
109
|
+
async getGame(reload = false): Promise<PlatformContract.Types.game_row> {
|
|
110
|
+
return this._context.getGame(reload)
|
|
224
111
|
}
|
|
225
112
|
|
|
226
|
-
async
|
|
227
|
-
|
|
228
|
-
return this.server.table('location').all({
|
|
229
|
-
index_position: 'secondary',
|
|
230
|
-
from: hash,
|
|
231
|
-
to: hash,
|
|
232
|
-
})
|
|
113
|
+
async getState(reload = false): Promise<GameState> {
|
|
114
|
+
return this._context.getState(reload)
|
|
233
115
|
}
|
|
234
116
|
}
|