2,877
edits
No edit summary |
(Add support for more currencies) |
||
(11 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
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 Icons = require('Module:Icons') | 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 function getItemIcon(itemName, amount) | ||
if | local iconFunc = iconTable[itemName] | ||
if iconFunc then | |||
return iconFunc(amount) | |||
else | |||
return Icons.Icon({itemName, type='item', qty = amount, notext=true}) | |||
end | |||
end | |||
return Icons.Icon({ | local function getObstacleIcon(obstacle) | ||
local obs = obstacle.Obstacle | |||
return Icons.getExpansionIcon(obs.id) .. Icons.Icon({obs.name, type='agility'}) | |||
end | end | ||
Line 25: | Line 39: | ||
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 36: | 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 | ||
Line 78: | Line 94: | ||
function p.calculateCourse(obstacleNames, checkDoubleSlots, costReduction) | 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) | Shared.addOrUpdate(tbl, item, function(x) x = x or 0 return x + amount end) | ||
end | end | ||
-- Calculate the highest level requirements and the total amount of items | -- Calculate the highest level requirements and the total amount of items | ||
Line 90: | Line 104: | ||
['Items'] = {} | ['Items'] = {} | ||
} | } | ||
local courseObstacles = getObstacles(obstacleNames, checkDoubleSlots, costReduction) | |||
for _, obstacle in pairs(courseObstacles) do | for _, obstacle in pairs(courseObstacles) do | ||
-- Pool together highest level requirements for the entire course. | -- Pool together highest level requirements for the entire course. | ||
Line 102: | Line 117: | ||
-- Pool together total item costs to build the entire course course. | -- Pool together total item costs to build the entire course course. | ||
local obstacleCosts = obstacle.ItemCosts | 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 | for item, amount in pairs(obstacleCosts['Items']) do | ||
poolItems(courseItemCosts['Items'], item, amount) | |||
end | end | ||
end | end | ||
Line 113: | 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 174: | Line 194: | ||
:wikitext(v.Slot) | :wikitext(v.Slot) | ||
:tag('td') | :tag('td') | ||
:wikitext( | :wikitext(getObstacleIcon(v)) | ||
end | end | ||
Line 186: | Line 206: | ||
local courseItems = courseRequirements.CourseItemCosts | local courseItems = courseRequirements.CourseItemCosts | ||
-- Put | -- 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'], | local itemList = Shared.sortDictionary(courseItems['Items'], | ||
Line 226: | Line 248: | ||
--== Local Functions for formatting Obstacle MetaData ==-- | --== Local Functions for formatting Obstacle MetaData ==-- | ||
local function getBonusses(obstacle) | 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 | ||
end | end | ||
Line 250: | Line 269: | ||
local function getCosts(costsTable) | local function getCosts(costsTable) | ||
local res = {} | local res = {} | ||
-- Order table with GP, SC first, then the other items. | -- 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'], | local sortedCosts = Shared.sortDictionary(costsTable['Items'], | ||
Line 266: | Line 288: | ||
local function getTotalBonuses(obstacles) | local function getTotalBonuses(obstacles) | ||
--[==[ | |||
local bonuses = {} | local bonuses = {} | ||
for _, obstacle in pairs(obstacles) do | for _, obstacle in pairs(obstacles) do | ||
Line 284: | Line 307: | ||
return table.concat(ret, '<br/>') | return table.concat(ret, '<br/>') | ||
--]==] | |||
return '' | |||
end | end | ||
--== Parse optional parameters==-- | --== Parse optional parameters==-- | ||
local showTotals = yesno(args['showtotals'], false) | local showTotals = yesno(args['showtotals'], false) | ||
local showbonus = yesno(args[' | local showbonus = yesno(args['showbonus'], true) | ||
local showrequirements = yesno(args[' | local showrequirements = yesno(args['showrequirements'], true) | ||
local showcosts = yesno(args[' | local showcosts = yesno(args['showcosts'], true) | ||
local obstacleMastery = yesno(args['obstacleMastery'], false) | local obstacleMastery = yesno(args['obstacleMastery'], false) | ||
Line 305: | Line 330: | ||
local tbl = mw.html.create("table") | local tbl = mw.html.create("table") | ||
:addClass("wikitable stickyheader") | :addClass("wikitable stickyheader") | ||
tbl :tag('tr') | local thr = tbl:tag('tr') | ||
thr:tag('th'):wikitext('Slot') | |||
thr:tag('th'):wikitext('Obstacle') | |||
if showbonus then | if showbonus then | ||
thr:tag('th'):wikitext('Bonuses') | |||
end | end | ||
if showrequirements then | if showrequirements then | ||
thr:tag('th'):wikitext('Requirements') | |||
end | end | ||
if showcosts then | if showcosts then | ||
thr:tag('th'):wikitext('Costs') | |||
end | end | ||
Line 325: | Line 350: | ||
:css('text-align', 'right') | :css('text-align', 'right') | ||
:wikitext(obstacle.Slot) | :wikitext(obstacle.Slot) | ||
:tag('td'):wikitext( | :tag('td'):wikitext(getObstacleIcon(obstacle)) | ||
if showbonus then | if showbonus then | ||
Line 344: | Line 369: | ||
:wikitext('Totals') | :wikitext('Totals') | ||
if showbonus then | if showbonus then | ||
tr:wikitext(getTotalBonuses(courseRequirements.Obstacles)) | tr :tag('td') | ||
:wikitext(getTotalBonuses(courseRequirements.Obstacles)) | |||
end | end | ||
if showrequirements then | if showrequirements then | ||
tr:wikitext(getRequirements(courseRequirements.CourseLevelRequirements)) | tr :tag('td') | ||
:wikitext(getRequirements(courseRequirements.CourseLevelRequirements)) | |||
end | end | ||
if showcosts then | if showcosts then | ||
tr:wikitext(getCosts(courseRequirements.CourseItemCosts)) | tr :tag('td') | ||
:wikitext(getCosts(courseRequirements.CourseItemCosts)) | |||
end | end | ||
end | end | ||
Line 357: | Line 385: | ||
end | end | ||
return p | return p |
edits