@shipload/sdk 0.6.0 → 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/lib/shipload.d.ts +4 -2
- package/lib/shipload.js +1205 -4
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +1205 -5
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/index-module.ts +1 -0
- package/src/shipload.ts +3 -1
- package/src/syllables.ts +1184 -0
- package/src/system.ts +36 -0
- package/src/travel.ts +1 -9
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,
|