fix: make guardian names deterministic per floor instead of using Math.random()
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m37s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m37s
- generateGuardianName() now takes a floor parameter and uses floor % prefixes.length for deterministic prefix selection - generateComboGuardianName() now takes a floor parameter and uses (floor + i) % prefixes.length for each element - getGuardianForFloor() passes floor to generateGuardianName for static guardians with empty names - getExtendedGuardian() passes floor to generateComboGuardianName for combo guardians - Removes dependency on Math.random() → names are stable across ticks/refreshes Fixes #161
This commit is contained in:
@@ -36,19 +36,19 @@ const GUARDIAN_TITLES: string[] = [
|
||||
'Guardian', 'Sentinel', 'Champion', 'Overlord', 'Archon',
|
||||
];
|
||||
|
||||
export function generateGuardianName(element: string): string {
|
||||
export function generateGuardianName(element: string, floor: number = 0): string {
|
||||
const prefixes = GUARDIAN_PREFIXES[element] || ['Unknown'];
|
||||
const prefix = prefixes[Math.floor(Math.random() * prefixes.length)];
|
||||
const title = GUARDIAN_TITLES[Math.floor(Math.random() * GUARDIAN_TITLES.length)];
|
||||
const prefix = prefixes[floor % prefixes.length];
|
||||
const title = GUARDIAN_TITLES[Math.floor(floor / 10) % GUARDIAN_TITLES.length];
|
||||
return `${prefix} the ${title}`;
|
||||
}
|
||||
|
||||
export function generateComboGuardianName(elements: string[]): string {
|
||||
const parts = elements.map((el) => {
|
||||
export function generateComboGuardianName(elements: string[], floor: number = 0): string {
|
||||
const parts = elements.map((el, i) => {
|
||||
const prefixes = GUARDIAN_PREFIXES[el] || ['Unknown'];
|
||||
return prefixes[Math.floor(Math.random() * prefixes.length)];
|
||||
return prefixes[(floor + i) % prefixes.length];
|
||||
});
|
||||
const title = GUARDIAN_TITLES[Math.floor(Math.random() * GUARDIAN_TITLES.length)];
|
||||
const title = GUARDIAN_TITLES[Math.floor(floor / 10) % GUARDIAN_TITLES.length];
|
||||
return `${parts.join('-')} the ${title}`;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ export function getExtendedGuardian(floor: number): GuardianDef | null {
|
||||
const g = getComboGuardian(floor);
|
||||
if (!g.name) {
|
||||
const elements = g.element.split('+');
|
||||
g.name = generateComboGuardianName(elements);
|
||||
g.name = generateComboGuardianName(elements, floor);
|
||||
}
|
||||
return g;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ export function getExtendedGuardian(floor: number): GuardianDef | null {
|
||||
export function getGuardianForFloor(floor: number): GuardianDef | null {
|
||||
if (BASE_GUARDIANS[floor]) {
|
||||
const g = { ...BASE_GUARDIANS[floor] };
|
||||
if (!g.name) g.name = generateGuardianName(g.element);
|
||||
if (!g.name) g.name = generateGuardianName(g.element, floor);
|
||||
return g;
|
||||
}
|
||||
return getExtendedGuardian(floor);
|
||||
|
||||
Reference in New Issue
Block a user