Anonymous

Module:ModifierTables: Difference between revisions

From Melvor Idle
Attempting to add Points of Interest to Modifier tables
(Further skill ID fixes)
(Attempting to add Points of Interest to Modifier tables)
(10 intermediate revisions by 2 users not shown)
Line 13: Line 13:
local Shop = require('Module:Shop')
local Shop = require('Module:Shop')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Cartography = require('Module:Skills/Cartography')


--First up, functions to get all the things in a category that have a given modifier:
--First up, functions to get all the things in a category that have a given modifier:
Line 197: Line 198:
end
end


function p._getModifierTable(modifiers, skill, columnName, getOpposites, displayOtherMods, maxOtherMods)
function p.getPOIsWithModifier(modifiers, skill, getOpposites)
if type(modifiers) == 'string' then
modifiers = {modifiers}
end
local POIList = Cartography.getPointsOfInterest(
function(POI)
if POI.activeModifiers == nil then
return false
end
for i, mod in ipairs(modifiers) do
if p.getModifierValue(POI.activeModifiers, mod, skill, getOpposites) ~= 0 then
return true
end
end
return false
end)
return POIList
end
 
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 222: Line 244:
elseif Constants.getSkillName(skill) == nil then
elseif Constants.getSkillName(skill) == nil then
-- skill is neither a skill name or ID
-- skill is neither a skill name or ID
return 'ERROR: Failed to find a skill ID for ' .. skill .. '[[Category:Pages with script errors]]'
return Shared.printError('Failed to find a skill ID for "' .. skill .. '"')
end
end
end
end
Line 248: Line 270:
                             includeInMainText = skill == nil or skill == '' or subVal.skillID == skill
                             includeInMainText = skill == nil or skill == '' or subVal.skillID == skill
                         end
                         end
                        subVal = {subVal}
                     end
                     end


Line 278: Line 301:
--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 307: Line 332:
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 324: Line 351:


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 345: Line 375:


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 370: Line 402:
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 387: Line 421:


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 = Shop._getPurchaseName(upgrade)
row.name = Shop._getPurchaseName(upgrade)
row.icon = Icons.Icon({row.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 409: Line 445:
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'
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


local modList = Skills._buildAstrologyModifierArray(cons, {1, 15}, true, true, true, true)
if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
row.modifierText, row.otherModifiers = getModText(modList)
hasOtherModifiers = true
end
 
table.insert(tableArray, row)
end
local POIList = p.getPOIsWithModifier(modifiers, skill, getOpposites)
for i, POI in ipairs(POIList) do
local row = {}
row.name = POI.name
row.icon = Icons.Icon({POI.name, type='poi'})
row.expIcon = Icons.getExpansionIcon(POI.id)
row.type = '[[Cartography|Point of Interest]]'
row.typeText = 'Point of Interest'
local totalVal = 0
for i, mod in ipairs(modifiers) do
totalVal = totalVal + p.getModifierValue(POI.activeModifiers, mod, skill, getOpposites)
end
row.val = totalVal
 
row.modifierText, row.otherModifiers = getModText(POI.activeModifiers)


if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
if not hasOtherModifiers and string.len(row.otherModifiers) > 0 then
Line 433: Line 498:
--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 461: Line 526:
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 478: Line 544:
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