17,105
edits
mNo edit summary |
(getItemUpgradeTable: Implement parameter 'usedItem', for restricting results to only those using the specified item) |
||
Line 425: | Line 425: | ||
function p.getItemUpgradeTable(frame) | function p.getItemUpgradeTable(frame) | ||
local | local args = frame.args ~= nil and frame.args or frame | ||
local category, usedItemName = args[1], args.usedItem | |||
local upgradeArray = {} | local upgradeArray = {} | ||
local isEquipment = false | local isEquipment = false | ||
local usedItemID = nil | |||
if usedItemName ~= nil and usedItemName ~= '' then | |||
local usedItem = Items.getItem(usedItemName) | |||
if usedItem == nil then | |||
return Shared.printError('Used item not found: ' .. usedItemName) | |||
end | |||
usedItemID = usedItem.id | |||
end | |||
local function upgradeConsumesItem(itemUpgrade, itemID) | |||
if itemID == nil then | |||
return true | |||
end | |||
for i, itemCost in ipairs(itemUpgrade.itemCosts) do | |||
if itemCost.id == itemID then | |||
return true | |||
end | |||
end | |||
return false | |||
end | |||
if string.upper(category) == 'POTION' then | if string.upper(category) == 'POTION' then | ||
upgradeArray = GameData.getEntities('itemUpgrades', | upgradeArray = GameData.getEntities('itemUpgrades', | ||
function(upgrade) return Shared.contains(upgrade.upgradedItemID, 'Potion') end | function(upgrade) | ||
return Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID) | |||
end | |||
) | ) | ||
elseif string.upper(category) == 'OTHER' then | elseif string.upper(category) == 'OTHER' then | ||
upgradeArray = GameData.getEntities('itemUpgrades', | upgradeArray = GameData.getEntities('itemUpgrades', | ||
function(upgrade) | function(upgrade) | ||
if not Shared.contains(upgrade.upgradedItemID, 'Potion') then | if not Shared.contains(upgrade.upgradedItemID, 'Potion') and upgradeConsumesItem(upgrade, usedItemID) then | ||
local item = Items.getItemByID(upgrade.upgradedItemID) | local item = Items.getItemByID(upgrade.upgradedItemID) | ||
if item ~= nil then | if item ~= nil then | ||
Line 454: | Line 478: | ||
upgradeArray = GameData.getEntities('itemUpgrades', | upgradeArray = GameData.getEntities('itemUpgrades', | ||
function(upgrade) | function(upgrade) | ||
local item = Items.getItemByID(upgrade.upgradedItemID) | if upgradeConsumesItem(upgrade, usedItemID) then | ||
local item = Items.getItemByID(upgrade.upgradedItemID) | |||
if item ~= nil then | |||
return item.validSlots ~= nil and Shared.contains(item.validSlots, category) | |||
end | |||
end | end | ||
return false | return false |