Skip to content

Commit

Permalink
Added support for level 60 skills
Browse files Browse the repository at this point in the history
  • Loading branch information
builder-247 committed Jan 16, 2021
1 parent 70273da commit bde4662
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
23 changes: 23 additions & 0 deletions src/constants/leveling.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ module.exports = {
48: 3400000,
49: 3700000,
50: 4000000,
51: 4300000,
52: 4600000,
53: 4900000,
54: 5200000,
55: 5500000,
56: 5800000,
57: 6100000,
58: 6400000,
59: 6700000,
60: 7000000,
},

levelCaps: {
farming: 60,
mining: 60,
combat: 50,
foraging: 50,
fishing: 50,
enchanting: 60,
alchemy: 50,
taming: 50,
carpentry: 50,
runecrafting: 25,
},

// XP required for each level of Runecrafting
Expand Down
7 changes: 4 additions & 3 deletions src/player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ class Player {
const getSkills = (regexp) => util.pickKeys(rest, {
regexp,
keyMap: (key) => key.replace(regexp, ''),
valueMap: (value) => util.getLevelByXp(value),
});
const getSlayer = ({
claimed_levels = {},
Expand All @@ -213,8 +212,10 @@ class Player {
};
};
const collection_tiers = getUnlockedTier(unlocked_coll_tiers);
const skills = getSkills(/^experience_skill_(?!runecrafting)/);
skills.runecrafting = util.getLevelByXp(rest.experience_skill_runecrafting, true);
const skills = getSkills(/^experience_skill_/);
Object.entries(skills).forEach(([key, value]) => {
skills[key] = util.getLevelByXp(value, key);
});

this.last_save = last_save;
this.first_join = first_join;
Expand Down
17 changes: 11 additions & 6 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ function removeZeroes(object = {}) {
return newObject;
}

function getLevelByXp(xp = 0, runecrafting) {
const xpTable = runecrafting ? constants.runecraftingXp : constants.levelingXp;
function getLevelByXp(xp = 0, type) {
let xpTable;
switch (type) {
case 'runecrafting':
xpTable = constants.runecraftingXp;
break;
default:
xpTable = constants.levelingXp;
}
if (Number.isNaN(xp)) {
return {
xp: 0,
Expand All @@ -150,10 +157,8 @@ function getLevelByXp(xp = 0, runecrafting) {
let xpTotal = 0;
let level = 0;
let xpForNext = Infinity;
const maxLevel = Object.keys(xpTable)
.sort((a, b) => Number(a) - Number(b))
.map((a) => Number(a))
.pop();

const maxLevel = constants.levelCaps[type] || 50;

for (let x = 1; x <= maxLevel; x += 1) {
xpTotal += xpTable[x];
Expand Down

0 comments on commit bde4662

Please sign in to comment.