using System; using System.Collections.Generic; using System.Linq; namespace Gibbed.Borderlands2.GameInfo { public static class Experience { private const float _Multiplier = 60.0f; private const float _Power = 2.8f; private const float _Offset = 7.33f; private static int Compute(int level) { return (int)Math.Floor((Math.Pow(level, _Power) + _Offset) * _Multiplier); } private static readonly int _MinimumLevel; private static readonly int _MaximumLevel; private static readonly int _Reduction; private static readonly KeyValuePair[] _LevelsAndTheirRequiredPoints; static Experience() { _MinimumLevel = 1; _MaximumLevel = 50 + 11 + 11; // TODO: put this in a resource generated by datamining _Reduction = Compute(_MinimumLevel); _LevelsAndTheirRequiredPoints = Enumerable .Range(1, _MaximumLevel) .Select(l => new KeyValuePair(l, GetPointsForLevel(l))) .ToArray(); } public static int GetPointsForLevel(int level) { if (level <= _MinimumLevel) { return 0; } return Compute(level) - _Reduction; } public static int GetLevelForPoints(int points) { if (points < 0) { return _MinimumLevel; } if (points >= _LevelsAndTheirRequiredPoints.Last().Value) { return _MaximumLevel; } return _LevelsAndTheirRequiredPoints .First(lp => points < lp.Value) .Key - 1; } } }