aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-03-27 19:05:17 -0500
committermat <github@matdoes.dev>2022-03-27 19:05:17 -0500
commit5105df276bfba0425d8acde26ab00862a83a7d82 (patch)
tree21bd56d854ce2974eb11a6709f99353922d922de
parent3c2ff3de1dc67dee2824d37a71cefaae32da6b23 (diff)
downloadskyblock-api-5105df276bfba0425d8acde26ab00862a83a7d82.tar.gz
skyblock-api-5105df276bfba0425d8acde26ab00862a83a7d82.tar.bz2
skyblock-api-5105df276bfba0425d8acde26ab00862a83a7d82.zip
Add default skills if they're missing from member
-rw-r--r--src/cleaners/skyblock/skills.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts
index 4180ab2..ac5c10c 100644
--- a/src/cleaners/skyblock/skills.ts
+++ b/src/cleaners/skyblock/skills.ts
@@ -1,4 +1,5 @@
import typedHypixelApi from 'typed-hypixel-api'
+import { fetchSkills } from '../../constants.js'
import { levelFromXpTable } from '../../util.js'
export interface Skill {
@@ -136,6 +137,7 @@ export function levelForSkillXp(xp: number, maxLevel: number) {
}
export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember): Promise<Skill[]> {
+ const allSkillNames = await fetchSkills()
const skills: Skill[] = []
for (const item in data) {
if (item.startsWith('experience_skill_')) {
@@ -170,5 +172,22 @@ export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember):
})
}
}
+
+ // add missing skills
+ const missingSkillNames = allSkillNames.filter(skillName => !skills.some(skill => skill.name === skillName))
+ for (const skillName of missingSkillNames) {
+ skills.push({
+ name: skillName,
+ xp: 0,
+ level: 0,
+ maxLevel: skillsMaxLevel[skillName] ?? skillsDefaultMaxLevel,
+ levelXp: 0,
+ levelXpRequired: 0
+ })
+ }
+
+ // sort skills by name
+ skills.sort((a, b) => a.name.localeCompare(b.name))
+
return skills
}