62 lines
1.8 KiB
Lua
62 lines
1.8 KiB
Lua
|
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"
|
||
|
AbstractCharacter:implement(CharacterHealth)
|
||
|
AbstractCharacter:implement(CharacterLevels)
|
||
|
AbstractCharacter:implement(CharacterDatas)
|
||
|
|
||
|
function AbstractCharacter:new(name)
|
||
|
self.simplename = name
|
||
|
self.super.new(self)
|
||
|
end
|
||
|
|
||
|
function AbstractCharacter:initBasicElements()
|
||
|
self:getCommonData()
|
||
|
self:initLevel()
|
||
|
end
|
||
|
|
||
|
function AbstractCharacter:createStats()
|
||
|
local statNames = self:getStatList()
|
||
|
local stats = {}
|
||
|
for _, name in ipairs(statNames) do
|
||
|
stats[name] = self:getStat(name)
|
||
|
end
|
||
|
|
||
|
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
|
||
|
|
||
|
return AbstractCharacter
|