Bug: Guardians with empty names get random names on every tick instead of being locked at loop start #161
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug Description
Guardians defined with
name: ''(floors 90-140 compound/exotic guardians) get a new random name generated every timegetGuardianForFloor()is called, becausegenerateGuardianName()usesMath.random(). This means the guardian's name changes every tick/refresh. Guardians should have their names locked in at loop start and remain stable.Additionally, the procedural combo guardians (floor 150+) also use
Math.random()for name generation ingenerateComboGuardianName(), which has the same issue — the name is regenerated on every lookup.Root Cause
In
src/lib/game/data/guardian-encounters.ts:generateGuardianName()usesMath.random()to pick a prefix and titlegenerateComboGuardianName()also usesMath.random()getGuardianForFloor()callsgenerateGuardianName()for static guardians with empty names on every invocationgetExtendedGuardian()callsgenerateComboGuardianName()on every invocationSince
getGuardianForFloor()is called during gameplay (tick processing, UI rendering), the names keep changing.Fix Required
Option A: Pre-generate names at loop start (recommended)
initializeGuardianNames()that runs once at loop start (called frominitGameor prestige reset)BASE_GUARDIANSentries withname: ''and assign a deterministic name using a seeded random or just pick the first prefixgetGuardianForFloor()return the same nameOption B: Deterministic names based on floor
Instead of
Math.random(), derive the name from the floor number:Option C: Pre-populate names in guardian-data.ts
Simply fill in the
namefield for floors 90, 100, 110, 120, 130, 140 inguardian-data.tswith fixed names, and remove theif (!g.name)fallback ingetGuardianForFloor().Affected Files
src/lib/game/data/guardian-encounters.ts—generateGuardianName()(lines 37-43),generateComboGuardianName()(lines 45-52),getGuardianForFloor()(lines 128-137),getExtendedGuardian()(lines 115-124)src/lib/game/data/guardian-data.ts— emptynamefields on floors 90, 100, 110, 120, 130, 140src/lib/game/stores/gameStore.ts— whereinitGame()is defined (to call name initialization)Starting work on #161 — Guardian names change every tick due to Math.random() in name generation. Will implement Option B (deterministic names based on floor number) for all procedural guardians.
Fixed #161 — Guardian names are now deterministic per floor.
Changes:
src/lib/game/data/guardian-encounters.ts— ReplacedMath.random()with floor-based deterministic indexing ingenerateGuardianName()andgenerateComboGuardianName(). Both functions now accept afloorparameter that is used to pick prefix/title from the arrays via modulo arithmetic.src/lib/game/__tests__/guardian-names.test.ts— 17 regression tests verifying name determinism across all guardian types (compound, exotic, combo) and edge cases.Root cause:
Math.random()was called on everygetGuardianForFloor()/getExtendedGuardian()invocation, producing different names each tick/refresh.Fix: Floor number is now used as the seed for prefix/title selection, making names stable regardless of how many times the function is called.
All 902 tests pass.