703d11d8b7
Fixes #71
123 lines
3.3 KiB
Lua
123 lines
3.3 KiB
Lua
local AbstractMobParent = require "game.abstractmobs.parent"
|
|
|
|
local AbstractCharacter = AbstractMobParent:extend()
|
|
|
|
local charutils = require "game.utils.characters"
|
|
|
|
function AbstractCharacter:new(name)
|
|
self.simplename = name
|
|
self.super.new(self)
|
|
end
|
|
|
|
function AbstractCharacter:initBasicElements()
|
|
self:getCommonData(self.simplename)
|
|
|
|
self.level = self.data.startlevel
|
|
self.exp = charutils.getExpValue(self.level)
|
|
self.exp_next = charutils.getExpValue(self.level + 1)
|
|
end
|
|
|
|
function AbstractCharacter:getCommonData(simplename)
|
|
self.data = charutils.getCharacterData(self.simplename)
|
|
self.name = self.data.name
|
|
self.fullname = self.data.fullname
|
|
self.turns = self.data.turns
|
|
end
|
|
|
|
function AbstractCharacter:createStats()
|
|
local stats = {}
|
|
local base_stats = self.data.stats
|
|
|
|
stats.hpmax = charutils.getHPValue(self.level, base_stats.hpmax)
|
|
stats.ppmax = charutils.getPPValue(self.level, base_stats.ppmax)
|
|
stats.attack = charutils.getStatValue(self.level, base_stats.attack)
|
|
stats.power = charutils.getStatValue(self.level, base_stats.power)
|
|
stats.defense = charutils.getStatValue(self.level, base_stats.defense)
|
|
stats.mind = charutils.getStatValue(self.level, base_stats.mind)
|
|
stats.technic = charutils.getStatValue(self.level, base_stats.technic)
|
|
stats.speed = charutils.getStatValue(self.level, base_stats.speed)
|
|
|
|
return stats
|
|
end
|
|
|
|
function AbstractCharacter:createSkills()
|
|
local learnedlist = {}
|
|
|
|
for i, v in ipairs(self.data.skills) do
|
|
local tech_name, tech_level, isLearned = v[1], v[2], false
|
|
if tech_level <= self.level then
|
|
local canLearn = true
|
|
for i, learnedSkill in ipairs(learnedlist) do
|
|
|
|
-- We check if the skill have already been learned, to level-up it
|
|
if learnedSkill.name == tech_name then
|
|
canLearn = false
|
|
learnedSkill.level = learnedSkill.level + 1
|
|
end
|
|
end
|
|
|
|
if (canLearn) then
|
|
local skilldata = {}
|
|
skilldata.name = tech_name
|
|
skilldata.level = 1
|
|
skilldata.learnedAt = tech_level
|
|
|
|
table.insert(learnedlist, skilldata)
|
|
end
|
|
|
|
end
|
|
-- On continue ensuite d'itérer dans la liste
|
|
end
|
|
|
|
return learnedlist
|
|
end
|
|
|
|
function AbstractCharacter:setLevel(newlevel)
|
|
self.level = newlevel
|
|
local exp, exp_next, exp_current
|
|
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 AbstractCharacter:levelUp()
|
|
self:setLevel(self.level + 1)
|
|
end
|
|
|
|
function AbstractCharacter:heal()
|
|
self:initLife()
|
|
end
|
|
|
|
function AbstractCharacter:getData()
|
|
local data = {}
|
|
data.simplename = self.simplename
|
|
data.level = self.level
|
|
data.exp = self.exp
|
|
data.exp_next = self.exp_next
|
|
data.hp = self.hp
|
|
data.pp = self.pp
|
|
data.statuts = self.statuts
|
|
|
|
return data
|
|
end
|
|
|
|
function AbstractCharacter:setData(data)
|
|
self.simplename = data.simplename
|
|
self:getCommonData(self.simplename)
|
|
|
|
self.level = data.level
|
|
self.exp = data.exp
|
|
self.exp_next = data.exp_next
|
|
self:createStats()
|
|
|
|
self.hp = data.hp
|
|
self.pp = data.pp
|
|
self.statuts = data.statuts
|
|
end
|
|
|
|
return AbstractCharacter
|