Module:Items/ComparisonTables: Difference between revisions

Update for v1.1
(added code to show special attacks in the Modifiers table for equipment because it seemed like the thing to do)
(Update for v1.1)
Line 3: Line 3:
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Items = require('Module:Items')
Line 23: Line 24:
local statColumns = {'stabAttackBonus', 'slashAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'meleeStrengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'meleeDefenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus', 'damageReduction', 'attackLevelRequired', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}
local statColumns = {'stabAttackBonus', 'slashAttackBonus','blockAttackBonus','rangedAttackBonus', 'magicAttackBonus', 'meleeStrengthBonus', 'rangedStrengthBonus', 'magicDamageBonus', 'meleeDefenceBonus', 'rangedDefenceBonus', 'magicDefenceBonus', 'damageReduction', 'attackLevelRequired', 'defenceLevelRequired', 'rangedLevelRequired', 'magicLevelRequired'}


if(Shared.tableCount(itemList) == 0) then
if Shared.tableIsEmpty(itemList) then
return 'ERROR: you must select at least one item to get stats for[[Category:Pages with script errors]]'
return 'ERROR: you must select at least one item to get stats for[[Category:Pages with script errors]]'
end
end
Line 166: Line 167:
if sortByName then
if sortByName then
table.sort(itemList, function(a, b) return a.name < b.name end)
table.sort(itemList, function(a, b) return a.name < b.name end)
else
table.sort(itemList, function(a, b) return a.id < b.id end)
end
end
for i, item in pairs(itemList) do
for i, item in ipairs(itemList) do
if isWeaponType then
if isWeaponType then
--Building rows for weapons
--Building rows for weapons
Line 202: Line 201:
end
end
--For items with a special attack, show the details
--For items with a special attack, show the details
if item.hasSpecialAttack then
if not Shared.tableIsEmpty(item.specialAttacks) then
table.insert(txtLines, "'''Special Attack:'''")
table.insert(txtLines, "'''Special Attack:'''")
for i, spAtt in ipairs(item.specialAttacks) do
for i, spAttID in ipairs(item.specialAttacks) do
local spAtt = GameData.getEntityByID('attacks', spAttID)
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.description)
table.insert(txtLines, spAtt.description)
Line 214: Line 214:
if includeDescription then
if includeDescription 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, item.description ~= nil and item.description or '')
table.insert(resultPart, item.customDescription ~= nil and item.customDescription or '')
end
end
else
else
Line 241: Line 241:
end
end
--For items with a special attack, show the details
--For items with a special attack, show the details
if item.hasSpecialAttack then
if not Shared.tableIsEmpty(item.specialAttacks) then
table.insert(txtLines, "'''Special Attack:'''")
table.insert(txtLines, "'''Special Attack:'''")
for i, spAtt in ipairs(item.specialAttacks) do
for i, spAttID in ipairs(item.specialAttacks) do
local spAtt = GameData.getEntityByID('attacks', spAttID)
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.defaultChance .. '% chance for ' .. spAtt.name .. ':')
table.insert(txtLines, spAtt.description)
table.insert(txtLines, spAtt.description)
Line 253: Line 254:
if includeDescription then
if includeDescription 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, item.description ~= nil and item.description or '')
table.insert(resultPart, item.customDescription ~= nil and item.customDescription or '')
end
end
end
end
Line 391: Line 392:
end
end
end)
end)
table.sort(itemList, function(a, b) return a.id < b.id end)


local resultPart = {}
local resultPart = {}
Line 405: Line 405:
table.insert(resultPart, '||'..Icons.Icon({item.name, type='item', noicon=true}))
table.insert(resultPart, '||'..Icons.Icon({item.name, type='item', noicon=true}))
table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..lootValue..'"|'..lootValue..'%')
table.insert(resultPart, '||style ="text-align: right;" data-sort-value="'..lootValue..'"|'..lootValue..'%')
table.insert(resultPart, '||'..item.description)
table.insert(resultPart, '||'..(item.customDescription or ''))
end
end


Line 476: Line 476:
end)
end)
end
end
table.sort(itemArray, function(a, b) return a.id < b.id end)


local resultPart = {}
local resultPart = {}