aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/skills.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/cleaners/skyblock/skills.ts')
-rw-r--r--src/cleaners/skyblock/skills.ts66
1 files changed, 59 insertions, 7 deletions
diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts
index d035a96..8d0f16d 100644
--- a/src/cleaners/skyblock/skills.ts
+++ b/src/cleaners/skyblock/skills.ts
@@ -2,9 +2,10 @@ import typedHypixelApi from 'typed-hypixel-api'
import { fetchSkills } from '../../constants.js'
import { levelFromXpTable } from '../../util.js'
import * as constants from '../../constants.js'
+import { CleanFullPlayer } from '../player.js'
export interface Skill {
- name: string
+ id: string
xp: number
level: number
@@ -14,6 +15,16 @@ export interface Skill {
levelXpRequired: number
}
+export interface Skills {
+ list: Skill[]
+ /**
+ * Whether the player has their skills API enabled. If this is off, that
+ * means the data doesn't include xp and is per-player. You should show a
+ * warning to the user.
+ */
+ apiEnabled: boolean
+}
+
// the highest level you can have in each skill
// numbers taken from https://hypixel-skyblock.fandom.com/wiki/Skills
const skillsMaxLevel: { [key: string]: number } = {
@@ -137,7 +148,39 @@ export function levelForSkillXp(xp: number, maxLevel: number) {
return levelFromXpTable(xp, xpTable)
}
-export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember): Promise<Skill[]> {
+function skillFromLevel(id: string, level: number): Skill {
+ const maxLevel = skillsMaxLevel[id] ?? skillsDefaultMaxLevel
+ const xpTable = (maxLevel <= 25 ? skillXpTableEasier : skillXpTable).slice(0, maxLevel)
+ const xp = level > 0 ? xpTable[level - 1] ?? 0 : 0
+
+ return {
+ id,
+ level,
+ levelXp: 0,
+ levelXpRequired: xpTable[level],
+ maxLevel: maxLevel,
+ xp
+ }
+}
+
+function skillsFromSkyBlockAchievements(achievements: CleanFullPlayer['achievements']['skyblock']): Skills {
+ return {
+ apiEnabled: false,
+ list: [
+ skillFromLevel('fishing', achievements['angler']),
+ skillFromLevel('enchanting', achievements['augmentation']),
+ skillFromLevel('combat', achievements['combat']),
+ skillFromLevel('alchemy', achievements['concoctor']),
+ skillFromLevel('taming', achievements['domesticator']),
+ skillFromLevel('dungeoneering', achievements['dungeoneer']),
+ skillFromLevel('mining', achievements['excavator']),
+ skillFromLevel('foraging', achievements['gatherer']),
+ skillFromLevel('farming', achievements['harvester'])
+ ]
+ }
+}
+
+export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember, player: CleanFullPlayer): Promise<Skills> {
const allSkillNames = await fetchSkills()
const skills: Skill[] = []
@@ -168,7 +211,7 @@ export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember):
const skillLevelXpRequired = xpTable[skillLevel] - previousLevelXp
skills.push({
- name: skillName,
+ id: skillName,
xp: skillXp,
level: skillLevel,
maxLevel: skillMaxLevel,
@@ -178,16 +221,22 @@ export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember):
}
}
+ // if the player has no skills but has kills, we can assume they have the skills api off
+ // (we check kills to know whether the profile is actually used, this is kinda arbitrary)
+ if (skills.length === 0 && Object.keys(data.stats).includes('kills')) {
+ return skillsFromSkyBlockAchievements(player.achievements.skyblock)
+ }
+
constants.addSkills(skillNamesFound)
// add missing skills
- const missingSkillNames = allSkillNames.filter(skillName => !skills.some(skill => skill.name === skillName))
+ const missingSkillNames = allSkillNames.filter(skillName => !skills.some(skill => skill.id === skillName))
for (const skillName of missingSkillNames) {
const skillMaxLevel = skillsMaxLevel[skillName] ?? skillsDefaultMaxLevel
const xpTable = (skillMaxLevel <= 25 ? skillXpTableEasier : skillXpTable).slice(0, skillMaxLevel)
skills.push({
- name: skillName,
+ id: skillName,
xp: 0,
level: 0,
maxLevel: skillMaxLevel,
@@ -197,7 +246,10 @@ export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember):
}
// sort skills by name
- skills.sort((a, b) => a.name.localeCompare(b.name))
+ skills.sort((a, b) => a.id.localeCompare(b.id))
- return skills
+ return {
+ apiEnabled: true,
+ list: skills,
+ }
}