chore: better organisation for characters.lua
This commit is contained in:
parent
040f67d32c
commit
855c2a2daf
1 changed files with 28 additions and 27 deletions
|
@ -45,6 +45,9 @@ function CharacterManager:init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- WRAPPER FUNCTIONS
|
||||||
|
-- Simple wrappers around characters functions
|
||||||
|
|
||||||
function CharacterManager:setLevel(name, newlevel)
|
function CharacterManager:setLevel(name, newlevel)
|
||||||
self.list[name]:setLevel(newlevel)
|
self.list[name]:setLevel(newlevel)
|
||||||
end
|
end
|
||||||
|
@ -53,21 +56,17 @@ function CharacterManager:levelUp(name)
|
||||||
self.list[name]:levelUp()
|
self.list[name]:levelUp()
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharacterManager:recalculateStats(id)
|
function CharacterManager:recalculateStats(name)
|
||||||
local character = self.list[id]
|
self.list[name]:createStats()
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function CharacterManager:heal(name)
|
||||||
|
self.list[name]:heal()
|
||||||
|
end
|
||||||
|
|
||||||
|
-- DATA FUNCTIONS
|
||||||
|
-- function to handle saving
|
||||||
|
|
||||||
function CharacterManager:getData()
|
function CharacterManager:getData()
|
||||||
local data = {}
|
local data = {}
|
||||||
data.team = self.team
|
data.team = self.team
|
||||||
|
@ -89,20 +88,8 @@ function CharacterManager:setData(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharacterManager:heal(name)
|
-- TEAM FUNCTIONS
|
||||||
self.list[name]:heal()
|
-- Team handling and management
|
||||||
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
|
|
||||||
|
|
||||||
function CharacterManager:addToTeam(name)
|
function CharacterManager:addToTeam(name)
|
||||||
self:heal(name)
|
self:heal(name)
|
||||||
|
@ -172,6 +159,20 @@ function CharacterManager:getActiveCharacterData()
|
||||||
return self.list[self.team[self.active]]
|
return self.list[self.team[self.active]]
|
||||||
end
|
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)
|
function CharacterManager:loadSprite(assets, name)
|
||||||
assets:addSprite(name, "datas/gamedata/characters/" .. name .. "/sprites")
|
assets:addSprite(name, "datas/gamedata/characters/" .. name .. "/sprites")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue