@shipload/sdk 0.5.1 → 0.7.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/src/goods.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import {UInt16, UInt16Type, UInt64} from '@wharfkit/antelope'
2
- import {Good, GoodType, PRECISION} from './types'
2
+ import {Coordinates, Good, GoodType, PRECISION} from './types'
3
3
 
4
4
  // List of goods with titles and descriptions
5
5
  const goods: GoodType[] = [
@@ -7,8 +7,8 @@ const goods: GoodType[] = [
7
7
  id: 1,
8
8
  name: 'FizzGlo',
9
9
  description: 'Pops with flavor! A neon drink that makes your burps glow.',
10
- base_price: 20,
11
- mass: 2000,
10
+ base_price: 50,
11
+ mass: 35_000,
12
12
  },
13
13
  // {
14
14
  // id: 2,
@@ -21,22 +21,22 @@ const goods: GoodType[] = [
21
21
  id: 3,
22
22
  name: 'Blob Buddies',
23
23
  description: 'Squishy friends! Clingy, cute and mood-matching pet blobs for every home!',
24
- base_price: 40,
25
- mass: 8000,
24
+ base_price: 95,
25
+ mass: 60_000,
26
26
  },
27
27
  {
28
28
  id: 4,
29
29
  name: 'TuneTooth',
30
30
  description: 'Whistle while you eat! Edible instrument treats that play tunes when chewed.',
31
- base_price: 60,
32
- mass: 12000,
31
+ base_price: 145,
32
+ mass: 75_000,
33
33
  },
34
34
  {
35
35
  id: 5,
36
36
  name: 'SunPods',
37
37
  description: 'Miniature suns in your pocket providing on-demand light & warmth.',
38
- base_price: 80,
39
- mass: 24000,
38
+ base_price: 295,
39
+ mass: 135_000,
40
40
  },
41
41
  // {
42
42
  // id: 6,
@@ -49,8 +49,8 @@ const goods: GoodType[] = [
49
49
  id: 7,
50
50
  name: 'GlowGo',
51
51
  description: 'Ingestible bioluminescent jelly, your inside glows in the dark!',
52
- base_price: 100,
53
- mass: 30000,
52
+ base_price: 650,
53
+ mass: 255_000,
54
54
  },
55
55
  // {
56
56
  // id: 8,
@@ -63,23 +63,23 @@ const goods: GoodType[] = [
63
63
  id: 9,
64
64
  name: 'PlasmaMints',
65
65
  description: 'Hypercharged candy giving plasma breath capable of cutting through steel.',
66
- base_price: 120,
67
- mass: 48000,
66
+ base_price: 3450,
67
+ mass: 1_100_000,
68
68
  },
69
69
  {
70
70
  id: 10,
71
71
  name: 'TimeTreats',
72
72
  description: 'Confectionery morsels releasing slow-mo effect over a limited period.',
73
- base_price: 140,
74
- mass: 56000,
73
+ base_price: 8500,
74
+ mass: 2_100_000,
75
75
  },
76
76
  {
77
77
  id: 11,
78
78
  name: 'QuantumQuencher',
79
79
  description:
80
80
  'Bottled hyper-fluid quenching thirst across multiple parallel realities simultaneously.',
81
- base_price: 160,
82
- mass: 80000,
81
+ base_price: 20_500,
82
+ mass: 4_100_000,
83
83
  },
84
84
  // {
85
85
  // id: 12,
@@ -92,15 +92,15 @@ const goods: GoodType[] = [
92
92
  id: 13,
93
93
  name: 'MemoryGum',
94
94
  description: 'Chewable gum storing or replaying memories while being chewed.',
95
- base_price: 180,
96
- mass: 90000,
95
+ base_price: 52_500,
96
+ mass: 9_500_000,
97
97
  },
98
98
  {
99
99
  id: 14,
100
100
  name: 'SymbioSnack',
101
101
  description: 'Edible alien larvae adopting owner’s taste preference upon consumption.',
102
- base_price: 200,
103
- mass: 120000,
102
+ base_price: 115_000,
103
+ mass: 16_000_000,
104
104
  },
105
105
  ]
106
106
 
@@ -111,12 +111,12 @@ export function getGood(good_id: UInt16Type): Good {
111
111
  if (!good) {
112
112
  throw new Error('Good does not exist')
113
113
  }
114
- return {
114
+ return Good.from({
115
115
  ...good,
116
116
  id: UInt16.from(good.id),
117
117
  base_price: UInt64.from(good.base_price),
118
118
  mass: UInt64.from(good.mass).multiplying(PRECISION),
119
- }
119
+ })
120
120
  }
121
121
 
122
122
  export function getGoods(): Good[] {
@@ -3,6 +3,7 @@ export * from './epoch'
3
3
  export * from './errors'
4
4
  export * from './goods'
5
5
  export * from './hash'
6
+ export * from './system'
6
7
  export * from './market'
7
8
  export * from './ship'
8
9
  export * from './travel'
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: 0,
79
- maxMultiplier: 0,
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
- epochSeed: Checksum256Type
169
- ): UInt64 {
170
- const {base_price} = getGood(good_id)
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, epochSeed, location, good_id)
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
- return UInt64.from(price)
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
- epochSeed: Checksum256Type
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,15 +9,17 @@ 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'
14
16
  import {ChainDefinition} from '@wharfkit/session'
15
17
  import ContractKit, {Contract} from '@wharfkit/contract'
16
- import {findNearbyPlanets, hasSystem, travelplan} from './travel'
18
+ import {findNearbyPlanets, travelplan} from './travel'
19
+
17
20
  import {Ship} from './ship'
18
21
  import {EpochInfo, getCurrentEpoch, getEpochInfo} from './epoch'
22
+ import {hasSystem} from './system'
19
23
 
20
24
  interface ShiploadOptions {
21
25
  platformContractName?: string
@@ -138,10 +142,10 @@ export class Shipload {
138
142
  async marketprice(
139
143
  location: ServerContract.ActionParams.Type.coordinates,
140
144
  good_id: number
141
- ): Promise<UInt64> {
145
+ ): Promise<GoodPrice> {
142
146
  const game = await this.getGame()
143
147
  const state = await this.getState()
144
- return marketprice(location, good_id, game.config.seed, state.seed)
148
+ return marketprice(location, good_id, game.config.seed, state)
145
149
  }
146
150
 
147
151
  async marketprices(
@@ -149,7 +153,7 @@ export class Shipload {
149
153
  ): Promise<GoodPrice[]> {
150
154
  const game = await this.getGame()
151
155
  const state = await this.getState()
152
- return marketprices(location, game.config.seed, state.seed)
156
+ return marketprices(location, game.config.seed, state)
153
157
  }
154
158
 
155
159
  async hasSystem(location: ServerContract.ActionParams.Type.coordinates): Promise<boolean> {
@@ -218,4 +222,13 @@ export class Shipload {
218
222
  const game = await this.getGame()
219
223
  return getEpochInfo(game, UInt64.from(height))
220
224
  }
225
+
226
+ async getLocation(location: Coordinates) {
227
+ const hash = Checksum256.hash(Bytes.from(`${location.x}-${location.y}`, 'utf8'))
228
+ return this.server.table('location').all({
229
+ index_position: 'secondary',
230
+ from: hash,
231
+ to: hash,
232
+ })
233
+ }
221
234
  }