Anonymous

Module:Calculator/AgilityObstacle: Difference between revisions

From Melvor Idle
no edit summary
(Update to reflect changes from Agility api)
No edit summary
Line 57: Line 57:
end
end


function p.calculateCourse(obstacleNames, checkDoubleSlots, costReduction)
local function getObstacles(obstacleNames, checkDoubleSlots, costReduction)
-- Collect all obstacles and filter out nill values.
-- Collect all obstacles and filter out nill values.
local courseObstacles = {}
local courseObstacles = {}
Line 74: Line 74:
end
end
return courseObstacles
end
function p.calculateCourse(obstacleNames, checkDoubleSlots, costReduction)
local funcPoolCosts = function(tbl, item, amount)
Shared.addOrUpdate(tbl, item, function(x) x = x or 0 return x + amount end)
end
local courseObstacles = getObstacles(obstacleNames, checkDoubleSlots, costReduction)
-- Calculate the highest level requirements and the total amount of items
-- Calculate the highest level requirements and the total amount of items
-- required to build this agility course.
-- required to build this agility course.
Line 90: Line 100:
-- Pool together total item costs to build the entire course course.
-- Pool together total item costs to build the entire course course.
local courseCosts = course.ItemCosts
local courseCosts = course.ItemCosts
if courseCosts['GP'] then courseItemCosts['GP'] = courseItemCosts['GP'] + courseCosts['GP'] end
funcPoolCosts(courseItemCosts, 'GP', courseCosts['GP'])
if courseCosts['SC'] then courseItemCosts['SC'] = courseItemCosts['SC'] + courseCosts['SC'] end
funcPoolCosts(courseItemCosts, 'SC', courseCosts['SC'])
for item, amount in pairs(courseCosts['Items']) do
for item, amount in pairs(courseCosts['Items']) do
Shared.addOrUpdate(courseItemCosts, item,  
funcPoolCosts(courseItemCosts, item, amount)
function(x)
x = x or 0 return x + amount
end)
end
end
end
end
2,875

edits