Upgrade Plugin
Upgrades are one of the most fundamental concepts of games: The player can spend some of their resources to gain a permanent bonus.
The upgrade plugin handles the buying of Upgrades.
When bought, the upgrade level increases and new bonuses are applied.
Bonuses can be accumulated up to the level of the upgrade, or only provide the bonus of the current level.
Demo
You have 0.00 money!
0
Cost: -10.00 0
Cost: -20.00Usage
import { UpgradePlugin } from '@123ishatest/ludiek';
const upgrade = new UpgradePlugin();
const upgrades = [
{
id: '/upgrade/shovel',
name: 'Shovel',
description: '+10% money',
bonusPerLevel: [
{ type: '/bonus/seed-global', amount: +0.1 },
{ type: '/bonus/seed-global', amount: +0.1 },
{ type: '/bonus/seed-global', amount: +0.1 },
],
costPerLevel: [
{ type: '/input/lose-currency', id: '/plant/sunflower', amount: 10 },
{ type: '/input/lose-currency', id: '/plant/sunflower', amount: 20 },
{ type: '/input/lose-currency', id: '/plant/sunflower', amount: 30 },
],
accumulateBonuses: true,
},
{
id: '/upgrade/watering-can',
name: 'Watering Can',
description: '+20% money',
bonusPerLevel: [
{ type: '/bonus/seed-global', amount: +0.2 },
{ type: '/bonus/seed-global', amount: +0.4 },
{ type: '/bonus/seed-global', amount: +0.6 },
],
costPerLevel: [
{ type: '/input/lose-currency', id: '/plant/sunflower', amount: 20 },
{ type: '/input/lose-currency', id: '/plant/sunflower', amount: 40 },
{ type: '/input/lose-currency', id: '/plant/sunflower', amount: 60 },
],
accumulateBonuses: false,
},
];
upgrade.loadContent(upgrades); Hook into the “upgrade bought” event for UI/popups
currency.onUpgradeBought.subscribe(({ id, level }) => {
console.log(`Congratulations, you have upgraded ${id} to level ${level}!`)
});