Gibbed Experience code


SUBMITTED BY: Guest

DATE: July 29, 2014, 12:16 p.m.

FORMAT: C#

SIZE: 2.0 kB

HITS: 9092

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Gibbed.Borderlands2.GameInfo
  5. {
  6. public static class Experience
  7. {
  8. private const float _Multiplier = 60.0f;
  9. private const float _Power = 2.8f;
  10. private const float _Offset = 7.33f;
  11. private static int Compute(int level)
  12. {
  13. return (int)Math.Floor((Math.Pow(level, _Power) + _Offset) * _Multiplier);
  14. }
  15. private static readonly int _MinimumLevel;
  16. private static readonly int _MaximumLevel;
  17. private static readonly int _Reduction;
  18. private static readonly KeyValuePair<int, int>[] _LevelsAndTheirRequiredPoints;
  19. static Experience()
  20. {
  21. _MinimumLevel = 1;
  22. _MaximumLevel = 50 + 11 + 11; // TODO: put this in a resource generated by datamining
  23. _Reduction = Compute(_MinimumLevel);
  24. _LevelsAndTheirRequiredPoints = Enumerable
  25. .Range(1, _MaximumLevel)
  26. .Select(l => new KeyValuePair<int, int>(l, GetPointsForLevel(l)))
  27. .ToArray();
  28. }
  29. public static int GetPointsForLevel(int level)
  30. {
  31. if (level <= _MinimumLevel)
  32. {
  33. return 0;
  34. }
  35. return Compute(level) - _Reduction;
  36. }
  37. public static int GetLevelForPoints(int points)
  38. {
  39. if (points < 0)
  40. {
  41. return _MinimumLevel;
  42. }
  43. if (points >= _LevelsAndTheirRequiredPoints.Last().Value)
  44. {
  45. return _MaximumLevel;
  46. }
  47. return _LevelsAndTheirRequiredPoints
  48. .First(lp => points < lp.Value)
  49. .Key - 1;
  50. }
  51. }
  52. }

comments powered by Disqus