41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
// Upgrade effects. To add a new effect type: register it here, add its
|
|
// `effect.<type>` string to the core locale files, and use it in upgrades.json.
|
|
|
|
export function newModifiers() {
|
|
return {
|
|
click: 1,
|
|
generators: {},
|
|
global: 1,
|
|
demand: 1,
|
|
value: 1,
|
|
materialEfficiency: 1,
|
|
batchDiscount: 1,
|
|
batchSize: 1,
|
|
autoBuyMaterial: false,
|
|
};
|
|
}
|
|
|
|
const APPLY = {
|
|
click_mult: (m, e) => void (m.click *= e.value),
|
|
generator_mult: (m, e) => void (m.generators[e.target] = (m.generators[e.target] ?? 1) * e.value),
|
|
global_mult: (m, e) => void (m.global *= e.value),
|
|
demand_mult: (m, e) => void (m.demand *= e.value),
|
|
value_mult: (m, e) => void (m.value *= e.value),
|
|
material_efficiency: (m, e) => void (m.materialEfficiency *= e.value),
|
|
batch_discount: (m, e) => void (m.batchDiscount *= e.value),
|
|
batch_size_mult: (m, e) => void (m.batchSize *= e.value),
|
|
auto_buy_material: (m) => void (m.autoBuyMaterial = true),
|
|
};
|
|
|
|
export const EFFECT_TYPES = Object.keys(APPLY);
|
|
|
|
/** Fold every owned upgrade into a single set of multipliers. */
|
|
export function computeModifiers(ownedIds, upgradesById) {
|
|
const m = newModifiers();
|
|
for (const id of ownedIds) {
|
|
const effect = upgradesById.get(id)?.effect;
|
|
if (effect) APPLY[effect.type]?.(m, effect);
|
|
}
|
|
return m;
|
|
}
|