2021-04-03 10:39:34 +02:00
|
|
|
local AbstractMobParent = require "game.abstractmobs.parent"
|
2020-07-19 14:02:22 +02:00
|
|
|
|
2021-04-03 10:39:34 +02:00
|
|
|
local AbstractCharacter = AbstractMobParent:extend()
|
2020-07-19 14:02:22 +02:00
|
|
|
|
2020-08-04 13:38:45 +02:00
|
|
|
local charutils = require "game.utils.characters"
|
2020-07-19 14:02:22 +02:00
|
|
|
|
|
|
|
function AbstractCharacter:new(name)
|
|
|
|
self.simplename = name
|
|
|
|
self.super.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function AbstractCharacter:initBasicElements()
|
2021-04-04 16:33:48 +02:00
|
|
|
self:getCommonData(self.simplename)
|
2020-07-19 14:02:22 +02:00
|
|
|
|
|
|
|
self.level = self.data.startlevel
|
|
|
|
self.exp = charutils.getExpValue(self.level)
|
|
|
|
self.exp_next = charutils.getExpValue(self.level + 1)
|
|
|
|
end
|
|
|
|
|
2021-04-04 16:33:48 +02:00
|
|
|
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
|
|
|
|
|
2020-07-19 14:02:22 +02:00
|
|
|
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
|
2020-09-13 16:57:06 +02:00
|
|
|
local exp_min = charutils.getExpValue(self.level)
|
|
|
|
local exp_max = charutils.getExpValue(self.level + 1)
|
2020-07-19 14:02:22 +02:00
|
|
|
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
|
|
|
|
|
2021-04-04 16:33:48 +02:00
|
|
|
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
|
|
|
|
|
2020-07-19 14:02:22 +02:00
|
|
|
return AbstractCharacter
|