UNPKG

@zikeji/hypixel

Version:

With IntelliSense support & test coverage, this is an unopinionated async/await API wrapper for Hypixel's Public API. It is developed in TypeScript complete with documentation, typed interfaces for all API responses, built-in rate-limit handling, flexible

76 lines 2.16 kB
"use strict"; /** * This portion of code was ported from the [hypixel-php](https://github.com/Plancke/hypixel-php) library. * * Copyright (c) 2020 Zikeji * Copyright (c) 2017 Aäron Plancke * * For the original full copyright and license information, please view the LICENSE-HYPIXEL-PHP.md that was distributed with this source code. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getGuildLevel = getGuildLevel; /** @internal */ const EXP_NEEDED = [ 100000, 150000, 250000, 500000, 750000, 1000000, 1250000, 1500000, 2000000, 2500000, 2500000, 2500000, 2500000, 2500000, 3000000, ]; /** * Calculates the guild level and returns a {@link GuildLevel} interface. * @param data The guild object or the raw EXP number. * @category Helper */ function getGuildLevel(data) { var _a; let currentExp = 0; if (typeof data === "number") { currentExp = data; } else { currentExp = typeof (data === null || data === void 0 ? void 0 : data.exp) === "number" ? data.exp : 0; } if (currentExp < 0) currentExp = 0; let remainingExp = currentExp; let level = 0; let needed = 0; let expToLevel = 0; const expNeededClone = [...EXP_NEEDED]; const maxExpNeeded = expNeededClone[expNeededClone.length - 1]; while (remainingExp >= 0) { needed = (_a = expNeededClone.shift()) !== null && _a !== void 0 ? _a : maxExpNeeded; expToLevel += needed; remainingExp -= needed; if (remainingExp > 0) { level += 1; } } const nextLevelExp = expToLevel; expToLevel -= needed; const expToNextLevel = nextLevelExp - expToLevel; const expInCurrentLevel = currentExp - expToLevel; const remainingExpToNextLevel = nextLevelExp - currentExp; const nextLevelProgress = expInCurrentLevel / expToNextLevel; const preciseLevel = level + nextLevelProgress; return { level, preciseLevel, currentExp, expToLevel, expToNextLevel, remainingExpToNextLevel, }; } //# sourceMappingURL=GuildLevel.js.map