Advertisement
Quoteory

LevelModule

Nov 17th, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | None | 0 0
  1. local LevelModule = {}
  2.  
  3. function LevelModule:getNeededExp(level)
  4.     return level * 115
  5. end
  6.  
  7.  
  8. function LevelModule:playerReadyToLevel(stats)
  9.     return stats.exp > stats.neededExp 
  10. end
  11.  
  12.  
  13. function LevelModule:addPlayerExp(stats, amountOfExp)
  14.     stats.exp = stats.exp + amountOfExp
  15. end
  16.  
  17. function LevelModule:levelPlayer(stats)
  18.     self:addPlayerExp(stats, -stats.neededExp)
  19.     self:addPlayerLevel(stats, 1)
  20.     self:setPlayerNeededExp(stats) 
  21. end
  22.  
  23. function LevelModule:levelLoop(stats)
  24.     while self:playerReadyToLevel(stats) and not self:isPlayerMaxLevel(stats) do
  25.         self:levelPlayer(stats)
  26.     end
  27. end
  28.  
  29. function LevelModule:clampPlayerExp(stats)
  30.     local neededExp = self:getNeededExp(stats.level)
  31.     stats.exp = math.clamp(stats.exp, 0, neededExp)
  32. end
  33.  
  34.  
  35. function LevelModule:setPlayerNeededExp(stats)
  36.     stats.neededExp = self:getNeededExp(stats.level)
  37. end
  38.  
  39.  
  40. function LevelModule:addPlayerLevel(stats, amountOfLevels)
  41.     stats.level = stats.level + amountOfLevels
  42. end
  43.  
  44.  
  45. function LevelModule:isPlayerMaxLevel(stats)
  46.     return stats.level >= stats.maxLevel
  47. end
  48.  
  49.  
  50. return LevelModule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement