2,875
edits
No edit summary |
(Update to reflect changes from Agility api) |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local Num = require('Module:Number') | |||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
local Agility = require('Module:Skills/Agility') | local Agility = require('Module:Skills/Agility') | ||
Line 20: | Line 21: | ||
-- Gets all associated metadata from an obstacle based on its name. | -- Gets all associated metadata from an obstacle based on its name. | ||
local function getObstacle(name) | local function getObstacle(name, costReduction) | ||
name = Shared.specialTitleCase(name) | name = Shared.specialTitleCase(name) | ||
local obstacle = Agility.getObstacle(name) or Agility.getPillar(name) | local obstacle = Agility.getObstacle(name) or Agility.getPillar(name) | ||
Line 37: | Line 38: | ||
else | else | ||
slot = obstacle.category + 1 | slot = obstacle.category + 1 | ||
end | |||
-- Apply cost reduction, if available. | |||
local itemCosts = Agility.getObstacleCosts(obstacle) | |||
if costReduction then | |||
Agility.applyCostReduction(itemCosts, costReduction) | |||
end | end | ||
Line 44: | Line 51: | ||
Obstacle = obstacle, | Obstacle = obstacle, | ||
LevelRequirements = Agility.getObstacleRequirements(obstacle), | LevelRequirements = Agility.getObstacleRequirements(obstacle), | ||
ItemCosts = | ItemCosts = itemCosts, | ||
} | } | ||
Line 50: | Line 57: | ||
end | end | ||
function p.calculateCourse(obstacleNames, checkDoubleSlots) | function p.calculateCourse(obstacleNames, checkDoubleSlots, costReduction) | ||
-- Collect all obstacles and filter out nill values. | -- Collect all obstacles and filter out nill values. | ||
local courseObstacles = {} | local courseObstacles = {} | ||
Line 56: | Line 63: | ||
for _, v in pairs(obstacleNames) do | for _, v in pairs(obstacleNames) do | ||
local currObstacle = getObstacle(v) | local currObstacle = getObstacle(v, costReduction) | ||
if currObstacle then | if currObstacle then | ||
if checkDoubleSlots and courseSlots[currObstacle.Slot] == true then | if checkDoubleSlots and courseSlots[currObstacle.Slot] == true then | ||
Line 73: | Line 80: | ||
for _, course in pairs(courseObstacles) do | for _, course in pairs(courseObstacles) do | ||
-- Pool together highest level requirements for the entire course. | |||
for skill, level in pairs(course.LevelRequirements) do | for skill, level in pairs(course.LevelRequirements) do | ||
Shared.addOrUpdate(courseLevelRequirements, skill, | Shared.addOrUpdate(courseLevelRequirements, skill, | ||
Line 80: | Line 88: | ||
end | end | ||
for item, amount in pairs( | -- Pool together total item costs to build the entire course course. | ||
local courseCosts = course.ItemCosts | |||
if courseCosts['GP'] then courseItemCosts['GP'] = courseItemCosts['GP'] + courseCosts['GP'] end | |||
if courseCosts['SC'] then courseItemCosts['SC'] = courseItemCosts['SC'] + courseCosts['SC'] end | |||
for item, amount in pairs(courseCosts['Items']) do | |||
Shared.addOrUpdate(courseItemCosts, item, | Shared.addOrUpdate(courseItemCosts, item, | ||
function(x) | function(x) | ||
Line 304: | Line 317: | ||
function p.test() | function p.test() | ||
local obstacles = {"Rope Climb","Monkey Bars"," Balance Seesaw","Elite Pillar of Conflict"} | local obstacles = {"Rope Climb","Monkey Bars"," Balance Seesaw","Elite Pillar of Conflict"} | ||
local obs = p. | local obs = p.calculateCourse(obstacles) | ||
Debug.log(obs) | Debug.log(obs.CourseItemCosts) | ||
end | end | ||
return p | return p |
edits