37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
// Gathers every source of bonuses for the current state and folds them.
|
|
|
|
import { foldEffects } from './effects.js';
|
|
import { chipDemandBonus } from './formulas.js';
|
|
|
|
/** 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 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 gives a small passive bonus.
|
|
const passive = 1 + ctx.rules.legacy.passivePerPoint;
|
|
entries.push({ effect: { type: 'global_mult', value: passive }, times: state.legacy.earned });
|
|
entries.push({ effect: { type: 'demand_mult', value: passive }, times: state.legacy.earned });
|
|
|
|
// 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));
|
|
}
|