Added function for calculating guild exp

This commit is contained in:
2023-11-16 00:38:11 +01:00
parent 325d310de5
commit b45fc07614
2 changed files with 55 additions and 1 deletions

48
utils/functions/guild.js Normal file
View File

@@ -0,0 +1,48 @@
/*
Code used from the slothpixel project https://github.com/slothpixel/core
*/
function guildLevel(exp) {
const EXP_NEEDED = [
100000,
150000,
250000,
500000,
750000,
1000000,
1250000,
1500000,
2000000,
2500000,
2500000,
2500000,
2500000,
2500000,
3000000,
];
let level = 0;
// Increments by one from zero to the level cap
for (let i = 0; i <= 1000; i += 1) {
// need is the required exp to get to the next level
let need = 0;
if (i >= EXP_NEEDED.length) {
need = EXP_NEEDED[EXP_NEEDED.length - 1];
} else { need = EXP_NEEDED[i]; }
// If the required exp to get to the next level isn't met returns
// the current level plus progress towards the next (unused exp/need)
// Otherwise increments the level and substracts the used exp from exp var
if ((exp - need) < 0) {
return Math.round((level + (exp / need)) * 100) / 100;
}
level += 1;
exp -= need;
}
// Returns the level cap - currently 1000
// If changed here, also change in for loop above
return 1000;
}
module.exports = { guildLevel }

View File

@@ -1,5 +1,11 @@
const { skywarsLevel } = require('./functions/skywars.js')
const { bedwarsLevel } = require('./functions/bedwars.js')
const { hypixelLevel } = require('./functions/hypixel.js')
const { guildLevel } = require('./functions/guild.js')
module.exports = { skywarsLevel, bedwarsLevel, hypixelLevel }
module.exports = {
skywarsLevel,
bedwarsLevel,
hypixelLevel,
guildLevel
}