2021-04-22 18:11:11 +02:00
|
|
|
local CharacterLevel = Object:extend()
|
|
|
|
|
|
|
|
local charutils = require "game.utils.characters"
|
2021-05-16 08:38:09 +02:00
|
|
|
local STATS = require "datas.consts.stats"
|
2021-04-22 18:11:11 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-07-03 10:41:16 +02:00
|
|
|
self:updateHPPP()
|
2021-08-20 23:15:35 +02:00
|
|
|
self.skills = self:createSkills()
|
2021-04-22 18:11:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function CharacterLevel:levelUp()
|
|
|
|
if (game.difficulty:get("levelUpHeal")) then
|
|
|
|
self:heal()
|
|
|
|
end
|
|
|
|
self:setLevel(self.level + 1)
|
|
|
|
end
|
|
|
|
|
2021-07-03 10:34:13 +02:00
|
|
|
function CharacterLevel:getLevelStat(statname)
|
2021-04-22 18:11:11 +02:00
|
|
|
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
|
|
|
|
|
2021-07-03 10:34:13 +02:00
|
|
|
function CharacterLevel:getComputedStat(statname)
|
|
|
|
core.debug:warning("CharacterLevel", "Function getComputedStat is deprecated")
|
|
|
|
return self:getLevelStat(statname)
|
|
|
|
end
|
|
|
|
|
2021-04-22 18:11:11 +02:00
|
|
|
function CharacterLevel:getStatList()
|
2021-04-22 23:41:20 +02:00
|
|
|
return STATS.LIST
|
2021-04-22 18:11:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return CharacterLevel
|