feat: ajout du lvlup des armes et armures
This commit is contained in:
parent
856df9d32f
commit
13df70437a
9 changed files with 136 additions and 10 deletions
46
classes/dataholders/armesholder.lua
Normal file
46
classes/dataholders/armesholder.lua
Normal 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
|
28
classes/dataholders/armureholder.lua
Normal file
28
classes/dataholders/armureholder.lua
Normal 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
|
|
@ -10,7 +10,7 @@ function StatHolder:applyCommand(command, args)
|
||||||
self.commands[command] = args
|
self.commands[command] = args
|
||||||
end
|
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 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
|
local modulo = commands.structs[self.key].modulo or 1
|
||||||
datas = commands.structs[self.key]
|
datas = commands.structs[self.key]
|
||||||
|
|
|
@ -5,6 +5,8 @@ local ListHolder = require "classes.dataholders.listholder"
|
||||||
local SimpleHolder = require "classes.dataholders.simpleholder"
|
local SimpleHolder = require "classes.dataholders.simpleholder"
|
||||||
local StatHolder = require "classes.dataholders.statholder"
|
local StatHolder = require "classes.dataholders.statholder"
|
||||||
local CompetenceHolder = require "classes.dataholders.competenceholder"
|
local CompetenceHolder = require "classes.dataholders.competenceholder"
|
||||||
|
local ArmesHolder = require "classes.dataholders.armesholder"
|
||||||
|
local ArmureHolder = require "classes.dataholders.armureholder"
|
||||||
|
|
||||||
function RawData.fromLine(line)
|
function RawData.fromLine(line)
|
||||||
line = utils.removeComment(line)
|
line = utils.removeComment(line)
|
||||||
|
@ -56,6 +58,10 @@ function DataList.getHolder(key, value)
|
||||||
return CompetenceHolder(key, value)
|
return CompetenceHolder(key, value)
|
||||||
elseif (value.dataType == "stat") then
|
elseif (value.dataType == "stat") then
|
||||||
return StatHolder(key, value)
|
return StatHolder(key, value)
|
||||||
|
elseif (value.dataType == "armure") then
|
||||||
|
return ArmureHolder(key, value)
|
||||||
|
elseif (value.dataType == "armes") then
|
||||||
|
return ArmesHolder(key, value)
|
||||||
end
|
end
|
||||||
return SimpleHolder(key, value)
|
return SimpleHolder(key, value)
|
||||||
end
|
end
|
||||||
|
@ -79,12 +85,17 @@ end
|
||||||
|
|
||||||
function DataList:reduce()
|
function DataList:reduce()
|
||||||
local level = 0
|
local level = 0
|
||||||
|
local mode = "creature"
|
||||||
for _, rawdata in ipairs(self.list) do
|
for _, rawdata in ipairs(self.list) do
|
||||||
if (rawdata.name == "level") then
|
if (rawdata.name == "level") then
|
||||||
level = rawdata.arguments
|
level = rawdata.arguments
|
||||||
end
|
end
|
||||||
|
if (rawdata.name == "mode") then
|
||||||
|
mode = rawdata.arguments
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if (self.forceLevel ~= nil) then
|
if (self.forceLevel ~= nil) then
|
||||||
level = self.forceLevel
|
level = self.forceLevel
|
||||||
end
|
end
|
||||||
|
@ -97,7 +108,7 @@ function DataList:reduce()
|
||||||
|
|
||||||
for key, holder in pairs(self.holders) do
|
for key, holder in pairs(self.holders) do
|
||||||
--self.reducedList[key] = holder:reduce(level)
|
--self.reducedList[key] = holder:reduce(level)
|
||||||
self:addToReducedList(key, holder:reduce(level))
|
self:addToReducedList(key, holder:reduce(level, mode))
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.forceLevel ~= nil) then
|
if (self.forceLevel ~= nil) then
|
||||||
|
|
39
libs/boosts.lua
Normal file
39
libs/boosts.lua
Normal 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
|
|
@ -35,11 +35,11 @@ local function addListCommands(name, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
for key, value in pairs(struct) do
|
for key, value in pairs(struct) do
|
||||||
if (value.dataType == "stat") then
|
if (value.dataType == "stat" or value.dataType == "armure") then
|
||||||
addStatCommands(key, value)
|
addStatCommands(key, value)
|
||||||
elseif (value.dataType == "list") then
|
elseif (value.dataType == "list") then
|
||||||
addListCommands(key, value)
|
addListCommands(key, value)
|
||||||
elseif (value.dataType == "comp") then
|
elseif (value.dataType == "comp" or value.dataType == "armes") then
|
||||||
addCompCommands(key, value)
|
addCompCommands(key, value)
|
||||||
else
|
else
|
||||||
addCommands(key, key, value.default)
|
addCommands(key, key, value.default)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
utils = require "libs.utils"
|
utils = require "libs.utils"
|
||||||
Object = require "libs.classic"
|
Object = require "libs.classic"
|
||||||
commands = require "libs.commands"
|
commands = require "libs.commands"
|
||||||
|
boosts = require "libs.boosts"
|
|
@ -1,5 +1,6 @@
|
||||||
return {
|
return {
|
||||||
name={contentType = "string", preParse = true, to="name"},
|
name={contentType = "string", preParse = true, to="name"},
|
||||||
|
mode={contentType = "string", preParse = true, to="mode", default = "creature"},
|
||||||
nomType={contentType = "string", to="type"},
|
nomType={contentType = "string", to="type"},
|
||||||
categorie={contentType = "string", to="categorie"},
|
categorie={contentType = "string", to="categorie"},
|
||||||
faiblesse={contentType = "list", args=1},
|
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},
|
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},
|
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"},
|
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"},
|
armurephy= {dataType= "armure", 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"},
|
armurepsy= {dataType= "armure", 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"},
|
armurespe= {dataType= "armure", modulo= 1, default= 0, max=9999999, min=0, to="armure.spe"},
|
||||||
armes= {dataType= "list", args=2},
|
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
|
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},
|
skill= {dataType= "list", args=2},
|
||||||
}
|
}
|
2
view.lua
2
view.lua
|
@ -18,7 +18,7 @@ print("Armure", "Phy:" .. creature.armure.phy, "Psy:" .. creature.armure.psy, "S
|
||||||
print(" ", "------")
|
print(" ", "------")
|
||||||
print("Armes:")
|
print("Armes:")
|
||||||
for key, value in ipairs(creature.armes) do
|
for key, value in ipairs(creature.armes) do
|
||||||
print(value[1], value[2])
|
print(value.nom, value.force)
|
||||||
end
|
end
|
||||||
print(" ", "------")
|
print(" ", "------")
|
||||||
print("Competences:")
|
print("Competences:")
|
||||||
|
|
Loading…
Reference in a new issue