@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/system.ts ADDED
@@ -0,0 +1,36 @@
1
+ import {Checksum256} from '@wharfkit/antelope'
2
+ import {hash512} from './hash'
3
+ import {Coordinates} from './types'
4
+ import {ServerContract} from './contracts'
5
+ import syllables from './syllables'
6
+
7
+ export function getSystemName(gameSeed: Checksum256, location: Coordinates): string {
8
+ if (!hasSystem(gameSeed, location)) {
9
+ throw new Error("System doesn't exist at location")
10
+ }
11
+ // Create a seed string using the location coordinates
12
+ const seed = `${location.x}${location.y}systemName`
13
+
14
+ // Hash the seed to get a consistent hash value
15
+ const hash = hash512(gameSeed, seed)
16
+
17
+ // Determine the number of syllables for the name (1 to 3)
18
+ const syllableCount = 1 + (hash.array[0] % 3)
19
+
20
+ // Use the hash to select syllables
21
+ const name: string[] = []
22
+ for (let i = 0; i < syllableCount; i++) {
23
+ const index = hash.array[i] % syllables.length
24
+ name.push(syllables[index])
25
+ }
26
+
27
+ return name.join('')
28
+ }
29
+
30
+ export function hasSystem(
31
+ gameSeed: Checksum256,
32
+ coordinates: ServerContract.ActionParams.Type.coordinates
33
+ ): boolean {
34
+ const str = ['system', coordinates.x, coordinates.y].join('-')
35
+ return String(hash512(gameSeed, str)).slice(0, 2) === '00'
36
+ }
package/src/travel.ts CHANGED
@@ -10,9 +10,9 @@ import {
10
10
  } from '@wharfkit/antelope'
11
11
 
12
12
  import {PlatformContract, ServerContract} from './contracts'
13
- import {hash512} from './hash'
14
13
  import {Distance, PRECISION, TRAVEL_MAXMASS_PENALTY} from './types'
15
14
  import {getGood} from './goods'
15
+ import {hasSystem} from './system'
16
16
 
17
17
  export function travelplanDuration(travelplan: ServerContract.Types.travel_plan) {
18
18
  return UInt64.from(travelplan.flighttime)
@@ -69,14 +69,6 @@ export function rotation(
69
69
  return Math.atan2(destination.y - origin.y, destination.x - origin.x) * (180 / Math.PI) + 90
70
70
  }
71
71
 
72
- export function hasSystem(
73
- seed: Checksum256,
74
- coordinates: ServerContract.ActionParams.Type.coordinates
75
- ): boolean {
76
- const str = ['system', coordinates.x, coordinates.y].join('-')
77
- return String(hash512(seed, str)).slice(0, 2) === '00'
78
- }
79
-
80
72
  export function findNearbyPlanets(
81
73
  seed: Checksum256,
82
74
  origin: ServerContract.ActionParams.Type.coordinates,
@@ -155,7 +147,7 @@ export function calc_mass_penalty(ship: ServerContract.Types.ship_row, mass: UIn
155
147
  const maximum = Number(ship.stats.maxmass)
156
148
  if (mass > ship.stats.maxmass) {
157
149
  const overage = (current - maximum) / PRECISION
158
- const penalty = TRAVEL_MAXMASS_PENALTY * Math.exp(0.00005 * overage)
150
+ const penalty = TRAVEL_MAXMASS_PENALTY * Math.exp(0.000005 * overage)
159
151
  return UInt32.from(penalty)
160
152
  }
161
153
  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
- export interface Good {
23
- id: UInt16
24
- name: string
25
- description: string
26
- base_price: UInt64
27
- mass: UInt64
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
- export interface GoodPrice {
39
- good: Good
40
- price: UInt64
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 {}