Session 15: Buy Max Prestige Upgrades (bulk-buy for prestige upgrades) + fix missing Stellar Essence spend

This commit is contained in:
2026-08-24 09:43:38 +00:00
parent 34074b8e65
commit 936f7fc4e8
5 changed files with 143 additions and 1 deletions
+47
View File
@@ -469,6 +469,53 @@ const Game = {
return { bought: bought.length, ids: bought };
},
/**
* Buy every prestige upgrade the player can currently afford at once,
* paid from Stellar Essence. Returns an object describing what happened:
* { bought: count, ids: [...] }. Prestige upgrades are one-time purchases,
* so we loop until a full pass buys nothing (purchasing one never unlocks
* another, but the loop is kept for symmetry with buyAllUpgrades and to
* stay safe should future prestige upgrades gain requirement gates).
*/
buyMaxPrestigeUpgrades() {
const bought = [];
let progress = true;
while (progress) {
progress = false;
for (const [id, upgrade] of Object.entries(PRESTIGE_UPGRADES)) {
if ((this.state.prestigeUpgrades || []).includes(id)) continue;
// Respect requirements before attempting purchase, mirroring
// PRESTIGE.buyUpgrade semantics.
if (upgrade.requirements) {
let met = true;
for (const [reqId, reqCount] of Object.entries(upgrade.requirements)) {
if ((this.state.buildings[reqId] || 0) < reqCount) {
met = false;
break;
}
}
if (!met) continue;
}
if ((this.state.stellarEssence || 0) >= upgrade.cost) {
this.state.prestigeUpgrades = this.state.prestigeUpgrades || [];
this.state.prestigeUpgrades.push(id);
// Spend Stellar Essence, mirroring PRESTIGE.buyUpgrade.
this.state.stellarEssence -= upgrade.cost;
bought.push(id);
progress = true;
}
}
}
if (bought.length > 0) {
UI.showNotification(`Bought ${bought.length} prestige upgrade(s)!`, 'achievement');
Audio.playPurchase();
UI.update();
}
return { bought: bought.length, ids: bought };
},
/**
* Golden Starbloom - random event system.
* A rare, time-limited bloom occasionally appears on screen. Clicking it
+47 -1
View File
@@ -43,6 +43,15 @@ const PrestigeUI = {
}
});
});
// Buy Max prestige upgrades button - buy every affordable prestige
// upgrade at once, paid from Stellar Essence.
const buyMaxBtn = document.getElementById('buy-all-prestige');
if (buyMaxBtn) {
buyMaxBtn.addEventListener('click', () => {
Game.buyMaxPrestigeUpgrades();
});
}
},
/**
@@ -119,7 +128,44 @@ const PrestigeUI = {
if (prestigeTab?.classList.contains('active')) {
this.renderPrestigeUpgrades();
}
}
// Show/hide the "Buy Max" button based on whether any unowned prestige
// upgrade is currently affordable with Stellar Essence. Read-only.
this.updateBuyMaxPrestigeButton();
},
/**
* Show/hide and enable/disable the "Buy Max" prestige-upgrades button
* depending on whether at least one unowned, requirement-met prestige
* upgrade is currently affordable with Stellar Essence. Read of game state
* only; never mutates it. Mirrors Game.buyMaxPrestigeUpgrades /
* PRESTIGE.buyUpgrade semantics.
*/
updateBuyMaxPrestigeButton() {
const btn = document.getElementById('buy-all-prestige');
if (!btn) return;
let affordableAny = false;
for (const [id, upgrade] of Object.entries(PRESTIGE_UPGRADES)) {
if ((Game.state.prestigeUpgrades || []).includes(id)) continue;
if ((Game.state.stellarEssence || 0) < upgrade.cost) continue;
if (upgrade.requirements) {
let met = true;
for (const [reqId, reqCount] of Object.entries(upgrade.requirements)) {
if ((Game.state.buildings[reqId] || 0) < reqCount) {
met = false;
break;
}
}
if (!met) continue;
}
affordableAny = true;
break;
}
btn.style.display = affordableAny ? '' : 'none';
btn.disabled = !affordableAny;
},
};
window.PrestigeUI = PrestigeUI;