NadekoBot/NadekoBot.Modules.Xp/Common/LevelStats.cs
2017-09-30 00:46:33 +02:00

44 lines
992 B
C#

using NadekoBot.Modules.Xp.Services;
using System;
namespace NadekoBot.Modules.Xp.Common
{
public class LevelStats
{
public int Level { get; }
public int LevelXp { get; }
public int RequiredXp { get; }
public int TotalXp { get; }
public LevelStats(int xp)
{
if (xp < 0)
xp = 0;
TotalXp = xp;
const int baseXp = XpService.XP_REQUIRED_LVL_1;
var required = baseXp;
var totalXp = 0;
var lvl = 1;
while (true)
{
required = (int)(baseXp + baseXp / 4.0 * (lvl - 1));
if (required + totalXp > xp)
break;
totalXp += required;
lvl++;
}
Level = lvl - 1;
LevelXp = xp - totalXp;
RequiredXp = required;
}
public static LevelStats FromXp(int xp) => new LevelStats(xp);
}
}