Module:Skills/Agility: Difference between revisions

Add public functions to grab obstacle requirements and costs
No edit summary
(Add public functions to grab obstacle requirements and costs)
Line 50: Line 50:
end
end


function p._getObstacleRequirements(obstacle)
--- Gets all required levels to build the given obstacle.
local resultPart = {}
function p.getObstacleRequirements(obstacle)
local level = Skills.getRecipeLevel('Agility', obstacle)
local levelRequirements = {}
if level ~= nil then
table.insert(resultPart, Icons._SkillReq('Agility', level))
-- Add agility level requirement.
end
levelRequirements['Agility'] = Skills.getRecipeLevel('Agility', obstacle)
 
-- Add other level requirements.
if type(obstacle.skillRequirements) == 'table' then
if type(obstacle.skillRequirements) == 'table' then
for i, skillReq in ipairs(obstacle.skillRequirements) do
for i, skillReq in ipairs(obstacle.skillRequirements) do
local skillName = Constants.getSkillName(skillReq.skillID)
local skillName = Constants.getSkillName(skillReq.skillID)
if skillName ~= nil then
if skillName ~= nil then
table.insert(resultPart, Icons._SkillReq(skillName, skillReq.level))
levelRequirements[skillName] = skillReq.level
end
end
end
end
end
end
return levelRequirements
end
function p._getObstacleRequirements(obstacle)
local resultPart = {}
local requirements = p.getObstacleRequirements(obstacle)
for skill, level in pairs(requirements) do
table.insert(resultPart, Icons._SkillReq(skill, level))
end
return table.concat(resultPart, '<br/>')
return table.concat(resultPart, '<br/>')
end
end


function p._getObstacleCosts(obstacle)
-- Gets all items and gp/sc costs required to build the given obstacle.
function p.getObstacleCosts(obstacle)
local costs = {}
local costs = {}
if obstacle.gpCost > 0 then table.insert(costs, Icons.GP(obstacle.gpCost)) end
 
if obstacle.scCost > 0 then table.insert(costs, Icons.SC(obstacle.scCost)) end
if obstacle.gpCost > 0 then
costs['GP'] = obstacle.gpCost
end
if obstacle.scCost > 0 then
costs['SC'] = obstacle.scCost
end
for j, itemCost in ipairs(obstacle.itemCosts) do
for j, itemCost in ipairs(obstacle.itemCosts) do
local item = Items.getItemByID(itemCost.id)
local item = Items.getItemByID(itemCost.id)
table.insert(costs, Icons.Icon({item.name, type='item', qty = itemCost.quantity, notext=true}))
costs[item.name] = itemCost.quantity
end
return costs
end
 
function p._getObstacleCosts(obstacle)
local costs = {}
local obstacleCosts = p.getObstacleCosts(obstacle)
-- Make sure SC and GP appear at the top.
if obstacleCosts['GP'] then table.insert(costs, Icons.GP(obstacleCosts['GP'])) end
if obstacleCosts['SC'] then table.insert(costs, Icons.SC(obstacleCosts['SC'])) end
for item, amount in pairs(obstacleCosts) do
if item ~= 'GP' and item ~= 'SC' then
table.insert(costs, Icons.Icon({item, type='item', qty = amount, notext=true}))
end
end
end
return table.concat(costs, '<br/>')
return table.concat(costs, '<br/>')
end
end
918

edits