Module:Items/ComparisonTables: Difference between revisions

no edit summary
(_getEquipmentTable: Avoid repeated string concatenation in an attempt to reduce memory usage)
No edit summary
Line 31: Line 31:


   if(Shared.tableCount(itemList) == 0) then
   if(Shared.tableCount(itemList) == 0) then
     return 'ERROR: you must select at least one item to get stats for[[Category:Pages with script errors]]'
     return 'ERROR: you must select at least one item to get stats for'
   end
   end


   local isWeaponType = itemList[1].validSlots ~= nil and Shared.contains(itemList[1].validSlots, 'Weapon') and Shared.contains(weaponTypes, itemList[1].type)
   local isWeaponType = Shared.contains(weaponTypes, itemList[1].type)


   --Now that we have a preliminary list, let's figure out which columns are irrelevant (IE are zero for all items in the selection)
   --Now that we have a preliminary list, let's figure out which columns are irrelevant (IE are zero for all items in the selection)
Line 67: Line 67:
     end
     end
   end
   end
 
 
   --Alright, let's start the table by building the shared header
   --Alright, let's start the table by building the shared header
   local resultPart = {}
   local result = '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"'
  table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"')
   if isWeaponType then
   if isWeaponType then
     --Weapons have extra columns here for Attack Speed and "Two Handed?"
     --Weapons have extra columns here for Attack Speed and "Two Handed?"
     table.insert(resultPart, '\r\n!colspan="4"|')
     result = result..'\r\n!colspan="4"|'
   else
   else
     table.insert(resultPart, '\r\n!colspan="2"|')
     result = result..'\r\n!colspan="2"|'
   end
   end
   if attBonusCols > 0 then
   if attBonusCols > 0 then
     table.insert(resultPart, '\r\n!colspan="'..attBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Attack Bonus')
     result = result..'\r\n!colspan="'..attBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Attack Bonus'
   end
   end
   if strBonusCols > 0 then
   if strBonusCols > 0 then
     table.insert(resultPart, '\r\n!colspan="'..strBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Str. Bonus')
     result = result..'\r\n!colspan="'..strBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Str. Bonus'
   end
   end
   if Shared.contains(statColumns, 'magicDamageBonus') then
   if Shared.contains(statColumns, 'magicDamageBonus') then
     table.insert(resultPart, '\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|% Dmg Bonus')
     result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|% Dmg Bonus'
   end
   end
   if defBonusCols > 0 then
   if defBonusCols > 0 then
     table.insert(resultPart, '\r\n!colspan="'..defBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Defence Bonus')
     result = result..'\r\n!colspan="'..defBonusCols..'"style="padding:0 0.5em 0 0.5em;"|Defence Bonus'
   end
   end
   if Shared.contains(statColumns, 'damageReduction') then
   if Shared.contains(statColumns, 'damageReduction') then
     table.insert(resultPart, '\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|DR')
     result = result..'\r\n!colspan="1"style="padding:0 0.5em 0 0.5em;"|DR'
   end
   end
   if lvlReqCols > 0 then
   if lvlReqCols > 0 then
     table.insert(resultPart, '\r\n!colspan="'..lvlReqCols..'"style="padding:0 0.5em 0 0.5em;"|Lvl Req')
     result = result..'\r\n!colspan="'..lvlReqCols..'"style="padding:0 0.5em 0 0.5em;"|Lvl Req'
   end
   end
   if includeModifiers and includeDescription then
   if includeModifiers and includeDescription then
     table.insert(resultPart, '\r\n!colspan="3"|')
     result = result..'\r\n!colspan="3"|'
   elseif includeModifiers or includeDescription then
   elseif includeModifiers or includeDescription then
     table.insert(resultPart, '\r\n!colspan="2"|')
     result = result..'\r\n!colspan="2"|'
   else
   else
     table.insert(resultPart, '\r\n!colspan="1"|')
     result = result..'\r\n!colspan="1"|'
   end
   end
   --One header row down, one to go
   --One header row down, one to go
   table.insert(resultPart, '\r\n|-class="headerRow-1"')
   result = result..'\r\n|-class="headerRow-1"'
   table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Item')
   result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Item'
   table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Name')
   result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Name'
   --Weapons have Attack Speed here
   --Weapons have Attack Speed here
   if isWeaponType then
   if isWeaponType then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Attack Speed')
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Attack Speed'
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Two Handed?')
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Two Handed?'
   end
   end
   --Attack bonuses
   --Attack bonuses
   if Shared.contains(statColumns, 'slashAttackBonus') then
   if Shared.contains(statColumns, 'slashAttackBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'stabAttackBonus') then
   if Shared.contains(statColumns, 'stabAttackBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'blockAttackBonus') then
   if Shared.contains(statColumns, 'blockAttackBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'rangedAttackBonus') then
   if Shared.contains(statColumns, 'rangedAttackBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'magicAttackBonus') then
   if Shared.contains(statColumns, 'magicAttackBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
   end
   end
   --Strength bonuses
   --Strength bonuses
   if Shared.contains(statColumns, 'strengthBonus') then
   if Shared.contains(statColumns, 'strengthBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Strength', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'rangedStrengthBonus') then
   if Shared.contains(statColumns, 'rangedStrengthBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'magicDamageBonus') then
   if Shared.contains(statColumns, 'magicDamageBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
   end
   end
   --Defence bonuses
   --Defence bonuses
   if Shared.contains(statColumns, 'defenceBonus') then
   if Shared.contains(statColumns, 'defenceBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'rangedDefenceBonus') then
   if Shared.contains(statColumns, 'rangedDefenceBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'magicDefenceBonus') then
   if Shared.contains(statColumns, 'magicDefenceBonus') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'damageReduction') then
   if Shared.contains(statColumns, 'damageReduction') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
   end
   end
   --Level requirements
   --Level requirements
   if Shared.contains(statColumns, 'attackLevelRequired') then
   if Shared.contains(statColumns, 'attackLevelRequired') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Attack', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'defenceLevelRequired') then
   if Shared.contains(statColumns, 'defenceLevelRequired') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Defence', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'rangedLevelRequired') then
   if Shared.contains(statColumns, 'rangedLevelRequired') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Ranged', type='skill', notext='true'})
   end
   end
   if Shared.contains(statColumns, 'magicLevelRequired') then
   if Shared.contains(statColumns, 'magicLevelRequired') then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'}))
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|'..Icons.Icon({'Magic', type='skill', notext='true'})
   end
   end
   --If includeModifiers is set to 'true', add the Modifiers column
   --If includeModifiers is set to 'true', add the Modifiers column
   if includeModifiers then
   if includeModifiers then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Modifiers')
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Modifiers'
   end
   end
   --If includeDescription is set to 'true', add the Description column
   --If includeDescription is set to 'true', add the Description column
   if includeDescription then
   if includeDescription then
     table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Description')
     result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Description'
   end
   end


   --And finally Sources
   --And finally Sources
   table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Sources')
   result = result..'\r\n!style="padding:0 1em 0 0.5em;"|Sources'


  local getStatValue = function(item, statName, equipStats, levelReqs)
    if string.find(statName, '^(.+)LevelRequired$') ~= nil then
      -- Level requirement
      local skillName = Shared.titleCase(string.match(statName, '^(.+)LevelRequired$'))
      return levelReqs[skillName] or 0
    elseif Shared.contains(ItemData.EquipmentStatKeys, statName) then
      -- Equipment stat
      return equipStats[statName] or 0
    else
      -- Something else that we'll assume _getItemStat() will handle
      return Items._getItemStat(item, statName, true)
    end
  end
   table.sort(itemList, function(a, b) return a.id < b.id end)
   table.sort(itemList, function(a, b) return a.id < b.id end)
   for i, item in pairs(itemList) do
   for i, item in pairs(itemList) do
    local equipStats = Items._processEquipmentStats(item.equipmentStats)
    local levelReqs = Items._processEquipmentLevelReqs(item.equipRequirements)
     if isWeaponType then
     if isWeaponType then
       --Building rows for weapons
       --Building rows for weapons
       table.insert(resultPart, '\r\n|-')
       result = result..'\r\n|-'
       table.insert(resultPart, '\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 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
       table.insert(resultPart, '\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]')
       result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
       table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(equipStats.attackSpeed))
       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
       --That's the first list out of the way, now for 2-Handed
       table.insert(resultPart, '\r\n| style ="text-align: right;"|')
       result = result..'\r\n| style ="text-align: right;"|'
       table.insert(resultPart, Items._getItemStat(item, 'isTwoHanded') and 'Yes' or 'No')
       if item.isTwoHanded then result = result..'Yes' else result = result..'No' end
       for j, statName in pairs(statColumns) do
       for j, statName in pairs(statColumns) do
         local statValue = getStatValue(item, statName, equipStats, levelReqs)
         local statValue = Items._getItemStat(item, statName, true)
         table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;')
         result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
         if string.find(statName, '^(.+)LevelRequired$') == nil then
         if not Shared.contains(statName, 'LevelRequired') then
           if statValue > 0 then
           if statValue > 0 then
             table.insert(resultPart, 'background-color:lightgreen;')
             result = result..'background-color:lightgreen;'
           elseif statValue < 0 then
           elseif statValue < 0 then
             table.insert(resultPart, 'background-color:lightpink;')
             result = result..'background-color:lightpink;'
           end
           end
         end
         end
         table.insert(resultPart, '"|'..Shared.formatnum(statValue))
         result = result..'"|'..Shared.formatnum(statValue)
         if statName == 'magicDamageBonus' or statName == 'damageReduction' then table.insert(resultPart, '%') end
         if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
       end
       end
       --If requested, add the item Modifiers
       --If requested, add the item Modifiers
       if includeModifiers then
       if includeModifiers then
         table.insert(resultPart, '\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|')
         result = result..'\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|'
         table.insert(resultPart, Constants.getModifiersText(item.modifiers, true))
         result = result..Constants.getModifiersText(item.modifiers, true)
       end
       end
       --If requested, add description
       --If requested, add description
       if includeDescription then
       if includeDescription then
         table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
         result = result..'\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|'
         table.insert(resultPart, item.description ~= nil and item.description or '')
         result = result..(item.description ~= nil and item.description or '')
       end
       end
       --Finally, the Sources
       --Finally, the Sources
       table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |')
       result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |'
       table.insert(resultPart, ItemSourceTables._getItemSources(item))
       result = result..ItemSourceTables._getItemSources(item)
     else
     else
       --Building rows for armour
       --Building rows for armour
       table.insert(resultPart, '\r\n|-')
       result = result..'\r\n|-'
       table.insert(resultPart, '\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 0 0;"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
       table.insert(resultPart, '\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]')
       result = result..'\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]'
       for j, statName in pairs(statColumns) do
       for j, statName in pairs(statColumns) do
         local statValue = getStatValue(item, statName, equipStats, levelReqs)
         local statValue = Items._getItemStat(item, statName, true)
         table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;')
         result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0;'
         if statValue > 0 then
         if statValue > 0 then
           table.insert(resultPart, 'background-color:lightgreen;')
           result = result..'background-color:lightgreen;'
         elseif statValue < 0 then
         elseif statValue < 0 then
           table.insert(resultPart, 'background-color:lightpink;')
           result = result..'background-color:lightpink;'
         end
         end
         table.insert(resultPart, '"|'..Shared.formatnum(statValue))
         result = result..'"|'..Shared.formatnum(statValue)
         if statName == 'magicDamageBonus' or statName == 'damageReduction' then table.insert(resultPart, '%') end
         if statName == 'magicDamageBonus' or statName == 'damageReduction' then result = result..'%' end
       end
       end
       --If requested, add the item Modifiers
       --If requested, add the item Modifiers
       if includeModifiers then
       if includeModifiers then
         table.insert(resultPart, '\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|')
         result = result..'\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|'
         table.insert(resultPart, Constants.getModifiersText(item.modifiers, true))
         result = result..Constants.getModifiersText(item.modifiers, true)
       end
       end
       --If requested, add description
       --If requested, add description
       if includeDescription then
       if includeDescription then
         table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
         result = result..'\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|'
         table.insert(resultPart, item.description ~= nil and item.description or '')
         result = result..(item.description ~= nil and item.description or '')
       end
       end
       --Finally, the Sources
       --Finally, the Sources
       table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |')
       result = result..'\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |'
       table.insert(resultPart, ItemSourceTables._getItemSources(item))
       result = result..ItemSourceTables._getItemSources(item)
     end
     end
   end
   end


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


Line 267: Line 251:
   local type = args.type
   local type = args.type
   local tier = args.tier
   local tier = args.tier
   local slot = args.slot
   local slotStr = args.slot
   local ammoTypeStr = args.ammoType
   local ammoTypeStr = args.ammoType
   local category = args.category ~= nil and args.category or 'Combat'
   local category = args.category ~= nil and args.category or 'Combat'
Line 285: Line 269:
   end
   end


  --Find out what slot we're working with
  local slot = nil
  if slotStr ~= nil then
    slot = Constants.getEquipmentSlotID(slotStr)
  end
 
   local isWeaponType = Shared.contains(weaponTypes, type)
   local isWeaponType = Shared.contains(weaponTypes, type)


Line 298: Line 288:
     else
     else
       --Now for handling armour
       --Now for handling armour
      local levelReqs = Items._processEquipmentLevelReqs(item.equipRequirements)
       if type == "Armour" or type == "Melee" then
       if type == "Armour" or type == "Melee" then
         listItem = levelReqs['Defence'] ~= nil or (item.category == 'Combat' and item.type == 'Armour')
         listItem = item.defenceLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Armour')
       elseif type == "Ranged Armour" or type == "Ranged" then
       elseif type == "Ranged Armour" or type == "Ranged" then
         listItem = levelReqs['Ranged'] ~= nil or (item.category == 'Combat' and item.type == 'Ranged Armour')
         listItem = item.rangedLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Ranged Armour')
       elseif type == "Magic Armour" or type == "Magic" then
       elseif type == "Magic Armour" or type == "Magic" then
         listItem = levelReqs['Magic'] or (item.category == 'Combat' and item.type == 'Magic Armour')
         listItem = item.magicLevelRequired ~= nil or (item.category == 'Combat' and item.type == 'Magic Armour')
       else
       else
         listItem = item.type == type and item.category ~= 'Combat'
         listItem = item.type == type and item.category ~= 'Combat'
       end
       end
       if ammoType ~= nil then listItem = listItem and item.ammoType == ammoType end
       if ammoType ~= nil then listItem = listItem and item.ammoType == ammoType end
       if slot ~= nil then listItem = listItem and Shared.contains(item.validSlots, slot) end
       if slot ~= nil then listItem = listItem and item.equipmentSlot == slot end
     end
     end
     if listItem then
     if listItem then
Line 320: Line 309:


function p._getCategoryTable(style, slot, other, includeModifiers, includeDescription)
function p._getCategoryTable(style, slot, other, includeModifiers, includeDescription)
   if type(slot) == 'number' then
   if type(slot) == 'string' then
     slot = Constants.getEquipmentSlotName(slot)
     slot = Constants.getEquipmentSlotID(slot)
   end
   end


   local itemList = Items.getItems(function(item)
   local itemList = Items.getItems(function(item)
       local isMatch = true
       local isMatch = true
      local levelReqs = Items._processEquipmentLevelReqs(item.equipRequirements)
       if style == 'Melee' then
       if style == 'Melee' then
         if (levelReqs['Defence'] == nil and levelReqs['Attack'] == nil) and not Shared.contains(styleOverrides.Melee, item.name) then isMatch = false end
         if (item.defenceLevelRequired == nil and item.attackLevelRequired == nil) and not Shared.contains(styleOverrides.Melee, item.name) then isMatch = false end
       elseif style == 'Ranged' then
       elseif style == 'Ranged' then
         if levelReqs['Ranged'] == nil and not Shared.contains(styleOverrides.Ranged, item.name) then isMatch = false end
         if item.rangedLevelRequired == nil and not Shared.contains(styleOverrides.Ranged, item.name) then isMatch = false end
       elseif style == 'Magic' then
       elseif style == 'Magic' then
         if levelReqs['Magic'] == nil and not Shared.contains(styleOverrides.Magic, item.name) then isMatch = false end
         if item.magicLevelRequired == nil and not Shared.contains(styleOverrides.Magic, item.name) then isMatch = false end
       elseif style == 'None' then
       elseif style == 'None' then
         if (levelReqs['Defence'] ~= nil or levelReqs['Ranged'] ~= nil or levelReqs['Magic'] ~= nil or
         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
           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
           not Shared.contains(styleOverrides.None, item.name) then
Line 340: Line 328:
         end
         end
       end
       end
       if slot == nil or not Shared.contains(item.validSlots, slot) then isMatch = false end
 
       if slot == nil or slot ~= item.equipmentSlot then isMatch = false end


       if isMatch and other ~= nil then
       if isMatch and other ~= nil then
         if slot == 'Weapon' then --For quiver slot or weapon slot, 'other' is the ammo type
         if slot == 4 then --For quiver slot or weapon slot, 'other' is the ammo type
           if other == 'Arrows' then
           if other == 'Arrows' then
             if item.ammoTypeRequired ~= 0 then isMatch = false end
             if item.ammoTypeRequired ~= 0 then isMatch = false end
Line 349: Line 338:
             if item.ammoTypeRequired ~= 1 then isMatch = false end
             if item.ammoTypeRequired ~= 1 then isMatch = false end
           end
           end
         elseif slot == 'Quiver' then
         elseif slot == 9 then
           if other == 'Arrows' then
           if other == 'Arrows' then
             if item.ammoType ~= 0 then isMatch = false end
             if item.ammoType ~= 0 then isMatch = false end
Line 391: Line 380:


   local itemList = {}
   local itemList = {}
   local errMsg = 'ERROR: Some items not found in database: [[Category:Pages with script errors]]'
   local errMsg = 'ERROR: Some items not found in database: '
   local hasErr = false
   local hasErr = false
   for i, name in Shared.skpairs(itemNames) do
   for i, name in Shared.skpairs(itemNames) do
Line 411: Line 400:


function p.getDoubleLootTable(frame)
function p.getDoubleLootTable(frame)
  local modsDL = {
   local itemList = Items.getItems(function(item) return item.chanceToDoubleLoot ~= nil and item.chanceToDoubleLoot > 0 end)
    'increasedChanceToDoubleLootCombat',
    'decreasedChanceToDoubleLootCombat',
    'increasedChanceToDoubleLootThieving',
    'decreasedChanceToDoubleLootThieving',
    'increasedChanceToDoubleItemsGlobal',
    'decreasedChanceToDoubleItemsGlobal'
  }
  local modDetail = {}
  for i, modName in pairs(modsDL) do
    local mName, mText, mSign, mIsNeg, mValUnsigned = Constants.getModifierDetails(modName)
    modDetail[modName] = { mult = (mSign == "+" and 1 or -1) }
  end
 
   local itemList = Items.getItems(function(item)
      if item.modifiers ~= nil then
        for modName, val in pairs(item.modifiers) do
          if Shared.contains(modsDL, modName) then return true end
        end
        return false
      end
    end)
   table.sort(itemList, function(a, b) return a.id < b.id end)
   table.sort(itemList, function(a, b) return a.id < b.id end)
   local result = '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"'
   local result = '{| class="wikitable sortable stickyHeader"\r\n|-class="headerRow-0"'
   result = result..'\r\n!colspan="2"|Name!!Bonus!!Description!!Sources'
   result = result..'\r\n!colspan="2"|Name!!Bonus!!Description!!Sources'
   for i, item in Shared.skpairs(itemList) do
   for i, item in Shared.skpairs(itemList) do
    local lootValue = 0
    for modName, modDet in pairs(modDetail) do
      lootValue = lootValue + (item.modifiers[modName] or 0) * modDet.mult
    end
     result = result..'\r\n|-'
     result = result..'\r\n|-'
     result = result..'\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
     result = result..'\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='item', size=50, notext=true})
     result = result..'||[['..item.name..']]'
     result = result..'||[['..item.name..']]'
     result = result..'||style ="text-align: right;" data-sort-value="'..lootValue..'"|'..lootValue..'%'
     result = result..'||style ="text-align: right;" data-sort-value="'..item.chanceToDoubleLoot..'"|'..item.chanceToDoubleLoot..'%'
     result = result..'||'..item.description
     result = result..'||'..item.description
     result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |'
     result = result..'\r\n| style ="text-align: right;white-space: nowrap;padding: 0 0.5em 0 0.5em;" |'
Line 460: Line 424:
   if rowCount == nil then rowCount = 200 end
   if rowCount == nil then rowCount = 200 end
   if type(rowCount) == 'string' then rowCount = tonumber(rowCount) end
   if type(rowCount) == 'string' then rowCount = tonumber(rowCount) end
 
 
   local rowResult = {}
   local rowResult = {}
   for i = startID, startID + rowCount - 1, 1 do
   for i = startID, startID + rowCount - 1, 1 do
Line 491: Line 455:


   --Unfortunately just gonna have to manually check all the changes I think...
   --Unfortunately just gonna have to manually check all the changes I think...
  local itemStats = {
    { Stat = Items._processEquipmentStats(item1.equipmentStats), Level = Items._processEquipmentLevelReqs(item1.equipRequirements), SlayBon = Items._getItemModifier(item1, 'increasedSkillXP', 'Slayer') },
    { Stat = Items._processEquipmentStats(item2.equipmentStats), Level = Items._processEquipmentLevelReqs(item2.equipRequirements), SlayBon = Items._getItemModifier(item2, 'increasedSkillXP', 'Slayer') },
  }
   local attBon1 = item1.attackBonus ~= nil and item1.attackBonus or {0, 0, 0}
   local attBon1 = item1.attackBonus ~= nil and item1.attackBonus or {0, 0, 0}
   local attBon2 = item2.attackBonus ~= nil and item2.attackBonus or {0, 0, 0}
   local attBon2 = item2.attackBonus ~= nil and item2.attackBonus or {0, 0, 0}
   getSpecificStatString(itemStats[1]['Stat']['stabAttackBonus'], itemStats[2]['Stat']['stabAttackBonus'], '{V} '..Icons.Icon({'Melee', notext=true})..' Stab Bonus')
   getSpecificStatString(attBon1[1], attBon2[1], '{V} '..Icons.Icon({'Melee', notext=true})..' Stab Bonus')
   getSpecificStatString(itemStats[1]['Stat']['slashAttackBonus'], itemStats[2]['Stat']['slashAttackBonus'], '{V} '..Icons.Icon({'Melee', notext=true})..' Slash Bonus')
   getSpecificStatString(attBon1[2], attBon2[2], '{V} '..Icons.Icon({'Melee', notext=true})..' Slash Bonus')
   getSpecificStatString(itemStats[1]['Stat']['blockAttackBonus'], itemStats[2]['Stat']['blockAttackBonus'], '{V} '..Icons.Icon({'Melee', notext=true})..' Block Bonus')
   getSpecificStatString(attBon1[3], attBon2[3], '{V} '..Icons.Icon({'Melee', notext=true})..' Block Bonus')


   getSpecificStatString(itemStats[1]['Stat']['meleeStrengthBonus'], itemStats[2]['Stat']['meleeStrengthBonus'], '{V} '..Icons.Icon({'Strength', type='skill', notext=true})..' Strength Bonus')
   getSpecificStatString(item1.strengthBonus, item2.strengthBonus, '{V} '..Icons.Icon({'Strength', type='skill', notext=true})..' Strength Bonus')
   getSpecificStatString(itemStats[1]['Stat']['rangedStrengthBonus'], itemStats[2]['Stat']['rangedStrengthBonus'], '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Strength Bonus')
   getSpecificStatString(item1.rangedStrengthBonus, item2.rangedStrengthBonus, '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Strength Bonus')
   getSpecificStatString(itemStats[1]['Stat']['magicStrengthBonus'], itemStats[2]['Stat']['magicStrengthBonus'], '{V}% '..Icons.Icon({'Magic', type='skill', notext=true})..' Damage Bonus')
   getSpecificStatString(item1.magicDamageBonus, item2.magicDamageBonus, '{V}% '..Icons.Icon({'Magic', type='skill', notext=true})..' Damage Bonus')


   getSpecificStatString(itemStats[1]['Stat']['meleeDefenceBonus'], itemStats[2]['Stat']['meleeDefenceBonus'], '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Defence Bonus')
   getSpecificStatString(item1.defenceBonus, item2.defenceBonus, '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Defence Bonus')
   getSpecificStatString(itemStats[1]['Stat']['rangedDefenceBonus'], itemStats[2]['Stat']['rangeDefenceBonus'], '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus')
   getSpecificStatString(item1.rangedDefenceBonus, item2.rangedDefenceBonus, '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus')
   getSpecificStatString(itemStats[1]['Stat']['magicDefenceBonus'], itemStats[2]['Stat']['magicDefenceBonus'], '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Defence Bonus')
   getSpecificStatString(item1.magicDefenceBonus, item2.magicDefenceBonus, '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Defence Bonus')
   getSpecificStatString(itemStats[1]['Stat']['damageReduction'], itemStats[2]['Stat']['damageReduction'], '{V}% Damage Reduction')
   getSpecificStatString(item1.damageReduction, item2.damageReduction, '{V}% Damage Reduction')


   getSpecificStatString(itemStats[1]['SlayBon'], itemStats[2]['SlayBon'], '{V}% '..Icons.Icon({'Slayer', type='skill', notext=true})..' Bonus XP')
   local SlayBon1 = Items._getItemModifier(item1, 'increasedSkillXP', 'Slayer')
  local SlayBon2 = Items._getItemModifier(item2, 'increasedSkillXP', 'Slayer')
  getSpecificStatString(SlayBon1, SlayBon2, '{V}% '..Icons.Icon({'Slayer', type='skill', notext=true})..' Bonus XP')


   getSpecificStatString(itemStats[1]['Level']['Attack'], itemStats[2]['Level']['Attack'], '{V} '..Icons.Icon({'Attack', type='skill', notext=true})..' Level Required')
   getSpecificStatString(item1.attackLevelRequired, item1.attackLevelRequired, '{V} '..Icons.Icon({'Attack', type='skill', notext=true})..' Level Required')
   getSpecificStatString(itemStats[1]['Level']['Defence'], itemStats[2]['Level']['Defence'], '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Level Required')
   getSpecificStatString(item1.defenceLevelRequired, item1.defenceLevelRequired, '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Level Required')
   getSpecificStatString(itemStats[1]['Level']['Ranged'], itemStats[2]['Level']['Ranged'], '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Level Required')
   getSpecificStatString(item1.rangedLevelRequired, item1.rangedLevelRequired, '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Level Required')
   getSpecificStatString(itemStats[1]['Level']['Magic'], itemStats[2]['Level']['Magic'], '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Level Required')
   getSpecificStatString(item1.magicLevelRequired, item1.magicLevelRequired, '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Level Required')


   return table.concat(changeArray, '<br/>')
   return table.concat(changeArray, '<br/>')
Line 528: Line 490:
     itemArray = Items.getItems(function(item) return Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil end)
     itemArray = Items.getItems(function(item) return Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil end)
   elseif string.upper(category) == 'OTHER' then
   elseif string.upper(category) == 'OTHER' then
     itemArray = Items.getItems(function(item)
     itemArray = Items.getItems(function(item)  
           return not Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil and item.validSlots == nil
           return not Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil and item.equipmentSlot == nil
         end)
         end)
   else
   else
     if Constants.getEquipmentSlotID(category) == nil then
     local equipSlot = Constants.getEquipmentSlotID(category)
    if equipSlot == nil then
       return 'ERROR: Invalid option. Choose either an equipment slot, Potion, or Other[[Category:Pages with script errors]]'
       return 'ERROR: Invalid option. Choose either an equipment slot, Potion, or Other[[Category:Pages with script errors]]'
     end
     end
     isEquipment = true
     isEquipment = true
     itemArray = Items.getItems(function(item)
     itemArray = Items.getItems(function(item)  
           return item.itemsRequired ~= nil and Shared.contains(item.validSlots, category)
           return item.itemsRequired ~= nil and item.equipmentSlot == equipSlot
         end)
         end)
   end
   end
Line 557: Line 520:
       table.insert(matArray, Icons.Icon({mat.name, type='item', qty=row[2]}))
       table.insert(matArray, Icons.Icon({mat.name, type='item', qty=row[2]}))


       if item.validSlots ~= nil and mat.validSlots ~= nil and statChangeString == '' then
       if item.equipmentSlot ~= nil and mat.equipmentSlot ~= nil and statChangeString == '' then
         statChangeString = p.getStatChangeString(item, mat)
         statChangeString = p.getStatChangeString(item, mat)
       end
       end