local CharacterLevel = Object:extend() local charutils = require "game.utils.characters" local statList = {"hpmax", "ppmax", "attack", "power", "defense", "mind", "technic", "speed"} function CharacterLevel:initLevel() self.level = self.data.startlevel self.exp = charutils.getExpValue(self.level) self.exp_next = charutils.getExpValue(self.level + 1) end function CharacterLevel:setLevel(newlevel) self.level = newlevel local exp local exp_min = charutils.getExpValue(self.level) local exp_max = charutils.getExpValue(self.level + 1) exp = self.exp self.exp = math.max(math.min(exp, exp_max - 1), exp_min) self.exp_next = exp_max self.stats = self:createStats() end function CharacterLevel:levelUp() if (game.difficulty:get("levelUpHeal")) then self:heal() end self:setLevel(self.level + 1) end function CharacterLevel:getComputedStat(statname) local baseStat = self.data.stats[statname] if (baseStat == nil) then error("Stat " .. statname .. " doesn't exist") else local stat = 0 if (statname == "hpmax") then stat = charutils.getHPValue(self.level, baseStat) elseif (statname == "ppmax") then stat = charutils.getPPValue(self.level, baseStat) else stat = charutils.getStatValue(self.level, baseStat) end return stat end end function CharacterLevel:getStatList() return statList end return CharacterLevel