sonic-radiance/sonic-radiance.love/game/abstractmobs/character/levels.lua

56 lines
1.4 KiB
Lua
Raw Normal View History

local CharacterLevel = Object:extend()
local charutils = require "game.utils.characters"
2021-04-22 23:41:20 +02:00
local STATS = require "datas.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 = 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()
2021-04-22 23:41:20 +02:00
return STATS.LIST
end
return CharacterLevel