Module:Sandbox/AuronTest/ComparisonTables: Difference between revisions

m
Revert to previous revision
mNo edit summary
m (Revert to previous revision)
Line 30: Line 30:
   end
   end


   local firstItem = Items.getItemByID(itemList[1])
   local isWeaponType = itemList[1].validSlots ~= nil and Shared.contains(itemList[1].validSlots, 'Weapon') and Shared.contains(weaponTypes, itemList[1].type)
 
  local isWeaponType = firstItem.validSlots ~= nil and Shared.contains(firstItem.validSlots, 'Weapon') and Shared.contains(weaponTypes, firstItem.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)
   local ignoreColumns = Shared.clone(statColumns)
   local ignoreColumns = Shared.clone(statColumns)
   for i, itemID in pairs(itemList) do
   for i, item in pairs(itemList) do
     local ndx = 1
     local ndx = 1
     while Shared.tableCount(ignoreColumns) >= ndx do
     while Shared.tableCount(ignoreColumns) >= ndx do
       if Items._getItemStat(ItemData.Items[itemID + 1], ignoreColumns[ndx], true) ~= 0 then
       if Items._getItemStat(item, ignoreColumns[ndx], true) ~= 0 then
         table.remove(ignoreColumns, ndx)
         table.remove(ignoreColumns, ndx)
       else
       else
Line 173: Line 171:
   table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Sources')
   table.insert(resultPart, '\r\n!style="padding:0 1em 0 0.5em;"|Sources')


   table.sort(itemList, function(a, b) return a < b end)
   table.sort(itemList, function(a, b) return a.id < b.id end)
   for i, itemID in pairs(itemList) do
   for i, item in pairs(itemList) do
    local item = ItemData.Items[itemID + 1]
     if isWeaponType then
     if isWeaponType then
       --Building rows for weapons
       --Building rows for weapons
       table.insert(resultPart, '\r\n|-')
       table.insert(resultPart, '\r\n|-')
       table.insert(resultPart, '\r\n|style="text-align: left;"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
       table.insert(resultPart, '\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;"|[['..item.name..']]')
       table.insert(resultPart, '\r\n|style ="text-align: left;padding: 0 0.5em 0 0.5em;"|[['..item.name..']]')
       table.insert(resultPart, '\r\n| style="text-align: right;" |'..Shared.formatnum(Items._getItemStat(item, 'attackSpeed', true)))
       table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;" |'..Shared.formatnum(Items._getItemStat(item, 'attackSpeed', true)))
       --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;"|')
       table.insert(resultPart, '\r\n| style ="text-align: right;"|')
Line 187: Line 184:
       for j, statName in pairs(statColumns) do
       for j, statName in pairs(statColumns) do
         local statValue = Items._getItemStat(item, statName, true)
         local statValue = Items._getItemStat(item, statName, true)
         table.insert(resultPart, '\r\n|style ="text-align: right;')
         table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0;')
         if string.find(statName, '^(.+)LevelRequired$') == nil then
         if string.find(statName, '^(.+)LevelRequired$') == nil then
           if statValue > 0 then
           if statValue > 0 then
Line 200: Line 197:
       --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;"|')
         table.insert(resultPart, '\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|')
         table.insert(resultPart, Constants.getModifiersText(item.modifiers, true))
         table.insert(resultPart, 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;"|')
         table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
         table.insert(resultPart, item.description ~= nil and item.description or '')
         table.insert(resultPart, item.description ~= nil and item.description or '')
       end
       end
       --Finally, the Sources
       --Finally, the Sources
       table.insert(resultPart, '\r\n| style="text-align: right;" |')
       table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |')
       table.insert(resultPart, ItemSourceTables._getItemSources(item))
       table.insert(resultPart, ItemSourceTables._getItemSources(item))
     else
     else
       --Building rows for armour
       --Building rows for armour
       table.insert(resultPart, '\r\n|-')
       table.insert(resultPart, '\r\n|-')
       table.insert(resultPart, '\r\n|style="text-align: left;"|'..Icons.Icon({item.name, type='item', size=50, notext=true}))
       table.insert(resultPart, '\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;"|[['..item.name..']]')
       table.insert(resultPart, '\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 = Items._getItemStat(item, statName, true)
         local statValue = Items._getItemStat(item, statName, true)
         table.insert(resultPart, '\r\n| style="text-align: right;')
         table.insert(resultPart, '\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;')
           table.insert(resultPart, 'background-color:lightgreen;')
Line 229: Line 226:
       --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;"|')
         table.insert(resultPart, '\r\n|style="text-align:left;white-space:nowrap;padding:0 0.5em 0 0.5em;"|')
         table.insert(resultPart, Constants.getModifiersText(item.modifiers, true))
         table.insert(resultPart, 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;"|')
         table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
         table.insert(resultPart, item.description ~= nil and item.description or '')
         table.insert(resultPart, item.description ~= nil and item.description or '')
       end
       end
       --Finally, the Sources
       --Finally, the Sources
       table.insert(resultPart, '\r\n| style ="text-align: right;" |')
       table.insert(resultPart, '\r\n| style ="text-align: right;padding: 0 0.5em 0 0.5em;" |')
       table.insert(resultPart, ItemSourceTables._getItemSources(item))
       table.insert(resultPart, ItemSourceTables._getItemSources(item))
     end
     end
Line 273: Line 270:
   --Now we need to figure out which items are in this list
   --Now we need to figure out which items are in this list
   local itemList = {}
   local itemList = {}
   for i, item in pairs(ItemData.Items) do
   for i, itemBase in pairs(ItemData.Items) do
    local item = Shared.clone(itemBase)
    item.id = i - 1
     local listItem = false
     local listItem = false
     if isWeaponType then
     if isWeaponType then
Line 293: Line 292:
     end
     end
     if listItem then
     if listItem then
       table.insert(itemList, item.id)
       table.insert(itemList, item)
     end
     end
   end
   end
Line 306: Line 305:


   local itemList = Items.getItems(function(item)
   local itemList = Items.getItems(function(item)
       local isMatch = item.isEquipment
       local isMatch = true
       if isMatch then
       if style == 'Melee' then
        if style == 'Melee' then
        if (Items._getItemStat(item, 'defenceLevelRequired') == nil and Items._getItemStat(item, 'attackLevelRequired') == nil) and not Shared.contains(styleOverrides.Melee, item.name) then isMatch = false end
          if (Items._getItemStat(item, 'defenceLevelRequired') == nil and Items._getItemStat(item, 'attackLevelRequired') == nil) and not Shared.contains(styleOverrides.Melee, item.name) then isMatch = false end
      elseif style == 'Ranged' then
        elseif style == 'Ranged' then
        if Items._getItemStat(item, 'rangedLevelRequired') == nil and not Shared.contains(styleOverrides.Ranged, item.name) then isMatch = false end
          if Items._getItemStat(item, 'rangedLevelRequired') == nil and not Shared.contains(styleOverrides.Ranged, item.name) then isMatch = false end
      elseif style == 'Magic' then
        elseif style == 'Magic' then
        if Items._getItemStat(item, 'magicLevelRequired') == nil and not Shared.contains(styleOverrides.Magic, item.name) then isMatch = false end
          if Items._getItemStat(item, 'magicLevelRequired') == nil and not Shared.contains(styleOverrides.Magic, item.name) then isMatch = false end
      elseif style == 'None' then
        elseif style == 'None' then
        if (Items._getItemStat(item, 'defenceLevelRequired') ~= nil or Items._getItemStat(item, 'rangedLevelRequired') ~= nil or Items._getItemStat(item, 'magicLevelRequired') ~= nil or
          if (Items._getItemStat(item, 'defenceLevelRequired') ~= nil or Items._getItemStat(item, 'rangedLevelRequired') ~= nil or Items._getItemStat(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
          isMatch = false
            isMatch = false
          end
         end
         end
        if slot == nil or not Shared.contains(item.validSlots, slot) then isMatch = false end
      end
      if slot == nil or not Shared.contains(item.validSlots, slot) 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 == 'Weapon' 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
            elseif other == 'Bolts' then
          elseif other == 'Bolts' then
              if item.ammoTypeRequired ~= 1 then isMatch = false end
            if item.ammoTypeRequired ~= 1 then isMatch = false end
            end
          end
          elseif slot == 'Quiver' then
        elseif slot == 'Quiver' 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
            elseif other == 'Bolts' then
          elseif other == 'Bolts' then
              if item.ammoType ~= 1 then isMatch = false end
            if item.ammoType ~= 1 then isMatch = false end
            elseif other == 'Javelins' then
          elseif other == 'Javelins' then
              if item.ammoType ~= 2 then isMatch = false end
            if item.ammoType ~= 2 then isMatch = false end
            elseif other == 'Throwing Knives' then
          elseif other == 'Throwing Knives' then
              if item.ammoType ~= 3 then isMatch = false end
            if item.ammoType ~= 3 then isMatch = false end
            elseif other == 'Thrown' then
          elseif other == 'Thrown' then
              if item.ammoType ~= 2 and item.ammoType ~= 3 then isMatch = false end
            if item.ammoType ~= 2 and item.ammoType ~= 3 then isMatch = false end
            end
           end
           end
         end
         end
Line 347: Line 344:


       return isMatch
       return isMatch
     end, true)
     end)


   return p._getEquipmentTable(itemList, includeModifiers, includeDescription)
   return p._getEquipmentTable(itemList, includeModifiers, includeDescription)
Line 381: Line 378:
       hasErr = true
       hasErr = true
     else
     else
       table.insert(itemList, nextItem.id)
       table.insert(itemList, nextItem)
     end
     end
   end
   end
Line 476: Line 473:


   --Unfortunately just gonna have to manually check all the changes I think...
   --Unfortunately just gonna have to manually check all the changes I think...
   getSpecificStatString(Items._getItemStat(item1, 'stabAttackBonus'), Items._getItemStat(item2, 'stabAttackBonus'), '{V} '..Icons.Icon({'Melee', notext=true})..' Stab Bonus')
   local statList = {
  getSpecificStatString(Items._getItemStat(item1, 'slashAttackBonus'), Items._getItemStat(item2, 'slashAttackBonus'), '{V} '..Icons.Icon({'Melee', notext=true})..' Slash Bonus')
    -- {'statName', 'statDescription'}
  getSpecificStatString(Items._getItemStat(item1, 'blockAttackBonus'), Items._getItemStat(item2, 'blockAttackBonus'), '{V} '..Icons.Icon({'Melee', notext=true})..' Block Bonus')
    {'stabAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Stab Bonus'},
 
    {'slashAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Slash Bonus'},
  getSpecificStatString(Items._getItemStat(item1, 'meleeStrengthBonus'), Items._getItemStat(item2, 'meleeStrengthBonus'), '{V} '..Icons.Icon({'Strength', type='skill', notext=true})..' Strength Bonus')
    {'blockAttackBonus', '{V} '..Icons.Icon({'Melee', notext=true})..' Block Bonus'},
  getSpecificStatString(Items._getItemStat(item1, 'rangedStrengthBonus'), Items._getItemStat(item2, 'rangedStrengthBonus'), '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Strength Bonus')
    {'meleeStrengthBonus', '{V} '..Icons.Icon({'Strength', type='skill', notext=true})..' Strength Bonus'},
  getSpecificStatString(Items._getItemStat(item1, 'magicStrengthBonus'), Items._getItemStat(item2, 'magicStrengthBonus'), '{V}% '..Icons.Icon({'Magic', type='skill', notext=true})..' Damage Bonus')
    {'rangedStrengthBonus', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Strength Bonus'},
 
    {'magicStrengthBonus', '{V}% '..Icons.Icon({'Magic', type='skill', notext=true})..' Damage Bonus'},
  getSpecificStatString(Items._getItemStat(item1, 'meleeDefenceBonus'), Items._getItemStat(item2, 'meleeDefenceBonus'), '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Defence Bonus')
    {'meleeDefenceBonus', '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Defence Bonus'},
  getSpecificStatString(Items._getItemStat(item1, 'rangedDefenceBonus'), Items._getItemStat(item2, 'rangedDefenceBonus'), '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus')
    {'rangedDefenceBonus', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus'},
  getSpecificStatString(Items._getItemStat(item1, 'magicDefenceBonus'), Items._getItemStat(item2, 'magicDefenceBonus'), '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Defence Bonus')
    {'magicDefenceBonus', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Defence Bonus'},
  getSpecificStatString(Items._getItemStat(item1, 'damageReduction'), Items._getItemStat(item2, 'damageReduction'), '{V}% Damage Reduction')
    {'damageReduction', '{V}% Damage Reduction'},
 
    {'increasedSlayerXP', '{V}% '..Icons.Icon({'Slayer', type='skill', notext=true})..' Bonus XP'},
  getSpecificStatString(Items._getItemModifier(item1, 'increasedSkillXP', 'Slayer'), Items._getItemModifier(item2, 'increasedSkillXP', 'Slayer'), '{V}% '..Icons.Icon({'Slayer', type='skill', notext=true})..' Bonus XP')
    {'attackLevelRequired', '{V} '..Icons.Icon({'Attack', type='skill', notext=true})..' Level Required'},
 
    {'defenceLevelRequired', '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Level Required'},
  getSpecificStatString(Items._getItemStat(item1, 'attackLevelRequired'), Items._getItemStat(item2, 'attackLevelRequired'), '{V} '..Icons.Icon({'Attack', type='skill', notext=true})..' Level Required')
    {'rangedLevelRequired', '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Level Required'},
  getSpecificStatString(Items._getItemStat(item1, 'defenceLevelRequired'), Items._getItemStat(item2, 'defenceLevelRequired'), '{V} '..Icons.Icon({'Defence', type='skill', notext=true})..' Level Required')
    {'magicLevelRequired', '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Level Required'},
  getSpecificStatString(Items._getItemStat(item1, 'rangedLevelRequired'), Items._getItemStat(item2, 'rangedLevelRequired'), '{V} '..Icons.Icon({'Ranged', type='skill', notext=true})..' Level Required')
  }
  getSpecificStatString(Items._getItemStat(item1, 'magicLevelRequired'), Items._getItemStat(item2, 'magicLevelRequired'), '{V} '..Icons.Icon({'Magic', type='skill', notext=true})..' Level Required')
  for i, stat in ipairs(statList) do
    if stat[1] == 'increasedSlayerXP' then
      getSpecificStatString(Items._getItemModifier(item1, stat[1], 'Slayer'), Items._getItemModifier(item2, stat[1], 'Slayer'), stat[2])
    else
      getSpecificStatString(Items._getItemStat(item1, stat[1]), Items._getItemStat(item2, stat[1]), stat[2])
    end
  end


   return table.concat(changeArray, '<br/>')
   return table.concat(changeArray, '<br/>')
Line 553: Line 556:
   table.insert(resultPart, '\r\n|}')
   table.insert(resultPart, '\r\n|}')
   return table.concat(resultPart)
   return table.concat(resultPart)
end
function p.EquipTest()
  local funcCalls = {
    {'Melee', 'Helmet'},
    {'Ranged', 'Helmet'},
    {'Magic', 'Helmet'},
    {'None', 'Helmet', includeDescription = 'true'},
    {'Melee', 'Platebody'},
    {'Ranged', 'Platebody'},
    {'Magic', 'Platebody'},
    {'None', 'Platebody', includeDescription = 'true'},
    {'Melee', 'Platelegs'},
    {'Ranged', 'Platelegs'},
    {'Magic', 'Platelegs'},
    {'None', 'Platelegs', includeDescription = 'true'},
    {'Melee', 'Boots'},
    {'Ranged', 'Boots'},
    {'Magic', 'Boots'},
    {'None', 'Boots', includeDescription = 'true'},
    {'Melee', 'Gloves'},
    {'Ranged', 'Gloves'},
    {'Magic', 'Gloves'},
    {'None', 'Gloves', includeDescription = 'true'},
    {'All', 'Cape', includeDescription = 'true'},
    {'All', 'Quiver', 'Arrows'},
    {'All', 'Quiver', 'Bolts'},
    {'All', 'Ring', includeModifiers = 'true'},
    {'All', 'Amulet', includeDescription = 'true'},
    {'Melee', 'Shield'},
    {'Ranged', 'Shield'},
    {'Magic', 'Shield'},
    {'None', 'Shield', includeDescription = 'true'},
    {'Melee', 'Weapon'},
    {'Ranged', 'Weapon', 'Arrows'},
    {'Ranged', 'Weapon', 'Bolts'},
    {'Ranged', 'Weapon', 'Javelins'},
    {'Ranged', 'Weapon', 'Knives'},
    {'Magic', 'Weapon'}
  }
  local funcResult = {}
  for i, args in ipairs(funcCalls) do
    mw.log('Calling with args: ' .. mw.dumpObject(args))
    local res = p.getCategoryTable({args=args})
    mw.log('Result has len ' .. Shared.formatnum(string.len(res)))
    table.insert(funcResult, res)
  end
  return 'Done, ' .. #funcResult .. ' calls'
end
end


return p
return p