Module:Calculator/AgilityObstacle: Difference between revisions

From Melvor Idle
No edit summary
(Add support for more currencies)
 
(45 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local yesno = require('Module:Shared/Yesno')
local Num = require('Module:Number')
local Num = require('Module:Number')
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Modifiers = require('Module:Modifiers')
local Agility = require('Module:Skills/Agility')
local Agility = require('Module:Skills/Agility')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Skills = require('Module:Skills')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Debug = require('Module:Debug') -- Comment out when Module is finalised.
 
local iconTable = {
    ['GP']  = function(amount) return Icons._Currency('GP', amount) end,
    ['SC']  = function(amount) return Icons._Currency('SC', amount) end,
    ['AP']  = function(amount) return Icons._Currency('AP', amount) end,
    ['ASC'] = function(amount) return Icons._Currency('ASC', amount) end,
}
 
local currencies = {
'GP', 'SC', 'AP', 'ASC'
}


local function getItemIcon(itemName, amount)
local function getItemIcon(itemName, amount)
if itemName == 'GP' then
local iconFunc = iconTable[itemName]
return Icons.GP(amount)
    if iconFunc then
end
        return iconFunc(amount)
    else
if itemName == 'SC' then
        return Icons.Icon({itemName, type='item', qty = amount, notext=true})
return Icons.SC(amount)
    end
end
end
 
return Icons.Icon({itemName, type='item', qty = amount, notext=true})
local function getObstacleIcon(obstacle)
local obs = obstacle.Obstacle
return Icons.getExpansionIcon(obs.id) .. Icons.Icon({obs.name, type='agility'})  
end
end


-- 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)
if obstacle == nil then
if obstacle == nil then
error("Unknown Agility obstacle or pillar name: " .. name)
error("Unknown Agility obstacle or pillar name: " .. (name or '<name is nil>'))
end
end


Line 38: Line 50:
slot = 'Pillar'
slot = 'Pillar'
end
end
elseif string.find(name, 'Obelisk') then
slot = 'Obelisk'
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 47: Line 67:
Obstacle = obstacle,
Obstacle = obstacle,
LevelRequirements = Agility.getObstacleRequirements(obstacle),
LevelRequirements = Agility.getObstacleRequirements(obstacle),
ItemCosts = Agility.getObstacleCosts(obstacle),
ItemCosts = itemCosts,
}
}


Line 53: Line 73:
end
end


function p.calculateCourse(obstacleNames, checkDoubleSlots)
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 59: Line 79:
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 70: Line 90:
end
end
return courseObstacles
end
function p.calculateCourse(obstacleNames, checkDoubleSlots, costReduction)
function poolItems(tbl, item, amount)
Shared.addOrUpdate(tbl, item, function(x) x = x or 0 return x + amount end)
end
-- 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.
local courseLevelRequirements = {}
local courseLevelRequirements = {}
local courseItemCosts = {}
local courseItemCosts = {
['Items'] = {}
for _, course in pairs(courseObstacles) do
}
for skill, level in pairs(course.LevelRequirements) do
local courseObstacles = getObstacles(obstacleNames, checkDoubleSlots, costReduction)
 
for _, obstacle in pairs(courseObstacles) do
-- Pool together highest level requirements for the entire course.
for skill, level in pairs(obstacle.LevelRequirements) do
Shared.addOrUpdate(courseLevelRequirements, skill,  
Shared.addOrUpdate(courseLevelRequirements, skill,  
function(x)
function(x)
Line 83: Line 115:
end
end
for item, amount in pairs(course.ItemCosts) do
-- Pool together total item costs to build the entire course course.
Shared.addOrUpdate(courseItemCosts, item,  
local obstacleCosts = obstacle.ItemCosts
function(x)
x = x or 0 return x + amount
-- Iterate over currencies and pool these costs
end)
for _, curr in ipairs(currencies) do
if obstacleCosts[curr] then
poolItems(courseItemCosts, curr, obstacleCosts[curr])
end
end
 
for item, amount in pairs(obstacleCosts['Items']) do
poolItems(courseItemCosts['Items'], item, amount)
end
end
end
end
Line 94: Line 133:
local sortFunc = function(a, b)
local sortFunc = function(a, b)
-- Special case to sort pillars AFTER all regular obstacles.
-- Special case to sort pillars AFTER all regular obstacles.
     local pillar = { ["Pillar"] = 99, ["Elite Pillar"] = 100 }
     local pillar = { ["Pillar"] = 99, ["Elite Pillar"] = 100, ["Obelisk"] = 60 }
return (pillar[a.Slot] or a.Slot) < (pillar[b.Slot] or b.Slot)
return (pillar[a.Slot] or a.Slot) < (pillar[b.Slot] or b.Slot)
end
end
Line 127: Line 166:


function p._getCourseList(args)
function p._getCourseList(args)
-- Parse optional parameters
local costReduction = {
['GP']  = Num.toNumberOrDefault(args['gpCostReduction'], 0),
['SC']  = Num.toNumberOrDefault(args['scCostReduction'], 0),
['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
}
local obstacleNames = parseObstacleArgs(args)
local obstacleNames = parseObstacleArgs(args)
local courseRequirements = p.calculateCourse(obstacleNames, true)
local courseRequirements = p.calculateCourse(obstacleNames, true, costReduction)
local includeItems = args['includeitems'] or true
local includeSkills = args['includeskills'] or true
local includeObstacles = args['includeObstacles'] or true
local html = mw.html.create()
local html = mw.html.create()
     local div = html:tag('div')
     local div = html:tag('div')
      
      
     if includeObstacles then
     if yesno(args['includeObstacles'], true) == true then
div:tag('b'):wikitext('Obstacles')
div:tag('b'):wikitext('Obstacles')
local tbl = mw.html.create("table")
local tbl = mw.html.create("table")
         :addClass("wikitable sticky-header text-align-left")
         :addClass("wikitable stickyHeader text-align-left")
        
        
         tbl :tag("tr")
         tbl :tag("tr")
Line 147: Line 189:


for _, v in pairs(courseRequirements.Obstacles) do
for _, v in pairs(courseRequirements.Obstacles) do
tab :tag('tr')
tbl :tag('tr')
:tag('td')
:tag('td')
:addClass('text-align-right')
:css('text-align', 'right')
:wikitext(v.Slot)
:wikitext(v.Slot)
:tag('td')
:tag('td')
:wikitext(Icons.Icon({v.Name, type='agility'}))
:wikitext(getObstacleIcon(v))
end
end
div:node(tbl)
div:node(tbl)
div:wikitext('<br>')
     end
     end


     if includeItems then
     if yesno(args['includeitems'], true) then
     div:tag('b'):wikitext('Items Required')
     div:tag('b'):wikitext('Items Required')
     local ul = div:tag('ul')
     local ul = div:tag('ul')
    
    
     local itemList = Shared.sortDictionary(courseRequirements.CourseItemCosts,  
    local courseItems = courseRequirements.CourseItemCosts
    -- Put currencies at the top.
    for _, curr in ipairs(currencies) do
    if courseItems[curr] then
    ul:tag('li'):wikitext(getItemIcon(curr, courseItems[curr]))
    end
    end
 
     local itemList = Shared.sortDictionary(courseItems['Items'],  
     function(a, b) return a.item < b.item end,
     function(a, b) return a.item < b.item end,
     function(a, b) return {item = a, amount = b} end)
     function(a, b) return {item = a, amount = b} end)
Line 168: Line 219:
for _, v in pairs(itemList) do
for _, v in pairs(itemList) do
     ul:tag('li'):wikitext(getItemIcon(v.item, v.amount))
     ul:tag('li'):wikitext(getItemIcon(v.item, v.amount))
    end
end
div:wikitext('<br>')
     end
     end
if includeSkills then
if yesno(args['includeskills'], true) then
div:tag('b'):wikitext('Skills Required')
div:tag('b'):wikitext('Skills Required')
     local ul2 = div:tag('ul')
     local ul2 = div:tag('ul')
Line 182: Line 234:
     ul2:tag('li'):wikitext(Icons._SkillReq(v.skill, v.level))
     ul2:tag('li'):wikitext(Icons._SkillReq(v.skill, v.level))
     end
     end
    div:wikitext('<br>')
end
end
Line 187: Line 240:
end
end


function p.test()
function p.getCourseTable(frame)
local obs = {'Elite Pillar of Conflict ', ' Cargo Net ',' Balance Beam','Pipe Climb'}
local args = frame:getParent().args
local a = p._getCourseList(obs)
return p._getCourseTable(args)
end
end


function p._getCourseTable(obstacleNames)
function p._getCourseTable(args)
local result = ''
--== Local Functions for formatting Obstacle MetaData ==--
local obstacles = {}
local function getBonusses(obstacle)
for i, name in ipairs(obstacleNames) do
if obstacle.modifiers == nil then
local obst = Agility.getObstacle(Shared.trim(name))
return '<span style="color:red">None :(</span>'
if obst == nil then
result = result .. Shared.printError('Invalid Obstacle Name "' .. name .. '"') .. '<br/>'
else
else
table.insert(obstacles, obst)
return Modifiers.getModifiersText(obstacle.modifiers, true, false, 10)
end
end
end
end
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!Slot!!Name!!Bonuses!!Requirements!!Cost'
local catLog = {}
table.sort(obstacles, function(a, b) return a.category < b.category end)
local function getRequirements(requirementsTable)
 
local skillList = Shared.sortDictionary(requirementsTable,  
local catCounts = {}
function(a, b) return a.skill < b.skill end,
for i, obst in ipairs(obstacles) do
function(a, b) return {skill = a, level = b} end)
if catCounts[obst.category] == nil then
catCounts[obst.category] = 1
local res = {}
else
for _, v in pairs(skillList) do
catCounts[obst.category] = catCounts[obst.category] + 1
table.insert(res, Icons._SkillReq(v.skill, v.level))
end
end
return table.concat(res, '<br/>')
end
end
local function getCosts(costsTable)
local res = {}
-- Order table with GP, SC first, then the other items.
    for _, curr in ipairs(currencies) do
    if costsTable[curr] then
    table.insert(res, getItemIcon(curr, costsTable[curr]))
    end
    end    


for i, obst in ipairs(obstacles) do
    local sortedCosts = Shared.sortDictionary(costsTable['Items'],
result = result..'\r\n|-'
function(a, b) return a.item < b.item end,
result = result..'\r\n|'
function(a, b) return {item = a, amount = b} end)
if catLog[obst.category] == nil then
 
local rowspan = catCounts[obst.category]
    for _, v in pairs(sortedCosts) do
result = result..'rowspan="'..rowspan..'" style="border:1px solid black"|'..(obst.category + 1)..'||'
    table.insert(res, getItemIcon(v.item, v.amount))
catLog[obst.category] = true
    end
return table.concat(res, '<br/>')
end
local function getTotalBonuses(obstacles)
--[==[
local bonuses = {}
for _, obstacle in pairs(obstacles) do
for bonusName, bonusValue in pairs(obstacle.Obstacle.modifiers) do
table.insert(bonuses, {name = bonusName, value = bonusValue})
end
end
end
result = result..obst.name


local bonuses = {}
table.sort(bonuses, function(a, b) return a.name < b.name end)
--After that, adding the bonuses
for bonusName, bonusValue in pairs(obst.modifiers) do
local ret = {}
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
for _, bonus in pairs(bonuses) do
table.insert(ret, Constants._getModifierText(bonus.name, bonus.value))
end
end
if Shared.tableIsEmpty(bonuses) then
if Shared.tableIsEmpty(ret) then
table.insert(bonuses, '<span style="color:red">None :(</span>')
table.insert(ret, '<span style="color:red">None :(</span>')
end
end
result = result..'||'..table.concat(bonuses, '<br/>')
return table.concat(ret, '<br/>')
--]==]
return ''
end


--Grabbing requirements to create
--== Parse optional parameters==--
result = result..'|| ' .. formatObstacleRequirements(obst)
local showTotals = yesno(args['showtotals'], false)
local showbonus = yesno(args['showbonus'], true)
local showrequirements = yesno(args['showrequirements'], true)
local showcosts = yesno(args['showcosts'], true)
local obstacleMastery = yesno(args['obstacleMastery'], false)


--Finally, the cost
local costReduction = {
result = result..'|| data-sort-value="'..obst.gpCost..'"|'.. formatObstacleCosts(obst)
['GP']  = Num.toNumberOrDefault(args['gpCostReduction'], 0),
['SC']  = Num.toNumberOrDefault(args['scCostReduction'], 0),
['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
}
local obstacleNames = parseObstacleArgs(args)
local courseRequirements = p.calculateCourse(obstacleNames, true, costReduction)
 
--== Start of table formatting ==--
local tbl = mw.html.create("table")
      :addClass("wikitable stickyheader")
   
    local thr = tbl:tag('tr')
    thr:tag('th'):wikitext('Slot')
thr:tag('th'):wikitext('Obstacle')
if showbonus then
thr:tag('th'):wikitext('Bonuses')
end
if showrequirements then
thr:tag('th'):wikitext('Requirements')
end
if showcosts then
thr:tag('th'):wikitext('Costs')
end
end


result = result..'\r\n|}'
for _, obstacle in pairs(courseRequirements.Obstacles) do
 
local tr = tbl:tag('tr')
return result
tr  :tag('td')
end
:css('text-align', 'right')
:wikitext(obstacle.Slot)
:tag('td'):wikitext(getObstacleIcon(obstacle))
if showbonus then
tr:tag('td'):wikitext(getBonusses(obstacle.Obstacle))
end
if showrequirements then
tr:tag('td'):wikitext(getRequirements(obstacle.LevelRequirements))
end
if showcosts then
tr:tag('td'):wikitext(getCosts(obstacle.ItemCosts))
end
end
if showTotals == true then
local tr = tbl:tag('tr')
tr  :tag('th')
:attr('colspan', 2)
:wikitext('Totals')
if showbonus then
tr  :tag('td')
:wikitext(getTotalBonuses(courseRequirements.Obstacles))
end
if showrequirements then
tr  :tag('td')
:wikitext(getRequirements(courseRequirements.CourseLevelRequirements))
end
if showcosts then
tr  :tag('td')
:wikitext(getCosts(courseRequirements.CourseItemCosts))
end
end


function p.getCourseTable(frame)
return tostring(tbl)
local obstNameStr = frame.args ~= nil and frame.args[1] or frame
local obstacleNames = Shared.splitString(obstNameStr, ',')
return p._getCourseTable(obstacleNames)
end
end


return p
return p

Latest revision as of 17:53, 22 July 2024

Documentation for this module may be created at Module:Calculator/AgilityObstacle/doc

local p = {}

local yesno = require('Module:Shared/Yesno')
local Num = require('Module:Number')
local Constants = require('Module:Constants')
local Modifiers = require('Module:Modifiers')
local Agility = require('Module:Skills/Agility')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')

local iconTable = {
    ['GP']  = function(amount) return Icons._Currency('GP', amount) end,
    ['SC']  = function(amount) return Icons._Currency('SC', amount) end,
    ['AP']  = function(amount) return Icons._Currency('AP', amount) end,
    ['ASC'] = function(amount) return Icons._Currency('ASC', amount) end,
}

local currencies = {
	'GP', 'SC', 'AP', 'ASC'
}

local function getItemIcon(itemName, amount)
	local iconFunc = iconTable[itemName]
    if iconFunc then
        return iconFunc(amount)
    else
        return Icons.Icon({itemName, type='item', qty = amount, notext=true})
    end
end

local function getObstacleIcon(obstacle)
	local obs = obstacle.Obstacle
	return Icons.getExpansionIcon(obs.id) .. Icons.Icon({obs.name, type='agility'}) 
end

-- Gets all associated metadata from an obstacle based on its name.
local function getObstacle(name, costReduction)
	name = Shared.specialTitleCase(name)
	local obstacle = Agility.getObstacle(name) or Agility.getPillar(name)
	if obstacle == nil then
		error("Unknown Agility obstacle or pillar name: " .. (name or '<name is nil>'))
	end

	-- Resolve obstacle slot.
	local slot = 0
	if string.find(name, 'Pillar') then
		if string.find(name, 'Elite') then
			slot = 'Elite Pillar'
		else
			slot = 'Pillar'
		end
	elseif string.find(name, 'Obelisk') then
		slot = 'Obelisk'
	else
		slot = obstacle.category + 1
	end
	
	-- Apply cost reduction, if available.
	local itemCosts = Agility.getObstacleCosts(obstacle)
	if costReduction then 
		Agility.applyCostReduction(itemCosts, costReduction) 
	end
	
	local obstacleInfo = {
		Name = obstacle.name,
		Slot = slot,
		Obstacle = obstacle,
		LevelRequirements = Agility.getObstacleRequirements(obstacle),
		ItemCosts = itemCosts,
	}

	return obstacleInfo
end

local function getObstacles(obstacleNames, checkDoubleSlots, costReduction)
	-- Collect all obstacles and filter out nill values.
	local courseObstacles = {}
	local courseSlots = {}
	
	for _, v in pairs(obstacleNames) do
		local currObstacle = getObstacle(v, costReduction)
		if currObstacle then
			if checkDoubleSlots and courseSlots[currObstacle.Slot] == true then
				error('There are two or more obstacles in the same slot. Obstacle: ' .. currObstacle.Name .. ' Slot: ' .. currObstacle.Slot)
			end
			
			courseSlots[currObstacle.Slot] = true
			table.insert(courseObstacles, currObstacle) 
		end
	end
	
	return courseObstacles
end

function p.calculateCourse(obstacleNames, checkDoubleSlots, costReduction)
	function poolItems(tbl, item, amount)
		Shared.addOrUpdate(tbl, item, function(x) x = x or 0 return x + amount end)
	end

	-- Calculate the highest level requirements and the total amount of items
	-- required to build this agility course.
	local courseLevelRequirements = {}
	local courseItemCosts = {
		['Items'] = {}
	}
	local courseObstacles = getObstacles(obstacleNames, checkDoubleSlots, costReduction)

	for _, obstacle in pairs(courseObstacles) do
		-- Pool together highest level requirements for the entire course.
		for skill, level in pairs(obstacle.LevelRequirements) do
				Shared.addOrUpdate(courseLevelRequirements, skill, 
					function(x)	
						if x then return math.max(x, level)	else return level end 
					end)
		end
		
		-- Pool together total item costs to build the entire course course.
		local obstacleCosts = obstacle.ItemCosts
		
		-- Iterate over currencies and pool these costs
		for _, curr in ipairs(currencies) do
			if obstacleCosts[curr] then 
				poolItems(courseItemCosts, curr, obstacleCosts[curr])
			end
		end

		for item, amount in pairs(obstacleCosts['Items']) do
			poolItems(courseItemCosts['Items'], item, amount)
		end
	end

	-- Sort course on category
	local sortFunc = function(a, b)
		-- Special case to sort pillars AFTER all regular obstacles.
    	local pillar = { ["Pillar"] = 99, ["Elite Pillar"] = 100, ["Obelisk"] = 60 }
		return (pillar[a.Slot] or a.Slot) < (pillar[b.Slot] or b.Slot)
	end
	
	table.sort(courseObstacles, sortFunc)
	
	return {
		Obstacles = courseObstacles,
		CourseLevelRequirements = courseLevelRequirements,
		CourseItemCosts = courseItemCosts
	}
end

-- Stupid shenanigans to filter out numeric parameters.
-- Because just iterating over #args doesn't work for some reason...
function parseObstacleArgs(args)
	local obstacleNames = {}
	for k, v in pairs(args) do
		k = tonumber(k)
		if k then 
			table.insert(obstacleNames, v:match("^%s*(.-)%s*$")) 
		end
	end
	
	return obstacleNames
end

function p.getCourseList(frame)
	local args = frame:getParent().args
	return p._getCourseList(args)
end

function p._getCourseList(args)
	-- Parse optional parameters
	local costReduction = {
		['GP']   = Num.toNumberOrDefault(args['gpCostReduction'], 0),
		['SC']   = Num.toNumberOrDefault(args['scCostReduction'], 0),
		['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
	}
	
	local obstacleNames = parseObstacleArgs(args)
	local courseRequirements = p.calculateCourse(obstacleNames, true, costReduction)
	
	local html = mw.html.create()
    local div = html:tag('div')
    
    if yesno(args['includeObstacles'], true) == true then
		div:tag('b'):wikitext('Obstacles')
		local tbl = mw.html.create("table")
        	:addClass("wikitable stickyHeader text-align-left")
        	
        tbl	:tag("tr")
        		:tag("th"):wikitext("Slot")
        		:tag("th"):wikitext("Obstacle")

		for _, v in pairs(courseRequirements.Obstacles) do
			tbl	:tag('tr')
					:tag('td')
						:css('text-align', 'right')
						:wikitext(v.Slot)
					:tag('td')
						:wikitext(getObstacleIcon(v))
		end
		
		div:node(tbl)
		div:wikitext('<br>')
    end

    if yesno(args['includeitems'], true) then
    	div:tag('b'):wikitext('Items Required')
    	local ul = div:tag('ul')
    	
    	local courseItems = courseRequirements.CourseItemCosts
    	-- Put currencies at the top.
    	for _, curr in ipairs(currencies) do
    		if courseItems[curr] then
    			ul:tag('li'):wikitext(getItemIcon(curr, courseItems[curr]))
    		end
    	end

    	local itemList = Shared.sortDictionary(courseItems['Items'], 
    		function(a, b) return a.item < b.item end,
    		function(a, b) return {item = a, amount = b} end)

		for _, v in pairs(itemList) do
    		ul:tag('li'):wikitext(getItemIcon(v.item, v.amount))
		end
		div:wikitext('<br>')
    end
	
	if yesno(args['includeskills'], true) then
		div:tag('b'):wikitext('Skills Required')
    	local ul2 = div:tag('ul')
    	
    	local skillList = Shared.sortDictionary(courseRequirements.CourseLevelRequirements, 
    		function(a, b) return a.skill < b.skill end,
    		function(a, b) return {skill = a, level = b} end)
    	
    	for _, v in pairs(skillList) do
    		ul2:tag('li'):wikitext(Icons._SkillReq(v.skill, v.level))
    	end
    	div:wikitext('<br>')
	end
	
    return tostring(html)
end

function p.getCourseTable(frame)
	local args = frame:getParent().args
	return p._getCourseTable(args)
end

function p._getCourseTable(args)
	--== Local Functions for formatting Obstacle MetaData ==--
	local function getBonusses(obstacle)
		if obstacle.modifiers == nil then
			return '<span style="color:red">None :(</span>'
		else
			return Modifiers.getModifiersText(obstacle.modifiers, true, false, 10)
		end
	end
	
	local function getRequirements(requirementsTable)
		local skillList = Shared.sortDictionary(requirementsTable, 
			function(a, b) return a.skill < b.skill end,
			function(a, b) return {skill = a, level = b} end)
		
		local res = {}
		for _, v in pairs(skillList) do
			table.insert(res, Icons._SkillReq(v.skill, v.level))
		end
		return table.concat(res, '<br/>')
	end
	
	local function getCosts(costsTable)
		local res = {}
		
		-- Order table with GP, SC first, then the other items.
    	for _, curr in ipairs(currencies) do
    		if costsTable[curr] then 
    			table.insert(res, getItemIcon(curr, costsTable[curr]))
    		end
    	end		    	

    	local sortedCosts = Shared.sortDictionary(costsTable['Items'], 
			function(a, b) return a.item < b.item end,
			function(a, b) return {item = a, amount = b} end)

    	for _, v in pairs(sortedCosts) do
    		table.insert(res, getItemIcon(v.item, v.amount))
    	end
		return table.concat(res, '<br/>')
	end
	
	local function getTotalBonuses(obstacles)
		--[==[
		local bonuses = {}
		for _, obstacle in pairs(obstacles) do
			for bonusName, bonusValue in pairs(obstacle.Obstacle.modifiers) do
				table.insert(bonuses, {name = bonusName, value = bonusValue})
			end
		end

		table.sort(bonuses, function(a, b) return a.name < b.name end)
		
		local ret = {}
		for _, bonus in pairs(bonuses) do
			table.insert(ret, Constants._getModifierText(bonus.name, bonus.value))
		end
		if Shared.tableIsEmpty(ret) then
			table.insert(ret, '<span style="color:red">None :(</span>')
		end
		
		return table.concat(ret, '<br/>')
		--]==]
		return ''
	end

	--== Parse optional parameters==--
	local showTotals = yesno(args['showtotals'], false)
	local showbonus = yesno(args['showbonus'], true)
	local showrequirements = yesno(args['showrequirements'], true)
	local showcosts = yesno(args['showcosts'], true)
	local obstacleMastery = yesno(args['obstacleMastery'], false)

	local costReduction = {
		['GP']   = Num.toNumberOrDefault(args['gpCostReduction'], 0),
		['SC']   = Num.toNumberOrDefault(args['scCostReduction'], 0),
		['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
	}
	
	local obstacleNames = parseObstacleArgs(args)
	local courseRequirements = p.calculateCourse(obstacleNames, true, costReduction)

	--== Start of table formatting ==--
	local tbl = mw.html.create("table")
       	:addClass("wikitable stickyheader")
    
    local thr = tbl:tag('tr')
    thr:tag('th'):wikitext('Slot')
	thr:tag('th'):wikitext('Obstacle')
	
	if showbonus then
		thr:tag('th'):wikitext('Bonuses')
	end
	if showrequirements then
		thr:tag('th'):wikitext('Requirements')
	end
	if showcosts then
		thr:tag('th'):wikitext('Costs')
	end

	for _, obstacle in pairs(courseRequirements.Obstacles) do
		local tr = tbl:tag('tr')
		tr  :tag('td')
				:css('text-align', 'right')
				:wikitext(obstacle.Slot)
			:tag('td'):wikitext(getObstacleIcon(obstacle))
			
		if showbonus then
			tr:tag('td'):wikitext(getBonusses(obstacle.Obstacle))
		end
		if showrequirements then
			tr:tag('td'):wikitext(getRequirements(obstacle.LevelRequirements))
		end
		if showcosts then
			tr:tag('td'):wikitext(getCosts(obstacle.ItemCosts))
		end
	end
	
	if showTotals == true then
		local tr = tbl:tag('tr')
		tr  :tag('th')
				:attr('colspan', 2)
				:wikitext('Totals')
		if showbonus then
			tr  :tag('td')
				:wikitext(getTotalBonuses(courseRequirements.Obstacles))
		end
		if showrequirements then
			tr  :tag('td')
				:wikitext(getRequirements(courseRequirements.CourseLevelRequirements))
		end
		if showcosts then
			tr  :tag('td')
				:wikitext(getCosts(courseRequirements.CourseItemCosts))
		end	
	end

	return tostring(tbl)
end

return p