@shipload/sdk 2.0.0-rc3 → 2.0.0-rc4
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 +48 -0
- package/lib/shipload.js +1887 -799
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +1887 -799
- package/lib/shipload.m.js.map +1 -1
- package/package.json +1 -1
- package/src/contracts/server.ts +73 -1
- package/src/data/nebula-adjectives.json +211 -0
- package/src/data/nebula-nouns.json +151 -0
- package/src/data/syllables.json +1386 -780
- package/src/derivation/stratum.ts +12 -10
- package/src/utils/system.ts +44 -10
|
@@ -100,17 +100,19 @@ export function deriveResourceStats(seed: bigint): ResourceStats {
|
|
|
100
100
|
const hashResult = Checksum256.hash(Bytes.from(data))
|
|
101
101
|
const hashBytes = hashResult.array
|
|
102
102
|
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
const extractU16 = (offset: number): number => (hashBytes[offset] << 8) | hashBytes[offset + 1]
|
|
104
|
+
|
|
105
|
+
const weibullStat = (raw: number): number => {
|
|
106
|
+
const u = raw / 65536
|
|
107
|
+
let x = 0.27 * Math.sqrt(-Math.log(1 - u))
|
|
108
|
+
if (x > 1) x = 1
|
|
109
|
+
return Math.floor(x * 999) + 1
|
|
110
|
+
}
|
|
109
111
|
|
|
110
112
|
return {
|
|
111
|
-
purity: (
|
|
112
|
-
density: (
|
|
113
|
-
reactivity: (
|
|
114
|
-
resonance: (
|
|
113
|
+
purity: weibullStat(extractU16(0)),
|
|
114
|
+
density: weibullStat(extractU16(2)),
|
|
115
|
+
reactivity: weibullStat(extractU16(4)),
|
|
116
|
+
resonance: weibullStat(extractU16(6)),
|
|
115
117
|
}
|
|
116
118
|
}
|
package/src/utils/system.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {Checksum256, Checksum256Type, UInt8} from '@wharfkit/antelope'
|
|
1
|
+
import {Checksum256, Checksum256Type, Checksum512, UInt8} from '@wharfkit/antelope'
|
|
2
2
|
import {hash512} from './hash'
|
|
3
3
|
import {Coordinates, CoordinatesType, LocationType} from '../types'
|
|
4
4
|
import {ServerContract} from '../contracts'
|
|
5
5
|
import syllables from '../data/syllables.json'
|
|
6
|
+
import nebulaAdjectives from '../data/nebula-adjectives.json'
|
|
7
|
+
import nebulaNouns from '../data/nebula-nouns.json'
|
|
6
8
|
|
|
7
9
|
const LOCATION_EXISTS_THRESHOLD = 0x10
|
|
8
10
|
const LOCATION_ACTIVE_THRESHOLD = 0x80
|
|
@@ -31,23 +33,55 @@ export function isExtractableLocation(locationType: LocationType): boolean {
|
|
|
31
33
|
return locationType !== LocationType.EMPTY
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
const hashResult = hash512(seed, seedStr)
|
|
41
|
-
const syllableCount = 1 + (hashResult.array[0] % 3)
|
|
36
|
+
function uint16(hash: Checksum512, offset: number): number {
|
|
37
|
+
return (hash.array[offset] << 8) | hash.array[offset + 1]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function generatePlanetName(hashResult: Checksum512): string {
|
|
41
|
+
const syllableCount = 2 + (hashResult.array[0] % 2)
|
|
42
42
|
const name: string[] = []
|
|
43
43
|
for (let i = 0; i < syllableCount; i++) {
|
|
44
|
-
const index = hashResult
|
|
44
|
+
const index = uint16(hashResult, 1 + i * 2) % syllables.length
|
|
45
45
|
const syllable = syllables[index]
|
|
46
46
|
name.push(i > 0 ? syllable.toLowerCase() : syllable)
|
|
47
47
|
}
|
|
48
48
|
return name.join('')
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function generateAsteroidName(hashResult: Checksum512): string {
|
|
52
|
+
const A = 65
|
|
53
|
+
const letter1 = String.fromCharCode(A + (hashResult.array[0] % 26))
|
|
54
|
+
const letter2 = String.fromCharCode(A + (hashResult.array[1] % 26))
|
|
55
|
+
const num = (uint16(hashResult, 2) % 9000) + 1000
|
|
56
|
+
return `${letter1}${letter2}-${num}`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function generateNebulaName(hashResult: Checksum512): string {
|
|
60
|
+
const adjIdx = uint16(hashResult, 0) % nebulaAdjectives.length
|
|
61
|
+
const nounIdx = uint16(hashResult, 2) % nebulaNouns.length
|
|
62
|
+
return `${nebulaAdjectives[adjIdx]} ${nebulaNouns[nounIdx]}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
|
|
66
|
+
const seed = Checksum256.from(gameSeed)
|
|
67
|
+
const locationType = getLocationType(seed, location)
|
|
68
|
+
if (locationType === LocationType.EMPTY) {
|
|
69
|
+
throw new Error("System doesn't exist at location")
|
|
70
|
+
}
|
|
71
|
+
const seedStr = `${location.x}-${location.y}-${locationType}-name`
|
|
72
|
+
const hashResult = hash512(seed, seedStr)
|
|
73
|
+
switch (locationType) {
|
|
74
|
+
case LocationType.PLANET:
|
|
75
|
+
return generatePlanetName(hashResult)
|
|
76
|
+
case LocationType.ASTEROID:
|
|
77
|
+
return generateAsteroidName(hashResult)
|
|
78
|
+
case LocationType.NEBULA:
|
|
79
|
+
return generateNebulaName(hashResult)
|
|
80
|
+
default:
|
|
81
|
+
return generatePlanetName(hashResult)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
51
85
|
export function hasSystem(gameSeed: Checksum256Type, coordinates: CoordinatesType): boolean {
|
|
52
86
|
return getLocationType(gameSeed, coordinates) !== LocationType.EMPTY
|
|
53
87
|
}
|