Ajout des derniers développement #1

Merged
kazhnuz merged 68 commits from chronicles-cbs into master 2020-08-02 11:14:18 +02:00
3 changed files with 105 additions and 104 deletions
Showing only changes of commit a63b4ddeb3 - Show all commits

View file

@ -0,0 +1,92 @@
AbstractMobParent = require "game.abstractmobs.parent"
AbstractCharacter = AbstractMobParent:extend()
local charutils = require "game.abstractmobs.utils"
function AbstractCharacter:new(name)
self.simplename = name
self.super.new(self)
end
function AbstractCharacter:initBasicElements()
self.data = charutils.getCharacterData(self.simplename)
self.name = self.data.name
self.fullname = self.data.fullname
self.turns = self.data.turns
self.level = self.data.startlevel
self.exp = charutils.getExpValue(self.level)
self.exp_next = charutils.getExpValue(self.level + 1)
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
exp_min = charutils.getExpValue(self.level)
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
return AbstractCharacter

View file

@ -39,7 +39,7 @@ function CharUtils.getCharacterData(charname)
-- va eprmettre de récupérer les données d'un personnage -- va eprmettre de récupérer les données d'un personnage
local charfolder = "datas.gamedata.characters." .. charname local charfolder = "datas.gamedata.characters." .. charname
local character = require(charfolder) local character = require(charfolder)
character.base_stats = require(charfolder .. ".stats") character.stats = require(charfolder .. ".stats")
character.inventory = require(charfolder .. ".inventory") character.inventory = require(charfolder .. ".inventory")
character.skills = require(charfolder .. ".skills") character.skills = require(charfolder .. ".skills")

View file

@ -25,6 +25,7 @@
local CharacterManager = Object:extend() local CharacterManager = Object:extend()
local charutils = require "game.abstractmobs.utils" local charutils = require "game.abstractmobs.utils"
local AbstractCharacter = require "game.abstractmobs.character"
function CharacterManager:new(controller) function CharacterManager:new(controller)
self.controller = controller self.controller = controller
@ -38,73 +39,17 @@ end
function CharacterManager:init() function CharacterManager:init()
for k, name in pairs(self.namelist) do for k, name in pairs(self.namelist) do
if (charutils.charDataExists(name)) then if (charutils.charDataExists(name)) then
self:initCharacter(name) self.list[name] = AbstractCharacter(name)
end end
end end
end end
function CharacterManager:charDataExists(name) function CharacterManager:setLevel(name, newlevel)
local dir = "datas/gamedata/characters/" .. name .. "/init.lua" self.list[name]:setLevel(newlevel)
local fileinfo = love.filesystem.getInfo(dir)
return (fileinfo ~= nil)
end end
function CharacterManager:getCharacterData(charname) function CharacterManager:levelUp(name)
-- va eprmettre de récupérer les données d'un personnage self.list[name]:levelUp()
local charfolder = "datas.gamedata.characters." .. charname
local character = require(charfolder)
character.base_stats = require(charfolder .. ".stats")
character.inventory = require(charfolder .. ".inventory")
character.skills = require(charfolder .. ".skills")
return character
end
function CharacterManager:initCharacter(id)
local stats = {}
local character = charutils.getCharacterData(id)
stats.level = character.startlevel
stats.exp = charutils.getExpValue(stats.level)
stats.exp_next = charutils.getExpValue(stats.level + 1)
stats.hpmax = character.base_stats.hpmax
stats.ppmax = character.base_stats.ppmax
stats.attack = character.base_stats.attack
stats.power = character.base_stats.power
stats.defense = character.base_stats.defense
stats.technic = character.base_stats.technic
stats.mind = character.base_stats.mind
stats.speed = character.base_stats.speed
character.stats = stats
self.list[id] = character
self:recalculateStats(id)
stats.hp = stats.hpmax
stats.pp = stats.ppmax
stats.status = 0
character.stats = stats
self.list[id] = character
end
function CharacterManager:setLevel(id, newlevel)
self.list[id].stats.level = newlevel
local stats = self.list[id].stats
local exp, exp_next, exp_current
exp = charutils.getExpValue(stats.level)
exp_next = charutils.getExpValue(stats.level + 1)
exp_current = self.list[id].stats.exp
self.list[id].stats.exp = math.max(math.min(exp_current, exp_next - 1), exp)
self.list[id].stats.exp_next = exp_next
self:recalculateStats(id)
end
function CharacterManager:levelUp(id)
self:setLevel(id, self.list[id].stats.level + 1)
end end
function CharacterManager:recalculateStats(id) function CharacterManager:recalculateStats(id)
@ -122,39 +67,6 @@ function CharacterManager:recalculateStats(id)
stats.speed = charutils.getStatValue(stats.level, base_stats.speed) stats.speed = charutils.getStatValue(stats.level, base_stats.speed)
end end
function CharacterManager:getSkillList(id)
local character = self.list[id]
local learnedlist = {}
for i, v in ipairs(character.skills) do
local tech_name, tech_level, isLearned = v[1], v[2], false
if tech_level <= character.stats.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 CharacterManager:getData() function CharacterManager:getData()
local data = {} local data = {}
data.list = self.list data.list = self.list
@ -168,15 +80,13 @@ function CharacterManager:setData(data)
self.team = data.team self.team = data.team
end end
function CharacterManager:heal(id) function CharacterManager:heal(name)
self.list[id].stats.hp = self.list[id].stats.hpmax self.list[name]:heal()
self.list[id].stats.hp = self.list[id].stats.ppmax
self.list[id].stats.status = 0
end end
function CharacterManager:addToTeam(id) function CharacterManager:addToTeam(name)
self:heal(id) self:heal(name)
table.insert(self.team, id) table.insert(self.team, name)
end end
function CharacterManager:removeToTeam(teamid) function CharacterManager:removeToTeam(teamid)
@ -191,9 +101,8 @@ end
function CharacterManager:printCharacter(id) function CharacterManager:printCharacter(id)
local character = self.list[id] local character = self.list[id]
local stats = character.stats
print(id .. ". " .. character.fullname) print(id .. ". " .. character.fullname)
print("Lvl " .. character.stats.level .. " (" .. stats.exp .. "/" .. stats.exp_next .. " exp)") print("Lvl " .. character.level .. " (" .. character.exp .. "/" .. character.exp_next .. " exp)")
end end
function CharacterManager:printTeam() function CharacterManager:printTeam()