Module:Calculator/AgilityObstacle: Difference between revisions

no edit summary
(First version)
No edit summary
Line 9: Line 9:
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')


-- Adds the the highest level to the dictionary, or the level, if the key isn't present.
local function addHighestLevelRequirement(tbl, skill, level)
Shared.addOrUpdate(tbl, skill,
function(x)
if x then
return math.max(x, level)
else
return level
end
end
)
end
-- Adds the item amount to the dictionary, or just the amount if the key isn't present.
local function concatItemRequirements(tbl, item, amount)
Shared.addOrUpdate(tbl, item,
function(x)
x = x or 0
return x + amount
end
)
end
--- Gets all required levels to build the given obstacle.
local function getLevelRequirements(obstacle)
local function getLevelRequirements(obstacle)
local levelRequirements = {}
local levelRequirements = {}
-- Add agility level requirement.
-- Add agility level requirement.
table.insert(levelRequirements, {
addHighestLevelRequirement(levelRequirements, 'Agility', Skills.getRecipeLevel('Agility', obstacle))
SkillName = 'Agility',
 
SkillLevel = Skills.getRecipeLevel('Agility', obstacle)
})
-- Add other level requirements.
-- Add other level requirements.
if type(obstacle.skillRequirements) == 'table' then
if type(obstacle.skillRequirements) == 'table' then
Line 23: Line 44:
local skillName = Constants.getSkillName(skillReq.skillID)
local skillName = Constants.getSkillName(skillReq.skillID)
if skillName ~= nil then
if skillName ~= nil then
table.insert(levelRequirements, {
addHighestLevelRequirement(levelRequirements, skillName, skillReq.level)
SkillName = skillName,
SkillLevel = skillReq.level
})
end
end
end
end
Line 32: Line 50:
return levelRequirements
return levelRequirements
end
local function getItemRequirements(obstacle)
local itemRequirements = {}
end
end


Line 50: Line 72:
-- Build and return obstacle information
-- Build and return obstacle information
mw.log(levelRequirements)
mw.log(levelRequirements)
for k, v in pairs(levelRequirements) do
mw.log(k)
mw.log(v)
end
end
end


2,875

edits