Module:Items: Difference between revisions

1,637 bytes added ,  1 October 2020
Added some categories
(Removed mastery requirement when it's level 0)
(Added some categories)
Line 399: Line 399:
    
    
   return p._getCreationTable(item)
   return p._getCreationTable(item)
end
function p.getEquipmentSlotName(id)
  for slotName, i in Shared.skpairs(Constants.equipmentSlot) do
    if i == id then
      return slotName
    end
  end
  return 'Invalid'
end
end


Line 405: Line 414:
   --For equipment, show the slot they go in
   --For equipment, show the slot they go in
   if item.equipmentSlot ~= nil then
   if item.equipmentSlot ~= nil then
     for slotName, i in Shared.skpairs(Constants.equipmentSlot) do
     result = result..'\r\n|-\r\n|Equipment Slot: '..p.getEquipmentSlotName(item.equipmentSlot)
      if i == item.equipmentSlot then
        result = result..'\r\n|-\r\n|Equipment Slot: '..slotName
        break
      end
    end
   end
   end
   --For weapons with a special attack, show the details
   --For weapons with a special attack, show the details
Line 444: Line 448:
end
end


function p._getItemSources(item, asList)
function p._getItemSources(item, asList, addCategories)
   local result = nil
   local result = nil
   local lineArray = {}
   local lineArray = {}
  local categoryArray = {}


   --Alright, time to go through all the ways you can get an item...
   --Alright, time to go through all the ways you can get an item...
Line 507: Line 512:
           upgradeStr = upgradeStr..Icons.Icon({item2.name, type="item", notext="true"})
           upgradeStr = upgradeStr..Icons.Icon({item2.name, type="item", notext="true"})
         else
         else
          table.insert(categoryArray, '[[Category:Upgraded Items]]')
           upgradeStr = upgradeStr..'Upgrading: '..Icons.Icon({item2.name, type="item", notext="true"})
           upgradeStr = upgradeStr..'Upgrading: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
Line 514: Line 520:
           cookStr = cookStr..','..Icons.Icon({item2.name, type="item", notext="true"})
           cookStr = cookStr..','..Icons.Icon({item2.name, type="item", notext="true"})
         else
         else
          table.insert(categoryArray, '[[Category:Cooked Items]]')
           cookStr = cookStr..'Cooking: '..Icons.Icon({item2.name, type="item", notext="true"})
           cookStr = cookStr..'Cooking: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
Line 521: Line 528:
           burnStr = burnStr..','..Icons.Icon({item2.name, type="item", notext="true"})
           burnStr = burnStr..','..Icons.Icon({item2.name, type="item", notext="true"})
         else
         else
          table.insert(categoryArray, '[[Category:Burnt Items]]')
           burnStr = burnStr..'Burning: '..Icons.Icon({item2.name, type="item", notext="true"})
           burnStr = burnStr..'Burning: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
Line 528: Line 536:
           growStr = growStr..','..Icons.Icon({item2.name, type="item", notext="true"})
           growStr = growStr..','..Icons.Icon({item2.name, type="item", notext="true"})
         else
         else
          table.insert(categoryArray, '[[Category:Harvestable Items]]')
           growStr = growStr..'Growing: '..Icons.Icon({item2.name, type="item", notext="true"})
           growStr = growStr..'Growing: '..Icons.Icon({item2.name, type="item", notext="true"})
         end
         end
Line 671: Line 680:
     result = '<div style="max-width:180px;text-align:right">'..result..'</div>'
     result = '<div style="max-width:180px;text-align:right">'..result..'</div>'
   end
   end
  if addCategories then result = result..table.concat(categoryArray, '') end
   return result
   return result
end
end
Line 679: Line 689:
   local item = p.getItem(itemName)
   local item = p.getItem(itemName)
   local asList = false
   local asList = false
  local addCategories = false
   if frame.args ~= nil then  
   if frame.args ~= nil then  
     asList = frame.args.asList ~= nil and frame.args.asList ~= '' and frame.args.asList ~= 'false'
     asList = frame.args.asList ~= nil and frame.args.asList ~= '' and frame.args.asList ~= 'false'
    addCategories = frame.args.addCategories ~= nil and frame.args.addCategories ~= '' and frame.args.addCategories ~= 'false'
   end
   end
   if item == nil then
   if item == nil then
Line 686: Line 698:
   end
   end


   return p._getItemSources(item, asList)
   return p._getItemSources(item, asList, addCategories)
end
end


Line 734: Line 746:
}
}


function p._getItemUses(item)
function p._getItemUses(item, addCategories)
   local useArray = {}
   local useArray = {}
  local categoryArray = {}
   --Another fun one. This time getting all the different possible ways an item can be used
   --Another fun one. This time getting all the different possible ways an item can be used


Line 745: Line 758:
   --First things added to the list are non-skill things that are easy to check
   --First things added to the list are non-skill things that are easy to check
   if item.equipmentSlot ~= nil or Shared.contains(itemUseArray.Combat, item.name) then
   if item.equipmentSlot ~= nil or Shared.contains(itemUseArray.Combat, item.name) then
    if item.equipmentSlot ~= nil then
      table.insert(categoryArray, '[[Category:'..p.getEquipmentSlotName(item.equipmentSlot)..' Slot Items]]')
    end
     table.insert(useArray, '* '..Icons.Icon({'Combat'}))
     table.insert(useArray, '* '..Icons.Icon({'Combat'}))
   end
   end
   if item.healsFor ~= nil then
   if item.healsFor ~= nil then
    table.insert(categoryArray, '[[Category:Food Items]]')
     table.insert(useArray, '* [[Food]]')
     table.insert(useArray, '* [[Food]]')
   end
   end
   if item.dropTable ~= nil then
   if item.dropTable ~= nil then
    table.insert(categoryArray, '[[Category:Openable Items]]')
     table.insert(useArray, '* [[Chest Drop Tables|Can Be Opened]]')  
     table.insert(useArray, '* [[Chest Drop Tables|Can Be Opened]]')  
   end
   end
Line 811: Line 829:
   end
   end
   if canUpgrade then
   if canUpgrade then
    if item.canUpgrade or (item.type == 'Armour' and item.canUpgrade == nil) then
      table.insert(categoryArray, '[[Category:Upgradeable Items]]')
    end
     table.insert(useArray, '* [[Upgrading Items]]')
     table.insert(useArray, '* [[Upgrading Items]]')
   end
   end
Line 848: Line 869:
   --Prayer
   --Prayer
   if item.prayerPoints ~= nil or Shared.contains(itemUseArray.Prayer, item.name) then
   if item.prayerPoints ~= nil or Shared.contains(itemUseArray.Prayer, item.name) then
    if item.prayerPoints ~= nil then table.insert(categoryArray, '[[Category:Buriable Items]]') end
     table.insert(useArray, '* '..Icons.Icon({'Prayer', type='skill'}))
     table.insert(useArray, '* '..Icons.Icon({'Prayer', type='skill'}))
   end
   end
Line 891: Line 913:
     table.insert(useArray, '* '..Icons.Icon({skillName, type='skill'}))
     table.insert(useArray, '* '..Icons.Icon({skillName, type='skill'}))
   end
   end
  if Shared.contains(item.name, 'Skillcape') then table.insert(categoryArray, '[[Category:Skillcapes]]') end


   --Special note for Charge Stone of Rhaelyx
   --Special note for Charge Stone of Rhaelyx
Line 897: Line 921:
   end
   end


   return table.concat(useArray,'\r\n')
   local result = table.concat(useArray,'\r\n')
  if addCategories then result = result..table.concat(categoryArray, '') end
  return result
end
end


Line 903: Line 929:
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local item = p.getItem(itemName)
   local item = p.getItem(itemName)
  local addCategories = false
  if frame.args ~= nil then
    addCategories = frame.args.addCategories ~= nil and frame.args.addCategories ~= '' and frame.args.addCategories ~= 'false'
  end
   if item == nil then
   if item == nil then
     return "ERROR: No item named "..itemName.." exists in the data module"
     return "ERROR: No item named "..itemName.." exists in the data module"
   end
   end


   return p._getItemUses(item)
   return p._getItemUses(item, addCategories)
end
end