Skip to content

Commit

Permalink
Add floatLevel and ASL to parser (#14)
Browse files Browse the repository at this point in the history
* Add t5 slayer kill value

Add tier 5 slayer kills to the getSlayer const

* Return floatLevel in getLevelByXp

Add the float level to the returned skill json

* Add ASL to parser

Add ASL to the returned skyblock profile request (only will appear if skills isn't empty)

* Add total dragon last hit kills to stats

* Update Player.js

Re-format getTotalDragonKills function

* Update Player.js

* Update total_dragon_kills

Added a surrounding Number() around the function for total_dragon_kills so that it will return a number and not the json object

* Update Player.js

* Update Player.js
  • Loading branch information
SomeRandom-WhoLikesCode authored May 6, 2021
1 parent 1e20668 commit 756e5df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/player/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ async function getInventory({ data = '' }, active = false) {
return Promise.all(i.map(async (item) => new Item(item, active)));
}

function getTotalDragonKills(json) {
let totalKills = 0;
Object.entries(json).forEach(
(stat) => { totalKills += stat[1]; },
);
return totalKills;
}

// Process the stats object
function processStats({
kills = 0,
Expand Down Expand Up @@ -87,6 +95,7 @@ function processStats({
total_kills: kills,
total_deaths: deaths,
kills: getStats(/^kills_/),
total_dragon_kills: Number(getTotalDragonKills(getStats(/^kills_(.*)_dragon/, (key) => key.replace(/^kills_(.*)_dragon/, '$1')))),
deaths: getStats(/^deaths_/),
highest_critical_damage: Math.round(highest_critical_damage),
ender_crystals_destroyed,
Expand Down Expand Up @@ -217,8 +226,14 @@ class Player {
};
const collection_tiers = getUnlockedTier(unlocked_coll_tiers);
const skills = getSkills(/^experience_skill_/);
let averageSkillLevel = 0.0;
// define variabe before forEach loop so it can be used out the loop scope
Object.entries(skills).forEach(([key, value]) => {
skills[key] = util.getLevelByXp(value, key);
if (!['runecrafting', 'carpentry'].includes(key)) { // array of skills that shouldn't be used in ASL sum
averageSkillLevel += parseFloat(skills[key].floatLevel) || 0;
// Handle things that can't be parsed as a float
}
});

this.last_save = last_save;
Expand All @@ -229,6 +244,8 @@ class Player {
this.fairy_exchanges = fairy_exchanges;
this.pets = pets;
this.skills = skills;
this.average_skill_level = parseFloat((averageSkillLevel / 8).toFixed(2));
// add average_skill_level to 'this' while also getting the average to 2 decimal places
this.collection = collection;
this.collection_tiers = collection_tiers;
this.collections_unlocked = Object.keys(collection_tiers).length;
Expand Down
3 changes: 2 additions & 1 deletion src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,11 @@ function getLevelByXp(xp = 0, type) {
const xpCurrent = Math.floor(xp - xpTotal);
if (level < maxLevel) xpForNext = Math.ceil(xpTable[level + 1]);
const progress = Number(Math.max(0, Math.min(xpCurrent / xpForNext, 1)).toFixed(2));

const floatLevel = level + Number(Math.max(0, Math.min(xpCurrent / xpForNext, 1))) || level; //Makes calculating weights easier for devs
return {
xp,
level,
floatLevel,
maxLevel,
xpCurrent,
xpForNext,
Expand Down

0 comments on commit 756e5df

Please sign in to comment.