diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-06-02 16:23:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-02 16:23:38 -0500 |
commit | 69910faa449ee9d4ff63fc1a764434e7bd974d1b (patch) | |
tree | 75efc15481ecf153044f1de214b0b4e212bc0cc4 | |
parent | 709d428b4cb94e8eca53b6f32e0f8b1be5a323b9 (diff) | |
download | skyblock-api-69910faa449ee9d4ff63fc1a764434e7bd974d1b.tar.gz skyblock-api-69910faa449ee9d4ff63fc1a764434e7bd974d1b.tar.bz2 skyblock-api-69910faa449ee9d4ff63fc1a764434e7bd974d1b.zip |
Extra skill info (#52)
* include more data about skills
* i decided that having manual stuff in skyblock-constants is a bad idea
* Update skills.js
-rw-r--r-- | build/cleaners/skyblock/skills.js | 107 | ||||
-rw-r--r-- | src/cleaners/skyblock/skills.ts | 112 | ||||
-rw-r--r-- | test-data-generator/index.ts | 2 | ||||
-rw-r--r-- | test/test.js | 44 |
4 files changed, 235 insertions, 30 deletions
diff --git a/build/cleaners/skyblock/skills.js b/build/cleaners/skyblock/skills.js index a761ec8..0cb8c16 100644 --- a/build/cleaners/skyblock/skills.js +++ b/build/cleaners/skyblock/skills.js @@ -4,7 +4,6 @@ exports.cleanSkills = exports.levelForSkillXp = void 0; const constants_1 = require("../../constants"); // the highest level you can have in each skill // numbers taken from https://hypixel-skyblock.fandom.com/wiki/Skills -// maybe these should be moved to skyblock-constants? const skillsMaxLevel = { farming: 60, mining: 60, @@ -19,6 +18,108 @@ const skillsMaxLevel = { runecrafting: 25, social: 25 }; +const skillXpTable = [ + 50, + 175, + 375, + 675, + 1175, + 1925, + 2925, + 4425, + 6425, + 9925, + 14925, + 22425, + 32425, + 47425, + 67425, + 97425, + 147425, + 222425, + 322425, + 522425, + 822425, + 1222425, + 1722425, + 2322425, + 3022425, + 3822425, + 4722425, + 5722425, + 6822425, + 8022425, + 9322425, + 10722425, + 12222425, + 13822425, + 15522425, + 17322425, + 19222425, + 21222425, + 23322425, + 25522425, + 27822425, + 30222425, + 32722425, + 35322425, + 38072425, + 40972425, + 44072425, + 47472425, + 51172425, + 55172425, + 59472425, + 64072425, + 68972425, + 74172425, + 79672425, + 85472425, + 91572425, + 97972425, + 104672425, + 111672425 // 60 +]; +const skillXpTableEasier = [ + 50, + 150, + 275, + 435, + 635, + 885, + 1200, + 1600, + 2100, + 2725, + 3510, + 4510, + 5760, + 7325, + 9325, + 11825, + 14950, + 18950, + 23950, + 30200, + 38050, + 47850, + 60100, + 75400, + 94450 // 25 +]; +// for skills that aren't in maxSkills, default to this +const skillsDefaultMaxLevel = 50; +/** + * Get the skill level for the amount of total xp + * @param xp The xp we're finding the level for + * @param easierLevel Whether it should use the alternate leveling xp table (used for cosmetic skills and dungeoneering) + */ +function levelForSkillXp(xp, maxLevel) { + const xpTable = maxLevel <= 25 ? skillXpTableEasier : skillXpTable; + const skillLevel = [...xpTable].reverse().findIndex(levelXp => xp >= levelXp); + return skillLevel === -1 ? 0 : xpTable.length - skillLevel; +} +exports.levelForSkillXp = levelForSkillXp; // for skills that aren't in maxSkills, default to this const skillsDefaultMaxLevel = 50; /** @@ -41,9 +142,9 @@ async function cleanSkills(data) { // the amount of total xp you have in this skill const skillXp = data[item]; const skillMaxLevel = (_a = skillsMaxLevel[skillName]) !== null && _a !== void 0 ? _a : skillsDefaultMaxLevel; - const xpTable = skillMaxLevel <= 25 ? await constants_1.fetchSkillXpEasier() : await constants_1.fetchSkillXp(); + const xpTable = skillMaxLevel <= 25 ? skillXpTableEasier : skillXpTable; // the level you're at for this skill - const skillLevel = await levelForSkillXp(skillXp, skillMaxLevel); + const skillLevel = levelForSkillXp(skillXp, skillMaxLevel); // the total xp required for the previous level const previousLevelXp = skillLevel >= 1 ? xpTable[skillLevel - 1] : 0; // the extra xp left over diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts index fa27217..154b269 100644 --- a/src/cleaners/skyblock/skills.ts +++ b/src/cleaners/skyblock/skills.ts @@ -11,7 +11,6 @@ export interface Skill { // the highest level you can have in each skill // numbers taken from https://hypixel-skyblock.fandom.com/wiki/Skills -// maybe these should be moved to skyblock-constants? const skillsMaxLevel: { [ key: string ]: number } = { farming: 60, mining: 60, @@ -27,6 +26,113 @@ const skillsMaxLevel: { [ key: string ]: number } = { social: 25 } +const skillXpTable = [ + 50, // 1 + 175, + 375, + 675, + 1175, + 1925, + 2925, + 4425, + 6425, + 9925, // 10 + 14925, + 22425, + 32425, + 47425, + 67425, + 97425, + 147425, + 222425, + 322425, + 522425, // 20 + 822425, + 1222425, + 1722425, + 2322425, + 3022425, + 3822425, + 4722425, + 5722425, + 6822425, + 8022425, // 30 + 9322425, + 10722425, + 12222425, + 13822425, + 15522425, + 17322425, + 19222425, + 21222425, + 23322425, + 25522425, // 40 + 27822425, + 30222425, + 32722425, + 35322425, + 38072425, + 40972425, + 44072425, + 47472425, + 51172425, + 55172425, // 50 + 59472425, + 64072425, + 68972425, + 74172425, + 79672425, + 85472425, + 91572425, + 97972425, + 104672425, + 111672425 // 60 + ] + + +const skillXpTableEasier = [ + 50, // 1 + 150, + 275, + 435, + 635, + 885, + 1200, + 1600, + 2100, + 2725, // 10 + 3510, + 4510, + 5760, + 7325, + 9325, + 11825, + 14950, + 18950, + 23950, + 30200, // 20 + 38050, + 47850, + 60100, + 75400, + 94450 // 25 +] + + +// for skills that aren't in maxSkills, default to this +const skillsDefaultMaxLevel: number = 50 + +/** + * Get the skill level for the amount of total xp + * @param xp The xp we're finding the level for + * @param easierLevel Whether it should use the alternate leveling xp table (used for cosmetic skills and dungeoneering) + */ +export function levelForSkillXp(xp: number, maxLevel: number) { + const xpTable = maxLevel <= 25 ? skillXpTableEasier : skillXpTable + const skillLevel = [...xpTable].reverse().findIndex(levelXp => xp >= levelXp) + return skillLevel === -1 ? 0 : xpTable.length - skillLevel +} + // for skills that aren't in maxSkills, default to this const skillsDefaultMaxLevel: number = 50 @@ -52,10 +158,10 @@ export async function cleanSkills(data: any): Promise<Skill[]> { const skillMaxLevel = skillsMaxLevel[skillName] ?? skillsDefaultMaxLevel - const xpTable = skillMaxLevel <= 25 ? await fetchSkillXpEasier() : await fetchSkillXp() + const xpTable = skillMaxLevel <= 25 ? skillXpTableEasier : skillXpTable // the level you're at for this skill - const skillLevel = await levelForSkillXp(skillXp, skillMaxLevel) + const skillLevel = levelForSkillXp(skillXp, skillMaxLevel) // the total xp required for the previous level const previousLevelXp = skillLevel >= 1 ? xpTable[skillLevel - 1] : 0 diff --git a/test-data-generator/index.ts b/test-data-generator/index.ts index b0b3ba6..18cefd7 100644 --- a/test-data-generator/index.ts +++ b/test-data-generator/index.ts @@ -42,8 +42,6 @@ async function addConstants() { 'slayers', 'stats', 'zones', - 'manual/skill_xp', - 'manual/skill_xp_easier', ] for (const constantName of constantNames) { const constantData = await constants.fetchJSONConstant(constantName + '.json') diff --git a/test/test.js b/test/test.js index e0e8b6c..bb96849 100644 --- a/test/test.js +++ b/test/test.js @@ -151,28 +151,28 @@ describe('hypixel', () => { }) describe('Individual utility things', () => { - describe('#levelForSkillXp()', async() => { - it('0 xp is level 0', async() => assert.strictEqual(await levelForSkillXp(0, 60), 0)) - it('49 xp is level 0', async() => assert.strictEqual(await levelForSkillXp(49, 60), 0)) - it('50 xp is level 1', async() => assert.strictEqual(await levelForSkillXp(50, 60), 1)) - it('174 xp is level 1', async() => assert.strictEqual(await levelForSkillXp(174, 60), 1)) - it('175 xp is level 2', async() => assert.strictEqual(await levelForSkillXp(175, 60), 2)) - it('176 xp is level 2', async() => assert.strictEqual(await levelForSkillXp(176, 60), 2)) - it('55172424 xp is level 49', async() => assert.strictEqual(await levelForSkillXp(55172424, 60), 49)) - it('55172425 xp is level 50', async() => assert.strictEqual(await levelForSkillXp(55172425, 60), 50)) - it('111672424 xp is level 59', async() => assert.strictEqual(await levelForSkillXp(111672424, 60), 59)) - it('111672425 xp is level 60', async() => assert.strictEqual(await levelForSkillXp(111672425, 60), 60)) - it('999999999 xp is level 60', async() => assert.strictEqual(await levelForSkillXp(999999999, 60), 60)) - - it('0 xp is level 0 (max 25)', async() => assert.strictEqual(await levelForSkillXp(0, 25), 0)) - it('49 xp is level 0 (max 25)', async() => assert.strictEqual(await levelForSkillXp(49, 25), 0)) - it('50 xp is level 1 (max 25)', async() => assert.strictEqual(await levelForSkillXp(50, 25), 1)) - it('149 xp is level 1 (max 25)', async() => assert.strictEqual(await levelForSkillXp(149, 25), 1)) - it('150 xp is level 2 (max 25)', async() => assert.strictEqual(await levelForSkillXp(150, 25), 2)) - it('151 xp is level 2 (max 25)', async() => assert.strictEqual(await levelForSkillXp(151, 25), 2)) - it('94449 xp is level 24 (max 25)', async() => assert.strictEqual(await levelForSkillXp(94449, 25), 24)) - it('94450 xp is level 25 (max 25)', async() => assert.strictEqual(await levelForSkillXp(94450, 25), 25)) - it('99999 xp is level 25 (max 25)', async() => assert.strictEqual(await levelForSkillXp(99999, 25), 25)) + describe('#levelForSkillXp()', () => { + it('0 xp is level 0', () => assert.strictEqual(levelForSkillXp(0, 60), 0)) + it('49 xp is level 0', () => assert.strictEqual(levelForSkillXp(49, 60), 0)) + it('50 xp is level 1', () => assert.strictEqual(levelForSkillXp(50, 60), 1)) + it('174 xp is level 1', () => assert.strictEqual(levelForSkillXp(174, 60), 1)) + it('175 xp is level 2', () => assert.strictEqual(levelForSkillXp(175, 60), 2)) + it('176 xp is level 2', () => assert.strictEqual(levelForSkillXp(176, 60), 2)) + it('55172424 xp is level 49', () => assert.strictEqual(levelForSkillXp(55172424, 60), 49)) + it('55172425 xp is level 50', () => assert.strictEqual(levelForSkillXp(55172425, 60), 50)) + it('111672424 xp is level 59', () => assert.strictEqual(levelForSkillXp(111672424, 60), 59)) + it('111672425 xp is level 60', () => assert.strictEqual(levelForSkillXp(111672425, 60), 60)) + it('999999999 xp is level 60', () => assert.strictEqual(levelForSkillXp(999999999, 60), 60)) + + it('0 xp is level 0 (max 25)', () => assert.strictEqual(levelForSkillXp(0, 25), 0)) + it('49 xp is level 0 (max 25)', () => assert.strictEqual(levelForSkillXp(49, 25), 0)) + it('50 xp is level 1 (max 25)', () => assert.strictEqual(levelForSkillXp(50, 25), 1)) + it('149 xp is level 1 (max 25)', () => assert.strictEqual(levelForSkillXp(149, 25), 1)) + it('150 xp is level 2 (max 25)', () => assert.strictEqual(levelForSkillXp(150, 25), 2)) + it('151 xp is level 2 (max 25)', () => assert.strictEqual(levelForSkillXp(151, 25), 2)) + it('94449 xp is level 24 (max 25)', () => assert.strictEqual(levelForSkillXp(94449, 25), 24)) + it('94450 xp is level 25 (max 25)', () => assert.strictEqual(levelForSkillXp(94450, 25), 25)) + it('99999 xp is level 25 (max 25)', () => assert.strictEqual(levelForSkillXp(99999, 25), 25)) }) }) |