Achievement Plugin
Achievements are great. Not only are they a way to reward the player for exploring and experimenting, they also provide a sense of purpose. If your players can see they have many achievements left to complete, they will keep playing for a longer time.
The achievement plugin handles the earning of Achievements. It uses your existing Conditions to determine when an achievement should unlock.
Demo
You have 0 money!
Gain 10 money Not earned
Gain 50 money Not earned
Manual Unlock Not earned
Usage
import { AchievementPlugin } from '@123ishatest/ludiek';
const achievement = new AchievementPlugin();
// Define your achievements
const achievements: AchievementDetail[] = [
{ id: '/achievement/10-total-money', condition: { type: '/condition/has-scalar-statistic', id: '/statistic/total-money', amount: 10 } },
{ id: '/achievement/manual' },
];
achievement.loadContent(achievements);
// Check all unearned achievement to see if the conditions are met
achievement.checkAchievements()
// Manually earn an achievement
achievement.earnAchievement('/achievement/manual')
// Check whether we have them
achievement.hasAchievement('/achievement/manual') // true Hook into the “achievement earned” event for UI/popups
achievement.onAchievementEarned.subscribe(({ id }) => {
console.log(`Congratulations, you have earned achievement ${id}!`)
});