Module:Items/ComparisonTables: Difference between revisions

Added first pass at a getDRTable function
(Added better sorting for rune providing table)
(Added first pass at a getDRTable function)
Line 554: Line 554:
table.insert(resultPart, '\r\n|}')
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
return table.concat(resultPart)
end
function p._getDRTable(slots, items)
local resultPart = {}
table.insert(resultPart, '{| class="wikitable sortable" style="width:90%;"')
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n! style="width:4%"|DR%')
for i, slot in pairs(slots) do
table.insert(resultPart, '\r\n! '..slot)
end
local DRTable = {}
for i, item in pairs(items) do
local DR = Items._getItemStat(item, 'damageReduction', true)
local EquipSlot = Items._getItemEquipSlot(item)
if DRTable[DR] == nil then
DRTable[DR] = {}
end
if DRTable[DR][EquipSlot] == nil then
DRTable[DR][EquipSlot] = {}
end
local itemString = Icons.getExpansionIcon(item.id)..Icons.Icon({item.name, type='item'})
table.insert(DRTable[DR][EquipSlot], itemString)
end
for DR, SlotTables in Shared.skpairs(DRTable) do
table.insert(resultPart, '\r\n|-\r\n|'..DR..'%')
for i, SlotName in pairs(slots) do
table.insert(resultPart, '\r\n|')
if SlotTables[SlotName] ~= nil then
table.sort(SlotTables[SlotName], function(a, b) return a < b end)
table.insert(resultPart, table.concat(SlotTables[SlotName], '<br/>'))
end
end
end
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end
function p.getDRTable(frame)
local style = frame.args ~= nil and frame.args[1] or frame
local SlotNames = {}
local ItemList = {}
if style == 'Other' then
SlotNames = {'Cape', 'Amulet', 'Ring'}
ItemList =  Items.getItems(function(item)
if Items._getItemStat(item, 'damageReduction', true) <= 0 then
return false
end
return Shared.contains(SlotNames, Items._getItemEquipSlot(item))
end)
else
SlotNames = {'Helmet', 'Platebody', 'Platelegs', 'Boots', 'Gloves', 'Shield'}
ItemList =  Items.getItems(function(item)
local isMatch = true
if Items._getItemStat(item, 'damageReduction', true) <= 0 then
return false
end
--Using the same checks for Melee/Ranged/Magic that the Equipment Tables use
if style == 'Melee' then
if ((Items._getItemStat(item, 'defenceLevelRequired') == nil and Items._getItemStat(item, 'attackLevelRequired') == nil) and not Shared.contains(styleOverrides.Melee, item.name)) or Shared.contains(styleOverrides.NotMelee, item.name) then isMatch = false end
elseif style == 'Ranged' then
if (Items._getItemStat(item, 'rangedLevelRequired') == nil and not Shared.contains(styleOverrides.Ranged, item.name)) or Shared.contains(styleOverrides.NotRanged, item.name)  then isMatch = false end
elseif style == 'Magic' then
if (Items._getItemStat(item, 'magicLevelRequired') == nil and not Shared.contains(styleOverrides.Magic, item.name)) or Shared.contains(styleOverrides.NotMagic, item.name) then isMatch = false end
end
if isMatch and not Shared.contains(SlotNames, Items._getItemEquipSlot(item)) then
isMatch = false
end
return isMatch
end)
end
return p._getDRTable(SlotNames, ItemList)
end
end


return p
return p