sonic-radiance/sonic-radiance.love/game/utils/characters.lua
2020-08-04 16:55:09 +02:00

63 lines
1.7 KiB
Lua

local CharUtils = {}
local datasutils = require "game.utils.datas"
local CONST = {}
CONST.EXP_MULTIPLICATOR = 4
CONST.EXP_RATIO = 5
CONST.BASE_STAT = 5
CONST.BASE_HP = 15
CONST.BASE_MP = 8
CONST.MULT_STAT = 2
CONST.MULT_HP = 7.5
CONST.SALT_HP = 35
CONST.MULT_MP = 1.5
local DIR = "characters"
function CharUtils.getBaseDirectory(lua)
return datasutils.concatDataFolder(DIR, lua)
end
function CharUtils.getCharacterDirectory(name, lua)
local baseDirectory = CharUtils.getBaseDirectory(lua)
return datasutils.concatFolder(baseDirectory, name, lua)
end
function CharUtils.getExpValue(level)
return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO )
end
function CharUtils.getStatValue(level, base)
return math.floor( (((base * CONST.MULT_STAT) * level)/100) ) + CONST.BASE_STAT
end
function CharUtils.getHPValue(level, base)
return math.floor( (((CONST.SALT_HP + base * CONST.MULT_HP) * level)/100) ) + CONST.BASE_HP + level
end
function CharUtils.getPPValue(level, base)
return math.floor( (((base * CONST.MULT_MP) * level)/100) ) + CONST.BASE_MP
end
function CharUtils.charDataExists(name)
local dir = CharUtils.getCharacterDirectory(name, false) .. "/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 = CharUtils.getCharacterDirectory(charname, true)
local character = require(charfolder)
character.stats = datasutils.require(charfolder, "stats")
character.inventory = datasutils.require(charfolder, "inventory")
character.skills = datasutils.require(charfolder, "skills")
return character
end
return CharUtils