2021-04-22 18:11:11 +02:00
|
|
|
local AbstractMobParent = require "game.abstractmobs.parent"
|
|
|
|
local AbstractCharacter = AbstractMobParent:extend()
|
|
|
|
|
|
|
|
local CharacterHealth = require "game.abstractmobs.character.health"
|
|
|
|
local CharacterLevels = require "game.abstractmobs.character.levels"
|
|
|
|
local CharacterDatas = require "game.abstractmobs.character.datas"
|
2021-04-22 20:03:46 +02:00
|
|
|
local CharacterEquip = require "game.abstractmobs.character.equip"
|
2021-04-22 18:11:11 +02:00
|
|
|
AbstractCharacter:implement(CharacterHealth)
|
|
|
|
AbstractCharacter:implement(CharacterLevels)
|
|
|
|
AbstractCharacter:implement(CharacterDatas)
|
2021-04-22 20:03:46 +02:00
|
|
|
AbstractCharacter:implement(CharacterEquip)
|
2021-04-22 18:11:11 +02:00
|
|
|
|
2021-07-03 10:34:13 +02:00
|
|
|
local CharacterStatManager = require "game.abstractmobs.character.statmanager"
|
|
|
|
|
2021-04-22 18:11:11 +02:00
|
|
|
function AbstractCharacter:new(name)
|
|
|
|
self.simplename = name
|
2021-07-03 10:34:13 +02:00
|
|
|
AbstractCharacter.super.new(self, {"simplename", "level", "exp", "exp_next", "hp", "pp", "statuts", "equip"}, nil, CharacterStatManager)
|
2021-07-03 10:41:16 +02:00
|
|
|
self:updateHPPP()
|
2021-04-22 18:11:11 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function AbstractCharacter:initBasicElements()
|
|
|
|
self:getCommonData()
|
2021-04-22 20:03:46 +02:00
|
|
|
self:initEquip()
|
2021-04-22 18:11:11 +02:00
|
|
|
self:initLevel()
|
|
|
|
end
|
|
|
|
|
2021-07-03 10:41:16 +02:00
|
|
|
function AbstractCharacter:updateHPPP()
|
2021-04-22 23:41:20 +02:00
|
|
|
if (self.hp ~= nil) then
|
2021-07-03 10:41:16 +02:00
|
|
|
self.hp = math.min(self.hp, self.stats:get(self.stats.HPMAX))
|
2021-04-22 23:41:20 +02:00
|
|
|
end
|
|
|
|
if (self.pp ~= nil) then
|
2021-07-03 10:41:16 +02:00
|
|
|
self.pp = math.min(self.pp, self.stats:get(self.stats.PPMAX))
|
2021-04-22 23:41:20 +02:00
|
|
|
end
|
2021-04-22 18:11:11 +02:00
|
|
|
end
|
|
|
|
|
2021-04-22 20:03:46 +02:00
|
|
|
function AbstractCharacter:getStat(statName, ignoreEquip)
|
2021-07-03 10:41:16 +02:00
|
|
|
return self.stats:get(statName, ignoreEquip)
|
2021-04-22 20:03:46 +02:00
|
|
|
end
|
|
|
|
|
2021-04-22 18:11:11 +02:00
|
|
|
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
|
|
|
|
|
2021-05-08 12:54:07 +02:00
|
|
|
function AbstractCharacter:finishDeserialization()
|
|
|
|
self:createStats()
|
|
|
|
end
|
|
|
|
|
2021-04-22 18:11:11 +02:00
|
|
|
return AbstractCharacter
|