sonic-radiance/sonic-radiance.love/game/abstractmobs/character/levels.lua
2021-07-03 09:49:11 +02:00

55 lines
1.4 KiB
Lua

local CharacterLevel = Object:extend()
local charutils = require "game.utils.characters"
local STATS = require "datas.consts.stats"
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:setStats(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 STATS.LIST
end
return CharacterLevel