Anonymous

Module:ModifierTables: Difference between revisions

From Melvor Idle
_getModifierTable: Amend Agility pillar links to use anchors
(_getModifierTable: Remove inline styles for collapsible toggle)
(_getModifierTable: Amend Agility pillar links to use anchors)
(20 intermediate revisions by 2 users not shown)
Line 8: Line 8:
local Pets = require('Module:Pets')
local Pets = require('Module:Pets')
local Items = require('Module:Items')
local Items = require('Module:Items')
local GatheringSkills = require('Module:Skills/Gathering')
local Skills = require('Module:Skills')
local Agility = require('Module:Skills/Agility')
local Agility = require('Module:Skills/Agility')
local Prayer = require('Module:Prayer')
local Prayer = require('Module:Prayer')
Line 22: Line 22:


--Make sure we have the skillID and not the name
--Make sure we have the skillID and not the name
if skill == '' then
if skill ~= nil then
skill = nil
if skill == '' then
elseif type(skill) == 'string' then
skill = nil
skill = Constants.getSkillID(skill)
elseif Constants.getSkillID(skill) ~= nil then
-- skill is a skill name
skill = Constants.getSkillID(skill)
elseif Constants.getSkillName(skill) == nil then
-- skill is neither a skill name or ID
return 0
end
end
end


--By default, attempt to add the increased and decreased prefixes to the modifier
--By default, attempt to add the increased and decreased prefixes to the modifier
--But if getOpposites is false, only look for an exact match
--But if getOpposites is false, only look for an exact match
local increaseMod, decreaseMod = '', ''
local mods = {}
if getOpposites == nil or getOpposites then
if getOpposites == nil or getOpposites then
increaseMod = 'increased'..modifier
mods.inc = 'increased'..modifier
decreaseMod = 'decreased'..modifier
mods.dec = 'decreased'..modifier
else
else
increaseMod = modifier
mods.inc = modifier
end
end
local magnitude = { inc = 0, dec = 0 }
for modType, modName in pairs(mods) do
if modifiers[modName] ~= nil then
local valueArray = nil
            if type(modifiers[modName]) ~= 'table' then
                valueArray = {modifiers[modName]}
            else
                valueArray = modifiers[modName]
            end


local increaseVal, decreaseVal = 0, 0
            for i, subVal in ipairs(valueArray) do
if modifiers[increaseMod] ~= nil and modifiers[increaseMod] ~= nil then
                if type(subVal) == 'table' then
if type(modifiers[increaseMod]) == 'table' then
if  subVal.skillID ~= nil then
for i, subVal in Shared.skpairs(modifiers[increaseMod]) do
-- Modifier value is skill specific
if subVal[1] == skill then
if skill == nil or skill == '' or subVal.skillID == skill then
increaseVal = subVal[2]
magnitude[modType] = magnitude[modType] + subVal.value
elseif skill == nil or skill == '' then
end
increaseVal = increaseVal + subVal[2]
else
end
-- Modifier value is a table of two numbers representing a range. Take the largest value
end
magnitude[modType] = magnitude[modType] + (subVal[2] or 0)
else
end
increaseVal = modifiers[increaseMod]
                else
end
                    magnitude[modType] = magnitude[modType] + subVal
end
                end
 
            end
if modifiers[decreaseMod] ~= nil and modifiers[decreaseMod] ~= nil then
if type(modifiers[decreaseMod]) == 'table' then
for i, subVal in Shared.skpairs(modifiers[decreaseMod]) do
if subVal[1] == skill then
decreaseVal = subVal[2]
elseif skill == nil or skill == '' then
decreaseVal = decreaseVal + subVal[2]
end
end
else
decreaseVal = modifiers[decreaseMod]
end
end
end
end


return increaseVal - decreaseVal
    return magnitude.inc - magnitude.dec
end
end


Line 77: Line 83:
function(item)
function(item)
if item.golbinRaidExclusive ~= nil and item.golbinRaidExclusive then
if item.golbinRaidExclusive ~= nil and item.golbinRaidExclusive then
return false
elseif item.modifiers == nil or Shared.tableIsEmpty(item.modifiers) then
return false
return false
end
end
for i, mod in Shared.skpairs(modifiers) do
for i, mod in ipairs(modifiers) do
if p.getModifierValue(item.modifiers, mod, skill, getOpposites) ~= 0 then
if p.getModifierValue(item.modifiers, mod, skill, getOpposites) ~= 0 then
return true
return true
Line 95: Line 103:
local obstList = Agility.getObstacles(
local obstList = Agility.getObstacles(
function(obst)
function(obst)
for i, mod in Shared.skpairs(modifiers) do
for i, mod in ipairs(modifiers) do
if p.getModifierValue(obst.modifiers, mod, skill, getOpposites) ~= 0 then
if p.getModifierValue(obst.modifiers, mod, skill, getOpposites) ~= 0 then
return true
return true
Line 109: Line 117:
modifiers = {modifiers}
modifiers = {modifiers}
end
end
local consList = GatheringSkills.getConstellations(
local consList = Skills.getConstellations(
function(cons)
function(cons)
local consMods = GatheringSkills._buildAstrologyModifierArray(cons, 1, true, true, true, true)
local consMods = Skills._buildAstrologyModifierArray(cons, 1, true, true, true, true)
for i, modifier in ipairs(modifiers) do
for i, modifier in ipairs(modifiers) do
if p.getModifierValue(consMods, modifier, skill, getOpposites) ~= 0 then
if p.getModifierValue(consMods, modifier, skill, getOpposites) ~= 0 then
Line 128: Line 136:
local pillarList = Agility.getPillars(
local pillarList = Agility.getPillars(
function(pillar)
function(pillar)
for i, mod in Shared.skpairs(modifiers) do
for i, mod in ipairs(modifiers) do
if p.getModifierValue(pillar.modifiers, mod, skill, getOpposites) ~= 0 then
if p.getModifierValue(pillar.modifiers, mod, skill, getOpposites) ~= 0 then
return true
return true
Line 144: Line 152:
local petList = Pets.getPets(
local petList = Pets.getPets(
function(pet)
function(pet)
for i, mod in Shared.skpairs(modifiers) do
for i, mod in ipairs(modifiers) do
if p.getModifierValue(pet.modifiers, mod, skill, getOpposites) ~= 0 then
if p.getModifierValue(pet.modifiers, mod, skill, getOpposites) ~= 0 then
return true
return true
Line 175: Line 183:
end
end
local upgradeList = Shop.getPurchases(
local upgradeList = Shop.getPurchases(
function(category, purchase)
function(purchase)
if category == 'GolbinRaid' then
if purchase.category == 'melvorD:GolbinRaid' then
return false
return false
end
end
for i, mod in Shared.skpairs(modifiers) do
for i, mod in ipairs(modifiers) do
if p.getModifierValue(purchase.contains.modifiers, mod, skill, getOpposites) ~= 0 then
if p.getModifierValue(purchase.contains.modifiers, mod, skill, getOpposites) ~= 0 then
return true
return true
Line 189: Line 197:
end
end


function p._getModifierTable(modifiers, skill, columnName, getOpposites, displayOtherMods, maxOtherMods)
function p._getModifierTable(modifiers, skill, columnName, getOpposites, displayOtherMods, maxOtherMods, forceMagnitudeSort)
local modifierNames = {}
local modifierNames = {}
if type(modifiers) == 'string' then
if type(modifiers) == 'string' then
Line 206: Line 214:
local modifierCount = Shared.tableCount(modifiers)
local modifierCount = Shared.tableCount(modifiers)


if skill == '' then
if skill ~= nil then
skill = nil
if skill == '' then
elseif type(skill) == 'string' then
skill = nil
skill = Constants.getSkillID(skill)
elseif Constants.getSkillID(skill) ~= nil then
-- skill is a skill name
skill = Constants.getSkillID(skill)
elseif Constants.getSkillName(skill) == nil then
-- skill is neither a skill name or ID
return Shared.printError('Failed to find a skill ID for "' .. skill .. '"')
end
end
end


Line 218: Line 232:
local mainModText = {}
local mainModText = {}
for modName, modValue in Shared.skpairs(modifiers) do
for modName, modValue in Shared.skpairs(modifiers) do
if Shared.contains(modifierNames, modName) then
                local includedMod = Shared.contains(modifierNames, modName)
if type(modValue) == 'table' and type(modValue[1]) == 'table' then
                local valueArray = nil
for j, subVal in ipairs(modValue) do
                if type(modValue) ~= 'table' then
if subVal[1] == skill or skill == nil or skill == '' then
                    valueArray = {modValue}
table.insert(mainModText, Constants._getModifierText(modName, subVal))
                else
else
                    valueArray = modValue
otherModCount = otherModCount + 1
                end
local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow'
 
table.insert(modTextArray[key], Constants._getModifierText(modName, subVal))
                for j, subVal in ipairs(valueArray) do
end
                    local includeInMainText = includedMod
end
                    if type(subVal) == 'table' and subVal.skillID ~= nil then
else
                        -- Modifier value is skill specific
table.insert(mainModText, Constants._getModifierText(modName, modValue))
                        if includeInMainText then
end
                            -- If the skill doesn't match then don't include in the main text
else
                            includeInMainText = skill == nil or skill == '' or subVal.skillID == skill
modValue = (type(modValue) == 'table' and type(modValue[1]) == 'table' and modValue or {modValue})
                        end
for j, subValue in ipairs(modValue) do
                        subVal = {subVal}
otherModCount = otherModCount + 1
                    end
local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow'
 
table.insert(modTextArray[key], Constants._getModifierText(modName, subValue))
                    if includeInMainText then
end
                        table.insert(mainModText, Constants._getModifierText(modName, subVal))
end
                    else
end
                        otherModCount = otherModCount + 1
                        local key = ((maxOtherMods == nil or otherModCount <= maxOtherMods) and 'visible') or 'overflow'
                        table.insert(modTextArray[key], Constants._getModifierText(modName, subVal))
                    end
                end
            end


local overflowModCount = Shared.tableCount(modTextArray['overflow'])
local overflowModCount = Shared.tableCount(modTextArray['overflow'])
Line 260: Line 279:
--Going through each type of thing to add to the array
--Going through each type of thing to add to the array
local itemList = p.getItemsWithModifier(modifiers, skill, getOpposites)
local itemList = p.getItemsWithModifier(modifiers, skill, getOpposites)
for i, item in Shared.skpairs(itemList) do
for i, item in ipairs(itemList) do
local row = {}
local row = {}
row.name = item.name
row.name = item.name
row.icon = Icons.Icon({item.name, type='item'})
row.icon = Icons.Icon({item.name, type='item'})
row.expIcon = Icons.getExpansionIcon(item.id)
row.type = 'Item'
row.type = 'Item'
--For equipment, show the slot they go in
--For equipment, show the slot they go in
if item.validSlots ~= nil then
if item.validSlots ~= nil then
row.type = row.type..' ('..table.concat(item.validSlots, ', ')..')'
row.type = row.type..' ('..table.concat(Shared.clone(item.validSlots), ', ')..')'
end
end
row.typeText = row.type
local totalVal = 0
local totalVal = 0
for i, mod in pairs(modifiers) do
for i, mod in pairs(modifiers) do
Line 289: Line 310:
row.name = pet.name
row.name = pet.name
row.icon = Icons.Icon({pet.name, type='pet'})
row.icon = Icons.Icon({pet.name, type='pet'})
row.expIcon = Icons.getExpansionIcon(pet.id)
row.type = '[[Pets|Pet]]'
row.type = '[[Pets|Pet]]'
row.typeText = 'Pet'
local totalVal = 0
local totalVal = 0
for i, mod in pairs(modifiers) do
for i, mod in pairs(modifiers) do
Line 306: Line 329:


local obstList = p.getObstaclesWithModifier(modifiers, skill, getOpposites)
local obstList = p.getObstaclesWithModifier(modifiers, skill, getOpposites)
table.sort(obstList, function(a, b) return a.category < b.category end)
for i, obst in Shared.skpairs(obstList) do
for i, obst in Shared.skpairs(obstList) do
local row = {}
local row = {}
row.name = obst.name
row.name = obst.name
row.icon = Icons.Icon({'Agility', obst.name, type='skill'})
row.icon = Icons.Icon({'Agility%23'..string.gsub(obst.name, ' ', ''), obst.name, type='skill', img='Agility'})
row.expIcon = Icons.getExpansionIcon(obst.id)
row.type = '[[Agility#Obstacles|Agility Obstacle '..tostring(tonumber(obst.category)+1)..']]'
row.type = '[[Agility#Obstacles|Agility Obstacle '..tostring(tonumber(obst.category)+1)..']]'
row.typeText = 'Agility Obstacle '..string.format("%02d", (obst.category + 1))
local totalVal = 0
local totalVal = 0
for i, mod in pairs(modifiers) do
for i, mod in pairs(modifiers) do
Line 327: Line 353:


local pillarList = p.getPillarsWithModifier(modifiers, skill, getOpposites)
local pillarList = p.getPillarsWithModifier(modifiers, skill, getOpposites)
for i, pillar in Shared.skpairs(pillarList) do
for i, pillar in ipairs(pillarList) do
local row = {}
local row = {}
row.name = pillar.name
row.name = pillar.name
row.icon = Icons.Icon({'Agility', pillar.name, type='skill'})
row.icon = Icons.Icon({'Agility%23'..string.gsub(pillar.name, ' ', ''), pillar.name, type='skill', img='Agility'})
row.expIcon = Icons.getExpansionIcon(pillar.id)
row.type = '[[Agility#Passive Pillars|Agility Pillar]]'
row.type = '[[Agility#Passive Pillars|Agility Pillar]]'
row.typeText = 'Agility Pillar'
local totalVal = 0
local totalVal = 0
for i, mod in pairs(modifiers) do
for i, mod in pairs(modifiers) do
Line 352: Line 380:
row.name = prayer.name
row.name = prayer.name
row.icon = Icons.Icon({prayer.name, type='prayer'})
row.icon = Icons.Icon({prayer.name, type='prayer'})
row.expIcon = Icons.getExpansionIcon(prayer.id)
row.type = [[Prayer]]
row.type = [[Prayer]]
row.typeText = 'Prayer'
local totalVal = 0
local totalVal = 0
for i, mod in ipairs(modifiers) do
for i, mod in ipairs(modifiers) do
Line 369: Line 399:


local upgradeList = p.getUpgradesWithModifier(modifiers, skill, getOpposites)
local upgradeList = p.getUpgradesWithModifier(modifiers, skill, getOpposites)
for i, upgrade in Shared.skpairs(upgradeList) do
for i, upgrade in ipairs(upgradeList) do
local row = {}
local row = {}
row.name = upgrade.name
row.name = Shop._getPurchaseName(upgrade)
row.icon = Icons.Icon({upgrade.name, type='upgrade'})
row.icon = Icons.Icon({row.name, type='upgrade'})
row.expIcon = Icons.getExpansionIcon(upgrade.id)
row.type = '[[Shop|Upgrade]]'
row.type = '[[Shop|Upgrade]]'
row.typeText = 'Upgrade'
local totalVal = 0
local totalVal = 0
for i, mod in pairs(modifiers) do
for i, mod in pairs(modifiers) do
Line 391: Line 423:
local constellationList = p.getConstellationsWithModifier(modifiers, skill, getOpposites)
local constellationList = p.getConstellationsWithModifier(modifiers, skill, getOpposites)
for i, cons in ipairs(constellationList) do
for i, cons in ipairs(constellationList) do
local modList = Skills._buildAstrologyModifierArray(cons, nil, true, true, true, true)
local row = {}
local row = {}
row.name = cons.name
row.name = cons.name
row.icon = Icons.Icon({cons.name, type='constellation'})
row.icon = Icons.Icon({cons.name, type='constellation'})
row.expIcon = Icons.getExpansionIcon(cons.id)
row.type = '[[Astrology#Constellations|Constellation]]'
row.type = '[[Astrology#Constellations|Constellation]]'
row.val = 15 -- Assume highest possible, the range is 1 to 15 inclusive
row.typeText = 'Constellation'
 
local modList = GatheringSkills._buildAstrologyModifierArray(cons, {1, 15}, true, true, true, true)
row.modifierText, row.otherModifiers = getModText(modList)
row.modifierText, row.otherModifiers = getModText(modList)
local totalVal = 0
for i, mod in pairs(modifiers) do
totalVal = totalVal + p.getModifierValue(modList, mod, skill, getOpposites)
end
row.val = totalVal


if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
Line 415: Line 453:
--Otherwise sort alphabetically by type, then name
--Otherwise sort alphabetically by type, then name
table.sort(tableArray, function(a, b)
table.sort(tableArray, function(a, b)
if modifierCount == 1 and a.val ~= b.val then
if (modifierCount == 1 or forceMagnitudeSort) and a.val ~= b.val then
return a.val > b.val
return a.val > b.val
elseif a.type ~= b.type then
elseif a.typeText ~= b.typeText then
return a.type < b.type
return a.typeText < b.typeText
else
else
return a.name < b.name
return a.name < b.name
end
end
end)
end)
for i, row in Shared.skpairs(tableArray) do
for i, row in ipairs(tableArray) do
result = result..'\r\n|-'
result = result..'\r\n|-'
result = result..'\r\n|data-sort-value="'..row.name..'"|'..row.icon
result = result..'\r\n|data-sort-value="'..row.name..'"|'..row.icon
result = result..'||'..row.type..'||data-sort-value="'..row.val..'"|'..row.modifierText
result = result..'|| data-sort-value="'..row.typeText..'" | '..row.expIcon..row.type..'||data-sort-value="'..row.val..'"| '..row.modifierText
if hasOtherModifiers and displayOtherMods then
if hasOtherModifiers and displayOtherMods then
result = result..'||'..row.otherModifiers
result = result..'|| '..row.otherModifiers
end
end
end
end
Line 443: Line 481:
local displayOtherMods = frame.args ~= nil and frame.args.displayOtherMods or frame.displayOtherMods
local displayOtherMods = frame.args ~= nil and frame.args.displayOtherMods or frame.displayOtherMods
local maxOtherMods = frame.args ~= nil and tonumber(frame.args.maxOtherMods) or 5
local maxOtherMods = frame.args ~= nil and tonumber(frame.args.maxOtherMods) or 5
local forceMagnitudeSort = frame.args ~= nil and string.upper(tostring(frame.args.forceMagnitudeSort)) == 'TRUE' or false


if Shared.contains(modifier, ',') then
if Shared.contains(modifier, ',') then
Line 460: Line 499:
end
end


return p._getModifierTable(modifier, skill, columnName, getOpposites, displayOtherMods, maxOtherMods)
return p._getModifierTable(modifier, skill, columnName, getOpposites, displayOtherMods, maxOtherMods, forceMagnitudeSort)
end
 
--Function for console testing of modifier tables
function p.getModifierTableTest()
return p.getModifierTable({args = {'MeleeMaxHit', 'GP Boosts'}})
end
end


return p
return p