feat: ajout du lvlup des armes et armures

This commit is contained in:
Kazhnuz 2024-08-10 19:32:28 +02:00
parent 856df9d32f
commit 13df70437a
9 changed files with 136 additions and 10 deletions

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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

39
libs/boosts.lua Normal file
View file

@ -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

View file

@ -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)

View file

@ -1,3 +1,4 @@
utils = require "libs.utils"
Object = require "libs.classic"
commands = require "libs.commands"
boosts = require "libs.boosts"

View file

@ -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},
}

View file

@ -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:")