chore(game/characters): more utils extraction
This commit is contained in:
parent
00396522fb
commit
cd9b9f37e4
2 changed files with 38 additions and 21 deletions
|
@ -1,4 +1,4 @@
|
||||||
local StatsUtils = {}
|
local CharUtils = {}
|
||||||
|
|
||||||
local CONST = {}
|
local CONST = {}
|
||||||
|
|
||||||
|
@ -13,20 +13,37 @@ CONST.MULT_STAT = 2
|
||||||
CONST.MULT_HP = 2.7
|
CONST.MULT_HP = 2.7
|
||||||
CONST.MULT_MP = 1.5
|
CONST.MULT_MP = 1.5
|
||||||
|
|
||||||
function StatsUtils.getExpValue(level)
|
function CharUtils.getExpValue(level)
|
||||||
return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO )
|
return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO )
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatsUtils.getStatValue(level, base)
|
function CharUtils.getStatValue(level, base)
|
||||||
return math.floor( (((base * CONST.MULT_STAT) * level)/100) ) + CONST.BASE_STAT
|
return math.floor( (((base * CONST.MULT_STAT) * level)/100) ) + CONST.BASE_STAT
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatsUtils.getHPValue(level, base)
|
function CharUtils.getHPValue(level, base)
|
||||||
return math.floor( (((base * CONST.MULT_HP) * level)/100) ) + CONST.BASE_HP + level
|
return math.floor( (((base * CONST.MULT_HP) * level)/100) ) + CONST.BASE_HP + level
|
||||||
end
|
end
|
||||||
|
|
||||||
function StatsUtils.getPPValue(level, base)
|
function CharUtils.getPPValue(level, base)
|
||||||
return math.floor( (((base * CONST.MULT_MP) * level)/100) ) + CONST.BASE_MP
|
return math.floor( (((base * CONST.MULT_MP) * level)/100) ) + CONST.BASE_MP
|
||||||
end
|
end
|
||||||
|
|
||||||
return StatsUtils
|
function CharUtils.charDataExists(name)
|
||||||
|
local dir = "datas/gamedata/characters/" .. name .. "/init.lua"
|
||||||
|
local fileinfo = love.filesystem.getInfo(dir)
|
||||||
|
return (fileinfo ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CharUtils.getCharacterData(charname)
|
||||||
|
-- va eprmettre de récupérer les données d'un personnage
|
||||||
|
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
|
||||||
|
|
||||||
|
return CharUtils
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
local CharacterManager = Object:extend()
|
local CharacterManager = Object:extend()
|
||||||
|
|
||||||
local statsutils = require "game.abstractmobs.utils"
|
local charutils = require "game.abstractmobs.utils"
|
||||||
|
|
||||||
function CharacterManager:new(controller)
|
function CharacterManager:new(controller)
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
|
@ -37,7 +37,7 @@ end
|
||||||
|
|
||||||
function CharacterManager:init()
|
function CharacterManager:init()
|
||||||
for k, name in pairs(self.namelist) do
|
for k, name in pairs(self.namelist) do
|
||||||
if (self:charDataExists(name)) then
|
if (charutils.charDataExists(name)) then
|
||||||
self:initCharacter(name)
|
self:initCharacter(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -62,11 +62,11 @@ end
|
||||||
|
|
||||||
function CharacterManager:initCharacter(id)
|
function CharacterManager:initCharacter(id)
|
||||||
local stats = {}
|
local stats = {}
|
||||||
local character = self:getCharacterData(id)
|
local character = charutils.getCharacterData(id)
|
||||||
|
|
||||||
stats.level = character.startlevel
|
stats.level = character.startlevel
|
||||||
stats.exp = statsutils.getExpValue(stats.level)
|
stats.exp = charutils.getExpValue(stats.level)
|
||||||
stats.exp_next = statsutils.getExpValue(stats.level + 1)
|
stats.exp_next = charutils.getExpValue(stats.level + 1)
|
||||||
stats.hpmax = character.base_stats.hpmax
|
stats.hpmax = character.base_stats.hpmax
|
||||||
stats.ppmax = character.base_stats.ppmax
|
stats.ppmax = character.base_stats.ppmax
|
||||||
stats.attack = character.base_stats.attack
|
stats.attack = character.base_stats.attack
|
||||||
|
@ -93,8 +93,8 @@ function CharacterManager:setLevel(id, newlevel)
|
||||||
self.list[id].stats.level = newlevel
|
self.list[id].stats.level = newlevel
|
||||||
local stats = self.list[id].stats
|
local stats = self.list[id].stats
|
||||||
local exp, exp_next, exp_current
|
local exp, exp_next, exp_current
|
||||||
exp = statsutils.getExpValue(stats.level)
|
exp = charutils.getExpValue(stats.level)
|
||||||
exp_next = statsutils.getExpValue(stats.level + 1)
|
exp_next = charutils.getExpValue(stats.level + 1)
|
||||||
exp_current = self.list[id].stats.exp
|
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 = math.max(math.min(exp_current, exp_next - 1), exp)
|
||||||
|
@ -112,14 +112,14 @@ function CharacterManager:recalculateStats(id)
|
||||||
local stats = character.stats
|
local stats = character.stats
|
||||||
local base_stats = character.base_stats
|
local base_stats = character.base_stats
|
||||||
|
|
||||||
stats.hpmax = statsutils.getHPValue(stats.level, base_stats.hpmax)
|
stats.hpmax = charutils.getHPValue(stats.level, base_stats.hpmax)
|
||||||
stats.ppmax = statsutils.getPPValue(stats.level, base_stats.ppmax)
|
stats.ppmax = charutils.getPPValue(stats.level, base_stats.ppmax)
|
||||||
stats.attack = statsutils.getStatValue(stats.level, base_stats.attack)
|
stats.attack = charutils.getStatValue(stats.level, base_stats.attack)
|
||||||
stats.power = statsutils.getStatValue(stats.level, base_stats.power)
|
stats.power = charutils.getStatValue(stats.level, base_stats.power)
|
||||||
stats.defense = statsutils.getStatValue(stats.level, base_stats.defense)
|
stats.defense = charutils.getStatValue(stats.level, base_stats.defense)
|
||||||
stats.mind = statsutils.getStatValue(stats.level, base_stats.mind)
|
stats.mind = charutils.getStatValue(stats.level, base_stats.mind)
|
||||||
stats.technic = statsutils.getStatValue(stats.level, base_stats.technic)
|
stats.technic = charutils.getStatValue(stats.level, base_stats.technic)
|
||||||
stats.speed = statsutils.getStatValue(stats.level, base_stats.speed)
|
stats.speed = charutils.getStatValue(stats.level, base_stats.speed)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharacterManager:getSkillList(id)
|
function CharacterManager:getSkillList(id)
|
||||||
|
|
Loading…
Reference in a new issue