feat: ajout du holder de competence
This commit is contained in:
parent
e9d05ebd30
commit
e816551eab
4 changed files with 72 additions and 4 deletions
57
classes/dataholders/competenceholder.lua
Normal file
57
classes/dataholders/competenceholder.lua
Normal file
|
@ -0,0 +1,57 @@
|
|||
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)
|
||||
return {
|
||||
name = self.name,
|
||||
value = self.base + (self.lvl * level) + self.bonus + self.add
|
||||
}
|
||||
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
|
|
@ -11,7 +11,7 @@ function StatHolder:applyCommand(command, args)
|
|||
end
|
||||
|
||||
function StatHolder:reduce(level)
|
||||
return self.commands.base + ((self.commands.level or 0) * level) + (self.commands.add or 0) + (self.commands.bonus or 0)
|
||||
return self.commands.base + ((self.commands.lvl or 0) * level) + (self.commands.add or 0) + (self.commands.bonus or 0)
|
||||
end
|
||||
|
||||
return StatHolder
|
|
@ -4,6 +4,7 @@ local DataList = Object:extend()
|
|||
local ListHolder = require "classes.dataholders.listholder"
|
||||
local SimpleHolder = require "classes.dataholders.simpleholder"
|
||||
local StatHolder = require "classes.dataholders.statholder"
|
||||
local CompetenceHolder = require "classes.dataholders.competenceholder"
|
||||
|
||||
function RawData.fromLine(line)
|
||||
line = utils.removeComment(line)
|
||||
|
@ -49,8 +50,10 @@ function RawData:getCommand()
|
|||
end
|
||||
|
||||
function DataList.getHolder(key, value)
|
||||
if (value.dataType == "comp" or value.dataType == "list") then
|
||||
if (value.dataType == "list") then
|
||||
return ListHolder(key, value)
|
||||
elseif (value.dataType == "comp") then
|
||||
return CompetenceHolder(key, value)
|
||||
elseif (value.dataType == "stat") then
|
||||
return StatHolder(key, value)
|
||||
end
|
||||
|
|
|
@ -20,6 +20,14 @@ local function addStatCommands(name, value)
|
|||
addCommands(name .. ".bonus", name, 0)
|
||||
end
|
||||
|
||||
local function addCompCommands(name, value)
|
||||
addCommands(name, name)
|
||||
addCommands(name .. ".reset", name)
|
||||
addCommands(name .. ".lvl", name)
|
||||
addCommands(name .. ".add", name)
|
||||
addCommands(name .. ".bonus", name)
|
||||
end
|
||||
|
||||
local function addListCommands(name, value)
|
||||
addCommands(name, name)
|
||||
addCommands(name .. ".replace", name)
|
||||
|
@ -32,7 +40,7 @@ for key, value in pairs(struct) do
|
|||
elseif (value.dataType == "list") then
|
||||
addListCommands(key, value)
|
||||
elseif (value.dataType == "comp") then
|
||||
addListCommands(key, value)
|
||||
addCompCommands(key, value)
|
||||
else
|
||||
addCommands(key, key, value.default)
|
||||
end
|
||||
|
@ -45,7 +53,7 @@ end
|
|||
function functions.clean(args, command)
|
||||
local baseCommand = commands[command]
|
||||
if (baseCommand == nil) then
|
||||
error("Command " .. baseCommand .. " doesn't exists")
|
||||
error("Command " .. command .. " doesn't exists")
|
||||
end
|
||||
local commandData = struct[baseCommand]
|
||||
if (commandData.args == nil or commandData.args == 1) then
|
||||
|
|
Loading…
Reference in a new issue