Session 15: Buy Max Prestige Upgrades (bulk-buy for prestige upgrades) + fix missing Stellar Essence spend
This commit is contained in:
+47
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user