Skip to content

Profectus / features/clickables/repeatable

features/clickables/repeatable ​

This feature represents an upgrade the player can buy multiple times, typically with scaling requirements.

The simplest form would be a requirements with a static cost, for something like a consumable:

ts
const points = createResource<DecimalSource>(10);

const repeatable = createRepeatable(() => ({
    requirements: createCostRequirement(() => ({ cost: 100, resource: noPersist(points) })),
    display: {
        title: "Potions",
        description: "Each heals you for 10 hp. Max 10."
    }
}));

Scaling costs will need to take advantage of a formula:

ts
const points = createResource<DecimalSource>(10);
const repeatable = createRepeatable(() => ({
    requirements: createCostRequirement((): CostRequirementOptions => ({
        cost: Formula.variable(repeatable.amount.value).pow_base(3).times(100),
        resource: noPersist(points)
    })),
    display: {
        title: "Point Doubler",
        description: "Double your points",
        effectDisplay: (): string => formatWhole(Decimal.pow(2, repeatable.amount.value)) + "x"
    }
}));

Keep in mind to set CostRequirement.maxBulkAmount and other properties to handle buying multiple at once, if desired.

If you want to give the player some benefit based on the number of times they've purchased this upgrade, you can refer to the amount property, like so:

ts
const pointGainModifier = createSequentialModifier(() => [
    ...,
    createMultiplicativeModifier(() => ({
        multiplier: () => Decimal.pow(2, repeatable.amount.value),
        enabled: () => Decimal.gt(repeatable.amount, 0)
    }))
]);

const pointGain = computed(() => pointGainModifier.apply(1));
layer.on("update", diff => {
    points.value = Decimal.add(points.value, Decimal.times(pointGain.value, diff));
});

Index ​

Interfaces ​

Variables ​

Functions ​