@shipload/sdk 0.6.0 → 0.7.1

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,37 @@
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
+ const syllable = syllables[index]
25
+ name.push(i > 0 ? syllable.toLowerCase() : syllable)
26
+ }
27
+
28
+ return name.join('')
29
+ }
30
+
31
+ export function hasSystem(
32
+ gameSeed: Checksum256,
33
+ coordinates: ServerContract.ActionParams.Type.coordinates
34
+ ): boolean {
35
+ const str = ['system', coordinates.x, coordinates.y].join('-')
36
+ return String(hash512(gameSeed, str)).slice(0, 2) === '00'
37
+ }
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,