bdd-creature/classes/dataholders/competenceholder.lua

59 lines
1.4 KiB
Lua
Raw Permalink Normal View History

2024-08-02 09:06:50 +02:00
local CompetenceHolder = Object:extend()
local Competence = Object:extend()
function Competence:new(name)
self.name = name;
self.base = 0;
self.lvl = 0;
self.bonus = 0;
self.add = 0;
end
function Competence:reduce(level)
2024-08-07 19:57:02 +02:00
local baseValue = self.base + (self.lvl * level) + self.bonus + self.add
2024-08-02 09:06:50 +02:00
return {
name = self.name,
2024-08-07 19:57:02 +02:00
value = math.floor(baseValue / 5) * 5
2024-08-02 09:06:50 +02:00
}
end
function CompetenceHolder:new(key, datas)
self.key = key
self.datas = datas
self.list = {}
end
function CompetenceHolder:applyCommand(command, args)
if (command == "reset") then
self.list = {}
return
end
local competence = self:getCompetence(args[1])
if (command == "") then
competence.base = tonumber(args[2]) or 0
elseif (command == "add") then
competence.add = tonumber(args[2]) or 0
elseif (command == "bonus") then
competence.bonus = tonumber(args[2]) or 0
elseif (command == "lvl") then
competence.lvl = tonumber(args[2]) or 0
end
end
function CompetenceHolder:getCompetence(name)
if self.list[name] == nil then
self.list[name] = Competence(name)
end
return self.list[name]
end
function CompetenceHolder:reduce(level)
local list = {}
for key, value in pairs(self.list) do
table.insert(list, value:reduce(level))
end
return list
end
return CompetenceHolder