2,875
edits
No edit summary |
No edit summary |
||
Line 37: | Line 37: | ||
local obstacle = Agility.getObstacle(name) or Agility.getPillar(name) | local obstacle = Agility.getObstacle(name) or Agility.getPillar(name) | ||
if obstacle == nil then | if obstacle == nil then | ||
error("Unknown Agility obstacle or pillar name: " .. name) | |||
end | end | ||
Line 55: | Line 55: | ||
Name = obstacle.name, | Name = obstacle.name, | ||
Slot = slot, | Slot = slot, | ||
Obstacle = obstacle, | |||
LevelRequirements = Agility.getObstacleRequirements(obstacle), | LevelRequirements = Agility.getObstacleRequirements(obstacle), | ||
ItemCosts = Agility.getObstacleCosts(obstacle), | ItemCosts = Agility.getObstacleCosts(obstacle), | ||
Line 62: | Line 63: | ||
end | end | ||
function p.calculateCourse( | function p.calculateCourse(obstacleNames, checkDoubleSlots) | ||
-- Collect all obstacles and filter out nill values. | -- Collect all obstacles and filter out nill values. | ||
local courseObstacles = {} | local courseObstacles = {} | ||
local courseSlots = {} | local courseSlots = {} | ||
for _, v in pairs( | for _, v in pairs(obstacleNames) do | ||
local currObstacle = getObstacle(v) | local currObstacle = getObstacle(v) | ||
if currObstacle then | if currObstacle then | ||
Line 86: | Line 87: | ||
for _, course in pairs(courseObstacles) do | for _, course in pairs(courseObstacles) do | ||
for skill, level in pairs(course.LevelRequirements) do | for skill, level in pairs(course.LevelRequirements) do | ||
Shared.addOrUpdate(courseLevelRequirements, skill, | |||
function(x) | |||
if x then return math.max(x, level) else return level end | |||
end) | |||
end | end | ||
for item, amount in pairs(course.ItemCosts) do | for item, amount in pairs(course.ItemCosts) do | ||
Shared.addOrUpdate(courseItemCosts, item, | |||
function(x) | |||
x = x or 0 return x + amount | |||
end) | |||
end | end | ||
end | end | ||
return { | return { | ||
Obstacles = courseObstacles, | |||
CourseLevelRequirements = courseLevelRequirements, | CourseLevelRequirements = courseLevelRequirements, | ||
CourseItemCosts = courseItemCosts | CourseItemCosts = courseItemCosts | ||
Line 102: | Line 110: | ||
-- Stupid shenanigans to filter out numeric parameters. | -- Stupid shenanigans to filter out numeric parameters. | ||
-- Because just iterating over #args doesn't work for some reason... | -- Because just iterating over #args doesn't work for some reason... | ||
function | function parseObstacleArgs(args) | ||
local | local obstacleNames = {} | ||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
k = tonumber(k) | k = tonumber(k) | ||
if k then table.insert( | if k then | ||
table.insert(obstacleNames, v:match("^%s*(.-)%s*$")) | |||
end | |||
end | end | ||
return | |||
return obstacleNames | |||
end | end | ||
Line 117: | Line 128: | ||
function p._main(args) | function p._main(args) | ||
local | local obstacleNames = parseObstacleArgs(args) | ||
local courseRequirements = p.calculateCourse(obstacleNames, true) | local courseRequirements = p.calculateCourse(obstacleNames, true) | ||
edits