Anonymous

Module:Items/ComparisonTables: Difference between revisions

From Melvor Idle
added code to show special attacks in the Modifiers table for equipment because it seemed like the thing to do
(Fixed Cape of Completion being counted as a Skillcape)
(added code to show special attacks in the Modifiers table for equipment because it seemed like the thing to do)
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local ItemData = mw.loadData('Module:Items/data')


local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
Line 198: Line 196:
if includeModifiers then
if includeModifiers then
table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
table.insert(resultPart, Constants.getModifiersText(item.modifiers, true))
local txtLines = {}
local modTxt = Constants.getModifiersText(item.modifiers, true)
if modTxt ~= '' then
table.insert(txtLines, modTxt)
end
--For items with a special attack, show the details
if item.hasSpecialAttack then
table.insert(txtLines, "'''Special Attack:'''")
for i, spAtt in ipairs(item.specialAttacks) do
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.description)
end
end
table.insert(resultPart, table.concat(txtLines, '<br/>'))
end
end
--If requested, add description
--If requested, add description
Line 224: Line 235:
if includeModifiers then
if includeModifiers then
table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
table.insert(resultPart, '\r\n|style="text-align:left;padding:0 0.5em 0 0.5em;"|')
table.insert(resultPart, Constants.getModifiersText(item.modifiers, true))
local txtLines = {}
local modTxt = Constants.getModifiersText(item.modifiers, true)
if modTxt ~= '' then
table.insert(txtLines, modTxt)
end
--For items with a special attack, show the details
if item.hasSpecialAttack then
table.insert(txtLines, "'''Special Attack:'''")
for i, spAtt in ipairs(item.specialAttacks) do
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.description)
end
end
table.insert(resultPart, table.concat(txtLines, '<br/>'))
end
end
--If requested, add description
--If requested, add description
Line 237: Line 261:


return table.concat(resultPart)
return table.concat(resultPart)
end
function p.getEquipmentTable(frame)
local args = frame.args ~= nil and frame.args or frame
local type = args.type
local tier = args.tier
local slot = args.slot
local ammoTypeStr = args.ammoType
local category = args.category ~= nil and args.category or 'Combat'
--Find out what Ammo Type we're working with
local ammoType = nil
if ammoTypeStr ~= nil then
if ammoTypeStr == "Arrows" then
ammoType = 0
elseif ammoTypeStr == 'Bolts' then
ammoType = 1
elseif ammoTypeStr == 'Javelins' then
ammoType = 2
elseif ammoTypeStr == 'Throwing Knives' then
ammoType = 3
end
end
local isWeaponType = Shared.contains(weaponTypes, type)
--Now we need to figure out which items are in this list
local itemList = {}
for i, itemBase in pairs(ItemData.Items) do
local item = Shared.clone(itemBase)
item.id = i - 1
local listItem = false
if isWeaponType then
listItem = item.type == type and item.category == category
if ammoType ~= nil then listItem = listItem and item.ammoTypeRequired == ammoType end
else
--Now for handling armour
if type == "Armour" or type == "Melee" then
listItem = Items._getItemStat(item, 'defenceLevelRequired') ~= nil or (item.category == 'Combat' and item.type == 'Armour')
elseif type == "Ranged Armour" or type == "Ranged" then
listItem = Items._getItemStat(item, 'rangedLevelRequired') ~= nil or (item.category == 'Combat' and item.type == 'Ranged Armour')
elseif type == "Magic Armour" or type == "Magic" then
listItem = Items._getItemStat(item, 'magicLevelRequired') or (item.category == 'Combat' and item.type == 'Magic Armour')
else
listItem = item.type == type and item.category ~= 'Combat'
end
if ammoType ~= nil then listItem = listItem and item.ammoType == ammoType end
if slot ~= nil then listItem = listItem and Shared.contains(item.validSlots, slot) end
end
if listItem then
table.insert(itemList, item)
end
end
local result = p._getEquipmentTable(itemList).."[[Category:getEquipmentTable]]"
return result
end
end


Line 302: Line 269:


local itemList = Items.getItems(function(item)
local itemList = Items.getItems(function(item)
-- Exclude Golbin raid exclusives for now, such that they don't
-- pollute various equipment tables
if item.golbinRaidExclusive ~= nil and item.golbinRaidExclusive then
return false
end
local isMatch = true
local isMatch = true
if style == 'Melee' then
if style == 'Melee' then
Line 311: Line 283:
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
Line 493: Line 465:
elseif string.upper(category) == 'OTHER' then
elseif string.upper(category) == 'OTHER' then
itemArray = Items.getItems(function(item)
itemArray = Items.getItems(function(item)
return not Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil and item.validSlots == nil
return not Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil and item.validSlots == nil
end)
end)
else
else
if Constants.getEquipmentSlotID(category) == nil then
if Constants.getEquipmentSlotID(category) == nil then
Line 501: Line 473:
isEquipment = true
isEquipment = true
itemArray = Items.getItems(function(item)
itemArray = Items.getItems(function(item)
return item.itemsRequired ~= nil and Shared.contains(item.validSlots, category)
return item.itemsRequired ~= nil and Shared.contains(item.validSlots, category)
end)
end)
end
end
table.sort(itemArray, function(a, b) return a.id < b.id end)
table.sort(itemArray, function(a, b) return a.id < b.id end)