bdd-creature/classes/dataholders/statholder.lua

23 lines
673 B
Lua
Raw Permalink Normal View History

2024-08-02 08:39:28 +02:00
local StatHolder = Object:extend()
function StatHolder:new(key, datas)
self.key = key
self.datas = datas
self.commands = {}
end
function StatHolder:applyCommand(command, args)
self.commands[command] = args
end
function StatHolder:reduce(level, mode)
2024-08-06 22:25:27 +02:00
local stat = self.commands.base + ((self.commands.lvl or 0) * level) + (self.commands.add or 0) + (self.commands.bonus or 0)
local modulo = commands.structs[self.key].modulo or 1
2024-08-07 19:57:11 +02:00
datas = commands.structs[self.key]
2024-08-06 22:25:27 +02:00
stat = math.floor(stat / modulo) * modulo
stat = math.min(stat, datas.max or 999999)
stat = math.max(stat, datas.min or -99999)
2024-08-06 22:25:27 +02:00
return stat
2024-08-02 08:39:28 +02:00
end
return StatHolder