chore: better organisation for characters.lua

This commit is contained in:
Kazhnuz 2021-04-22 17:44:19 +02:00
parent 040f67d32c
commit 855c2a2daf

View file

@ -45,6 +45,9 @@ function CharacterManager:init()
end
end
-- WRAPPER FUNCTIONS
-- Simple wrappers around characters functions
function CharacterManager:setLevel(name, newlevel)
self.list[name]:setLevel(newlevel)
end
@ -53,21 +56,17 @@ function CharacterManager:levelUp(name)
self.list[name]:levelUp()
end
function CharacterManager:recalculateStats(id)
local character = self.list[id]
local stats = character.stats
local base_stats = character.base_stats
stats.hpmax = charutils.getHPValue(stats.level, base_stats.hpmax)
stats.ppmax = charutils.getPPValue(stats.level, base_stats.ppmax)
stats.attack = charutils.getStatValue(stats.level, base_stats.attack)
stats.power = charutils.getStatValue(stats.level, base_stats.power)
stats.defense = charutils.getStatValue(stats.level, base_stats.defense)
stats.mind = charutils.getStatValue(stats.level, base_stats.mind)
stats.technic = charutils.getStatValue(stats.level, base_stats.technic)
stats.speed = charutils.getStatValue(stats.level, base_stats.speed)
function CharacterManager:recalculateStats(name)
self.list[name]:createStats()
end
function CharacterManager:heal(name)
self.list[name]:heal()
end
-- DATA FUNCTIONS
-- function to handle saving
function CharacterManager:getData()
local data = {}
data.team = self.team
@ -89,20 +88,8 @@ function CharacterManager:setData(data)
end
end
function CharacterManager:heal(name)
self.list[name]:heal()
end
function CharacterManager:sendDamageFromMap(name, damageRatio)
local character = self.list[name]
if (character.hp > 0) then
local newHP = math.floor(character.hp - (character.stats.hpmax * damageRatio))
if (not game.difficulty:get("hazardMakesKo")) then
newHP = math.max(1, newHP)
end
self.list[name]:setHP(newHP, false)
end
end
-- TEAM FUNCTIONS
-- Team handling and management
function CharacterManager:addToTeam(name)
self:heal(name)
@ -172,6 +159,20 @@ function CharacterManager:getActiveCharacterData()
return self.list[self.team[self.active]]
end
-- SCENES FUNCTIONS
-- Handle damages from the scenes
function CharacterManager:sendDamageFromMap(name, damageRatio)
local character = self.list[name]
if (character.hp > 0) then
local newHP = math.floor(character.hp - (character.stats.hpmax * damageRatio))
if (not game.difficulty:get("hazardMakesKo")) then
newHP = math.max(1, newHP)
end
self.list[name]:setHP(newHP, false)
end
end
function CharacterManager:loadSprite(assets, name)
assets:addSprite(name, "datas/gamedata/characters/" .. name .. "/sprites")
end