2,875
edits
No edit summary |
(Add public functions to grab obstacle requirements and costs) |
||
Line 50: | Line 50: | ||
end | end | ||
function p. | --- Gets all required levels to build the given obstacle. | ||
local | function p.getObstacleRequirements(obstacle) | ||
local levelRequirements = {} | |||
-- Add agility level requirement. | |||
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 | ||
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. | -- 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 | |||
if obstacle.scCost > 0 then | 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 | 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 |
edits