Anonymous

Module:Items/UseTables: Difference between revisions

From Melvor Idle
(Hopefully) fixed issue with items not including Agility Obstacles as a use if no other uses existed
(Trying a slightly different format to hopefully fix a lack of linebreaks that's happening on FEZ use table for some reason.)
((Hopefully) fixed issue with items not including Agility Obstacles as a use if no other uses existed)
(15 intermediate revisions by the same user not shown)
Line 4: Line 4:
local ItemData = mw.loadData('Module:Items/data')
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')
local SkillData = mw.loadData('Module:Skills/data')
local Constants = mw.loadData('Module:Constants/data')


local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Magic = require('Module:Magic')
local Magic = require('Module:Magic')
Line 11: Line 11:
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Agility = require('Module:Skills/Agility')
local Shop = require('Module:Shop')




--Brute forcing some item uses to make things easier
--Brute forcing some item uses to make things easier
local itemUseArray = {
local itemUseArray = {
  Agility = {},
   Combat = {},
   Combat = {},
   Cooking = {'Cooking Gloves', 'Crown of Rhaelyx'},
   Cooking = {'Cooking Gloves', 'Crown of Rhaelyx'},
Line 28: Line 31:
   Slayer = {},
   Slayer = {},
   Smithing = {'Smithing Gloves', 'Crown of Rhaelyx'},
   Smithing = {'Smithing Gloves', 'Crown of Rhaelyx'},
   Thieving = {'Chapeau Noir', 'Thieving Gloves'},
   Thieving = {'Chapeau Noir', 'Thieving Gloves', 'Gloves of Silence'},
   Woodcutting = {},
   Woodcutting = {},
   }
   }
Line 56: Line 59:
   [22] = 'Combat',
   [22] = 'Combat',
   [23] = 'Combat',
   [23] = 'Combat',
  [24] = 'Agility'
}
}


function p._getItemUses(item, addCategories)
function p._getItemUses(item, asList, addCategories)
   local useArray = {}
   local useArray = {}
   local categoryArray = {}
   local categoryArray = {}
  local chr = asList and '* ' or ''
   --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 73: Line 78:
       --table.insert(categoryArray, '[[Category:'..Items.getEquipmentSlotName(item.equipmentSlot)..' Slot Items]]')  
       --table.insert(categoryArray, '[[Category:'..Items.getEquipmentSlotName(item.equipmentSlot)..' Slot Items]]')  
     end
     end
     table.insert(useArray, '* '..Icons.Icon({'Combat'}))
     table.insert(useArray, chr..Icons.Icon({'Combat'}))
   end
   end
   if item.healsFor ~= nil then
   if item.healsFor ~= nil then
     table.insert(categoryArray, '[[Category:Food Items]]')
     table.insert(categoryArray, '[[Category:Food Items]]')
     table.insert(useArray, '* [[Food]]')
     table.insert(useArray, chr..'[[Food]]')
   end
   end
   if item.dropTable ~= nil then
   if item.dropTable ~= nil then
     table.insert(categoryArray, '[[Category:Openable Items]]')
     table.insert(categoryArray, '[[Category:Openable Items]]')
     table.insert(useArray, '* [[Chest Drop Tables|Can Be Opened]]')  
     table.insert(useArray, chr..'[[Chest Drop Tables|Can Be Opened]]')  
   end
   end


Line 90: Line 95:
   local canRunecraft = false
   local canRunecraft = false
   local canHerblore = false
   local canHerblore = false
  local canAgile = false
   if item.trimmedItemID ~= nil then
   if item.trimmedItemID ~= nil then
     canUpgrade = true
     canUpgrade = true
Line 140: Line 146:
     end
     end
   end
   end
  --Check if Agility applies here
  canAgile = Shared.tableCount(Agility.getObstaclesForItem(item.id)) > 0
   if canUpgrade then
   if canUpgrade then
     if item.canUpgrade or (item.type == 'Armour' and item.canUpgrade == nil) then
     if item.canUpgrade or (item.type == 'Armour' and item.canUpgrade == nil) then
       table.insert(categoryArray, '[[Category:Upgradeable Items]]')
       table.insert(categoryArray, '[[Category:Upgradeable Items]]')
     end
     end
     table.insert(useArray, '* [[Upgrading Items]]')
     table.insert(useArray, chr..'[[Upgrading Items]]')
  end
 
  --Agility
  if canAgile or Shared.contains(itemUseArray.Agility, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Agility', type='skill'}))
   end
   end
   
   --Cooking
   --Cooking
   if item.cookedItemID ~= nil or Shared.contains(itemUseArray.Cooking, item.name) then
   if item.cookedItemID ~= nil or Shared.contains(itemUseArray.Cooking, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Cooking', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Cooking', type='skill'}))
   end
   end
   --Crafting
   --Crafting
   if canCraft or Shared.contains(itemUseArray.Crafting, item.name) then
   if canCraft or Shared.contains(itemUseArray.Crafting, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Crafting', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Crafting', type='skill'}))
   end
   end
   --Farming
   --Farming
   if item.grownItemID ~= nil or Shared.contains(itemUseArray.Farming, item.name) then
   if item.grownItemID ~= nil or Shared.contains(itemUseArray.Farming, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Farming', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Farming', type='skill'}))
   end
   end
   --Firemaking
   --Firemaking
   if item.firemakingID ~= nil or Shared.contains(itemUseArray.Firemaking, item.name) then
   if SkillData.Firemaking[item.id + 1] ~= nil or Shared.contains(itemUseArray.Firemaking, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Firemaking', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Firemaking', type='skill'}))
   end
   end
   --Fishing
   --Fishing
   if Shared.contains(itemUseArray.Fishing, item.name) then
   if Shared.contains(itemUseArray.Fishing, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Fishing', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Fishing', type='skill'}))
   end
   end
   --Fletching
   --Fletching
   if canFletch or Shared.contains(itemUseArray.Fletching, item.name) then
   if canFletch or Shared.contains(itemUseArray.Fletching, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Fletching', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Fletching', type='skill'}))
   end
   end
   --Herblore
   --Herblore
   if canHerblore or Shared.contains(itemUseArray.Herblore, item.name) then
   if canHerblore or Shared.contains(itemUseArray.Herblore, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Herblore', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Herblore', type='skill'}))
   end
   end
   --Mining
   --Mining
   if Shared.contains(itemUseArray.Mining, item.name) then
   if Shared.contains(itemUseArray.Mining, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Mining', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Mining', type='skill'}))
   end
   end
   --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
     if item.prayerPoints ~= nil then table.insert(categoryArray, '[[Category:Buriable Items]]') end
     table.insert(useArray, '* '..Icons.Icon({'Prayer', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Prayer', type='skill'}))
   end
   end
   --Runecrafting
   --Runecrafting
   if canRunecraft or Shared.contains(itemUseArray.Runecrafting, item.name) then
   if canRunecraft or Shared.contains(itemUseArray.Runecrafting, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Runecrafting', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Runecrafting', type='skill'}))
   end
   end
   --Slayer
   --Slayer
   if item.slayerCost ~= nil or Shared.contains(itemUseArray.Slayer, item.name) then
   if item.slayerCost ~= nil or Shared.contains(itemUseArray.Slayer, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Slayer', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Slayer', type='skill'}))
   end
   end
   --Smithing
   --Smithing
   if item.type == 'Bar' or item.type == 'Ore' or Shared.contains(itemUseArray.Smithing, item.name) then
   if item.type == 'Bar' or item.type == 'Ore' or Shared.contains(itemUseArray.Smithing, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Smithing', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Smithing', type='skill'}))
   end
   end
   --Thieving
   --Thieving
   if Shared.contains(itemUseArray.Thieving, item.name) then
   if Shared.contains(itemUseArray.Thieving, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Thieving', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Thieving', type='skill'}))
   end
   end
   --Woodcutting
   --Woodcutting
   if Shared.contains(itemUseArray.Woodcutting, item.name) then
   if Shared.contains(itemUseArray.Woodcutting, item.name) then
     table.insert(useArray, '* '..Icons.Icon({'Woodcutting', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Woodcutting', type='skill'}))
   end
   end
    
    
   --Other odds and ends:
   --Other odds and ends:
   --Mastery Tokens are tied to 'Mastery'
   --Mastery Tokens are tied to 'Mastery'
   if item.type == 'Token' then
   if item.type == 'Token' then
     table.insert(useArray, '* '..Icons.Icon({'Mastery'}))
     table.insert(useArray, chr..Icons.Icon({'Mastery'}))
   end
   end


Line 217: Line 231:
   local ignoreCapes = {'Ranged Skillcape', 'Attack Skillcape', 'Strength Skillcape', 'Hitpoints Skillcape', 'Defence Skillcape'}
   local ignoreCapes = {'Ranged Skillcape', 'Attack Skillcape', 'Strength Skillcape', 'Hitpoints Skillcape', 'Defence Skillcape'}
   if item.name == 'Max Skillcape' or item.name == 'Aorpheat's Signet Ring' or item.name == 'Cape of Completion' then
   if item.name == 'Max Skillcape' or item.name == 'Aorpheat's Signet Ring' or item.name == 'Cape of Completion' then
     table.insert(useArray, '* All skills')
     table.insert(useArray, chr..'All skills')
   elseif item.name == 'Magic Skillcape' then
   elseif item.name == 'Magic Skillcape' then
     table.insert(useArray, '* '..Icons.Icon({'Magic', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Magic', type='skill'}))
     table.insert(useArray, '* '..Icons.Icon({'Alt. Magic', type='skill'}))
     table.insert(useArray, chr..Icons.Icon({'Alt. Magic', type='skill'}))
   elseif Shared.contains(item.name, 'Skillcape') and not Shared.contains(ignoreCapes, item.name) then
   elseif Shared.contains(item.name, 'Skillcape') and not Shared.contains(ignoreCapes, item.name) then
     local skillName = Shared.splitString(item.name, ' ')[1]
     local skillName = Shared.splitString(item.name, ' ')[1]
     table.insert(useArray, '* '..Icons.Icon({skillName, type='skill'}))
     table.insert(useArray, chr..Icons.Icon({skillName, type='skill'}))
   end
   end


Line 230: Line 244:
   --Special note for Charge Stone of Rhaelyx
   --Special note for Charge Stone of Rhaelyx
   if item.name == 'Charge Stone of Rhaelyx' then
   if item.name == 'Charge Stone of Rhaelyx' then
     table.insert(useArray, '* Powering '..Icons.Icon({'Crown of Rhaelyx', type='item'}))
     table.insert(useArray, chr..'Powering '..Icons.Icon({'Crown of Rhaelyx', type='item'}))
   end
   end


   local result = table.concat(useArray,'\r\n')
  --Some items are needed to make shop purchases
  local shopArray = Shop.getItemCostArray(item.id)
  if Shared.tableCount(shopArray) > 0 then
    table.insert(useArray, chr..Icons.Icon({'Shop'}))
  end
 
   local result = asList and table.concat(useArray,'\r\n') or table.concat(useArray, '<br/>')
   if addCategories then result = result..table.concat(categoryArray, '') end
   if addCategories then result = result..table.concat(categoryArray, '') end
   return result
   return result
Line 242: Line 262:
   local item = Items.getItem(itemName)
   local item = Items.getItem(itemName)
   local addCategories = false
   local addCategories = false
  local asList = true
   if frame.args ~= nil then  
   if frame.args ~= nil then  
     addCategories = frame.args.addCategories ~= nil and frame.args.addCategories ~= '' and frame.args.addCategories ~= 'false'
     addCategories = frame.args.addCategories ~= nil and frame.args.addCategories ~= '' and frame.args.addCategories ~= 'false'
    asList = frame.args.addCategories == nil or frame.args.addCategories == '' or frame.args.addCategories == 'true'
   end
   end
   if item == nil then
   if item == nil then
Line 249: Line 271:
   end
   end


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


Line 269: Line 291:
           end
           end
           table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Upgrade', req = rowReq, xp = xp, gp = item2.trimmedGPCost})
           table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Upgrade', req = rowReq, xp = xp, gp = item2.trimmedGPCost})
          break
        end
      end
    end
    if item.name == 'Leather' and item2.buysForLeather ~= nil then
      local mat = {{id = item.id, qty = item2.buysForLeather}}
      local xp = 'N/A'
      local rowReq = 'None'
      table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Shop', req = rowReq, xp = xp, gp = item2.buysFor})
    elseif item2.buysForItems ~= nil then
      for j, req in pairs(item2.buysForItems) do
        if req[1] == item.id then
          local mat = item2.buysForItems
          local xp = 'N/A'
          local rowReq = 'None'
          table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Shop', req = rowReq, xp = xp, gp = item2.buysForGP})
           break
           break
         end
         end
Line 384: Line 390:
     local qty = 1
     local qty = 1
     table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Cooking', req = rowReq, xp = xp})
     table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Cooking', req = rowReq, xp = xp})
  end
  --Handle shop purchases using Module:Shop
  local shopUses = Shop.getItemCostArray(item.id)
  for i, purchase in Shared.skpairs(shopUses) do
    local rowReq = Shop.getRequirementString(purchase.unlockRequirements)
    local iconType = (purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 0) and 'item' or 'upgrade'
    table.insert(useArray, {item = {name = purchase.name}, qty = 1, mats = purchase.cost.items, skill = 'Shop', req = rowReq, xp = 'N/A', gp = purchase.cost.gp, type = iconType})
   end
   end


Line 399: Line 413:
                           return a.item.name < b.item.name
                           return a.item.name < b.item.name
                         end end)
                         end end)
  local obstacles = Agility.getObstaclesForItem(item.id)


   local spellUseTable = p._getSpellUseTable(item)
   local spellUseTable = p._getSpellUseTable(item)
   local result = ''
   local result = ''
   if Shared.tableCount(useArray) == 0 then
   if Shared.tableCount(useArray) == 0 and Shared.tableCount(obstacles) == 0 then
     if string.len(spellUseTable) > 0 then
     if string.len(spellUseTable) > 0 then
       return '==Uses==\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable
       return '==Uses==\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable
Line 413: Line 429:
   for i, row in pairs(useArray) do
   for i, row in pairs(useArray) do
     local qty = row.qty ~= nil and row.qty or 1
     local qty = row.qty ~= nil and row.qty or 1
    local iconType = row.type ~= nil and row.type or 'item'
     result = result..'\r\n|-\r\n|data-sort-value="'..row.item.name..'"|'
     result = result..'\r\n|-\r\n|data-sort-value="'..row.item.name..'"|'
     result = result..Icons.Icon({row.item.name, type='item', notext=true, size=50})..'||'
     result = result..Icons.Icon({row.item.name, type=iconType, notext=true, size=50})..'||'
     if qty > 1 then result = result.."'''"..qty.."x''' " end
     if qty > 1 then result = result.."'''"..qty.."x''' " end
     result = result..'[['..row.item.name..']]'
     result = result..'[['..row.item.name..']]'
Line 420: Line 437:
       result = result..'||data-sort-value="Upgrade"|[[Upgrading Items|Upgrade]]'
       result = result..'||data-sort-value="Upgrade"|[[Upgrading Items|Upgrade]]'
     elseif row.skill == 'Shop' then
     elseif row.skill == 'Shop' then
       result = result..'||data-sort-value="Shop"|[[Shop]]'
       result = result..'||data-sort-value="Shop"|'..Icons.Icon({'Shop'})
     else
     else
       result = result..'||data-sort-value="'..row.skill..'"|'..Icons.Icon({row.skill, type='skill'})
       result = result..'||data-sort-value="'..row.skill..'"|'..Icons.Icon({row.skill, type='skill'})
Line 437: Line 454:
     end
     end
     result = result..'||'
     result = result..'||'
     for i, mat in pairs(row.mats) do
     for i, mat in Shared.skpairs(row.mats) do
       local matID = mat.id ~= nil and mat.id or mat[1]
       local matID = mat.id ~= nil and mat.id or mat[1]
       local matQty = mat.qty ~= nil and mat.qty or mat[2]
       local matQty = mat.qty ~= nil and mat.qty or mat[2]
       matItem = Items.getItemByID(matID)
       matItem = Items.getItemByID(matID)
       if i > 1 then result = result..'\r\n\r\n' end
       if i > 1 then result = result..'<br/>' end
       result = result..Icons.Icon({matItem.name, type='item', qty=matQty})
       result = result..Icons.Icon({matItem.name, type='item', qty=matQty})
     end
     end
     if row.gp ~= nil then result = result..'<br/>'..Icons.GP(row.gp) end
     if row.gp ~= nil then result = result..'<br/>'..Icons.GP(row.gp) end
  end
  --Agility obstacles are weird and get their own section
  for i, obst in Shared.skpairs(obstacles) do
    result = result..'\r\n|-\r\n|'
    result = result..Icons.Icon({"Agility", type="skill", size="50", notext=true})
    result = result..'||[[Agility#Obstacles|'..obst.name..']]'
    result = result..'||'..Icons.Icon({"Agility", type="skill"})
    --Adding the requirements for the Agility Obstacle
    local reqArray = {}
    if obst.category == nil then --nil category means this is a passive pillar
      table.insert(reqArray, Icons._SkillReq('Agility', 99))
    elseif obst.category > 0 then --Otherwise it's category * 10
      table.insert(reqArray, Icons._SkillReq('Agility', obst.category * 10))
    end
    --Then the other skill levels if any are added
    if obst.requirements ~= nil and obst.requirements.skillLevel ~= nil then
      for j, req in Shared.skpairs(obst.requirements.skillLevel) do
        table.insert(reqArray, Icons._SkillReq(Constants.getSkillName(req[1]), req[2]))
      end
    end
    result = result..'||'..table.concat(reqArray, '<br/>')
    --Just including 'N/A' for XP since it doesn't really apply for Agility Obstacles
    result = result..'||N/A'
    --Finally the cost
    local cost = obst.cost
    local costArray = {}
    if cost.gp ~= nil and cost.gp > 0 then
      table.insert(costArray, Icons.GP(cost.gp))
    end
    if cost.slayerCoins ~= nil and cost.slayerCoins > 0 then
      table.insert(costArray, Icons.SC(cost.slayerCoins))
    end
    for j, mat in Shared.skpairs(cost.items) do
      local item = Items.getItemByID(mat[1])
      table.insert(costArray, Icons.Icon({item.name, type="item", qty=mat[2]}))
    end
   
    result = result..'||'..table.concat(costArray, '<br/>')
   end
   end


Line 472: Line 532:


   local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
   local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
   result = result..'!!'..Icons.Icon({'Magic', type='skill', notext='true'})..' Level'
   result = result..'!!Requirements'
   result = result..'!!Type!!style="width:275px"|Description'
   result = result..'!!Type!!style="width:275px"|Description'
   result = result..'!!Runes'
   result = result..'!!Runes'
Line 484: Line 544:
       rowTxt = rowTxt..Icons.Icon({spell.name, type='spell', notext=true, size=50})
       rowTxt = rowTxt..Icons.Icon({spell.name, type='spell', notext=true, size=50})
     end
     end
     rowTxt = rowTxt..'||'..spell.name
     rowTxt = rowTxt..'||[['..spell.name..']]'
     rowTxt = rowTxt..'||data-sort-value="'..spell.magicLevelRequired..'"|'..Icons._SkillReq('Magic', spell.magicLevelRequired)
     rowTxt = rowTxt..'||data-sort-value="'..spell.magicLevelRequired..'"|'..Icons._SkillReq('Magic', spell.magicLevelRequired)
     --Handle required items/dungeon clears
     --Handle required items/dungeon clears
Line 503: Line 563:
     end
     end
     rowTxt = rowTxt..'||style="text-align:center"|'
     rowTxt = rowTxt..'||style="text-align:center"|'
     for i, req in pairs(spell.runesRequired) do
     rowTxt = rowTxt..Magic._getSpellRunes(spell)
      local rune = Items.getItemByID(req.id)
      if i > 1 then rowTxt = rowTxt..', ' end
      rowTxt = rowTxt..Icons.Icon({rune.name, type='item', notext=true, qty=req.qty})
    end
    if spell.runesRequiredAlt ~= nil then
      rowTxt = rowTxt.."<br/>'''OR'''<br/>"
      for i, req in pairs(spell.runesRequiredAlt) do
        local rune = Items.getItemByID(req.id)
        if i > 1 then rowTxt = rowTxt..', ' end
        rowTxt = rowTxt..Icons.Icon({rune.name, type='item', notext=true, qty=req.qty})
      end
    end
     result = result..rowTxt
     result = result..rowTxt
   end
   end