calculateExperienceProgress

Calculate the progress towards the next level based on current experience.

Method calculateExperienceProgress

Parameters:

  • level (number): The current level.

  • experience (number): The current experience points.

Returns:

  • object: Object containing progress in fractional and whole values.

    • fractional (object):

      • progress (number): Progress towards the next level as a percentage (float).

      • remaining (number): Remaining progress towards the next level as a percentage (float).

    • whole (object):

      • progress (number): Rounded down progress towards the next level as a percentage (integer).

      • remaining (number): Rounded down remaining progress towards the next level as a percentage (integer).

Example Usage:

const LevelAlgorithm = require('level-algorithm');

const levelAlgorithm = new LevelAlgorithm({
  baseExperience: 100,
  experienceMultiplier: 1.5
});

const currentLevel = 5;
const currentExperience = 350;

const progress = levelAlgorithm.calculateExperienceProgress(currentLevel, currentExperience );

console.log(progress);
// Output:
// {
//   fractional: { progress: 70.0, remaining: 30.0 },
//   whole: { progress: 70, remaining: 30 }
// }

This method calculates the progress towards the next level based on the provided current level, current experience, base experience, and experience multiplier within the LevelAlgorithm instance. It returns progress values as both floating-point and integer percentages.

Last updated