Module:Items/ComparisonTables: Difference between revisions

getItemUpgradeTable: Update for v1.1
(Fix check for empty special attacks table)
(getItemUpgradeTable: Update for v1.1)
Line 448: Line 448:
function p.getItemUpgradeTable(frame)
function p.getItemUpgradeTable(frame)
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
local itemArray = {}
local upgradeArray = {}
local isEquipment = false
local isEquipment = false


if string.upper(category) == 'POTION' then
if string.upper(category) == 'POTION' then
itemArray = Items.getItems(function(item) return Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil end)
upgradeArray = GameData.getEntities('itemUpgrades',
function(upgrade) return Shared.contains(upgrade.upgradedItemID, 'Potion') end
)
elseif string.upper(category) == 'OTHER' then
elseif string.upper(category) == 'OTHER' then
itemArray = Items.getItems(function(item)
upgradeArray = GameData.getEntities('itemUpgrades',
return not Shared.contains(item.name, 'Potion') and item.itemsRequired ~= nil and item.validSlots == nil
function(upgrade)
end)
if not Shared.contains(upgrade.upgradedItemID, 'Potion') then
local item = Items.getItemByID(upgrade.upgradedItemID)
if item ~= nil then
return item.validSlots == nil or Shared.tableIsEmpty(item.validSlots)
end
end
return false
end
)
else
else
if Constants.getEquipmentSlotID(category) == nil then
if Constants.getEquipmentSlotID(category) == nil then
Line 462: Line 472:
end
end
isEquipment = true
isEquipment = true
itemArray = Items.getItems(function(item)
upgradeArray = GameData.getEntities('itemUpgrades',
return item.itemsRequired ~= nil and Shared.contains(item.validSlots, category)
function(upgrade)
end)
local item = Items.getItemByID(upgrade.upgradedItemID)
if item ~= nil then
return item.validSlots ~= nil and Shared.contains(item.validSlots, category)
end
return false
end
)
end
end


Line 473: Line 489:
if isEquipment then table.insert(resultPart, '!!Stat Change') end
if isEquipment then table.insert(resultPart, '!!Stat Change') end


for i, item in Shared.skpairs(itemArray) do
for i, upgrade in ipairs(upgradeArray) do
local item = Items.getItemByID(upgrade.upgradedItemID)
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|'..Icons.Icon({item.name, type='item', size='50', notext=true}))
table.insert(resultPart, '\r\n|'..Icons.Icon({item.name, type='item', size='50', notext=true}))
Line 480: Line 497:
local matArray = {}
local matArray = {}
local statChangeString = ''
local statChangeString = ''
for i, row in Shared.skpairs(item.itemsRequired) do
for i, itemCost in ipairs(upgrade.itemCosts) do
local mat = Items.getItemByID(row[1])
local mat = Items.getItemByID(itemCost.id)
table.insert(matArray, Icons.Icon({mat.name, type='item', qty=row[2]}))
if mat ~= nil then
 
table.insert(matArray, Icons.Icon({mat.name, type='item', qty=itemCost.quantity}))
if item.validSlots ~= nil and mat.validSlots ~= nil and statChangeString == '' then
if isEquipment and item.validSlots ~= nil and mat.validSlots ~= nil and statChangeString == '' then
statChangeString = p.getStatChangeString(item, mat)
statChangeString = p.getStatChangeString(item, mat)
end
end
end
end
end
if item.trimmedGPCost ~= nil and item.trimmedGPCost > 0 then
if upgrade.gpCost ~= nil and upgrade.gpCost > 0 then
table.insert(matArray, Icons.GP(item.trimmedGPCost))
table.insert(matArray, Icons.GP(upgrade.gpCost))
end
if upgrade.scCost ~= nil and upgrade.scCost > 0 then
table.insert(matArray, Icons.SC(upgrade.scCost))
end
end
table.insert(resultPart, '||'..table.concat(matArray, '<br/>'))
table.insert(resultPart, '||'..table.concat(matArray, '<br/>'))