File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -116,18 +116,21 @@ export function rollWithSeed(seed: string): Roll {
116116 return rollFrom ( mulberry32 ( hashString ( seed ) ) )
117117}
118118
119+ export function generateSeed ( ) : string {
120+ return `rehatch-${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 10 ) } `
121+ }
122+
119123export function companionUserId ( ) : string {
120124 const config = getGlobalConfig ( )
121125 return config . oauthAccount ?. accountUuid ?? config . userID ?? 'anon'
122126}
123127
124- // Regenerate bones from userId, merge with stored soul. Bones never persist
125- // so species renames and SPECIES-array edits can't break stored companions,
126- // and editing config.companion can't fake a rarity.
128+ // Regenerate bones from seed or userId, merge with stored soul.
127129export function getCompanion ( ) : Companion | undefined {
128130 const stored = getGlobalConfig ( ) . companion
129131 if ( ! stored ) return undefined
130- const { bones } = roll ( companionUserId ( ) )
132+ const seed = stored . seed ?? companionUserId ( )
133+ const { bones } = rollWithSeed ( seed )
131134 // bones last so stale bones fields in old-format configs get overridden
132135 return { ...stored , ...bones }
133136}
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ export type CompanionBones = {
111111export type CompanionSoul = {
112112 name : string
113113 personality : string
114+ seed ?: string
114115}
115116
116117export type Companion = CompanionBones &
Original file line number Diff line number Diff line change 11import {
22 getCompanion ,
3- roll ,
3+ rollWithSeed ,
4+ generateSeed ,
45 type Roll ,
5- companionUserId ,
66} from '../../buddy/companion.js'
77import {
88 type StoredCompanion ,
@@ -133,14 +133,16 @@ export const call: LocalCommandCall = async (args, _context) => {
133133 }
134134 }
135135
136- const r = roll ( companionUserId ( ) )
136+ const seed = generateSeed ( )
137+ const r = rollWithSeed ( seed )
137138 const name = SPECIES_NAMES [ r . bones . species ] ?? 'Buddy'
138139 const personality =
139140 SPECIES_PERSONALITY [ r . bones . species ] ?? 'Mysterious and code-savvy.'
140141
141142 const stored : StoredCompanion = {
142143 name,
143144 personality,
145+ seed,
144146 hatchedAt : Date . now ( ) ,
145147 }
146148
@@ -212,14 +214,16 @@ export const call: LocalCommandCall = async (args, _context) => {
212214
213215 // /buddy rehatch — re-roll a new companion (replaces existing)
214216 if ( sub === 'rehatch' ) {
215- const r = roll ( companionUserId ( ) )
217+ const seed = generateSeed ( )
218+ const r = rollWithSeed ( seed )
216219 const name = SPECIES_NAMES [ r . bones . species ] ?? 'Buddy'
217220 const personality =
218221 SPECIES_PERSONALITY [ r . bones . species ] ?? 'Mysterious and code-savvy.'
219222
220223 const stored : StoredCompanion = {
221224 name,
222225 personality,
226+ seed,
223227 hatchedAt : Date . now ( ) ,
224228 }
225229
You can’t perform that action at this time.
0 commit comments