Module:Sandbox/AuronTest: Difference between revisions

From Melvor Idle
No edit summary
m (Rebase to Module:Items)
Line 1: Line 1:
--This module contains all sorts of functions for getting data on items
--Several functions related to use tables can be found at Module:Items/UseTables
--Functions related to source tables can be found at Module:Items/SourceTables
--Other functions moved to Module:Items/ComparisonTables
local p = {}
local p = {}


Line 7: Line 12:
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Magic = require('Module:Magic')
local Areas = require('Module:CombatAreas')
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')


p.EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon', 'Easter Egg', 'Abnormal Log', 'Red Herring'}
p.OtherShopItems = {'Cooking Gloves', 'Mining Gloves', 'Gem Gloves', 'Smithing Gloves', 'Thieving Gloves'}
--This is hardcoded, so there's no easy way to scrape it. Hopefully it doesn't change
p.GemTable = {["Topaz"] = {name = 'Topaz', id = 128, chance = 50},
                  ["Sapphire"] = {name = "Sapphire", id = 129, chance = 17.5},
                  ["Ruby"] = {name = "Ruby", id = 130, chance = 17.5},
                  ["Emerald"] = {name = "Emerald", id = 131, chance = 10},
                  ["Diamond"] = {name = "Diamond", id = 132, chance = 5}}
--The base chance to receive a gem while mining
p.GemChance = .01
--The number of different fishing junk items
p.junkCount = 8
--Items (aside from bars & gems) which can be created via Alt Magic
local AltMagicProducts = {'Rune Essence', 'Bones', 'Holy Dust'}
--The kinds of gloves with cost & charges
p.GloveTable = {['Cooking Gloves'] = {cost=50000, charges=500},
                    ['Mining Gloves'] = {cost=75000, charges=500},
                    ['Smithing Gloves'] = {cost=100000, charges=500},
                    ['Thieving Gloves'] = {cost=100000, charges=500},
                    ['Gem Gloves'] = {cost=500000, charges=2000}}


--Brute forcing some item uses to make things easier
local itemUseArray = {
  Agility = {},
  Attack = {},
  Combat = {'Gold Emerald Ring'},
  Cooking = {'Cooking Gloves', 'Crown of Rhaelyx'},
  Crafting = {'Crown of Rhaelyx'},
  Defence = {},
  Farming = {'Compost', 'Weird Gloop', 'Bob's Rake'},
  Firemaking = {'Crown of Rhaelyx'},
  Fishing = {'Amulet of Fishing', 'Message in a Bottle'},
  Fletching = {'Crown of Rhaelyx'},
  Herblore = {'Crown of Rhaelyx'},
  Hitpoints = {},
  Magic = {},
  Mining = {'Mining Gloves', 'Gem Gloves'},
  Prayer = {},
  Ranged = {},
  Runecrafting = {'Crown of Rhaelyx'},
  Slayer = {},
  Smithing = {'Smithing Gloves', 'Crown of Rhaelyx'},
  Strength = {},
  Summoning = {'Crown of Rhaelyx'},
  Thieving = {'Chapeau Noir', 'Thieving Gloves', 'Gloves of Silence'},
  Woodcutting = {},
  }
local potionUseArray = {
  [0] = 'Combat',
  [1] = 'Combat',
  [2] = 'Combat',
  [3] = 'Combat',
  [4] = 'Combat',
  [5] = 'Combat',
  [6] = 'Combat',
  [7] = 'Woodcutting',
  [8] = 'Fishing',
  [9] = 'Firemaking',
  [10] = 'Cooking',
  [11] = 'Mining',
  [12] = 'Smithing',
  [13] = 'Thieving',
  [14] = 'Farming',
  [15] = 'Fletching',
  [16] = 'Crafting',
  [17] = 'Runecrafting',
  [18] = 'Herblore',
  [19] = 'Combat',
  [20] = 'Combat',
  [21] = 'Combat',
  [22] = 'Combat',
  [23] = 'Combat',
  [24] = 'Agility',
  [25] = 'Summoning'
}


function p._getItemUses(item, asList, addCategories)
p.specialFishWt = 6722
  local useArray = {}
p.specialFishLoot = {{128, 2000}, {129, 1600}, {130, 1400}, {131, 1000}, {132, 400}, {667, 10}, {668, 10}, {902, 1}, {670, 1}, {669, 50}, {120, 250}}
  local categoryArray = {}
  local chr = asList and '* ' or ''
  --Another fun one. This time getting all the different possible ways an item can be used


   --Before anything else, if this is a potion add it to the appropriate override section
function p.buildSpecialFishingTable()
   if item.masteryID ~= nil and item.masteryID[1] == 19 then
  --This shouldn't ever be included in a page
    table.insert(itemUseArray[potionUseArray[item.masteryID[2]]], item.name)
   --This is for generating the above 'specialFishLoot' variable if it ever needs to change
   end
   --To re-run, edit the module, type in "console.log(p.buildSpecialFishingTable())" and copy+paste the result as the new value of the variable
   --Also gives you the total fishing weight for saving time later
  local lootArray = {}
  local totalWt = 0


   --If the item has any modifiers that affect a given skill, add it to those lists
   for i, item in pairs(ItemData.Items) do
  if item.modifiers ~= nil then
    if item.fishingCatchWeight ~= nil then
    local skillArray = Constants.getModifierSkills(item.modifiers)
      totalWt = totalWt + item.fishingCatchWeight
    for i, skillName in Shared.skpairs(skillArray) do
      table.insert(lootArray, '{'..(i - 1)..', '..item.fishingCatchWeight..'}')
      table.insert(itemUseArray[skillName], item.name)
     end
     end
   end
   end


   --First things added to the list are non-skill things that are easy to check
   local result = 'p.specialFishWt = '..totalWt..'\r\n'
   if Items.hasCombatStats(item) or Shared.contains(itemUseArray.Combat, item.name) then
   result = result..'p.specialFishLoot = {'..table.concat(lootArray, ', ')..'}'
    table.insert(useArray, chr..Icons.Icon({'Combat'}))
   return result
   end
end


   if item.healsFor ~= nil then
function p.getSpecialAttackByID(ID)
    table.insert(categoryArray, '[[Category:Food Items]]')
   local result = Shared.clone(ItemData.SpecialAttacks[ID + 1])
     table.insert(useArray, chr..'[[Food]]')
  if result ~= nil then
     result.id = ID
   end
   end
  return result
end


   if item.dropTable ~= nil then
function p.getItemByID(ID)
    table.insert(categoryArray, '[[Category:Openable Items]]')
   local result = Shared.clone(ItemData.Items[ID + 1])
     table.insert(useArray, chr..'[[Chest Drop Tables|Can Be Opened]]')
  if result ~= nil then
     result.id = ID
   end
   end
  return result
end


  -- Check if the item is an entry requirement for any Slayer area
function p.getItem(name)
   local isSlayerAreaReq = false
   local result = nil
   if item.isEquipment then
   name = string.gsub(name, "%%27", "'")
    local slayerAreas = Areas.getAreas(function(area) return area.type == 'slayer' end)
  name = string.gsub(name, "'", "'")
    for i, area in pairs(slayerAreas) do
  name = string.gsub(name, "'", "'")
      if area.entryRequirements ~= nil and type(area.entryRequirements) == 'table' then
  for i, item in pairs(ItemData.Items) do
        for j, req in pairs(area.entryRequirements) do
    local itemName = string.gsub(item.name, '#', '')
          if req.type == "SlayerItem" and req.itemID == item.id then
    if(name == itemName) then
            isSlayerAreaReq = true
      result = Shared.clone(item)
            break
      --Make sure every item has an id, and account for Lua being 1-index
          end
      result.id = i - 1
        end
      break
        if isSlayerAreaReq then break end
      end
     end
     end
   end
   end
  return result
end


  --Next, upgrading, crafting, herblore, fletching, and runecrafting since we have to sift through other items for these
function p.getItems(checkFunc)
   local canUpgrade = false
   local result = {}
   local canCraft = false
   for i, item in pairs(ItemData.Items) do
  local canFletch = false
    if checkFunc(item) then
  local canRunecraft = false
      local newItem = Shared.clone(item)
  local canHerblore = false
      newItem.id = i - 1
  local canAgile = false
      table.insert(result, newItem)
  local canSummon = false
     end
 
  if item.trimmedItemID ~= nil then
     canUpgrade = true
   end
   end
  return result
end


  for i, item2 in pairs(ItemData.Items) do
function p._getItemStat(item, StatName, ZeroIfNil)
    if item2.itemsRequired ~= nil then
  local result = item[StatName]
      for j, req in pairs(item2.itemsRequired) do
  --Special Overrides:
        if req[1] == item.id then
  if StatName == 'stabAttackBonus' then
          canUpgrade = true
    if item.attackBonus == nil then  
          break
      result = nil
        end
    else
       end
       result = item.attackBonus[1]
     end
     end
 
  elseif StatName == 'slashAttackBonus' then
     if item2.craftReq ~= nil then
     if item.attackBonus == nil then  
       for j, req in pairs(item2.craftReq) do
       result = nil
        if req.id == item.id then
    else
          canCraft = true
      result = item.attackBonus[2]
          break
        end
      end
     end
     end
    if item2.fletchReq ~= nil then
  elseif StatName == 'blockAttackBonus' then
      for j, req in pairs(item2.fletchReq) do
    if item.attackBonus == nil then  
        if req.id == item.id then
      result = nil
          canFletch = true
    else
          break
       result = item.attackBonus[3]
        end
       end
     end
     end
     if item2.runecraftReq ~= nil then
  elseif StatName == 'attackType' then
      for j, req in pairs(item2.runecraftReq) do
    result = p._getWeaponAttackType(item)
        if req.id == item.id then
  elseif StatName == 'description' then
          canRunecraft = true
    result = item.description
          break
     if result == nil or result == '' then result = 'No Description' end
        end
  elseif StatName == 'completionReq' then
       end
    if item.ignoreCompletion == nil or not item.ignoreCompletion then
      return 'Yes'
    else
       return 'No'
     end
     end
  elseif StatName == 'slayerBonusXP' then
    return p._getItemModifier(item, 'increasedSkillXP', 'Slayer', false)
  end
  if result == nil and ZeroIfNil then result = 0 end
  return result
end
function p.getItemStat(frame)
  local args = frame.args ~= nil and frame.args or frame
  local ItemName = args[1]
  local StatName = args[2]
  local ZeroIfNil = args.ForceZero ~= nil and args.ForceZero ~= '' and args.ForceZero ~= 'false'
  local formatNum = args.formatNum ~= nil and args.formatNum ~= '' and args.formatNum ~= 'false'
  local item = p.getItem(ItemName)
  if item == nil then
    return "ERROR: No item named "..ItemName.." exists in the data module[[Category:Pages with script errors]]"
  end
  local result = p._getItemStat(item, StatName, ZeroIfNil)
  if formatNum then result = Shared.formatnum(result) end
  return result
end
--Gets the value of a given modifier for a given item
--asString is false by default, when true it writes the full bonus text
function p._getItemModifier(item, modifier, skill, asString)
  if asString == nil then asString = false end
  if skill == '' then
    skill = nil
  elseif type(skill) == 'string' then
    skill = Constants.getSkillID(skill)
  end


    if item2.herbloreReq ~= nil then
  mw.log(item.name..', '..modifier)
       for j, req in pairs(item2.herbloreReq) do
 
         if req.id == item.id then
  local result = 0
           canHerblore = true
 
  if item.modifiers ~= nil and item.modifiers[modifier] ~= nil then
    if type(item.modifiers[modifier]) == 'table' then
       for i, subVal in Shared.skpairs(item.modifiers[modifier]) do
         if subVal[1] == skill then
           result = subVal[2]
           break
           break
         end
         end
       end
       end
    else
      result = item.modifiers[modifier]
     end
     end
  end


     if item2.summoningReq ~= nil then
  if asString then
       for j, reqSet in pairs(item2.summoningReq) do
     if skill ~= nil then
        for k, req in pairs(reqSet) do
       return Constants._getModifierText(modifier, {skill, result})
          if req.id == item.id then
    else
            canSummon = true
       return Constants._getModifierText(modifier, result)
            break
          end
        end
       end
     end
     end
  else
    return result
   end
   end
end


  --Check if Agility applies here
function p.hasCombatStats(item)
  canAgile = Shared.tableCount(Agility.getObstaclesForItem(item.id)) > 0
   if item.equipmentSlot == nil then
 
     return false
  --Agility
   elseif item.equipmentSlot == Constants.getEquipmentSlotID('Weapon') then
  if canAgile or Shared.contains(itemUseArray.Agility, item.name) then
     return true
    table.insert(useArray, chr..Icons.Icon({'Agility', type='skill'}))
  end
  --Cooking
  if item.cookedItemID ~= nil or Shared.contains(itemUseArray.Cooking, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Cooking', type='skill'}))
  end
  --Crafting
  if canCraft or Shared.contains(itemUseArray.Crafting, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Crafting', type='skill'}))
  end
  --Farming
  if item.grownItemID ~= nil or Shared.contains(itemUseArray.Farming, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Farming', type='skill'}))
  end
  --Firemaking
  if item.firemakingID ~= nil or Shared.contains(itemUseArray.Firemaking, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Firemaking', type='skill'}))
  end
  --Fishing
  if Shared.contains(itemUseArray.Fishing, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Fishing', type='skill'}))
  end
  --Fletching
  if canFletch or Shared.contains(itemUseArray.Fletching, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Fletching', type='skill'}))
  end
  --Herblore
  if canHerblore or Shared.contains(itemUseArray.Herblore, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Herblore', type='skill'}))
  end
  --Mining
  if Shared.contains(itemUseArray.Mining, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Mining', type='skill'}))
  end
  --Prayer
   if item.prayerPoints ~= nil or (Shared.contains(itemUseArray.Prayer, item.name) and not Shared.contains(itemUseArray.Combat, item.name)) then
    if item.prayerPoints ~= nil then table.insert(categoryArray, '[[Category:Buriable Items]]') end
    table.insert(useArray, chr..Icons.Icon({'Prayer', type='skill'}))
  end
  --Runecrafting
  if canRunecraft or Shared.contains(itemUseArray.Runecrafting, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Runecrafting', type='skill'}))
  end
  --Slayer
  if isSlayerAreaReq or Shared.contains(itemUseArray.Slayer, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Slayer', type='skill'}))
  end
  --Smithing
  if item.type == 'Bar' or item.type == 'Ore' or Shared.contains(itemUseArray.Smithing, item.name) then
     table.insert(useArray, chr..Icons.Icon({'Smithing', type='skill'}))
  end
  --Summoning
   if canSummon or (item.type == 'Shard' and item.category == 'Summoning') or item.type == 'Familiar' or Shared.contains(itemUseArray.Summoning, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Summoning', type='skill'}))
  end
  --Thieving
  if Shared.contains(itemUseArray.Thieving, item.name) then
    table.insert(useArray, chr..Icons.Icon({'Thieving', type='skill'}))
  end
  --Woodcutting
  if Shared.contains(itemUseArray.Woodcutting, item.name) then
     table.insert(useArray, chr..Icons.Icon({'Woodcutting', type='skill'}))
   end
   end


   --Other odds and ends:
   local combatStatList = {'strengthBonus', 'defenceBonus', 'stabAttackBonus', 'slashAttackBonus', 'blockAttackBonus', 'damageReduction',
 
                          'rangedDefenceBonus', 'magicDefenceBonus', 'rangedAttackBonus', 'rangedStrengthBonus', 'magicAttackBonus', 'magicDamageBonus'}
   --Mastery Tokens are tied to 'Mastery'
    
   if item.isToken and item.skill ~= nil then
   for i, stat in Shared.skpairs(combatStatList) do
     table.insert(useArray, chr..Icons.Icon({'Mastery'}))
     if p._getItemStat(item, stat, true) > 0 then
      return true
    end
   end
   end


   --Skillcapes are tied to the appropriate skill
   return false
  --Except Max Skillcape, which is tied to all skills. (And so is the Signet Ring)
end
  --And combat skillcapes, since combat skills don't get special treatment


  local ignoreCapes = {'Ranged Skillcape', 'Attack Skillcape', 'Strength Skillcape', 'Hitpoints Skillcape', 'Defence Skillcape'}
function p.getItemModifier(frame)
  if Shared.contains({'Max Skillcape', 'Aorpheat's Signet Ring', 'Cape of Completion'}, item.name) then
  local itemName = frame.args ~= nil and frame.args[1] or frame[1]
    table.insert(useArray, chr..'All skills')
   local modName = frame.args ~= nil and frame.args[2] or frame[2]
   elseif item.name == 'Magic Skillcape' then
   local skillName = frame.args ~= nil and frame.args[3] or frame[3]
    table.insert(useArray, chr..Icons.Icon({'Magic', type='skill'}))
  local asString = frame.args ~= nil and frame.args[4] or frame[4]
    table.insert(useArray, chr..Icons.Icon({'Alt. Magic', type='skill'}))
  if asString ~= nil then
   elseif Shared.contains(item.name, 'Skillcape') and not Shared.contains(ignoreCapes, item.name) then
     if string.upper(asString) == 'FALSE' then
    local skillName = Shared.splitString(item.name, ' ')[1]
    asString = false
    --Avoiding double-listing the same skill twice
    else
     if not Shared.contains(itemUseArray[skillName], item.name) then
    asString = true
      table.insert(useArray, chr..Icons.Icon({skillName, type='skill'}))
     end
     end
   end
   end


   if Shared.contains(item.name, 'Skillcape') or item.name == 'Cape of Completion' then table.insert(categoryArray, '[[Category:Skillcapes]]') end
   local item = p.getItem(itemName)
 
   if item == nil then
  --Special note for Charge Stone of Rhaelyx
     return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
   if item.name == 'Charge Stone of Rhaelyx' then
     table.insert(useArray, chr..'Powering '..Icons.Icon({'Crown of Rhaelyx', type='item'}))
   end
   end


   --Some items are needed to make shop purchases
   return p._getItemModifier(item, modName, skillName, asString)
  local shopArray = Shop.getItemCostArray(item.id)
end
  if Shared.tableCount(shopArray) > 0 then
    table.insert(useArray, chr..Icons.Icon({'Shop'}))
  end


   if canUpgrade then
function p._getWeaponAttackType(item)
     if item.canUpgrade or (item.type == 'Armour' and item.canUpgrade == nil) then
   if item.type == 'Weapon' then
      table.insert(categoryArray, '[[Category:Upgradeable Items]]')
     return Icons.Icon({'Melee', nolink='true'})
    end
  elseif item.type == 'Ranged Weapon' then
     table.insert(useArray, chr..'[[Upgrading Items]]')
    return Icons.Icon({'Ranged', type='skill', nolink='true'})
  elseif item.type == 'Magic Staff' or item.type == 'Magic Wand' then
     return Icons.Icon({'Magic', type='skill', nolink='true'})
  else
    return "Invalid"
   end
   end
end


  local result = asList and table.concat(useArray,'\r\n') or table.concat(useArray, '<br/>')
  if addCategories then result = result..table.concat(categoryArray, '') end
  return result
end


function p.getItemUses(frame)
function p.getWeaponAttackType(frame)
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local item = Items.getItem(itemName)
   local item = p.getItem(itemName)
  local addCategories = false
  local asList = true
  if frame.args ~= nil then
    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
   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[[Category:Pages with script errors]]"
   end
   end
  return p._getWeaponAttackType(item)
end


  return p._getItemUses(item, asList, addCategories)
function p.getPotionTable(frame)
end
  local potionName = frame.args ~= nil and frame.args[1] or frame
  local tiers = {'I', 'II', 'III', 'IV'}


function p._getItemUseTable(item)
   local result = '{| class="wikitable"'
   local useArray = {}
   result = result..'\r\n!Potion!!Tier!!Charges!!Effect'
   local potTierMastery = {[0] = 0, [1] = 20, [2] = 50, [3] = 90}


   --First, loop through all items to find anything that can be made or upgraded into using our source
   local tier1potion = p.getItem(potionName..' I')
  for i, item2 in pairs(ItemData.Items) do
  for i, tier in pairs(tiers) do
    if item2.itemsRequired ~= nil then
    local tierName = potionName..' '..tier
      for j, req in pairs(item2.itemsRequired) do
    local potion = p.getItemByID(tier1potion.id + i - 1)
        if req[1] == item.id then
     if potion ~= nil then
          local mat = item2.itemsRequired
       result = result..'\r\n|-'
          local xp = 'N/A'
      result = result..'\r\n|'..Icons.Icon({tierName, type='item', notext='true', size='60'})
          local rowReq = 'None'
       result = result..'||'..'[['..tierName..'|'..tier..']]'
          --Potions do have upgrade requirements though
      result = result..'||'..potion.potionCharges..'||'..potion.description
          if item2.potionTier ~= nil then
            rowReq = Icons._MasteryReq(item2.name, potTierMastery[item2.potionTier])
          end
          table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Upgrade', req = rowReq, xp = xp, gp = item2.trimmedGPCost})
          break
        end
      end
    end
    if item2.craftReq ~= nil then
      for j, req in pairs(item2.craftReq) do
        if req.id == item.id then
          local mat = item2.craftReq
          local xp = item2.craftingXP
          local rowReq = item2.craftingLevel
          local qty = item2.craftQty
          table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Crafting', req = rowReq, xp = xp})
          break
        end
      end
    end
     if item2.fletchReq ~= nil then
       for j, req in pairs(item2.fletchReq) do
        if req.id == item.id then
          local xp = item2.fletchingXP
          local rowReq = item2.fletchingLevel
          --Arrow Shafts are special and have to be treated specially
          local qty = item2.fletchQty
          local mat = item2.fletchReq
          if item2.name == 'Arrow Shafts' then
            mat = {{id = item.id, qty = 1}}
            qty =  qty + (qty * item.id)
          end
          table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Fletching', req = rowReq, xp = xp})
          break
        end
       end
    end
    if item2.smithReq ~= nil then
      for j, req in pairs(item2.smithReq) do
        if req.id == item.id then
          local mat = item2.smithReq
          local xp = item2.smithingXP
          local rowReq = item2.smithingLevel
          local qty = item2.smithingQty
          table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Smithing', req = rowReq, xp = xp})
          break
        end
      end
    end
    if item2.runecraftReq ~= nil then
      for j, req in pairs(item2.runecraftReq) do
        if req.id == item.id then
          local mat = item2.runecraftReq
          local xp = item2.runecraftingXP
          local rowReq = item2.runecraftingLevel
          local qty = item2.runecraftQty
          table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Runecrafting', req = rowReq, xp = xp})
          break
        end
      end
    end
    if item2.herbloreReq ~= nil then
      for j, req in pairs(item2.herbloreReq) do
        if req.id == item.id then
          local potionData = SkillData.Herblore.ItemData[item2.masteryID[2] + 1]
          local mat = item2.herbloreReq
          local xp = potionData.herbloreXP
          --Potions do have upgrade requirements though
          local rowReq = Icons._SkillReq('Herblore', potionData.herbloreLevel)
          local masteryLvl = potTierMastery[item2.potionTier]
          if masteryLvl > 0 then
            rowReq = rowReq..'<br/>'..Icons._MasteryReq(item2.name, masteryLvl)
          end
          local reqVal = potionData.herbloreLevel + (masteryLvl * 0.01)
          table.insert(useArray, {item = item2, qty = 1, mats = mat, skill = 'Herblore', reqVal = reqVal, req = rowReq, xp = xp})
          break
        end
      end
     end
     end
  end
  result = result..'\r\n|}'
  return result
end


    if item2.summoningReq ~= nil then
function p._getOtherItemBoxText(item)
      for j, reqSet in pairs(item2.summoningReq) do
  result = ''
        for k, req in pairs(reqSet) do
  --For equipment, show the slot they go in
          if req.id == item.id then
  if item.equipmentSlot ~= nil then
            local mat = Shared.clone(reqSet)
    result = result.."\r\n|-\r\n|'''Equipment Slot:''' "..Constants.getEquipmentSlotName(item.equipmentSlot)
            mat[k].qty = math.max(math.floor(1000 / math.max(item.sellsFor, 20)), 1)
    if item.isPassiveItem then
            local xp = 5 + 2 * math.floor(item2.summoningLevel * 0.2)
      result = result..', Passive'
            local rowReq = item2.summoningLevel
            table.insert(useArray, {item = item2, qty = 25, mats = mat, skill = 'Summoning', req = rowReq, xp = xp})
          end
        end
      end
     end
     end
   end
   end
   if item.grownItemID ~= nil then
  --For weapons with a special attack, show the details
     local item2 = Items.getItemByID(item.grownItemID)
   if item.hasSpecialAttack then
     local mat = {{id = item.id, qty = item.seedsRequired}}
     local spAtt = p.getSpecialAttackByID(item.specialAttackID)
     local xp = item.farmingXP
     result = result.."\r\n|-\r\n|'''Special Attack:'''"
     local rowReq = item.farmingLevel
     result = result..'\r\n* '..spAtt.chance..'% chance for '..spAtt.name..':'
    local qty = 5
     result = result..'\r\n** '..spAtt.description
    table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Farming', req = rowReq, xp = xp})
   end
   end
   if item.cookedItemID ~= nil then
  --For potions, show the number of charges
     local item2 = Items.getItemByID(item.cookedItemID)
   if item.potionCharges ~= nil then
    local mat = {{id = item.id, qty = 1}}
     result = result.."\r\n|-\r\n|'''Charges:''' "..item.potionCharges
    local xp = item.cookingXP
    local rowReq = item.cookingLevel
    local qty = 1
    table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Cooking', req = rowReq, xp = xp})
   end
   end
   if item.burntItemID ~= nil then
  --For food, show how much it heals for
     local item2 = Items.getItemByID(item.burntItemID)
   if item.healsFor ~= nil then
    local mat = {{id = item.id, qty = 1}}
     result = result.."\r\n|-\r\n|'''Heals for:''' "..Icons.Icon({"Hitpoints", type="skill", notext="true"})..' '..(item.healsFor * 10)
    local xp = 1
    local rowReq = item.cookingLevel
    local qty = 1
    table.insert(useArray, {item = item2, qty = qty, mats = mat, skill = 'Cooking', req = rowReq, xp = xp})
   end
   end
 
   --For Prayer Points, show how many you get
   --Handle shop purchases using Module:Shop
   if item.prayerPoints ~= nil then
   local shopUses = Shop.getItemCostArray(item.id)
    result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Prayer', type='skill'}).." Points:''' "..item.prayerPoints
  for i, purchase in Shared.skpairs(shopUses) do
  end
    local rowReq = Shop.getRequirementString(purchase.unlockRequirements)
  --For items with modifiers, show what those are
    local iconType = (purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 0) and 'item' or 'upgrade'
  if item.modifiers ~= nil and Shared.tableCount(item.modifiers) > 0 then
     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})
     result = result.."\r\n|-\r\n|'''Modifiers:'''\r\n"..Constants.getModifiersText(item.modifiers, true)
   end
   end
  return result
end


  --Finally build the table using what we've learned
function p.getOtherItemBoxText(frame)
  table.sort(useArray, function(a, b)
  local itemName = frame.args ~= nil and frame.args[1] or frame
                        local aReqVal = a.reqVal ~= nil and a.reqVal or a.req
   local item = p.getItem(itemName)
                        local bReqVal = b.reqVal ~= nil and b.reqVal or b.req
   local asList = false
                        if a.skill ~= b.skill then
   if frame.args ~= nil then  
                          return a.skill < b.skill
     asList = frame.args.asList ~= nil and frame.args.asList ~= '' and frame.args.asList ~= 'false'
                        elseif type(aReqVal) ~= type(bReqVal) then
                          return tostring(aReqVal) < tostring(bReqVal)
                        elseif aReqVal ~= bReqVal then
                          return aReqVal < bReqVal
                        else
                          return a.item.name < b.item.name
                        end end)
 
   local obstacles = Agility.getObstaclesForItem(item.id)
 
  local spellUseTable = p._getSpellUseTable(item)
   local resultPart = {}
   if Shared.tableCount(useArray) == 0 and Shared.tableCount(obstacles) == 0 then
     if string.len(spellUseTable) > 0 then
      return '==Uses==\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable
    else
      return ''
    end
   end
   end
   table.insert(resultPart, '{| class="wikitable sortable"')
   if item == nil then
  table.insert(resultPart, '\r\n!colspan=2|Item Created!!Type!!Requirements!!XP!!Ingredients')
     return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
  for i, row in pairs(useArray) do
    local qty = row.qty ~= nil and row.qty or 1
    local iconType = row.type ~= nil and row.type or 'item'
    table.insert(resultPart, '\r\n|-\r\n|data-sort-value="'..row.item.name..'"|')
    table.insert(resultPart, Icons.Icon({row.item.name, type=iconType, notext=true, size=50})..'||')
    if qty > 1 then table.insert(resultPart, "'''"..qty.."x''' ") end
    table.insert(resultPart, '[['..row.item.name..']]')
    if row.skill == 'Upgrade' then
      table.insert(resultPart, '||data-sort-value="Upgrade"|[[Upgrading Items|Upgrade]]')
    elseif row.skill == 'Shop' then
      table.insert(resultPart, '||data-sort-value="Shop"|'..Icons.Icon({'Shop'}))
    else
      table.insert(resultPart, '||data-sort-value="'..row.skill..'"|'..Icons.Icon({row.skill, type='skill'}))
    end
    if type(row.req) == 'number' then
      table.insert(resultPart, '|| data-sort-value="'..row.req..'"|'..Icons._SkillReq(row.skill, row.req))
    elseif row.reqVal ~= nil then
      table.insert(resultPart, '|| data-sort-value="'..row.reqVal..'"|'..row.req)
    else
      table.insert(resultPart, '||'..row.req)
    end
    if type(row.xp) == 'string' then
      table.insert(resultPart, '||data-sort-value="0"|'..row.xp)
     else
      table.insert(resultPart, '||data-sort-value="'..row.xp..'"|'..row.xp..' '..Icons.Icon({row.skill, type='skill', notext=true})..' XP')
    end
    table.insert(resultPart, '||')
    for i, mat in Shared.skpairs(row.mats) do
      local matID = mat.id ~= nil and mat.id or mat[1]
      local matQty = mat.qty ~= nil and mat.qty or mat[2]
      local matText = ''
 
      if i > 1 then table.insert(resultPart, '<br/>') end
      if matID >= 0 then
        -- Item
        local matItem = Items.getItemByID(matID)
        if matItem == nil then
          matText = 'ERROR: Failed to find item with ID ' .. matID .. '[[Category:Pages with Script Errors]]'
        else
          matText = Icons.Icon({matItem.name, type='item', qty=matQty})
        end
      elseif matID == -4 then
        -- GP
        matText = Icons.GP(SkillData.Summoning.Settings.recipeGPCost)
      elseif matID == -5 then
        -- Slayer Coins
        matText = Icons.SC(SkillData.Summoning.Settings.recipeGPCost)
      else
        matText = 'ERROR: Unknown item ID: ' .. matID .. ' [[Category:Pages with Script Errors]]'
      end
      table.insert(resultPart, matText)
    end
    if row.gp ~= nil then table.insert(resultPart, '<br/>'..Icons.GP(row.gp)) end
   end
   end


   --Agility obstacles are weird and get their own section
   return p._getOtherItemBoxText(item, asList)
  for i, obst in Shared.skpairs(obstacles) do
end
    table.insert(resultPart, '\r\n|-\r\n|')
    table.insert(resultPart, Icons.Icon({"Agility", type="skill", size="50", notext=true}))
    table.insert(resultPart, '||[[Agility#Obstacles|'..obst.name..']]')
    table.insert(resultPart, '||'..Icons.Icon({"Agility", type="skill"}))


    --Adding the requirements for the Agility Obstacle
function p._getItemCategories(item)
    local reqArray = {}
  local result = ''
    if obst.category == nil then --nil category means this is a passive pillar
  if item.category ~= nil then result = result..'[[Category:'..item.category..']]' end
      table.insert(reqArray, Icons._SkillReq('Agility', 99))
  if item.type ~= nil then result = result..'[[Category:'..item.type..']]' end
    elseif obst.category > 0 then --Otherwise it's category * 10
  if item.equipmentSlot ~= nil then result = result..'[[Category:'..Constants.getEquipmentSlotName(item.equipmentSlot)..']]' end
      table.insert(reqArray, Icons._SkillReq('Agility', obst.category * 10))
  if item.tier ~= nil then result = result..'[[Category:'..Shared.titleCase(item.tier)..' '..item.type..']]' end
    end
  if item.hasSpecialAttack then result = result..'[[Category:Items With Special Attacks]]' end
    --Then the other skill levels if any are added
   if item.isPassiveItem then result = result..'[[Category:Passive Items]]' end
    if obst.requirements ~= nil and obst.requirements.skillLevel ~= nil then
   if item.chanceToDoubleLoot ~= nil and item.chanceToDoubleLoot > 0 then result = result..'[[Category:Double Loot Chance Items]]' end
      for j, req in Shared.skpairs(obst.requirements.skillLevel) do
   return result
        table.insert(reqArray, Icons._SkillReq(Constants.getSkillName(req[1]), req[2]))
      end
    end
    table.insert(resultPart, '||'..table.concat(reqArray, '<br/>'))
 
    --Just including 'N/A' for XP since it doesn't really apply for Agility Obstacles
    table.insert(resultPart, '||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
 
    table.insert(resultPart, '||'..table.concat(costArray, '<br/>'))
 
  end
 
   table.insert(resultPart, '\r\n|}')
   if string.len(spellUseTable) > 0 then
    table.insert(resultPart, '\r\n==='..Icons.Icon({'Magic', type='skill', size='30'})..'===\r\n'..spellUseTable)
  end
   return '==Uses==\r\n'..table.concat(resultPart)
end
end


function p.getItemUseTable(frame)
function p.getItemCategories(frame)
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local item = Items.getItem(itemName)
   local item = p.getItem(itemName)
   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[[Category:Pages with script errors]]"
   end
   end


   return p._getItemUseTable(item)
   return p._getItemCategories(item)
end
end


function p._getSpellUseTable(item)
function p.getSkillcapeTable(frame)
   local spellList = Magic.getSpellsForRune(item.id)
   local skillName = frame.args ~= nil and frame.args[1] or frame
   --Bail immediately if no spells are found
  local cape = p.getItem(skillName..' Skillcape')
   if Shared.tableCount(spellList) == 0 then
   local result = '{| class="wikitable"\r\n'
    return ''
  result = result..'!Skillcape!!Name!!Effect'
   end
   result = result..'\r\n|-\r\n|'..Icons.Icon({cape.name, type='item', size='60', notext=true})
  result = result..'||[['..cape.name..']]||'..cape.description
  result = result..'\r\n|}'
   return result
end


   local result = '{|class="wikitable sortable"\r\n!colspan="2"|Spell'
function p.getItemGrid(frame)
   result = result..'!!Requirements'
   result = '{|'
  result = result..'!!Type!!style="width:275px"|Description'
   for i, item in Shared.skpairs(ItemData.Items) do
  result = result..'!!Runes'
    if i % 17 == 1 then
  for i, spell in pairs(spellList) do
      result = result..'\r\n|-\r\n|'
    local rowTxt = '\r\n|-\r\n|data-sort-value="'..spell.name..'"|'
    if spell.type == 'Auroras' then
      rowTxt = rowTxt..Icons.Icon({spell.name, type='aurora', notext=true, size=50})
    elseif spell.type == 'Curses' then
      rowTxt = rowTxt..Icons.Icon({spell.name, type='curse', notext=true, size=50})
     else
     else
       rowTxt = rowTxt..Icons.Icon({spell.name, type='spell', notext=true, size=50})
       result = result..'||'
     end
     end
     rowTxt = rowTxt..'||[['..spell.name..']]'
     result = result..'style="padding:3px"|'..Icons.Icon({item.name, type='item', notext=true, size='40'})
    rowTxt = rowTxt..'||data-sort-value="'..spell.magicLevelRequired..'"|'..Icons._SkillReq('Magic', spell.magicLevelRequired)
    --Handle required items/dungeon clears
    if spell.requiredItem ~= nil and spell.requiredItem >= 0 then
      local reqItem = Items.getItemByID(spell.requiredItem)
      rowTxt = rowTxt..'<br/>'..Icons.Icon({reqItem.name, type='item', notext=true})..' equipped'
    end
    if spell.requiredDungeonCompletion ~= nil then
      local dung = Areas.getAreaByID('dungeon', spell.requiredDungeonCompletion[1])
      rowTxt = rowTxt..'<br/>'..Icons.Icon({dung.name, type='dungeon', notext=true, qty=spell.requiredDungeonCompletion[2]})..' Clears'
    end
    rowTxt = rowTxt..'||data-sort-value="'..Magic.getSpellTypeIndex(spell.type)..'"|'
    rowTxt = rowTxt..Magic.getSpellTypeLink(spell.type)
    rowTxt = rowTxt..'||'..Magic._getSpellStat(spell, 'description')
    rowTxt = rowTxt..'||style="text-align:center"|'
    rowTxt = rowTxt..Magic._getSpellRunes(spell)
    result = result..rowTxt
   end
   end
  --Add the table end and add the table to the result string
   result = result..'\r\n|}'
   result = result..'\r\n|}'
   return result
   return result
end
end


function p.getSpellUseTable(frame)
function p.getSpecialAttackTable(frame)
   local itemName = frame.args ~= nil and frame.args[1] or frame
   local spAttTable = {}
   local item = Items.getItem(itemName)
 
   if item == nil then
  for i, item in Shared.skpairs(ItemData.Items) do
     return "ERROR: No item named "..itemName.." exists in the data module"
    if item.hasSpecialAttack then
      if spAttTable[item.specialAttackID] == nil then spAttTable[item.specialAttackID] = {sortName=item.name, Icons = {}} end
      table.insert(spAttTable[item.specialAttackID].Icons, Icons.Icon({item.name, type='item'}))
    end
  end 
 
   local result = '{|class="wikitable sortable stickyHeader"'
  result = result..'\r\n|-class="headerRow-0"'
  result = result..'\r\n!style="min-width:180px"|Weapon(s)!!Name!!Chance!!Effect'
   for i, spAttData in Shared.skpairs(spAttTable) do
    local spAtt = p.getSpecialAttackByID(i)
    table.sort(spAttData.Icons, function(a, b) return a < b end)
    result = result..'\r\n|-'
     result = result..'\r\n|data-sort-value="'..spAttData.sortName..'"|'..table.concat(spAttData.Icons, '<br/>')
    result = result..'||'..spAtt.name..'||data-sort-value="'..spAtt.chance..'"|'..spAtt.chance..'%'
    result = result..'||'..spAtt.description
   end
   end
  result = result..'\r\n|}'


   return p._getSpellUseTable(item)
   return result
end
end


return p
return p

Revision as of 21:10, 29 August 2021

Documentation for this module may be created at Module:Sandbox/AuronTest/doc

--This module contains all sorts of functions for getting data on items
--Several functions related to use tables can be found at Module:Items/UseTables
--Functions related to source tables can be found at Module:Items/SourceTables
--Other functions moved to Module:Items/ComparisonTables

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 Icons = require('Module:Icons')

p.EasterEggs = {'Amulet of Calculated Promotion', 'Clue Chasers Insignia', '8', 'Lemon', 'Easter Egg', 'Abnormal Log', 'Red Herring'}
p.OtherShopItems = {'Cooking Gloves', 'Mining Gloves', 'Gem Gloves', 'Smithing Gloves', 'Thieving Gloves'}
--This is hardcoded, so there's no easy way to scrape it. Hopefully it doesn't change
p.GemTable = {["Topaz"] = {name = 'Topaz', id = 128, chance = 50}, 
                  ["Sapphire"] = {name = "Sapphire", id = 129, chance = 17.5}, 
                  ["Ruby"] = {name = "Ruby", id = 130, chance = 17.5}, 
                  ["Emerald"] = {name = "Emerald", id = 131, chance = 10}, 
                  ["Diamond"] = {name = "Diamond", id = 132, chance = 5}}
--The base chance to receive a gem while mining
p.GemChance = .01
--The number of different fishing junk items
p.junkCount = 8
--Items (aside from bars & gems) which can be created via Alt Magic
local AltMagicProducts = {'Rune Essence', 'Bones', 'Holy Dust'}
--The kinds of gloves with cost & charges
p.GloveTable = {['Cooking Gloves'] = {cost=50000, charges=500},
                    ['Mining Gloves'] = {cost=75000, charges=500},
                    ['Smithing Gloves'] = {cost=100000, charges=500},
                    ['Thieving Gloves'] = {cost=100000, charges=500},
                    ['Gem Gloves'] = {cost=500000, charges=2000}}


p.specialFishWt = 6722
p.specialFishLoot = {{128, 2000}, {129, 1600}, {130, 1400}, {131, 1000}, {132, 400}, {667, 10}, {668, 10}, {902, 1}, {670, 1}, {669, 50}, {120, 250}}

function p.buildSpecialFishingTable()
  --This shouldn't ever be included in a page
  --This is for generating the above 'specialFishLoot' variable if it ever needs to change
  --To re-run, edit the module, type in "console.log(p.buildSpecialFishingTable())" and copy+paste the result as the new value of the variable
  --Also gives you the total fishing weight for saving time later
  local lootArray = {}
  local totalWt = 0

  for i, item in pairs(ItemData.Items) do
    if item.fishingCatchWeight ~= nil then
      totalWt = totalWt + item.fishingCatchWeight
      table.insert(lootArray, '{'..(i - 1)..', '..item.fishingCatchWeight..'}')
    end
  end

  local result = 'p.specialFishWt = '..totalWt..'\r\n'
  result = result..'p.specialFishLoot = {'..table.concat(lootArray, ', ')..'}'
  return result
end

function p.getSpecialAttackByID(ID)
  local result = Shared.clone(ItemData.SpecialAttacks[ID + 1])
  if result ~= nil then
    result.id = ID
  end
  return result
end

function p.getItemByID(ID)
  local result = Shared.clone(ItemData.Items[ID + 1])
  if result ~= nil then
    result.id = ID
  end
  return result
end

function p.getItem(name)
  local result = nil
  name = string.gsub(name, "%%27", "&apos;")
  name = string.gsub(name, "'", "&apos;")
  name = string.gsub(name, "&#39;", "&apos;")
  for i, item in pairs(ItemData.Items) do
    local itemName = string.gsub(item.name, '#', '')
    if(name == itemName) then
      result = Shared.clone(item)
      --Make sure every item has an id, and account for Lua being 1-index
      result.id = i - 1
      break
    end
  end
  return result
end

function p.getItems(checkFunc)
  local result = {}
  for i, item in pairs(ItemData.Items) do
    if checkFunc(item) then
      local newItem = Shared.clone(item)
      newItem.id = i - 1
      table.insert(result, newItem)
    end
  end
  return result
end

function p._getItemStat(item, StatName, ZeroIfNil)
  local result = item[StatName]
  --Special Overrides:
  if StatName == 'stabAttackBonus' then
    if item.attackBonus == nil then 
      result = nil
    else
      result = item.attackBonus[1]
    end
  elseif StatName == 'slashAttackBonus' then
    if item.attackBonus == nil then 
      result = nil
    else
      result = item.attackBonus[2]
    end
  elseif StatName == 'blockAttackBonus' then
    if item.attackBonus == nil then 
      result = nil
    else
      result = item.attackBonus[3]
    end
  elseif StatName == 'attackType' then
    result = p._getWeaponAttackType(item)
  elseif StatName == 'description' then
    result = item.description
    if result == nil or result == '' then result = 'No Description' end
  elseif StatName == 'completionReq' then
    if item.ignoreCompletion == nil or not item.ignoreCompletion then
      return 'Yes'
    else
      return 'No'
    end
  elseif StatName == 'slayerBonusXP' then
    return p._getItemModifier(item, 'increasedSkillXP', 'Slayer', false)
  end
  if result == nil and ZeroIfNil then result = 0 end
  return result
end

function p.getItemStat(frame)
  local args = frame.args ~= nil and frame.args or frame
  local ItemName = args[1]
  local StatName = args[2]
  local ZeroIfNil = args.ForceZero ~= nil and args.ForceZero ~= '' and args.ForceZero ~= 'false'
  local formatNum = args.formatNum ~= nil and args.formatNum ~= '' and args.formatNum ~= 'false'
  local item = p.getItem(ItemName)
  if item == nil then
    return "ERROR: No item named "..ItemName.." exists in the data module[[Category:Pages with script errors]]"
  end
  local result = p._getItemStat(item, StatName, ZeroIfNil)
  if formatNum then result = Shared.formatnum(result) end
  return result
end

--Gets the value of a given modifier for a given item
--asString is false by default, when true it writes the full bonus text
function p._getItemModifier(item, modifier, skill, asString)
  if asString == nil then asString = false end
  if skill == '' then
    skill = nil
  elseif type(skill) == 'string' then
    skill = Constants.getSkillID(skill)
  end

  mw.log(item.name..', '..modifier)

  local result = 0

  if item.modifiers ~= nil and item.modifiers[modifier] ~= nil then
    if type(item.modifiers[modifier]) == 'table' then
      for i, subVal in Shared.skpairs(item.modifiers[modifier]) do
        if subVal[1] == skill then
          result = subVal[2]
          break
        end
      end
    else
      result = item.modifiers[modifier]
    end
  end

  if asString then
    if skill ~= nil then
      return Constants._getModifierText(modifier, {skill, result})
    else
      return Constants._getModifierText(modifier, result)
    end
  else
    return result
  end
end

function p.hasCombatStats(item)
  if item.equipmentSlot == nil then
    return false
  elseif item.equipmentSlot == Constants.getEquipmentSlotID('Weapon') then
    return true
  end

  local combatStatList = {'strengthBonus', 'defenceBonus', 'stabAttackBonus', 'slashAttackBonus', 'blockAttackBonus', 'damageReduction',
                          'rangedDefenceBonus', 'magicDefenceBonus', 'rangedAttackBonus', 'rangedStrengthBonus', 'magicAttackBonus', 'magicDamageBonus'}
  
  for i, stat in Shared.skpairs(combatStatList) do
    if p._getItemStat(item, stat, true) > 0 then
      return true
    end
  end

  return false
end

function p.getItemModifier(frame)
  local itemName = frame.args ~= nil and frame.args[1] or frame[1]
  local modName = frame.args ~= nil and frame.args[2] or frame[2]
  local skillName = frame.args ~= nil and frame.args[3] or frame[3]
  local asString = frame.args ~= nil and frame.args[4] or frame[4]
  if asString ~= nil then
    if string.upper(asString) == 'FALSE' then
     asString = false
    else
     asString = true
    end
  end

  local item = p.getItem(itemName)
  if item == nil then
    return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
  end

  return p._getItemModifier(item, modName, skillName, asString)
end

function p._getWeaponAttackType(item)
  if item.type == 'Weapon' then
    return Icons.Icon({'Melee', nolink='true'})
  elseif item.type == 'Ranged Weapon' then
    return Icons.Icon({'Ranged', type='skill', nolink='true'})
  elseif item.type == 'Magic Staff' or item.type == 'Magic Wand' then
    return Icons.Icon({'Magic', type='skill', nolink='true'})
  else
    return "Invalid"
  end
end


function p.getWeaponAttackType(frame)
  local itemName = frame.args ~= nil and frame.args[1] or frame
  local item = p.getItem(itemName)
  if item == nil then
    return "ERROR: No item named "..ItemName.." exists in the data module[[Category:Pages with script errors]]"
  end
  return p._getWeaponAttackType(item)
end

function p.getPotionTable(frame)
  local potionName = frame.args ~= nil and frame.args[1] or frame
  local tiers = {'I', 'II', 'III', 'IV'}

  local result = '{| class="wikitable"'
  result = result..'\r\n!Potion!!Tier!!Charges!!Effect'

  local tier1potion = p.getItem(potionName..' I')
  for i, tier in pairs(tiers) do
    local tierName = potionName..' '..tier
    local potion = p.getItemByID(tier1potion.id + i - 1)
    if potion ~= nil then
      result = result..'\r\n|-'
      result = result..'\r\n|'..Icons.Icon({tierName, type='item', notext='true', size='60'})
      result = result..'||'..'[['..tierName..'|'..tier..']]'
      result = result..'||'..potion.potionCharges..'||'..potion.description
    end
  end

  result = result..'\r\n|}'
  return result
end

function p._getOtherItemBoxText(item)
  result = ''
  --For equipment, show the slot they go in
  if item.equipmentSlot ~= nil then
    result = result.."\r\n|-\r\n|'''Equipment Slot:''' "..Constants.getEquipmentSlotName(item.equipmentSlot)
    if item.isPassiveItem then
      result = result..', Passive'
    end
  end
  --For weapons with a special attack, show the details
  if item.hasSpecialAttack then
    local spAtt = p.getSpecialAttackByID(item.specialAttackID)
    result = result.."\r\n|-\r\n|'''Special Attack:'''"
    result = result..'\r\n* '..spAtt.chance..'% chance for '..spAtt.name..':'
    result = result..'\r\n** '..spAtt.description
  end
  --For potions, show the number of charges
  if item.potionCharges ~= nil then
    result = result.."\r\n|-\r\n|'''Charges:''' "..item.potionCharges
  end
  --For food, show how much it heals for
  if item.healsFor ~= nil then
    result = result.."\r\n|-\r\n|'''Heals for:''' "..Icons.Icon({"Hitpoints", type="skill", notext="true"})..' '..(item.healsFor * 10)
  end
  --For Prayer Points, show how many you get
  if item.prayerPoints ~= nil then
    result = result.."\r\n|-\r\n|'''"..Icons.Icon({'Prayer', type='skill'}).." Points:''' "..item.prayerPoints
  end
  --For items with modifiers, show what those are
  if item.modifiers ~= nil and Shared.tableCount(item.modifiers) > 0 then
    result = result.."\r\n|-\r\n|'''Modifiers:'''\r\n"..Constants.getModifiersText(item.modifiers, true)
  end
  return result
end

function p.getOtherItemBoxText(frame)
  local itemName = frame.args ~= nil and frame.args[1] or frame
  local item = p.getItem(itemName)
  local asList = false
  if frame.args ~= nil then 
    asList = frame.args.asList ~= nil and frame.args.asList ~= '' and frame.args.asList ~= 'false'
  end
  if item == nil then
    return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
  end

  return p._getOtherItemBoxText(item, asList)
end

function p._getItemCategories(item)
  local result = ''
  if item.category ~= nil then result = result..'[[Category:'..item.category..']]' end
  if item.type ~= nil then result = result..'[[Category:'..item.type..']]' end
  if item.equipmentSlot ~= nil then result = result..'[[Category:'..Constants.getEquipmentSlotName(item.equipmentSlot)..']]' end
  if item.tier ~= nil then result = result..'[[Category:'..Shared.titleCase(item.tier)..' '..item.type..']]' end
  if item.hasSpecialAttack then result = result..'[[Category:Items With Special Attacks]]' end
  if item.isPassiveItem then result = result..'[[Category:Passive Items]]' end
  if item.chanceToDoubleLoot ~= nil and item.chanceToDoubleLoot > 0 then result = result..'[[Category:Double Loot Chance Items]]' end
  return result
end

function p.getItemCategories(frame)
  local itemName = frame.args ~= nil and frame.args[1] or frame
  local item = p.getItem(itemName)
  if item == nil then
    return "ERROR: No item named "..itemName.." exists in the data module[[Category:Pages with script errors]]"
  end

  return p._getItemCategories(item)
end

function p.getSkillcapeTable(frame)
  local skillName = frame.args ~= nil and frame.args[1] or frame
  local cape = p.getItem(skillName..' Skillcape')
  local result = '{| class="wikitable"\r\n'
  result = result..'!Skillcape!!Name!!Effect'
  result = result..'\r\n|-\r\n|'..Icons.Icon({cape.name, type='item', size='60', notext=true})
  result = result..'||[['..cape.name..']]||'..cape.description
  result = result..'\r\n|}'
  return result
end

function p.getItemGrid(frame)
  result = '{|'
  for i, item in Shared.skpairs(ItemData.Items) do
    if i % 17 == 1 then
      result = result..'\r\n|-\r\n|'
    else
      result = result..'||'
    end
    result = result..'style="padding:3px"|'..Icons.Icon({item.name, type='item', notext=true, size='40'})
  end
  result = result..'\r\n|}'
  return result
end

function p.getSpecialAttackTable(frame)
  local spAttTable = {}
  
  for i, item in Shared.skpairs(ItemData.Items) do
    if item.hasSpecialAttack then
      if spAttTable[item.specialAttackID] == nil then spAttTable[item.specialAttackID] = {sortName=item.name, Icons = {}} end
      table.insert(spAttTable[item.specialAttackID].Icons, Icons.Icon({item.name, type='item'}))
    end
  end  

  local result = '{|class="wikitable sortable stickyHeader"'
  result = result..'\r\n|-class="headerRow-0"'
  result = result..'\r\n!style="min-width:180px"|Weapon(s)!!Name!!Chance!!Effect'
  for i, spAttData in Shared.skpairs(spAttTable) do
    local spAtt = p.getSpecialAttackByID(i)
    table.sort(spAttData.Icons, function(a, b) return a < b end)
    result = result..'\r\n|-'
    result = result..'\r\n|data-sort-value="'..spAttData.sortName..'"|'..table.concat(spAttData.Icons, '<br/>')
    result = result..'||'..spAtt.name..'||data-sort-value="'..spAtt.chance..'"|'..spAtt.chance..'%'
    result = result..'||'..spAtt.description
  end
  result = result..'\r\n|}'

  return result
end

return p