2020-07-19 13:41:20 +02:00
|
|
|
local CharUtils = {}
|
2020-07-19 10:50:43 +02:00
|
|
|
|
2020-08-04 16:55:09 +02:00
|
|
|
local datasutils = require "game.utils.datas"
|
2020-07-19 10:50:43 +02:00
|
|
|
|
2020-08-04 16:55:09 +02:00
|
|
|
local CONST = {}
|
2020-07-19 10:50:43 +02:00
|
|
|
CONST.EXP_MULTIPLICATOR = 4
|
|
|
|
CONST.EXP_RATIO = 5
|
|
|
|
|
|
|
|
CONST.BASE_STAT = 5
|
|
|
|
CONST.BASE_HP = 15
|
|
|
|
CONST.BASE_MP = 8
|
|
|
|
|
|
|
|
CONST.MULT_STAT = 2
|
2020-08-02 21:26:49 +02:00
|
|
|
CONST.MULT_HP = 7.5
|
|
|
|
CONST.SALT_HP = 35
|
2020-07-19 10:50:43 +02:00
|
|
|
CONST.MULT_MP = 1.5
|
|
|
|
|
2020-08-04 16:55:09 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2020-07-19 13:41:20 +02:00
|
|
|
function CharUtils.getExpValue(level)
|
2020-07-19 10:50:43 +02:00
|
|
|
return math.floor( ( CONST.EXP_MULTIPLICATOR * ( level ^ 3 ) ) / CONST.EXP_RATIO )
|
|
|
|
end
|
|
|
|
|
2020-08-06 19:10:54 +02:00
|
|
|
function CharUtils.getRelativeExpValue(exp, level)
|
|
|
|
return exp - CharUtils.getExpValue(level)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CharUtils.getLevelExpRange(level)
|
|
|
|
return CharUtils.getExpValue(level + 1) - CharUtils.getExpValue(level)
|
|
|
|
end
|
|
|
|
|
|
|
|
function CharUtils.getRemainingExp(exp, level)
|
|
|
|
return CharUtils.getExpValue(level + 1) - exp
|
|
|
|
end
|
|
|
|
|
2020-07-19 13:41:20 +02:00
|
|
|
function CharUtils.getStatValue(level, base)
|
2020-07-19 10:50:43 +02:00
|
|
|
return math.floor( (((base * CONST.MULT_STAT) * level)/100) ) + CONST.BASE_STAT
|
|
|
|
end
|
|
|
|
|
2020-07-19 13:41:20 +02:00
|
|
|
function CharUtils.getHPValue(level, base)
|
2020-08-02 21:26:49 +02:00
|
|
|
return math.floor( (((CONST.SALT_HP + base * CONST.MULT_HP) * level)/100) ) + CONST.BASE_HP + level
|
2020-07-19 10:50:43 +02:00
|
|
|
end
|
|
|
|
|
2020-07-19 13:41:20 +02:00
|
|
|
function CharUtils.getPPValue(level, base)
|
2020-07-19 10:50:43 +02:00
|
|
|
return math.floor( (((base * CONST.MULT_MP) * level)/100) ) + CONST.BASE_MP
|
|
|
|
end
|
|
|
|
|
2020-07-19 13:41:20 +02:00
|
|
|
function CharUtils.charDataExists(name)
|
2020-08-04 16:55:09 +02:00
|
|
|
local dir = CharUtils.getCharacterDirectory(name, false) .. "/init.lua"
|
2020-07-19 13:41:20 +02:00
|
|
|
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
|
2020-08-04 16:55:09 +02:00
|
|
|
local charfolder = CharUtils.getCharacterDirectory(charname, true)
|
2020-08-07 13:26:29 +02:00
|
|
|
local character = datasutils.copy(charfolder)
|
|
|
|
character.stats = datasutils.copyDataset(charfolder, "stats")
|
|
|
|
character.inventory = datasutils.copyDataset(charfolder, "inventory")
|
|
|
|
character.skills = datasutils.copyDataset(charfolder, "skills")
|
2020-07-19 13:41:20 +02:00
|
|
|
|
|
|
|
return character
|
|
|
|
end
|
|
|
|
|
|
|
|
return CharUtils
|