fix: Bilbo randomness flickering - move random rolls from updateRates() to tick()
Some checks failed
Accessibility Checks / a11y-audit (pull_request) Failing after 2s
Smoke Test / smoke (pull_request) Failing after 3s

updateRates() is called from buyBuilding, buyProject, resolveEvent, sprint
activation, and other non-tick contexts. Having Math.random() inside it caused
the creativity rate to flicker unpredictably whenever ANY of those functions ran.

Fix: roll Bilbo burst/vanish once per tick, store as flags, read flags in
updateRates(). Deterministic rate calculation, consistent randomness.
This commit is contained in:
Alexander Whitestone
2026-04-12 06:02:09 -04:00
parent cd9ac2f88a
commit 760d7b8542

28
game.js
View File

@@ -1125,13 +1125,16 @@ function updateRates() {
G.userRate += 5 * timmyCount * (timmyMult - 1);
}
// Bilbo randomness: 10% chance of massive creative burst
if (G.buildings.bilbo > 0 && Math.random() < CONFIG.BILBO_BURST_CHANCE) {
G.creativityRate += 50 * G.buildings.bilbo;
}
// Bilbo vanishing: 5% chance of zero creativity this tick
if (G.buildings.bilbo > 0 && Math.random() < CONFIG.BILBO_VANISH_CHANCE) {
G.creativityRate = 0;
// Bilbo randomness: flags are set per-tick in tick(), not here
// updateRates() is called from many non-tick contexts (buy, resolve, sprint)
// and would cause rate flickering if random rolls happened here
if (G.buildings.bilbo > 0) {
if (G.bilboBurstActive) {
G.creativityRate += 50 * G.buildings.bilbo;
}
if (G.bilboVanishActive) {
G.creativityRate = 0;
}
}
// Allegro requires trust
@@ -1228,6 +1231,17 @@ function tick() {
G.tick += dt;
G.playTime += dt;
// Bilbo randomness: roll once per tick, store as flags for updateRates()
// Previously this was inside updateRates() which caused flickering
// since updateRates() is called from many non-tick contexts
if (G.buildings.bilbo > 0) {
G.bilboBurstActive = Math.random() < CONFIG.BILBO_BURST_CHANCE;
G.bilboVanishActive = Math.random() < CONFIG.BILBO_VANISH_CHANCE;
} else {
G.bilboBurstActive = false;
G.bilboVanishActive = false;
}
// Sprint ability
tickSprint(dt);