diff options
author | mat <github@matdoes.dev> | 2022-05-20 22:16:27 -0500 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-05-20 22:16:27 -0500 |
commit | 4fd6512897cbc37b6e5181656b78e5f7d192a97a (patch) | |
tree | 0c53d83db3d5b272091e36238ebb469ac2b61b13 | |
parent | fad0de1fec8c3ac5eea06000f0bc31c769a33145 (diff) | |
download | skyblock-api-4fd6512897cbc37b6e5181656b78e5f7d192a97a.tar.gz skyblock-api-4fd6512897cbc37b6e5181656b78e5f7d192a97a.tar.bz2 skyblock-api-4fd6512897cbc37b6e5181656b78e5f7d192a97a.zip |
Improve achievements
-rw-r--r-- | src/cleaners/achievements.ts | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/cleaners/achievements.ts b/src/cleaners/achievements.ts index 5d10209..dcb1bec 100644 --- a/src/cleaners/achievements.ts +++ b/src/cleaners/achievements.ts @@ -4,7 +4,13 @@ import { fetchAchievements } from '../hypixelCached.js' interface TieredAchievement { id: string name: string - value: number | null + tier: number + amount: number + /** + * The amount that has to be gotten to get to the next tier. If this is + * null, that means the player is at the max tier. + */ + next: number | null description: string } @@ -29,15 +35,27 @@ export async function cleanPlayerAchievements(data: typedHypixelApi.PlayerDataRe let tieredAchievements: TieredAchievement[] = [] for (const [achievementId, achievementData] of Object.entries(achievementsData.tiered)) { - const value = data.achievements[`skyblock_${achievementId.toLowerCase()}`] ?? null + const amount = data.achievements[`skyblock_${achievementId.toLowerCase()}`] ?? null + + let tier = 0 + for (const tierData of achievementData.tiers) { + if (amount >= tierData.amount) + tier = tierData.tier + else + break + } + const next = achievementData.tiers[tier]?.amount ?? null + tieredAchievements.push({ id: achievementId.toLowerCase(), name: achievementData.name, - value, - description: value ? achievementData.description.replace(/%s/g, value.toString()) : achievementData.description + tier, + next, + amount, + description: achievementData.description.replace(/%s/g, (achievementData.tiers[Math.max(0, tier - 1)].amount).toString()) }) } - tieredAchievements.sort((a, b) => (b.value ?? 0) - (a.value ?? 0)) + tieredAchievements.sort((a, b) => (b.amount ?? 0) - (a.amount ?? 0)) let unlockedChallengeAchievements: ChallengeAchievement[] = [] let lockedChallengeAchievements: ChallengeAchievement[] = [] |