@shipload/sdk 0.5.1 → 0.6.0
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 +77 -6
- package/lib/shipload.js +199 -37
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +198 -39
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/contracts/server.ts +95 -1
- package/src/goods.ts +23 -23
- package/src/market.ts +32 -13
- package/src/shipload.ts +15 -4
- package/src/travel.ts +1 -1
- package/src/types.ts +23 -10
package/src/market.ts
CHANGED
|
@@ -75,8 +75,8 @@ export function getRarity(
|
|
|
75
75
|
// ~40.30% chance = no value change
|
|
76
76
|
return {
|
|
77
77
|
rarity: Rarities.trash,
|
|
78
|
-
minMultiplier:
|
|
79
|
-
maxMultiplier:
|
|
78
|
+
minMultiplier: 1,
|
|
79
|
+
maxMultiplier: 1.07,
|
|
80
80
|
} // Product is not available
|
|
81
81
|
} else if (rarityRoll < 62508) {
|
|
82
82
|
// (White) ~25.33% chance = slightly lower value
|
|
@@ -161,18 +161,32 @@ export function getLocationMultiplier(
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
export function getSupply(
|
|
165
|
+
gameSeed: Checksum256Type,
|
|
166
|
+
state: ServerContract.Types.state_row,
|
|
167
|
+
location: Coordinates,
|
|
168
|
+
good_id: UInt16Type
|
|
169
|
+
): number {
|
|
170
|
+
const seed = `${state.seed}${location.x}${location.y}${good_id}supply`
|
|
171
|
+
const r = roll(gameSeed, seed)
|
|
172
|
+
const percent = r / 65535
|
|
173
|
+
const epoch = 1 + Number(state.epoch) / 90
|
|
174
|
+
const ship = Math.pow(Number(state.ships), 1 / 3)
|
|
175
|
+
return UInt64.from((128 / good_id) * percent * ship * epoch).toNumber()
|
|
176
|
+
}
|
|
177
|
+
|
|
164
178
|
export function marketprice(
|
|
165
179
|
location: ServerContract.ActionParams.Type.coordinates,
|
|
166
180
|
good_id: UInt16Type,
|
|
167
181
|
gameSeed: Checksum256Type,
|
|
168
|
-
|
|
169
|
-
):
|
|
170
|
-
const
|
|
171
|
-
let price = Number(base_price)
|
|
182
|
+
state: ServerContract.Types.state_row
|
|
183
|
+
): GoodPrice {
|
|
184
|
+
const good = getGood(good_id)
|
|
185
|
+
let price = Number(good.base_price)
|
|
172
186
|
|
|
173
187
|
// Rarity multiplier of the deal (changes with epoch)
|
|
174
188
|
// Large impact range on price, from 0.285x to 3.0x
|
|
175
|
-
const rarityMultiplier = getRarityMultiplier(gameSeed,
|
|
189
|
+
const rarityMultiplier = getRarityMultiplier(gameSeed, state.seed, location, good_id)
|
|
176
190
|
price *= rarityMultiplier
|
|
177
191
|
|
|
178
192
|
// Location multiplier of the deal (static, based on game seed)
|
|
@@ -180,16 +194,21 @@ export function marketprice(
|
|
|
180
194
|
const locationMultiplier = getLocationMultiplier(gameSeed, location, good_id)
|
|
181
195
|
price *= locationMultiplier
|
|
182
196
|
|
|
183
|
-
|
|
197
|
+
// Determine the current supply of the good at the location
|
|
198
|
+
const supply = getSupply(gameSeed, state, location, good_id)
|
|
199
|
+
|
|
200
|
+
return GoodPrice.from({
|
|
201
|
+
id: good_id,
|
|
202
|
+
good,
|
|
203
|
+
price: UInt64.from(price),
|
|
204
|
+
supply: UInt64.from(supply),
|
|
205
|
+
})
|
|
184
206
|
}
|
|
185
207
|
|
|
186
208
|
export function marketprices(
|
|
187
209
|
location: ServerContract.ActionParams.Type.coordinates,
|
|
188
210
|
gameSeed: Checksum256Type,
|
|
189
|
-
|
|
211
|
+
state: ServerContract.Types.state_row
|
|
190
212
|
): GoodPrice[] {
|
|
191
|
-
return getGoods().map((good) =>
|
|
192
|
-
const price = marketprice(location, good.id, gameSeed, epochSeed)
|
|
193
|
-
return {price, good: good}
|
|
194
|
-
})
|
|
213
|
+
return getGoods().map((good) => marketprice(location, good.id, gameSeed, state))
|
|
195
214
|
}
|
package/src/shipload.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
APIClient,
|
|
3
|
+
Bytes,
|
|
4
|
+
Checksum256,
|
|
3
5
|
Name,
|
|
4
6
|
NameType,
|
|
5
7
|
Serializer,
|
|
@@ -7,7 +9,7 @@ import {
|
|
|
7
9
|
UInt64,
|
|
8
10
|
UInt64Type,
|
|
9
11
|
} from '@wharfkit/antelope'
|
|
10
|
-
import {Distance, GoodPrice} from './types'
|
|
12
|
+
import {Coordinates, Distance, GoodPrice} from './types'
|
|
11
13
|
import {marketprice, marketprices} from './market'
|
|
12
14
|
import {PlatformContract, ServerContract} from './contracts'
|
|
13
15
|
import {ERROR_SYSTEM_NOT_INITIALIZED} from './errors'
|
|
@@ -138,10 +140,10 @@ export class Shipload {
|
|
|
138
140
|
async marketprice(
|
|
139
141
|
location: ServerContract.ActionParams.Type.coordinates,
|
|
140
142
|
good_id: number
|
|
141
|
-
): Promise<
|
|
143
|
+
): Promise<GoodPrice> {
|
|
142
144
|
const game = await this.getGame()
|
|
143
145
|
const state = await this.getState()
|
|
144
|
-
return marketprice(location, good_id, game.config.seed, state
|
|
146
|
+
return marketprice(location, good_id, game.config.seed, state)
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
async marketprices(
|
|
@@ -149,7 +151,7 @@ export class Shipload {
|
|
|
149
151
|
): Promise<GoodPrice[]> {
|
|
150
152
|
const game = await this.getGame()
|
|
151
153
|
const state = await this.getState()
|
|
152
|
-
return marketprices(location, game.config.seed, state
|
|
154
|
+
return marketprices(location, game.config.seed, state)
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
async hasSystem(location: ServerContract.ActionParams.Type.coordinates): Promise<boolean> {
|
|
@@ -218,4 +220,13 @@ export class Shipload {
|
|
|
218
220
|
const game = await this.getGame()
|
|
219
221
|
return getEpochInfo(game, UInt64.from(height))
|
|
220
222
|
}
|
|
223
|
+
|
|
224
|
+
async getLocation(location: Coordinates) {
|
|
225
|
+
const hash = Checksum256.hash(Bytes.from(`${location.x}-${location.y}`, 'utf8'))
|
|
226
|
+
return this.server.table('location').all({
|
|
227
|
+
index_position: 'secondary',
|
|
228
|
+
from: hash,
|
|
229
|
+
to: hash,
|
|
230
|
+
})
|
|
231
|
+
}
|
|
221
232
|
}
|
package/src/travel.ts
CHANGED
|
@@ -155,7 +155,7 @@ export function calc_mass_penalty(ship: ServerContract.Types.ship_row, mass: UIn
|
|
|
155
155
|
const maximum = Number(ship.stats.maxmass)
|
|
156
156
|
if (mass > ship.stats.maxmass) {
|
|
157
157
|
const overage = (current - maximum) / PRECISION
|
|
158
|
-
const penalty = TRAVEL_MAXMASS_PENALTY * Math.exp(0.
|
|
158
|
+
const penalty = TRAVEL_MAXMASS_PENALTY * Math.exp(0.000005 * overage)
|
|
159
159
|
return UInt32.from(penalty)
|
|
160
160
|
}
|
|
161
161
|
return UInt32.from(0)
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {UInt16, UInt16Type, UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
1
|
+
import {Struct, UInt16, UInt16Type, UInt64, UInt64Type} from '@wharfkit/antelope'
|
|
2
2
|
import {ServerContract} from './contracts'
|
|
3
3
|
|
|
4
4
|
export const PRECISION = 10000
|
|
@@ -19,12 +19,18 @@ export interface Distance {
|
|
|
19
19
|
distance: UInt16
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
@Struct.type('good')
|
|
23
|
+
export class Good extends Struct {
|
|
24
|
+
@Struct.field(UInt16)
|
|
25
|
+
id!: UInt16
|
|
26
|
+
@Struct.field('string')
|
|
27
|
+
name!: string
|
|
28
|
+
@Struct.field('string')
|
|
29
|
+
description!: string
|
|
30
|
+
@Struct.field(UInt64)
|
|
31
|
+
base_price!: UInt64
|
|
32
|
+
@Struct.field(UInt64)
|
|
33
|
+
mass!: UInt64
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
export interface GoodType {
|
|
@@ -35,9 +41,16 @@ export interface GoodType {
|
|
|
35
41
|
mass: UInt64Type
|
|
36
42
|
}
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
@Struct.type('GoodPrice')
|
|
45
|
+
export class GoodPrice extends Struct {
|
|
46
|
+
@Struct.field(UInt16)
|
|
47
|
+
id!: UInt16
|
|
48
|
+
@Struct.field(Good)
|
|
49
|
+
good!: Good
|
|
50
|
+
@Struct.field(UInt64)
|
|
51
|
+
price!: UInt64
|
|
52
|
+
@Struct.field(UInt64)
|
|
53
|
+
supply!: UInt64
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
export interface Coordinates extends ServerContract.ActionParams.Type.coordinates {}
|