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
(Exclude Golbin raid exclusive equipment (for now))
(added code to show special attacks in the Modifiers table for equipment because it seemed like the thing to do)
(One intermediate revision 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