115 lines
3.6 KiB
Lua
115 lines
3.6 KiB
Lua
-- game/characters :: The character handler. This object handle all the character
|
|
-- and is able to get and set datas about them.
|
|
|
|
--[[
|
|
Copyright © 2019 Kazhnuz
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
the Software without restriction, including without limitation the rights to
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
]]
|
|
|
|
local CharacterManager = Object:extend()
|
|
|
|
local charutils = require "game.abstractmobs.utils"
|
|
local AbstractCharacter = require "game.abstractmobs.character"
|
|
|
|
function CharacterManager:new(controller)
|
|
self.controller = controller
|
|
self.namelist = require "datas.gamedata.characters"
|
|
self.list = {}
|
|
self.team = require "datas.gamedata.characters.baseteam"
|
|
self.active = 1
|
|
self:init()
|
|
end
|
|
|
|
function CharacterManager:init()
|
|
for k, name in pairs(self.namelist) do
|
|
if (charutils.charDataExists(name)) then
|
|
self.list[name] = AbstractCharacter(name)
|
|
end
|
|
end
|
|
end
|
|
|
|
function CharacterManager:setLevel(name, newlevel)
|
|
self.list[name]:setLevel(newlevel)
|
|
end
|
|
|
|
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)
|
|
end
|
|
|
|
function CharacterManager:getData()
|
|
local data = {}
|
|
data.list = self.list
|
|
data.team = self.team
|
|
return data
|
|
end
|
|
|
|
function CharacterManager:setData(data)
|
|
local data = data
|
|
self.list = data.list
|
|
self.team = data.team
|
|
end
|
|
|
|
function CharacterManager:heal(name)
|
|
self.list[name]:heal()
|
|
end
|
|
|
|
function CharacterManager:addToTeam(name)
|
|
self:heal(name)
|
|
table.insert(self.team, name)
|
|
end
|
|
|
|
function CharacterManager:removeToTeam(teamid)
|
|
self.team[teamid] = ""
|
|
end
|
|
|
|
function CharacterManager:getActiveCharacter()
|
|
return self.team[self.active]
|
|
end
|
|
|
|
-- DEBUG FUNCTIONS
|
|
|
|
function CharacterManager:printCharacter(id)
|
|
local character = self.list[id]
|
|
print(id .. ". " .. character.fullname)
|
|
print("Lvl " .. character.level .. " (" .. character.exp .. "/" .. character.exp_next .. " exp)")
|
|
end
|
|
|
|
function CharacterManager:printTeam()
|
|
for i,v in ipairs(self.team) do
|
|
self:printCharacter(v)
|
|
print("-----")
|
|
end
|
|
end
|
|
|
|
return CharacterManager
|