Module:Items/ComparisonTables: Difference between revisions

From Melvor Idle
m (Fix for Bob's Rake)
(Add two-handed indicator column for weapon tables)
 
(91 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local MonsterData = mw.loadData('Module:Monsters/data')
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Magic = require('Module:Magic')
local GameData = require('Module:GameData')
local Areas = require('Module:CombatAreas')
local Common = require('Module:Common')
local Modifiers = require('Module:Modifiers')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Items = require('Module:Items')
local ItemSourceTables = require('Module:Items/SourceTables')
local Num = require('Module:Number')
local ItemUseTables = require('Module:Items/UseTables')
local FL = require('Module:FunList')


local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'}
local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'}


local styleOverrides = {
local styleOverrides = {
  Melee = {'Slayer Helmet (Basic)', 'Slayer Platebody (Basic)', 'Paladin Gloves', 'Desert Wrappings', 'Almighty Lute', 'Candy Cane', 'Bob's Rake'},
Melee = {'Slayer Helmet (Basic)', 'Slayer Platebody (Basic)', 'Paladin Gloves', 'Desert Wrappings', 'Almighty Lute', 'Candy Cane', "Bob's Rake", "Knight's Defender", "Ward of Flame Platebody"},
  Ranged = {'Slayer Cowl (Basic)', 'Slayer Leather Body (Basic)'},
Ranged = {'Slayer Cowl (Basic)', 'Slayer Leather Body (Basic)', 'Ice Arrows'},
  Magic = {'Slayer Wizard Hat (Basic)', 'Slayer Wizard Robes (Basic)', 'Enchanted Shield', 'Elementalist Gloves'},
Magic = {'Slayer Wizard Hat (Basic)', 'Slayer Wizard Robes (Basic)', 'Enchanted Shield', 'Elementalist Gloves', 'Frostspark Boots', 'Freezing Touch Body', 'Lightning Boots'},
  None = {},
None = {},
NotMelee = {'Frostspark Boots', 'Freezing Touch Body', 'Lightning Boots'},
NotRanged = {},
NotMagic = {'Torrential Blast Crossbow', 'Spectral Ice Sword', 'Lightning Strike 1H Sword', 'FrostSpark 1H Sword'}
}
 
local slotOverrides = {
['Enhancement'] = 'melvorD:Enhancement'
}
}


function p._getEquipmentTable(itemList, includeModifiers, includeDescription)
local itemStyleOverrides = {
  if includeModifiers == nil then includeModifiers = false end
['Melee'] = {
'melvorF:Slayer_Helmet_Basic',
'melvorF:Slayer_Platebody_Basic',
'melvorF:Paladin_Gloves',
'melvorF:Desert_Wrappings',
'melvorF:Knights_Defender',
},
['Ranged'] = {
'melvorF:Slayer_Cowl_Basic',
'melvorF:Slayer_Leather_Body_Basic',
'melvorD:Cape_Of_Prat',
'melvorD:Ice_Arrows',
},
['Magic'] = {
'melvorF:Slayer_Wizard_Hat_Basic',
'melvorF:Slayer_Wizard_Robes_Basic',
'melvorF:Skull_Cape',
'melvorD:Enchanted_Shield',
'melvorF:Elementalist_Gloves',
'melvorTotH:Freezing_Touch_Body',
'melvorTotH:Lightning_Boots',
},
['Other'] = {
 
}
}


  --Getting some lists set up here that will be used later
-- Categorise equipment by:
  --First, the list of columns used by both weapons & armour
-- - Equipment slot ID
  local statColumns = {'stabAttackBonus', 'slashAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'strengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'defenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus', 'damageReduction', 'attackLevelRequired', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}
-- - Style (Melee, Ranged, Magic, Other)
p.SlotEquipment = {}


  if(Shared.tableCount(itemList) == 0) then
function p.populateSlotEquipment()
    return 'ERROR: you must select at least one item to get stats for'
-- Populate from item data
  end
local hiddenItems = {}
for _, itemID in ipairs(Items.HiddenItems) do
hiddenItems[itemID] = true
end


  local isWeaponType = Shared.contains(weaponTypes, itemList[1].type)
-- Transform style overrides into a form where items are indexed by ID
local styleOverrides = {}
for overType, itemIDs in pairs(itemStyleOverrides) do
for _, itemID in ipairs(itemIDs) do
styleOverrides[itemID] = overType
end
end


  --Now that we have a preliminary list, let's figure out which columns are irrelevant (IE are zero for all items in the selection)
for _, item in ipairs(GameData.rawData.items) do
  local ignoreColumns = Shared.clone(statColumns)
if (
  for i, item in pairs(itemList) do
-- Item is not hidden (includes debug items)
    local ndx = 1
hiddenItems[item.id] == nil
    while Shared.tableCount(ignoreColumns) >= ndx do
-- Item isn't exclusive to Golbin Raid minigame
      if Items._getItemStat(item, ignoreColumns[ndx], true) ~= 0 then
and (item.golbinRaidExclusive == nil or not item.golbinRaidExclusive)
        table.remove(ignoreColumns, ndx)
-- Item can be equipped to any slot
      else
and item.validSlots ~= nil
        ndx = ndx + 1
) then
      end
-- Item is equippment to be included within equipment tables
    end
local equipEntry = {
  end
['item'] = item,
['slots'] = {},
['isWeapon'] = nil,
['style'] = nil
}
-- Determine which slots the equipment can be equipped to
local occupiesSlots = item.occupiesSlots or {}
for _, slotLocalID in ipairs(item.validSlots) do
local newSlotID = slotLocalID
-- Classify javelins and throwing knives as weapons
if slotLocalID == 'Quiver' and Shared.contains({'Javelins', 'ThrowingKnives'}, item.ammoType) then
newSlotID = 'Weapon'
-- Combine all enhancements
elseif Shared.contains({'Enhancement1', 'Enhancement2', 'Enhancement3'}, slotLocalID) then
newSlotID = 'Enhancement'
end
equipEntry.slots[newSlotID] = true
end
equipEntry.isWeapon = equipEntry.slots['Weapon'] or Shared.contains(occupiesSlots, 'Weapon')
 
-- Determine the style of the item (Melee, Ranged, Magic, Other)
local function hasSkillReq(reqs, localSkillID)
if reqs ~= nil then
local skillID = Shared.getNamespacedID('melvorD', localSkillID)
for levelType, typeReqs in pairs(reqs) do
if typeReqs[skillID] ~= nil then
return true
end
end
end
return false
end
local levelReqs = Items._getItemLevelReqs(item)
-- Apply any overrides first
if styleOverrides[item.id] ~= nil then
equipEntry.style = styleOverrides[item.id]
-- Weapon styles can be checked using the attackType property
elseif equipEntry.isWeapon and Shared.contains({'melee', 'ranged', 'magic'}, item.attackType) then
equipEntry.style = Shared.titleCase(item.attackType)
-- Magic
elseif hasSkillReq(levelReqs, 'Magic') then
equipEntry.style = 'Magic'
-- Ranged
elseif (
hasSkillReq(levelReqs, 'Ranged')
or equipEntry.slots.Quiver ~= nil
or item.ammoType ~= nil
) then
equipEntry.style = 'Ranged'
-- Melee
elseif (
hasSkillReq(levelReqs, 'Attack')
or hasSkillReq(levelReqs, 'Defence')
) then
equipEntry.style = 'Melee'
-- Other, default style if unmatched
else
equipEntry.style = 'Other'
end
-- Finally, add the entry into the slotEquipment table
table.insert(p.SlotEquipment, equipEntry)
end
end
end
 
p.populateSlotEquipment()
 
local function getEquipItemList(filter)
local equip = GameData.getEntities(p.SlotEquipment, function(x) return filter(x) end)
local items = {}
for _, entry in ipairs(equip) do
table.insert(items, entry.item)
end
return items
end
 
local function getSlotID(slot)
local slotID = Shared.getNamespacedID('melvorD', slot)
local slotData = GameData.getEntityByID('equipmentSlots', slotID)
 
if slotData == nil then
if slotOverrides[slot] ~= nil then
return slotOverrides[slot]
end


  --Now to remove the ignored columns (and also we need to track groups like defence bonuses to see how many remain)
-- slotID invalid, check if user provided a slot name
  local attBonusCols = 5
slotData = GameData.getEntityByProperty('equipmentSlots', 'emptyName', slot)
  local strBonusCols = 2
if slotData == nil then
  local defBonusCols = 3
return nil
  local lvlReqCols = 4
end
  local ndx = 1
slotID = slotData.id
  while Shared.tableCount(statColumns) >= ndx do
end
    local colName = statColumns[ndx]
return slotID
    if Shared.contains(ignoreColumns, colName) then
end
      if Shared.contains(colName, 'AttackBonus') then attBonusCols = attBonusCols - 1 end
      if Shared.contains(colName, 'trengthBonus') then strBonusCols = strBonusCols - 1 end
      if Shared.contains(colName, 'efenceBonus') then defBonusCols = defBonusCols - 1 end
      if Shared.contains(colName, 'LevelRequired') then lvlReqCols = lvlReqCols - 1 end
      table.remove(statColumns, ndx)
    else
      ndx = ndx + 1
    end
  end
 
  --Alright, let's start the table by building the shared header
  local result = '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"'
  if isWeaponType then
    --Weapons have extra columns here for Attack Speed and "Two Handed?"
    result = result..'\r\n!colspan="4"|'
  else
    result = result..'\r\n!colspan="2"|'
  end
  if attBonusCols > 0 then
    result = result..'\r\n!colspan="'..attBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Attack Bonus'
  end
  if strBonusCols > 0 then
    result = result..'\r\n!colspan="'..strBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Str. Bonus'
  end
  if Shared.contains(statColumns, 'magicDamageBonus') then
    result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|% Dmg Bonus'
  end
  if defBonusCols > 0 then
    result = result..'\r\n!colspan="'..defBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Defence Bonus'
  end
  if Shared.contains(statColumns, 'damageReduction') then
    result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|DR'
  end
  if lvlReqCols > 0 then
    result = result..'\r\n!colspan="'..lvlReqCols..'"style="padding:0 0.5em 0 0.5em;"|Lvl Req'
  end
  if includeModifiers and includeDescription then
    result = result..'\r\n!colspan="3"|'
  elseif includeModifiers or includeDescription then
    result = result..'\r\n!colspan="2"|'
  else
    result = result..'\r\n!colspan="1"|'
  end
  --One header row down, one to go
  result = result..'\r\n|-class="headerRow-1"'
  result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Item'
  result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Name'
  --Weapons have Attack Speed here
  if isWeaponType then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Attack Speed'
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Two Handed?'
  end
  --Attack bonuses
  if Shared.contains(statColumns, 'slashAttackBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'stabAttackBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'blockAttackBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'rangedAttackBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'magicAttackBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
  end
  --Strength bonuses
  if Shared.contains(statColumns, 'strengthBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'rangedStrengthBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'magicDamageBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
  end
  --Defence bonuses
  if Shared.contains(statColumns, 'defenceBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'rangedDefenceBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'magicDefenceBonus') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'damageReduction') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
  end
  --Level requirements
  if Shared.contains(statColumns, 'attackLevelRequired') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'defenceLevelRequired') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'rangedLevelRequired') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
  end
  if Shared.contains(statColumns, 'magicLevelRequired') then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
  end
  --If includeModifiers is set to 'true', add the Modifiers column
  if includeModifiers then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Modifiers'
  end
  --If includeDescription is set to 'true', add the Description column
  if includeDescription then
    result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Description'
  end


  --And finally Sources
local function getItemDesc(item)
  result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Sources'
if item.customDescription ~= nil then
return item.customDescription
elseif item.modifiers ~= nil then
return Modifiers.getModifiersText(item.modifiers, false, false)
else
return ''
end
end


  table.sort(itemList, function(a, b) return a.id < b.id end)
local function getItems(slotID, style)
  for i, item in pairs(itemList) do
local _, slotLocalID = Shared.getLocalID(slotID)
    if isWeaponType then
      --Building rows for weapons
      result = result..'\r\n|-'
      result = result..'\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
      result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
      result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(item.attackSpeed)
      --That's the first list out of the way, now for 2-Handed
      result = result..'\r\n| style ="text-align: right;"|'
      if item.isTwoHanded then result = result..'Yes' else result = result..'No' end
      for j, statName in pairs(statColumns) do
        local statValue = Items._getItemStat(item, statName, true)
        result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
        if not Shared.contains(statName, 'LevelRequired') then
          if statValue > 0 then
            result = result..'background-color:lightgreen;'
          elseif statValue < 0 then
            result = result..'background-color:lightpink;'
          end
        end
        result = result..'"|'..Shared.formatnum(statValue)
        if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
      end
      --If requested, add the item Modifiers
      if includeModifiers then
        result = result..'\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|'
        result = result..Constants.getModifiersText(item.modifiers, true)
      end
      --If requested, add description
      if includeDescription then
        result = result..'\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|'
        result = result..(item.description ~= nil and item.description or '')
      end
      --Finally, the Sources
      result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |'
      result = result..ItemSourceTables._getItemSources(item)
    else
      --Building rows for armour
      result = result..'\r\n|-'
      result = result..'\r\n|style ="text-align: left;padding: 0 0 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
      result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
      for j, statName in pairs(statColumns) do
        local statValue = Items._getItemStat(item, statName, true)
        result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
        if statValue > 0 then
          result = result..'background-color:lightgreen;'
        elseif statValue < 0 then
          result = result..'background-color:lightpink;'
        end
        result = result..'"|'..Shared.formatnum(statValue)
        if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
      end
      --If requested, add the item Modifiers
      if includeModifiers then
        result = result..'\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|'
        result = result..Constants.getModifiersText(item.modifiers, true)
      end
      --If requested, add description
      if includeDescription then
        result = result..'\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|'
        result = result..(item.description ~= nil and item.description or '')
      end
      --Finally, the Sources
      result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |'
      result = result..ItemSourceTables._getItemSources(item)
    end
  end


  result = result..'\r\n|}'
return getEquipItemList(
  return result
function(entry)
return (
entry.slots[slotLocalID] ~= nil
and (style == nil or style == '' or style == entry.style)
)
end
)
end
end


function p.getEquipmentTable(frame)
--== Helper Functions for getCategoryTable ==--
  local args = frame.args ~= nil and frame.args or frame
local function createStatCell(row, statVal)
  local type = args.type
local cell = row:tag('td')
  local tier = args.tier
if statVal > 0 then
  local slotStr = args.slot
cell:addClass('table-positive')
  local ammoTypeStr = args.ammoType
elseif statVal < 0 then
  local category = args.category ~= nil and args.category or 'Combat'
cell:addClass('table-negative')
end
if math.abs(statVal) >= 1000 then
cell:attr('data-sort-value', statVal)
end
cell:css('text-align', 'right')
return cell
end


  --Find out what Ammo Type we're working with
local function addStatCell(row, item, stat)
  local ammoType = nil
local statVal = 0
  if ammoTypeStr ~= nil then
if item.equipmentStats ~= nil then
    if ammoTypeStr == "Arrows" then
statVal = item.equipmentStats[stat] or 0
      ammoType = 0
end
    elseif ammoTypeStr == 'Bolts' then
      ammoType = 1
return createStatCell(row, statVal)
    elseif ammoTypeStr == 'Javelins' then
:wikitext(Num.formatnum(statVal))
      ammoType = 2
end
    elseif ammoTypeStr == 'Throwing Knives' then
      ammoType = 3
    end
  end


  --Find out what slot we're working with
local function addDRCell(row, item)
  local slot = nil
local dr = 0
  if slotStr ~= nil then
local icon = nil
    slot = Constants.getEquipmentSlotID(slotStr)
  end
-- Grab damage reduction figure
 
if item.equipmentStats ~= nil then
  local isWeaponType = Shared.contains(weaponTypes, type)
if item.equipmentStats.damageReduction then
dr, icon = item.equipmentStats.damageReduction, 'Damage Reduction'
elseif item.equipmentStats.resistanceAbyssal then
dr, icon = item.equipmentStats.resistanceAbyssal, 'Abyssal Resistance'
elseif item.equipmentStats.resistanceEternal then
dr, icon = item.equipmentStats.resistanceEternal, 'Eternal Resistance'
end
end
local cell = createStatCell(row, dr)
-- Add DR icons, if there's any value
if dr ~= 0 then
cell:wikitext(Icons.Icon({icon, size=15, notext='true'}) .. ' ')
end
-- Add DR value
cell:wikitext(dr .. '%')
return cell
end


  --Now we need to figure out which items are in this list
local function getRequirements(item)
  local itemList = {}
if item.equipRequirements == nil then
  for i, itemBase in pairs(ItemData.Items) do
return nil
    local item = Shared.clone(itemBase)
end
    item.id = i - 1
    local listItem = false
local function getSkillName(skillID)
    if isWeaponType then
local _, localSkillID = GameData.getLocalID(skillID)
    listItem = item.type == type and item.category == category
return localSkillID
      if ammoType ~= nil then listItem = listItem and item.ammoTypeRequired == ammoType end
end
    else
      --Now for handling armour
local iconFuncs = {
      if type == "Armour" or type == "Melee" then
['AbyssalLevel'] = function(x)
        listItem = item.defenceLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Armour')
return Icons._SkillRealmIcon(getSkillName(x.skillID), 'melvorItA:Abyssal') .. ' ' .. x.level
      elseif type == "Ranged Armour" or type == "Ranged" then
end,
        listItem = item.rangedLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Ranged Armour')
['SkillLevel'] = function(x)
      elseif type == "Magic Armour" or type == "Magic" then
return Icons._SkillRealmIcon(getSkillName(x.skillID)) .. ' ' .. x.level
        listItem = item.magicLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Magic Armour')
end,
      else
}
        listItem = item.type == type and item.category ~= 'Combat'
      end
local reqs = {}
      if ammoType ~= nil then listItem = listItem and item.ammoType == ammoType end
local abyssalSkills = {}
      if slot ~= nil then listItem = listItem and item.equipmentSlot == slot end
local highestLvReq = 0
-- Filter out all Abyssal Levels
    for _, req in ipairs(item.equipRequirements) do
        if req.type == 'AbyssalLevel' then abyssalSkills[req.skillID] = true end
    end
-- If the req is a SkillLevel, but the skillID is already an AbyssalLevel, skip the entry
-- These are likely 99 Level requirements in addition to the AbyssalLevel requirement.
    for _, req in ipairs(item.equipRequirements) do
if not (req.type == 'SkillLevel' and abyssalSkills[req.skillID] == true) then
-- Add requirement via factory function.
local func = iconFuncs[req.type]
if func then table.insert(reqs, func(req)) end
-- Track highest level for data sorting.
local lv = req.level or 0
if lv > highestLvReq then highestLvReq = lv end
end
     end
     end
     if listItem then
   
      table.insert(itemList, item)
     if Shared.tableIsEmpty(abyssalSkills) == false then
    highestLvReq = highestLvReq + 200
     end
     end
  end


  return p._getEquipmentTable(itemList).."[[Category:getEquipmentTable]]"
return {
['datasortvalue'] = highestLvReq,
['requirements'] = table.concat(reqs, '<br>')
}
end
end


function p._getCategoryTable(style, slot, other, includeModifiers, includeDescription)
function p.getEquipmentTable(itemList, slot, style)
  if type(slot) == 'string' then
local iconSize = 20
    slot = Constants.getEquipmentSlotID(slot)
local fl = FL.new(itemList)
  end
-- If slot is nil, find out if we have any weapons.
if slot == nil then
if fl:any(function(x) return Shared.contains(x.validSlots, 'Weapon') end) then
slot = 'Weapon'
end
end
-- Sort itemList by name
itemList = fl:sortBy(function(x) return x.name end)
:sort()
:toTable()
local isWeapon = (slot == 'Weapon')
local itemColspan = (isWeapon and 5) or 3
local html = mw.html.create('table')
:addClass('wikitable sortable stickyHeader')
:addClass('col-1-center col-3-center')


  local itemList = Items.getItems(function(item)
local header0 = html:tag('tr'):addClass('headerRow-0')
      local isMatch = true
header0:tag('th'):attr('colspan', itemColspan)
      if style == 'Melee' then
header0:tag('th'):attr('colspan', 5)
        if (item.defenceLevelRequired == nil and item.attackLevelRequired == nil) and not Shared.contains(styleOverrides.Melee, item.name) then isMatch = false end
:wikitext("Attack Bonus")
      elseif style == 'Ranged' then
header0:tag('th'):attr('colspan', 3)
        if item.rangedLevelRequired == nil and not Shared.contains(styleOverrides.Ranged, item.name) then isMatch = false end
:wikitext("Strength Bonus")
      elseif style == 'Magic' then
header0:tag('th'):attr('colspan', 3)
        if item.magicLevelRequired == nil and not Shared.contains(styleOverrides.Magic, item.name) then isMatch = false end
:wikitext("Defence Bonus")
      elseif style == 'None' then
        if (item.defenceLevelRequired ~= nil or item.rangedLevelRequired ~= nil or item.magicLevelRequired ~= nil or
          Shared.contains(styleOverrides.Melee, item.name) or Shared.contains(styleOverrides.Ranged, item.name) or Shared.contains(styleOverrides.Magic, item.name)) and
          not Shared.contains(styleOverrides.None, item.name) then
          isMatch = false
        end
      end


      if slot == nil or slot ~= item.equipmentSlot then isMatch = false end
header0:tag('th'):wikitext("DR/AR")
header0:tag('th'):wikitext()
local header1 = html:tag('tr'):addClass('headerRow-1')
header1:tag('th'):wikitext('Name')
:attr('colspan', 2)
header1:tag('th'):wikitext('DLC')
if isWeapon == true then
header1:tag('th'):wikitext('Two<br>Handed')
header1:tag('th'):wikitext('Attack<br>Speed')
end


      if isMatch and other ~= nil then
-- Attack bonuses
        if slot == 4 then --For quiver slot or weapon slot, 'other' is the ammo type
header1:tag('th'):wikitext(Icons.Icon({'Attack', type='skill', size=iconSize, notext='true'}))
          if other == 'Arrows' then
header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
            if item.ammoTypeRequired ~= 0 then isMatch = false end
header1:tag('th'):wikitext(Icons.Icon({'Defence', type='skill', size=iconSize, notext='true'}))
          elseif other == 'Bolts' then
header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
            if item.ammoTypeRequired ~= 1 then isMatch = false end
header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))
          end
        elseif slot == 9 then
          if other == 'Arrows' then
            if item.ammoType ~= 0 then isMatch = false end
          elseif other == 'Bolts' then
            if item.ammoType ~= 1 then isMatch = false end
          elseif other == 'Javelins' then
            if item.ammoType ~= 2 then isMatch = false end
          elseif other == 'Throwing Knives' then
            if item.ammoType ~= 3 then isMatch = false end
          elseif other == 'Thrown' then
            if item.ammoType ~= 2 and item.ammoType ~= 3 then isMatch = false end
          end
        end
      end


      return isMatch
--Strength bonuses
    end)
header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))


  return p._getEquipmentTable(itemList, includeModifiers, includeDescription)
--Defence bonuses
end
header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))
-- Damage reduction
header1:tag('th'):wikitext(Icons.Icon({'Damage Reduction', size=iconSize, notext='true'}))
--Level requirements
header1:tag('th'):wikitext('Equip Req')


function p.getCategoryTable(frame)
-- Fill the table with all items
  local style = frame.args ~= nil and frame.args[1] or frame[1]
for _, item in ipairs(itemList) do
  local slot = frame.args ~= nil and frame.args[2] or frame[2]
local row = html:tag('tr')
  local other = frame.args ~= nil and frame.args[3] or frame[3]
row:tag('td'):wikitext(Icons.Icon({item.name, type='item', notext=true}))
  local includeModifiers = frame.args ~= nil and frame.args.includeModifiers or frame.includeModifiers
:attr('data-sort-value', item.name)
  local includeDescription = frame.args ~= nil and frame.args.includeDescription or frame.includeDescription
row:tag('td'):wikitext(Icons.Icon({item.name, type='item', noicon=true}))
:attr('data-sort-value', item.name)
row:tag('td'):wikitext(Icons.getDLCColumnIcon(item.id))
:attr('data-sort-value', Icons.getExpansionID(item.id))


  includeModifiers = includeModifiers ~= nil and string.upper(includeModifiers) == 'TRUE' or false
-- Add two-handed & attack speed.
  includeDescription = includeDescription ~= nil and string.upper(includeDescription) == 'TRUE' or false
if isWeapon == true then
local twoHandText = (Items._getItemStat(item, 'isTwoHanded') and 'Yes') or 'No'
row:tag('td'):wikitext(twoHandText)
:css('text-align', 'center')
local atkSpeed = Items._getItemStat(item, 'attackSpeed') or 0
if atkSpeed > 0 then
row:tag('td'):wikitext(Num.round(atkSpeed / 1000, 3, 1) .. 's')
:attr('data-sort-value', atkSpeed)
:css('text-align', 'right')
else
row:tag('td'):wikitext('N/A')
:addClass('table-na')
end
end
-- Attack bonuses
addStatCell(row, item, 'stabAttackBonus')
addStatCell(row, item, 'slashAttackBonus')
addStatCell(row, item, 'blockAttackBonus')
addStatCell(row, item, 'rangedAttackBonus')
addStatCell(row, item, 'magicAttackBonus')
-- Strength bonuses
addStatCell(row, item, 'meleeStrengthBonus')
addStatCell(row, item, 'rangedStrengthBonus')
addStatCell(row, item, 'magicDamageBonus'):wikitext('%')


  return p._getCategoryTable(style, slot, other, includeModifiers, includeDescription)
-- Defence bonuses
end
addStatCell(row, item, 'meleeDefenceBonus')
addStatCell(row, item, 'rangedDefenceBonus')
addStatCell(row, item, 'magicDefenceBonus')


function p.getTableForList(frame)
-- Add Damage Reduction / Abyssal Resistance
  local stuffString = frame.args ~= nil and frame.args[1] or frame[1]
addDRCell(row, item)
  local itemNames = Shared.splitString(stuffString, ',')


  local includeModifiers = frame.args ~= nil and frame.args[2] or frame[2]
local reqs = getRequirements(item)
  includeModifiers = includeModifiers ~= nil and string.upper(includeModifiers) == 'TRUE' or false
if reqs == nil then
row:tag('td'):wikitext('None')
:attr('data-sort-value', 0)
else
row:tag('td'):wikitext(reqs.requirements)
:attr('data-sort-value', reqs.datasortvalue)
end
end


  local itemList = {}
return tostring(html)
  local errMsg = 'ERROR: Some items not found in database: '
  local hasErr = false
  for i, name in Shared.skpairs(itemNames) do
    local nextItem = Items.getItem(Shared.trim(name))
    if nextItem == nil then
      errMsg = errMsg.." '"..name.."'"
      hasErr = true
    else
      table.insert(itemList, nextItem)
    end
  end
 
  if hasErr then
    return errMsg
  else
    return p._getEquipmentTable(itemList, includeModifiers)
  end
end
end


function p.getDoubleLootTable(frame)
function p.getCategoryTable(frame)
  local itemList = Items.getItems(function(item) return item.chanceToDoubleLoot ~= nil and item.chanceToDoubleLoot > 0 end)
local args = frame.args ~= nil and frame.args or frame
  table.sort(itemList, function(a, b) return a.id < b.id end)
local slot, style = args[1], Shared.titleCase(args[2] or '')
  local result = '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"'
local slotID = getSlotID(slot)
  result = result..'\r\n!colspan="2"|Name!!Bonus!!Description!!Sources'
if slotID == nil then
  for i, item in Shared.skpairs(itemList) do
return Shared.printError('Invalid slot ID: ' .. (slot or 'nil'))
    result = result..'\r\n|-'
elseif style ~= nil and style ~= '' and itemStyleOverrides[style] == nil then
    result = result..'\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
return Shared.printError('Invalid style: ' .. (style or 'nil'))
    result = result..'||[['..item.name..']]'
end
    result = result..'||style ="text-align: right;" data-sort-value="'..item.chanceToDoubleLoot..'"|'..item.chanceToDoubleLoot..'%'
    result = result..'||'..item.description
    result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |'
    result = result..ItemSourceTables._getItemSources(item)
  end


  result = result..'\r\n|}'
return p.getEquipmentTable(getItems(slotID, style), slot)
  return result
end
end


function p.getItemTableRows(frame)
function p.getTableForList(frame)
  local startID = frame.args ~= nil and frame.args[1] or frame[1]
local pFrame = frame:getParent()
  local rowCount = frame.args ~= nil and frame.args[2] or frame[2]
local frameArgs = pFrame.args ~= nil and pFrame.args or frame
  if type(startID ) == 'string' then startID = tonumber(startID) end
local includeModifiers = frameArgs.includeModifiers ~= nil and string.upper(frameArgs.includeModifiers) == 'TRUE' or false
  if rowCount == nil then rowCount = 200 end
  if type(rowCount) == 'string' then rowCount = tonumber(rowCount) end
 
  local rowResult = {}
  for i = startID, startID + rowCount - 1, 1 do
    local item = Items.getItemByID(i)
    if item == nil then break end
    local rowTxt = '|-\r\n|'..Icons.Icon({item.name, type='item', size='50', notext=true})..'||[['..item.name..']]'
    rowTxt = rowTxt..'||style="text-align:right;"|'..i..'||'..item.category..'||'..item.type
    rowTxt = rowTxt..'||style="text-align:right;" data-sort-value="'..item.sellsFor..'"|'..Icons.GP(item.sellsFor)
    rowTxt = rowTxt..'||style="text-align:right;"|'..ItemSourceTables._getItemSources(item, false, 'false')
    rowTxt = rowTxt..'||style="text-align:right;"|'..ItemUseTables._getItemUses(item, false, 'false')
    table.insert(rowResult, rowTxt)
  end


  return table.concat(rowResult, '\r\n')
local itemList, errItems = {}, {}
for i, rawItemName in ipairs(frameArgs) do
local itemName = Shared.trim(rawItemName)
local item = Items.getItem(itemName)
if item == nil then
table.insert(errItems, "'" .. itemName .. "'")
else
table.insert(itemList, item)
end
end
if not Shared.tableIsEmpty(errItems) then
return Shared.printError('Some items not found in database: ' .. table.concat(errItems, ', '))
else
return p.getEquipmentTable(itemList)
end
end
end


function p.getStatChangeString(item1, item2)
function p.getItemUpgradeTable(frame)
  --Used by getItemUpgradeTable to get the stat change between two items
local args = frame.args ~= nil and frame.args or frame
  local changeArray = {}
local category, usedItemName = args[1], args.usedItem
local upgradeArray = {}
local isEquipment = false
local usedItemID = nil
if usedItemName ~= nil and usedItemName ~= '' then
local usedItem = Items.getItem(usedItemName)
if usedItem == nil then
return Shared.printError('Used item not found: ' .. usedItemName)
end
usedItemID = usedItem.id
end
local function upgradeConsumesItem(itemUpgrade, itemID)
if itemID == nil then
return true
end
for i, itemCost in ipairs(itemUpgrade.itemCosts) do
if itemCost.id == itemID then
return true
end
end
return false
end


  local getSpecificStatString = function(val1, val2, subStr)
if string.upper(category) == 'POTION' then
      if val1 == nil then val1 = 0 end
upgradeArray = GameData.getEntities('itemUpgrades',
      if val2 == nil then val2 = 0 end
function(upgrade)
return Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID)
end
)
elseif string.upper(category) == 'OTHER' then
upgradeArray = GameData.getEntities('itemUpgrades',
function(upgrade)
if not Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID) then
local item = Items.getItemByID(upgrade.upgradedItemID)
if item ~= nil then
return item.validSlots == nil or Shared.tableIsEmpty(item.validSlots)
end
end
return false
end
)
else
-- If category is a slot name, convert it to the slot ID instead
local slotID = getSlotID(category)
if slotID ~= nil then
local slotNS, slotLocalID = Shared.getLocalID(slotID)
category = slotLocalID
end


      if val1 ~= val2 then
if category == nil then
        local txt = string.gsub(subStr, '{V}', Shared.numStrWithSign(val1 - val2))
return Shared.printError('Invalid option. Choose either an equipment slot, Potion, or Other')
        table.insert(changeArray, txt)
end
      end
isEquipment = true
    end
upgradeArray = GameData.getEntities('itemUpgrades',
function(upgrade)
if upgradeConsumesItem(upgrade, usedItemID) then
local item = Items.getItemByID(upgrade.upgradedItemID)
if item ~= nil then
return item.validSlots ~= nil and Shared.contains(item.validSlots, category)
end
end
return false
end
)
end


  --Unfortunately just gonna have to manually check all the changes I think...
local useStatChange = isEquipment or (string.upper(category) == 'POTION')
  local attBon1 = item1.attackBonus ~= nil and item1.attackBonus or {0, 0, 0}
local resultPart = {}
  local attBon2 = item2.attackBonus ~= nil and item2.attackBonus or {0, 0, 0}
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
  getSpecificStatString(attBon1[1], attBon2[1], '{V} '..Icons.Icon({'Melee', notext=true})..' Stab Bonus')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
  getSpecificStatString(attBon1[2], attBon2[2], '{V} '..Icons.Icon({'Melee', notext=true})..' Slash Bonus')
table.insert(resultPart, '\r\n!colspan="2"|Upgraded Item!!Ingredients')
  getSpecificStatString(attBon1[3], attBon2[3], '{V} '..Icons.Icon({'Melee', notext=true})..' Block Bonus')
if useStatChange then table.insert(resultPart, '!!Stat Change') end


  getSpecificStatString(item1.strengthBonus, item2.strengthBonus, '{V} '..Icons.Icon({'Strength', type='skill', notext=true})..' Strength Bonus')
for i, upgrade in ipairs(upgradeArray) do
  getSpecificStatString(item1.rangedStrengthBonus, item2.rangedStrengthBonus, '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Strength Bonus')
local item = Items.getItemByID(upgrade.upgradedItemID)
  getSpecificStatString(item1.magicDamageBonus, item2.magicDamageBonus, '{V}% '..Icons.Icon({'Magic', type='skill', notext=true})..' Damage Bonus')
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|'..Icons.Icon({item.name, type='item', size='50', notext=true}))
table.insert(resultPart, '||' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))


  getSpecificStatString(item1.defenceBonus, item2.defenceBonus, '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Defence Bonus')
table.insert(resultPart, '|| ' .. Common.getCostString({ items = upgrade.itemCosts, gp = upgrade.gpCost, sc = upgrade.scCost}, 'None'))
  getSpecificStatString(item1.rangedDefenceBonus, item2.rangedDefenceBonus, '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus')
  getSpecificStatString(item1.magicDefenceBonus, item2.magicDefenceBonus, '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Defence Bonus')
  getSpecificStatString(item1.damageReduction, item2.damageReduction, '{V}% Damage Reduction')


  local SlayBon1 = Items._getItemModifier(item1, 'increasedSkillXP', 'Slayer')
if useStatChange then
  local SlayBon2 = Items._getItemModifier(item2, 'increasedSkillXP', 'Slayer')
-- Generate stat change column
  getSpecificStatString(SlayBon1, SlayBon2, '{V}% '..Icons.Icon({'Slayer', type='skill', notext=true})..' Bonus XP')
local statChangeString = ''
if not Shared.tableIsEmpty(upgrade.rootItemIDs) then
-- Some items (e.g. FEZ) may have multiple root items. Simply use the first one
local rootItem = Items.getItemByID(upgrade.rootItemIDs[1])
if rootItem ~= nil then
statChangeString = Items.getStatChangeString(item, rootItem)
end
end
table.insert(resultPart, '|| '..statChangeString)
end
end


  getSpecificStatString(item1.attackLevelRequired, item1.attackLevelRequired, '{V} '..Icons.Icon({'Attack', type='skill', notext=true})..' Level Required')
table.insert(resultPart, '\r\n|}')
  getSpecificStatString(item1.defenceLevelRequired, item1.defenceLevelRequired, '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Level Required')
return table.concat(resultPart)
  getSpecificStatString(item1.rangedLevelRequired, item1.rangedLevelRequired, '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Level Required')
end
  getSpecificStatString(item1.magicLevelRequired, item1.magicLevelRequired, '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Level Required')


  return table.concat(changeArray, '<br/>')
function p.getRuneProvidingItemTable(frame)
local itemArray = Items.getItems(function(item) return item.providedRunes ~= nil end)
local resultPart = {}
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
table.insert(resultPart, '\r\n|- class="headerRow-0"')
table.insert(resultPart, '\r\n!colspan="2"|Item!!Runes Provided')
for i, item in pairs(itemArray) do
local PR = item.providedRunes
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|style="text-align: center;"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
table.insert(resultPart, '\r\n|' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
local runeLines = {}
local sortVal = ''
for j, runePair in pairs(PR) do
local runeID = runePair.id
local qty = runePair.quantity
local rune = Items.getItemByID(runeID)
sortVal = sortVal..rune.name..qty
table.insert(runeLines, Icons.Icon({rune.name, type='item', qty=qty}))
end
table.insert(resultPart, '\r\n|data-sort-value="'..sortVal..'"|'..table.concat(runeLines, '<br/>'))
end
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end
end


function p.getItemUpgradeTable(frame)
function p._getDRTable(slots, items)
  local category = frame.args ~= nil and frame.args[1] or frame
local resultPart = {}
  local itemArray = {}
  local isEquipment = false
table.insert(resultPart, '{| class="wikitable sortable" style="width:90%;"')
 
table.insert(resultPart, '\r\n|-')
  if string.upper(category) == 'POTION' then
table.insert(resultPart, '\r\n! style="width:4%"|DR%')
    itemArray = Items.getItems(function(item) return Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil end)
for i, slot in pairs(slots) do
  elseif string.upper(category) == 'OTHER' then
table.insert(resultPart, '\r\n! '..slot)
    itemArray = Items.getItems(function(item)  
end
          return not Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil and item.equipmentSlot == nil
        end)
local DRTable = {}
  else
table.sort(items, function(a, b) return a.name < b.name end)
    local equipSlot = Constants.getEquipmentSlotID(category)
    if equipSlot == nil then
for i, item in pairs(items) do
      return 'ERROR: Invalid option. Choose either an equipment slot, Potion, or Other[[Category:Pages with script errors]]'
local DR = Items._getItemStat(item, 'damageReduction', true)
    end
local EquipSlot = Items._getItemEquipSlot(item)
    isEquipment = true
if DRTable[DR] == nil then
    itemArray = Items.getItems(function(item)
DRTable[DR] = {}
          return item.itemsRequired ~= nil and item.equipmentSlot == equipSlot
end
        end)
if DRTable[DR][EquipSlot] == nil then
  end
DRTable[DR][EquipSlot] = {}
  table.sort(itemArray, function(a, b) return a.id < b.id end)
end
 
table.insert(DRTable[DR][EquipSlot], Icons.Icon({item.name, type='item', expicon = Icons.getExpansionIcon(item.id)}))
  local result = '{| class="wikitable sortable stickyHeader"'
end
  result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan="2"|Upgraded Item!!Ingredients'
for DR, SlotTables in Shared.skpairs(DRTable) do
  if isEquipment then result = result..'!!Stat Change' end
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.insert(resultPart, table.concat(SlotTables[SlotName], '<br/>'))
end
end
end
table.insert(resultPart, '\r\n|}')
return table.concat(resultPart)
end


  for i, item in Shared.skpairs(itemArray) do
function p.getDRTable(frame)
    result = result..'\r\n|-'
local style = frame.args ~= nil and frame.args[1] or frame
    result = result..'\r\n|'..Icons.Icon({item.name, type='item', size='50', notext=true})..'||[['..item.name..']]'
local slotNames = {}
if style == 'Other' then
slotNames = {'Helmet', 'Platelegs', 'Gloves', 'Shield', 'Cape', 'Amulet', 'Ring'}
else
slotNames = {'Helmet', 'Platebody', 'Platelegs', 'Boots', 'Gloves', 'Weapon', 'Shield'}
end
local itemList = getEquipItemList(
function(entry)
if Items._getItemStat(entry.item, 'damageReduction', true) <= 0 then
-- Item provides no DR: Exclude
return false
end


    local matArray = {}
-- Check equipment slot matches
    local statChangeString = ''
local slotMatch = false
    for i, row in Shared.skpairs(item.itemsRequired) do
for _, slotName in ipairs(slotNames) do
      local mat = Items.getItemByID(row[1])
if entry.slots[slotName] ~= nil then
      table.insert(matArray, Icons.Icon({mat.name, type='item', qty=row[2]}))
slotMatch = true
break
end
end
if not slotMatch then
return false
end


      if item.equipmentSlot ~= nil and mat.equipmentSlot ~= nil and statChangeString == '' then
-- Finally, ensure the style matches. If no style specified then return evertyhing
        statChangeString = p.getStatChangeString(item, mat)
return (style == nil or style == '' or style == entry.style)
      end
end
    end
)
    if item.trimmedGPCost ~= nil and item.trimmedGPCost > 0 then
      table.insert(matArray, Icons.GP(item.trimmedGPCost))
    end
    result = result..'||'..table.concat(matArray, '<br/>')
 
    if isEquipment then
      result = result..'||'..statChangeString
    end
  end


  result = result..'\r\n|}'
return p._getDRTable(slotNames, itemList)
  return result
end
end


return p
return p

Latest revision as of 09:48, 3 September 2024

Documentation for this module may be created at Module:Items/ComparisonTables/doc

local p = {}

local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Modifiers = require('Module:Modifiers')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Num = require('Module:Number')
local FL = require('Module:FunList')

local weaponTypes = {'Magic Staff', 'Magic Wand', 'Ranged Weapon', 'Weapon'}

local styleOverrides = {
	Melee = {'Slayer Helmet (Basic)', 'Slayer Platebody (Basic)', 'Paladin Gloves', 'Desert Wrappings', 'Almighty Lute', 'Candy Cane', "Bob's Rake", "Knight's Defender", "Ward of Flame Platebody"},
	Ranged = {'Slayer Cowl (Basic)', 'Slayer Leather Body (Basic)', 'Ice Arrows'},
	Magic = {'Slayer Wizard Hat (Basic)', 'Slayer Wizard Robes (Basic)', 'Enchanted Shield', 'Elementalist Gloves', 'Frostspark Boots', 'Freezing Touch Body', 'Lightning Boots'},
	None = {},
	NotMelee = {'Frostspark Boots', 'Freezing Touch Body', 'Lightning Boots'},
	NotRanged = {},
	NotMagic = {'Torrential Blast Crossbow', 'Spectral Ice Sword', 'Lightning Strike 1H Sword', 'FrostSpark 1H Sword'}
}

local slotOverrides = {
	['Enhancement'] = 'melvorD:Enhancement'
}

local itemStyleOverrides = {
	['Melee'] = {
		'melvorF:Slayer_Helmet_Basic',
		'melvorF:Slayer_Platebody_Basic',
		'melvorF:Paladin_Gloves',
		'melvorF:Desert_Wrappings',
		'melvorF:Knights_Defender',
	},
	['Ranged'] = {
		'melvorF:Slayer_Cowl_Basic',
		'melvorF:Slayer_Leather_Body_Basic',
		'melvorD:Cape_Of_Prat',
		'melvorD:Ice_Arrows',
	},
	['Magic'] = {
		'melvorF:Slayer_Wizard_Hat_Basic',
		'melvorF:Slayer_Wizard_Robes_Basic',
		'melvorF:Skull_Cape',
		'melvorD:Enchanted_Shield',
		'melvorF:Elementalist_Gloves',
		'melvorTotH:Freezing_Touch_Body',
		'melvorTotH:Lightning_Boots',
	},
	['Other'] = {

	}
}

-- Categorise equipment by:
-- - Equipment slot ID
-- - Style (Melee, Ranged, Magic, Other)
p.SlotEquipment = {}

function p.populateSlotEquipment()
	-- Populate from item data
	local hiddenItems = {}
	for _, itemID in ipairs(Items.HiddenItems) do
		hiddenItems[itemID] = true
	end

	-- Transform style overrides into a form where items are indexed by ID
	local styleOverrides = {}
	for overType, itemIDs in pairs(itemStyleOverrides) do
		for _, itemID in ipairs(itemIDs) do
			styleOverrides[itemID] = overType
		end
	end

	for _, item in ipairs(GameData.rawData.items) do
		if (
			-- Item is not hidden (includes debug items)
			hiddenItems[item.id] == nil
			-- Item isn't exclusive to Golbin Raid minigame
			and (item.golbinRaidExclusive == nil or not item.golbinRaidExclusive)
			-- Item can be equipped to any slot
			and item.validSlots ~= nil
		) then
			-- Item is equippment to be included within equipment tables
			local equipEntry = {
				['item'] = item,
				['slots'] = {},
				['isWeapon'] = nil,
				['style'] = nil
			}
			-- Determine which slots the equipment can be equipped to
			local occupiesSlots = item.occupiesSlots or {}
			for _, slotLocalID in ipairs(item.validSlots) do
				local newSlotID = slotLocalID
				-- Classify javelins and throwing knives as weapons
				if slotLocalID == 'Quiver' and Shared.contains({'Javelins', 'ThrowingKnives'}, item.ammoType) then
					newSlotID = 'Weapon'
				-- Combine all enhancements
				elseif Shared.contains({'Enhancement1', 'Enhancement2', 'Enhancement3'}, slotLocalID) then
					newSlotID = 'Enhancement'
				end
				equipEntry.slots[newSlotID] = true
			end
			equipEntry.isWeapon = equipEntry.slots['Weapon'] or Shared.contains(occupiesSlots, 'Weapon')

			-- Determine the style of the item (Melee, Ranged, Magic, Other)
			local function hasSkillReq(reqs, localSkillID)
				if reqs ~= nil then
					local skillID = Shared.getNamespacedID('melvorD', localSkillID)
					for levelType, typeReqs in pairs(reqs) do
						if typeReqs[skillID] ~= nil then
							return true
						end
					end
				end
				return false
			end
			local levelReqs = Items._getItemLevelReqs(item)
			-- Apply any overrides first
			if styleOverrides[item.id] ~= nil then
				equipEntry.style = styleOverrides[item.id]
			-- Weapon styles can be checked using the attackType property
			elseif equipEntry.isWeapon and Shared.contains({'melee', 'ranged', 'magic'}, item.attackType) then
				equipEntry.style = Shared.titleCase(item.attackType)
			-- Magic
			elseif hasSkillReq(levelReqs, 'Magic') then
				equipEntry.style = 'Magic'
			-- Ranged
			elseif (
				hasSkillReq(levelReqs, 'Ranged')
				or equipEntry.slots.Quiver ~= nil
				or item.ammoType ~= nil
		 	) then
				equipEntry.style = 'Ranged'
			-- Melee
			elseif (
				hasSkillReq(levelReqs, 'Attack')
				or hasSkillReq(levelReqs, 'Defence')
			) then
				equipEntry.style = 'Melee'
			-- Other, default style if unmatched
			else
				equipEntry.style = 'Other'
			end
			-- Finally, add the entry into the slotEquipment table
			table.insert(p.SlotEquipment, equipEntry)
		end
	end
end

p.populateSlotEquipment()

local function getEquipItemList(filter)
	local equip = GameData.getEntities(p.SlotEquipment, function(x) return filter(x) end)
	local items = {}
	for _, entry in ipairs(equip) do
		table.insert(items, entry.item)
	end
	return items
end

local function getSlotID(slot)
	local slotID = Shared.getNamespacedID('melvorD', slot)
	local slotData = GameData.getEntityByID('equipmentSlots', slotID)

	if slotData == nil then
		if slotOverrides[slot] ~= nil then
			return slotOverrides[slot]
		end

		-- slotID invalid, check if user provided a slot name
		slotData = GameData.getEntityByProperty('equipmentSlots', 'emptyName', slot)
		if slotData == nil then
			return nil
		end
		slotID = slotData.id
	end
	return slotID
end

local function getItemDesc(item)
	if item.customDescription ~= nil then
		return item.customDescription
	elseif item.modifiers ~= nil then
		return Modifiers.getModifiersText(item.modifiers, false, false)
	else
		return ''
	end
end

local function getItems(slotID, style)
	local _, slotLocalID = Shared.getLocalID(slotID)

	return getEquipItemList(
		function(entry)
			return (
				entry.slots[slotLocalID] ~= nil
				and (style == nil or style == '' or style == entry.style)
			)
		end
	)
end

--== Helper Functions for getCategoryTable ==--
local function createStatCell(row, statVal)
	local cell = row:tag('td')
	if statVal > 0 then
		cell:addClass('table-positive')
	elseif statVal < 0 then
		cell:addClass('table-negative')
	end
	if math.abs(statVal) >= 1000 then
		cell:attr('data-sort-value', statVal)
	end
	cell:css('text-align', 'right')
	return cell
end

local function addStatCell(row, item, stat)
	local statVal = 0
	if item.equipmentStats ~= nil then
		statVal = item.equipmentStats[stat] or 0
	end
	
	return createStatCell(row, statVal)
		:wikitext(Num.formatnum(statVal))
end

local function addDRCell(row, item)
	local dr = 0
	local icon = nil
	
	-- Grab damage reduction figure
	if item.equipmentStats ~= nil then
		if item.equipmentStats.damageReduction then
			dr, icon = item.equipmentStats.damageReduction, 'Damage Reduction'
		elseif item.equipmentStats.resistanceAbyssal then
			dr, icon = item.equipmentStats.resistanceAbyssal, 'Abyssal Resistance'
		elseif item.equipmentStats.resistanceEternal then
			dr, icon = item.equipmentStats.resistanceEternal, 'Eternal Resistance'
		end
	end
	
	local cell = createStatCell(row, dr)
	
	-- Add DR icons, if there's any value
	if dr ~= 0 then
		cell:wikitext(Icons.Icon({icon, size=15, notext='true'}) .. ' ')
	end
	
	-- Add DR value
	cell:wikitext(dr .. '%')
	return cell
end

local function getRequirements(item)
	if item.equipRequirements == nil then 
		return nil
	end
	
	local function getSkillName(skillID)
		local _, localSkillID = GameData.getLocalID(skillID)
		return localSkillID
	end
	
	local iconFuncs = {
		['AbyssalLevel'] = function(x) 
			return Icons._SkillRealmIcon(getSkillName(x.skillID), 'melvorItA:Abyssal') .. ' ' .. x.level 
		end,
		['SkillLevel'] = function(x) 
			return Icons._SkillRealmIcon(getSkillName(x.skillID)) .. ' ' .. x.level 
		end,
	}
	
	local reqs = {}
	local abyssalSkills = {}
	local highestLvReq = 0
	
	-- Filter out all Abyssal Levels
    for _, req in ipairs(item.equipRequirements) do
        if req.type == 'AbyssalLevel' then abyssalSkills[req.skillID] = true end
    end
	
	-- If the req is a SkillLevel, but the skillID is already an AbyssalLevel, skip the entry
	-- These are likely 99 Level requirements in addition to the AbyssalLevel requirement.
    for _, req in ipairs(item.equipRequirements) do
		if not (req.type == 'SkillLevel' and abyssalSkills[req.skillID] == true) then
			-- Add requirement via factory function.
			local func = iconFuncs[req.type]
			if func then table.insert(reqs, func(req)) end
			
			-- Track highest level for data sorting.
			local lv = req.level or 0
			if lv > highestLvReq then highestLvReq = lv end
		end
    end
    
    if Shared.tableIsEmpty(abyssalSkills) == false then
    	highestLvReq = highestLvReq + 200
    end

	return {
		['datasortvalue'] = highestLvReq,
		['requirements'] = table.concat(reqs, '<br>')
	}
end

function p.getEquipmentTable(itemList, slot, style)
	local iconSize = 20
	local fl = FL.new(itemList)
	
	-- If slot is nil, find out if we have any weapons.
	if slot == nil then
		if fl:any(function(x) return Shared.contains(x.validSlots, 'Weapon') end) then
			slot = 'Weapon'
		end
	end
	
	-- Sort itemList by name
	itemList = fl:sortBy(function(x) return x.name end)
				 :sort()
				 :toTable()
				 
	local isWeapon = (slot == 'Weapon')
	local itemColspan = (isWeapon and 5) or 3
	
	local html = mw.html.create('table')
		:addClass('wikitable sortable stickyHeader')
		:addClass('col-1-center col-3-center')

	local header0 = html:tag('tr'):addClass('headerRow-0')
	header0:tag('th'):attr('colspan', itemColspan)
	header0:tag('th'):attr('colspan', 5)
					 :wikitext("Attack Bonus")
	header0:tag('th'):attr('colspan', 3)
					 :wikitext("Strength Bonus")
	header0:tag('th'):attr('colspan', 3)
					 :wikitext("Defence Bonus")

	header0:tag('th'):wikitext("DR/AR")
	header0:tag('th'):wikitext()
	
	local header1 = html:tag('tr'):addClass('headerRow-1')
	header1:tag('th'):wikitext('Name')
					 :attr('colspan', 2)
	header1:tag('th'):wikitext('DLC')
	if isWeapon == true then
		header1:tag('th'):wikitext('Two<br>Handed')
		header1:tag('th'):wikitext('Attack<br>Speed')
	end

	-- Attack bonuses
	header1:tag('th'):wikitext(Icons.Icon({'Attack', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Defence', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))

	--Strength bonuses
	header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))

	--Defence bonuses
	header1:tag('th'):wikitext(Icons.Icon({'Strength', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Ranged', type='skill', size=iconSize, notext='true'}))
	header1:tag('th'):wikitext(Icons.Icon({'Magic', type='skill', size=iconSize, notext='true'}))
	
	-- Damage reduction
	header1:tag('th'):wikitext(Icons.Icon({'Damage Reduction', size=iconSize, notext='true'}))
	
	--Level requirements
	header1:tag('th'):wikitext('Equip Req')

	-- Fill the table with all items
	for _, item in ipairs(itemList) do
		local row = html:tag('tr')
		row:tag('td'):wikitext(Icons.Icon({item.name, type='item', notext=true}))
					 :attr('data-sort-value', item.name)
		row:tag('td'):wikitext(Icons.Icon({item.name, type='item', noicon=true}))
					 :attr('data-sort-value', item.name)
		row:tag('td'):wikitext(Icons.getDLCColumnIcon(item.id))
					 :attr('data-sort-value', Icons.getExpansionID(item.id))

		-- Add two-handed & attack speed.
		if isWeapon == true then
			local twoHandText = (Items._getItemStat(item, 'isTwoHanded') and 'Yes') or 'No'
			row:tag('td'):wikitext(twoHandText)
						 :css('text-align', 'center')
			
			local atkSpeed = Items._getItemStat(item, 'attackSpeed') or 0
			if atkSpeed > 0 then
				row:tag('td'):wikitext(Num.round(atkSpeed / 1000, 3, 1) .. 's')
							 :attr('data-sort-value', atkSpeed)
							 :css('text-align', 'right')
			else
				row:tag('td'):wikitext('N/A')
							 :addClass('table-na')
			end
		end
		
		-- Attack bonuses
		addStatCell(row, item, 'stabAttackBonus')
		addStatCell(row, item, 'slashAttackBonus')
		addStatCell(row, item, 'blockAttackBonus')
		addStatCell(row, item, 'rangedAttackBonus')
		addStatCell(row, item, 'magicAttackBonus')
		
		-- Strength bonuses
		addStatCell(row, item, 'meleeStrengthBonus')
		addStatCell(row, item, 'rangedStrengthBonus')
		addStatCell(row, item, 'magicDamageBonus'):wikitext('%')	

		-- Defence bonuses
		addStatCell(row, item, 'meleeDefenceBonus')
		addStatCell(row, item, 'rangedDefenceBonus')
		addStatCell(row, item, 'magicDefenceBonus')

		-- Add Damage Reduction / Abyssal Resistance
		addDRCell(row, item)

		local reqs = getRequirements(item)
		if reqs == nil then
			row:tag('td'):wikitext('None')
						 :attr('data-sort-value', 0)
		else
			row:tag('td'):wikitext(reqs.requirements)
						 :attr('data-sort-value', reqs.datasortvalue)
		end
	end

	return tostring(html)
end

function p.getCategoryTable(frame)
	local args = frame.args ~= nil and frame.args or frame
	local slot, style = args[1], Shared.titleCase(args[2] or '')
	local slotID = getSlotID(slot)
	if slotID == nil then
		return Shared.printError('Invalid slot ID: ' .. (slot or 'nil'))
	elseif style ~= nil and style ~= '' and itemStyleOverrides[style] == nil then
		return Shared.printError('Invalid style: ' .. (style or 'nil'))
	end

	return p.getEquipmentTable(getItems(slotID, style), slot)
end

function p.getTableForList(frame)
	local pFrame = frame:getParent()
	local frameArgs = pFrame.args ~= nil and pFrame.args or frame
	local includeModifiers = frameArgs.includeModifiers ~= nil and string.upper(frameArgs.includeModifiers) == 'TRUE' or false

	local itemList, errItems = {}, {}
	for i, rawItemName in ipairs(frameArgs) do
		local itemName = Shared.trim(rawItemName)
		local item = Items.getItem(itemName)
		if item == nil then
			table.insert(errItems, "'" .. itemName .. "'")
		else
			table.insert(itemList, item)
		end
	end
	
	if not Shared.tableIsEmpty(errItems) then
		return Shared.printError('Some items not found in database: ' .. table.concat(errItems, ', '))
	else
		return p.getEquipmentTable(itemList)
	end
end

function p.getItemUpgradeTable(frame)
	local args = frame.args ~= nil and frame.args or frame
	local category, usedItemName = args[1], args.usedItem
	local upgradeArray = {}
	local isEquipment = false
	
	local usedItemID = nil
	if usedItemName ~= nil and usedItemName ~= '' then
		local usedItem = Items.getItem(usedItemName)
		if usedItem == nil then
			return Shared.printError('Used item not found: ' .. usedItemName)
		end
		usedItemID = usedItem.id
	end
	
	local function upgradeConsumesItem(itemUpgrade, itemID)
		if itemID == nil then
			return true
		end	
		for i, itemCost in ipairs(itemUpgrade.itemCosts) do
			if itemCost.id == itemID then
				return true
			end
		end
		return false
	end

	if string.upper(category) == 'POTION' then
		upgradeArray = GameData.getEntities('itemUpgrades',
			function(upgrade)
				return Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID)
			end
			)
	elseif string.upper(category) == 'OTHER' then
		upgradeArray = GameData.getEntities('itemUpgrades',
			function(upgrade)
				if not Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID) then
					local item = Items.getItemByID(upgrade.upgradedItemID)
					if item ~= nil then
						return item.validSlots == nil or Shared.tableIsEmpty(item.validSlots)
					end
				end
				return false
			end
			)
	else
		-- If category is a slot name, convert it to the slot ID instead
		local slotID = getSlotID(category)
		if slotID ~= nil then
			local slotNS, slotLocalID = Shared.getLocalID(slotID)
			category = slotLocalID
		end

		if category == nil then
			return Shared.printError('Invalid option. Choose either an equipment slot, Potion, or Other')
		end
		isEquipment = true
		upgradeArray = GameData.getEntities('itemUpgrades',
			function(upgrade)
				if upgradeConsumesItem(upgrade, usedItemID) then
					local item = Items.getItemByID(upgrade.upgradedItemID)
					if item ~= nil then
						return item.validSlots ~= nil and Shared.contains(item.validSlots, category)
					end
				end
				return false
			end
			)
	end

	local useStatChange = isEquipment or (string.upper(category) == 'POTION')
	local resultPart = {}
	table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
	table.insert(resultPart, '\r\n|- class="headerRow-0"')
	table.insert(resultPart, '\r\n!colspan="2"|Upgraded Item!!Ingredients')
	if useStatChange then table.insert(resultPart, '!!Stat Change') end

	for i, upgrade in ipairs(upgradeArray) do
		local item = Items.getItemByID(upgrade.upgradedItemID)
		table.insert(resultPart, '\r\n|-')
		table.insert(resultPart, '\r\n|'..Icons.Icon({item.name, type='item', size='50', notext=true}))
		table.insert(resultPart, '||' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))

		table.insert(resultPart, '|| ' .. Common.getCostString({ items = upgrade.itemCosts, gp = upgrade.gpCost, sc = upgrade.scCost}, 'None'))

		if useStatChange then
			-- Generate stat change column
			local statChangeString = ''
			if not Shared.tableIsEmpty(upgrade.rootItemIDs) then
				-- Some items (e.g. FEZ) may have multiple root items. Simply use the first one
				local rootItem = Items.getItemByID(upgrade.rootItemIDs[1])
				if rootItem ~= nil then
					statChangeString = Items.getStatChangeString(item, rootItem)
				end
			end
			table.insert(resultPart, '|| '..statChangeString)
		end
	end

	table.insert(resultPart, '\r\n|}')
	return table.concat(resultPart)
end

function p.getRuneProvidingItemTable(frame)
	local itemArray = Items.getItems(function(item) return item.providedRunes ~= nil end)
	
	local resultPart = {}
	table.insert(resultPart, '{| class="wikitable sortable stickyHeader"')
	table.insert(resultPart, '\r\n|- class="headerRow-0"')
	table.insert(resultPart, '\r\n!colspan="2"|Item!!Runes Provided')
	
	for i, item in pairs(itemArray) do
		local PR = item.providedRunes
		table.insert(resultPart, '\r\n|-')
		table.insert(resultPart, '\r\n|style="text-align: center;"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
		table.insert(resultPart, '\r\n|' .. Icons.getExpansionIcon(item.id) .. Icons.Icon({item.name, type='item', noicon=true}))
		local runeLines = {}
		local sortVal = ''
		for j, runePair in pairs(PR) do
			local runeID = runePair.id
			local qty = runePair.quantity
			local rune = Items.getItemByID(runeID)
			sortVal = sortVal..rune.name..qty
			table.insert(runeLines, Icons.Icon({rune.name, type='item', qty=qty}))
		end
		table.insert(resultPart, '\r\n|data-sort-value="'..sortVal..'"|'..table.concat(runeLines, '<br/>'))
	end
	
	table.insert(resultPart, '\r\n|}')
	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 = {}
	table.sort(items, function(a, b) return a.name < b.name end)
	
	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
		table.insert(DRTable[DR][EquipSlot], Icons.Icon({item.name, type='item', expicon = Icons.getExpansionIcon(item.id)}))
	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.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 = {}
	if style == 'Other' then
		slotNames = {'Helmet', 'Platelegs', 'Gloves', 'Shield', 'Cape', 'Amulet', 'Ring'}
	else
		slotNames = {'Helmet', 'Platebody', 'Platelegs', 'Boots', 'Gloves', 'Weapon', 'Shield'}
	end
	
	local itemList = getEquipItemList(
		function(entry)
			if Items._getItemStat(entry.item, 'damageReduction', true) <= 0 then
				-- Item provides no DR: Exclude
				return false
			end

			-- Check equipment slot matches
			local slotMatch = false
			for _, slotName in ipairs(slotNames) do
				if entry.slots[slotName] ~= nil then
					slotMatch = true
					break
				end
			end
			if not slotMatch then
				return false
			end

			-- Finally, ensure the style matches. If no style specified then return evertyhing
			return (style == nil or style == '' or style == entry.style)
		end
	)

	return p._getDRTable(slotNames, itemList)
end

return p