diff --git a/classes/dataholders/armesholder.lua b/classes/dataholders/armesholder.lua new file mode 100644 index 0000000..30813bd --- /dev/null +++ b/classes/dataholders/armesholder.lua @@ -0,0 +1,46 @@ +local ArmesHolder = Object:extend() + +local function applyBoost(level, mode, value) + return math.floor(value * boosts.getBoost(level, mode)) +end + +function ArmesHolder:new(key, datas) + self.key = key + self.datas = datas + self.list = {} +end + +function ArmesHolder:applyCommand(command, args) + if (command == "") then + self:add(args) + elseif (command == "reset") then + self:reset() + elseif (command == "replace") then + self:replace(args) + end +end + +function ArmesHolder:reset() + self.list = {} +end + +function ArmesHolder:add(datas) + table.insert(self.list, {nom = datas[1], force = tonumber(datas[2]) or "0"}) +end + +function ArmesHolder:replace(datas) + for index, args in ipairs(self.list) do + if (args.nom == datas[1]) then + self.list[index] = {nom = datas[1], force = tonumber(datas[2] or "0")} + end + end +end + +function ArmesHolder:reduce(level, mode) + for key, value in pairs(self.list) do + value.force = applyBoost(level, mode, value.force) + end + return self.list +end + +return ArmesHolder \ No newline at end of file diff --git a/classes/dataholders/armureholder.lua b/classes/dataholders/armureholder.lua new file mode 100644 index 0000000..8d5f2bb --- /dev/null +++ b/classes/dataholders/armureholder.lua @@ -0,0 +1,28 @@ +local ArmureHolder = Object:extend() + +function ArmureHolder:new(key, datas) + self.key = key + self.datas = datas + self.commands = {} +end + +function ArmureHolder:applyCommand(command, args) + self.commands[command] = args +end + +function ArmureHolder:reduce(level, mode) + local stat = self:getBase(level, mode) + ((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 + datas = commands.structs[self.key] + stat = math.floor(stat / modulo) * modulo + stat = math.min(stat, datas.max or 999999) + stat = math.max(stat, datas.min or -99999) + + return stat +end + +function ArmureHolder:getBase(level, mode) + return math.floor(self.commands.base * boosts.getBoost(level, mode)) +end + +return ArmureHolder \ No newline at end of file diff --git a/classes/dataholders/statholder.lua b/classes/dataholders/statholder.lua index da53e64..175b889 100644 --- a/classes/dataholders/statholder.lua +++ b/classes/dataholders/statholder.lua @@ -10,7 +10,7 @@ function StatHolder:applyCommand(command, args) self.commands[command] = args end -function StatHolder:reduce(level) +function StatHolder:reduce(level, mode) 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 datas = commands.structs[self.key] diff --git a/classes/datalist.lua b/classes/datalist.lua index f61390f..7db1f34 100644 --- a/classes/datalist.lua +++ b/classes/datalist.lua @@ -5,6 +5,8 @@ local ListHolder = require "classes.dataholders.listholder" local SimpleHolder = require "classes.dataholders.simpleholder" local StatHolder = require "classes.dataholders.statholder" local CompetenceHolder = require "classes.dataholders.competenceholder" +local ArmesHolder = require "classes.dataholders.armesholder" +local ArmureHolder = require "classes.dataholders.armureholder" function RawData.fromLine(line) line = utils.removeComment(line) @@ -56,6 +58,10 @@ function DataList.getHolder(key, value) return CompetenceHolder(key, value) elseif (value.dataType == "stat") then return StatHolder(key, value) + elseif (value.dataType == "armure") then + return ArmureHolder(key, value) + elseif (value.dataType == "armes") then + return ArmesHolder(key, value) end return SimpleHolder(key, value) end @@ -79,12 +85,17 @@ end function DataList:reduce() local level = 0 + local mode = "creature" for _, rawdata in ipairs(self.list) do if (rawdata.name == "level") then level = rawdata.arguments end + if (rawdata.name == "mode") then + mode = rawdata.arguments + end end + if (self.forceLevel ~= nil) then level = self.forceLevel end @@ -97,7 +108,7 @@ function DataList:reduce() for key, holder in pairs(self.holders) do --self.reducedList[key] = holder:reduce(level) - self:addToReducedList(key, holder:reduce(level)) + self:addToReducedList(key, holder:reduce(level, mode)) end if (self.forceLevel ~= nil) then diff --git a/libs/boosts.lua b/libs/boosts.lua new file mode 100644 index 0000000..259ca20 --- /dev/null +++ b/libs/boosts.lua @@ -0,0 +1,39 @@ +local boost = {} + +local BOOST_ARM_CREATURE = { + {lvl = 0, value = 1}, + {lvl = 5, value = 1.5}, + {lvl = 10, value = 2}, + {lvl = 15, value = 3}, + {lvl = 20, value = 3.5}, + {lvl = 25, value = 4} +} + +local BOOST_ARM_PNJ = { + {lvl = 0, value = 1}, + {lvl = 6, value = 1.5}, + {lvl = 10, value = 2}, + {lvl = 15, value = 3} +} + + +local function getBoost(level, table) + local bestBoost = {lvl = -1, value = 1} + for _, boost in ipairs(table) do + if (level >= boost.lvl and boost.lvl > bestBoost.lvl) then + bestBoost = boost + end + end + return bestBoost.value +end + +function boost.getBoost(level, mode) + if (mode == "pnj") then + return getBoost(level, BOOST_ARM_PNJ) + else + return getBoost(level, BOOST_ARM_CREATURE) + end +end + + +return boost \ No newline at end of file diff --git a/libs/commands.lua b/libs/commands.lua index 6f252e1..a736b33 100644 --- a/libs/commands.lua +++ b/libs/commands.lua @@ -35,11 +35,11 @@ local function addListCommands(name, value) end for key, value in pairs(struct) do - if (value.dataType == "stat") then + if (value.dataType == "stat" or value.dataType == "armure") then addStatCommands(key, value) elseif (value.dataType == "list") then addListCommands(key, value) - elseif (value.dataType == "comp") then + elseif (value.dataType == "comp" or value.dataType == "armes") then addCompCommands(key, value) else addCommands(key, key, value.default) diff --git a/libs/init.lua b/libs/init.lua index a32612e..7d3b8c1 100644 --- a/libs/init.lua +++ b/libs/init.lua @@ -1,3 +1,4 @@ utils = require "libs.utils" Object = require "libs.classic" -commands = require "libs.commands" \ No newline at end of file +commands = require "libs.commands" +boosts = require "libs.boosts" \ No newline at end of file diff --git a/struct.lua b/struct.lua index 7208f4d..2de9a26 100644 --- a/struct.lua +++ b/struct.lua @@ -1,5 +1,6 @@ return { name={contentType = "string", preParse = true, to="name"}, + mode={contentType = "string", preParse = true, to="mode", default = "creature"}, nomType={contentType = "string", to="type"}, categorie={contentType = "string", to="categorie"}, faiblesse={contentType = "list", args=1}, @@ -20,10 +21,10 @@ return { pv= {dataType= "stat", modulo= 1, default= 12, max=9999999, min=1, to="vita.pv", lvl=3}, pe= {dataType= "stat", modulo= 1, default= 12, max=9999999, min=1, to="vita.pe", lvl=3}, eclat= {dataType= "stat", modulo= 1, default= 10, max=200, min=1, to="vita.eclat"}, - armurephy= {dataType= "stat", modulo= 1, default= 0, max=9999999, min=0, to="armure.phy"}, - armurepsy= {dataType= "stat", modulo= 1, default= 0, max=9999999, min=0, to="armure.psy"}, - armurespe= {dataType= "stat", modulo= 1, default= 0, max=9999999, min=0, to="armure.spe"}, - armes= {dataType= "list", args=2}, + armurephy= {dataType= "armure", modulo= 1, default= 0, max=9999999, min=0, to="armure.phy"}, + armurepsy= {dataType= "armure", modulo= 1, default= 0, max=9999999, min=0, to="armure.psy"}, + armurespe= {dataType= "armure", modulo= 1, default= 0, max=9999999, min=0, to="armure.spe"}, + armes= {dataType= "armes", args=2}, competence= {dataType= "comp", args=3}, -- on va le gérer différemment comme du code lol sinon c'est trop relou skill= {dataType= "list", args=2}, } \ No newline at end of file diff --git a/view.lua b/view.lua index ff4b352..b40657d 100644 --- a/view.lua +++ b/view.lua @@ -18,7 +18,7 @@ print("Armure", "Phy:" .. creature.armure.phy, "Psy:" .. creature.armure.psy, "S print(" ", "------") print("Armes:") for key, value in ipairs(creature.armes) do - print(value[1], value[2]) + print(value.nom, value.force) end print(" ", "------") print("Competences:")