// Gathers every source of bonuses for the current state and folds them. import { foldEffects } from './effects.js'; import { chipDemandBonus } from './formulas.js'; /** The multiplier given by all legacy points earned so far: diminishing returns (a power below 1). */ export function passiveBonus(state, ctx) { const { passiveScale, passivePower } = ctx.rules.legacy; return 1 + passiveScale * state.legacy.earned ** passivePower; } /** All `{ effect, times }` entries that apply to `state`. */ export function collectEffects(state, ctx) { const entries = []; for (const id of state.upgrades) entries.push({ effect: ctx.upgradesById.get(id)?.effect }); for (const [id, level] of Object.entries(state.endless)) { entries.push({ effect: ctx.endlessById.get(id)?.effect, times: level }); } for (const id of state.research) entries.push({ effect: ctx.researchById.get(id)?.effect }); for (const id of state.achievements) entries.push({ effect: ctx.achievementsById.get(id)?.effect }); for (const [id, level] of Object.entries(state.legacy.perks)) { entries.push({ effect: ctx.perksById.get(id)?.effect, times: level }); } // Every legacy point ever earned adds a flat bonus. It has diminishing returns and does // not compound: stacking x1.05 per point once reached 1e100 within a few runs. entries.push({ effect: { type: 'global_mult', value: passiveBonus(state, ctx) } }); entries.push({ effect: { type: 'demand_mult', value: passiveBonus(state, ctx) } }); // Chips make the brand more attractive, with diminishing returns. entries.push({ effect: { type: 'demand_mult', value: chipDemandBonus(state.chips, ctx.rules.gamble) }, }); // Temporary buffs from events and contracts. for (const buff of state.events.buffs) entries.push({ effect: { type: buff.type, value: buff.value } }); return entries; } export function modifiersFor(state, ctx) { return foldEffects(collectEffects(state, ctx)); }