Anonymous

Module:Calculator/AgilityObstacle: Difference between revisions

From Melvor Idle
m
Fix derp again
No edit summary
m (Fix derp again)
(11 intermediate revisions by 2 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 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 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


Line 26: Line 35:
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 148: Line 157:
function p._getCourseList(args)
function p._getCourseList(args)
-- Parse optional parameters
-- Parse optional parameters
local costReduction = {
local costReduction = {
['GP']  = args['gpCostReduction'] or 0,
['GP']  = Num.toNumberOrDefault(args['gpCostReduction'], 0),
['SC']  = args['scCostReduction'] or 0,
['SC']  = Num.toNumberOrDefault(args['scCostReduction'], 0),
['Item'] = args['itemCostReduction'] or 0,
['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
}
}
Line 176: Line 184:
:wikitext(v.Slot)
:wikitext(v.Slot)
:tag('td')
:tag('td')
:wikitext(Icons.Icon({v.Name, type='agility'}))
:wikitext(getObstacleIcon(v))
end
end
Line 228: Line 236:
--== Local Functions for formatting Obstacle MetaData ==--
--== Local Functions for formatting Obstacle MetaData ==--
local function getBonusses(obstacle)
local function getBonusses(obstacle)
local bonuses = {}
if obstacle.modifiers == nil then
for bonusName, bonusValue in pairs(obstacle.modifiers) do
return '<span style="color:red">None :(</span>'
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
else
return Modifiers.getModifiersText(obstacle.modifiers, true, false, 10)
end
end
if Shared.tableIsEmpty(bonuses) then
table.insert(bonuses, '<span style="color:red">None :(</span>')
end
return table.concat(bonuses, '<br/>')
end
end
Line 268: Line 273:
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 286: Line 292:
return table.concat(ret, '<br/>')
return table.concat(ret, '<br/>')
--]==]
return ''
end
end


--== Parse optional parameters==--
--== Parse optional parameters==--
local showTotals = yesno(args['showtotals'], true)
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 obstacleMastery = yesno(args['obstacleMastery'], false)
 
local costReduction = {
local costReduction = {
['GP']  = args['gpCostReduction'] or 0,
['GP']  = Num.toNumberOrDefault(args['gpCostReduction'], 0),
['SC']  = args['scCostReduction'] or 0,
['SC']  = Num.toNumberOrDefault(args['scCostReduction'], 0),
['Item'] = args['itemCostReduction'] or 0,
['Item'] = Num.toNumberOrDefault(args['itemCostReduction'], 0),
}
}
Line 303: Line 314:
--== Start of table formatting ==--
--== Start of table formatting ==--
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')
:tag('th'):wikitext('Slot')
    thr:tag('th'):wikitext('Slot')
:tag('th'):wikitext('Obstacle')
thr:tag('th'):wikitext('Obstacle')
:tag('th'):wikitext('Bonuses')
:tag('th'):wikitext('Requirements')
if showbonus then
:tag('th'):wikitext('Costs')
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
for _, obstacle in pairs(courseRequirements.Obstacles) do
tbl :tag('tr')
local tr = tbl:tag('tr')
:tag('td')
tr  :tag('td')
:css('text-align', 'right')
:css('text-align', 'right')
:wikitext(obstacle.Slot)
:wikitext(obstacle.Slot)
:tag('td'):wikitext(Icons.Icon({obstacle.Name, type='agility'}))
:tag('td'):wikitext(getObstacleIcon(obstacle))
:tag('td'):wikitext(getBonusses(obstacle.Obstacle))
:tag('td'):wikitext(getRequirements(obstacle.LevelRequirements))
if showbonus then
:tag('td'):wikitext(getCosts(obstacle.ItemCosts))
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
end
if showTotals == true then
if showTotals == true then
tbl :tag('tr')
local tr = tbl:tag('tr')
:tag('th')
tr  :tag('th')
:attr('colspan', 2)
:attr('colspan', 2)
:wikitext('Totals')
:wikitext('Totals')
:tag('td')
if showbonus then
:wikitext(getTotalBonuses(courseRequirements.Obstacles))
tr  :tag('td')
:tag('td')
:wikitext(getTotalBonuses(courseRequirements.Obstacles))
:wikitext(getRequirements(courseRequirements.CourseLevelRequirements))
end
:tag('td')
if showrequirements then
:wikitext(getCosts(courseRequirements.CourseItemCosts))
tr  :tag('td')
:wikitext(getRequirements(courseRequirements.CourseLevelRequirements))
end
if showcosts then
tr  :tag('td')
:wikitext(getCosts(courseRequirements.CourseItemCosts))
end
end
end


Line 340: Line 371:


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.calculateCourse(obstacles)
--local obs = p.calculateCourse(obstacles)
 
mw.logObject(getObstacle('rope trap'))
 
Debug.log(obs.CourseItemCosts)
end
end
return p
return p
2,875

edits