Module:Items/UseTables: Difference between revisions

_getItemUseTable: Amend to show XP harvested per quantity for Farming
(Update for v1.1)
(_getItemUseTable: Amend to show XP harvested per quantity for Farming)
(12 intermediate revisions by 3 users not shown)
Line 17: Line 17:
Astrology = {'melvorF:Stardust', 'melvorF:Golden_Stardust'},
Astrology = {'melvorF:Stardust', 'melvorF:Golden_Stardust'},
Attack = {},
Attack = {},
Cartography = {'melvorD:Crown_of_Rhaelyx'},
Combat = {'melvorF:Gold_Emerald_Ring', 'melvorD:Obsidian_Cape', 'melvorF:Throwing_Power_Gloves'},
Combat = {'melvorF:Gold_Emerald_Ring', 'melvorD:Obsidian_Cape', 'melvorF:Throwing_Power_Gloves'},
Cooking = {'melvorD:Cooking_Gloves', 'melvorD:Crown_of_Rhaelyx'},
Cooking = {'melvorD:Cooking_Gloves', 'melvorD:Crown_of_Rhaelyx'},
Line 37: Line 38:
Summoning = {'melvorD:Crown_of_Rhaelyx'},
Summoning = {'melvorD:Crown_of_Rhaelyx'},
Thieving = {'melvorF:Chapeau_Noir', 'melvorF:Thieving_Gloves', 'melvorF:Gloves_of_Silence'},
Thieving = {'melvorF:Chapeau_Noir', 'melvorF:Thieving_Gloves', 'melvorF:Gloves_of_Silence'},
Township = {},
Woodcutting = {},
Woodcutting = {},
}
}
Line 54: Line 56:
["AltMagic"] = Icons.Icon({'Alt. Magic', type='skill'}),
["AltMagic"] = Icons.Icon({'Alt. Magic', type='skill'}),
["ChargeStone"] = 'Powering ' .. Icons.Icon({'Crown of Rhaelyx', type='item'}),
["ChargeStone"] = 'Powering ' .. Icons.Icon({'Crown of Rhaelyx', type='item'}),
["Shop"] = Icons.Icon({'Shop'})
["Shop"] = Icons.Icon({'Shop'}),
["TownshipTask"] = Icons.Icon({'Tasks', type='township'})
}
}


Line 141: Line 144:
end
end


-- Can the item be upgraded, or is it part of an upgrade recipe?
-- Is the item a cost in an upgrade?
for i, upgrade in ipairs(GameData.rawData.itemUpgrades) do
for i, upgrade in ipairs(GameData.rawData.itemUpgrades) do
if upgrade.upgradedItemID == item.id then
for j, itemCost in ipairs(upgrade.itemCosts) do
addUse('Upgrade')
if itemCost.id == item.id then
else
addUse('Upgrade')
for j, itemCost in ipairs(upgrade.itemCosts) do
table.insert(categoryArray, '[[Category:Upgradeable Items]]')
if itemCost.id == item.id then
break
addUse('Upgrade')
break
end
end
end
end
end
Line 156: Line 156:
break
break
end
end
end
if hasUse('Upgrade') then
table.insert(categoryArray, '[[Category:Upgradeable Items]]')
end
end


Line 183: Line 180:
for i, recipeSkillID in ipairs(recipeSkillIDs) do
for i, recipeSkillID in ipairs(recipeSkillIDs) do
if not hasUse(recipeSkillID) then
if not hasUse(recipeSkillID) then
local localSkillID = GameData.getLocalID(recipeSkillID)
local _, localSkillID = GameData.getLocalID(recipeSkillID)
-- Iterate over all recipes for the current skill
-- Iterate over all recipes for the current skill
for j, recipe in ipairs(SkillData[localSkillID].recipes) do
for j, recipe in ipairs(SkillData[localSkillID].recipes) do
Line 341: Line 338:
end
end


-- Township Tasks
for _, task in ipairs(SkillData.Township.tasks) do
if task.goals.items[1] ~= nil then -- Skip tasks with no items
if GameData.getEntityByID(task.goals.items, item.id) then
addUse('TownshipTask')
break
end
end
end
-- Generate result text
-- Generate result text
local useArray = {}
local useArray = {}
Line 364: Line 371:
end
end
if item == nil then
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module"
return Shared.printError('No item named "' .. itemName .. '" exists in the data module')
end
end


Line 379: Line 386:
local rowReq = nil
local rowReq = nil
-- Potions do have upgrade requirements though
-- Potions do have upgrade requirements though
local upgradeItem = Items.GetItemByID(upgrade.upgradedItemID)
local upgradeItem = Items.getItemByID(upgrade.upgradedItemID)
if upgradeItem ~= nil and upgradeItem.charges ~= nil and upgradeItem.tier ~= nil then
if upgradeItem ~= nil and upgradeItem.charges ~= nil and upgradeItem.tier ~= nil then
local levelUnlock = GameData.getEntityByProperty(SkillData.Herblore.masteryLevelUnlocks, 'descriptionID', upgradeItem.tier + 1)
local levelUnlock = GameData.getEntityByProperty(SkillData.Herblore.masteryLevelUnlocks, 'descriptionID', upgradeItem.tier + 1)
Line 403: Line 410:
for i, recipeSkillID in ipairs(recipeSkillIDs) do
for i, recipeSkillID in ipairs(recipeSkillIDs) do
local skillName = Constants.getSkillName(recipeSkillID)
local skillName = Constants.getSkillName(recipeSkillID)
local localSkillID = GameData.getLocalID(recipeSkillID)
local _, localSkillID = GameData.getLocalID(recipeSkillID)
-- Iterate over all recipes for the current skill
-- Iterate over all recipes for the current skill
for j, recipe in ipairs(SkillData[localSkillID].recipes) do
for j, recipe in ipairs(SkillData[localSkillID].recipes) do
Line 449: Line 457:
for i, recipe in ipairs(SkillData.Farming.recipes) do
for i, recipe in ipairs(SkillData.Farming.recipes) do
if recipe.seedCost.id == item.id then
if recipe.seedCost.id == item.id then
local product = Items.getItemByID(recipe.productID)
local product = Items.getItemByID(recipe.productId)
local mat = {{id = recipe.seedCost.id, qty = recipe.seedCost.quantity}}
local mat = {{id = recipe.seedCost.id, quantity = recipe.seedCost.quantity}}
local xp = recipe.baseExperience
local rowReq = recipe.level
local rowReq = recipe.level
local category = GameData.getEntityByID(SkillData.Farming.categories, recipe.categoryID)
local category = GameData.getEntityByID(SkillData.Farming.categories, recipe.categoryID)
local qty = 5 * category.harvestMultiplier
local qty = 5 * category.harvestMultiplier
local xp = recipe.baseExperience
table.insert(useArray, {item = {id = product.id, name = product.name}, qty = qty, mats = mat, skill = 'Farming', req = rowReq, xp = xp})
table.insert(useArray, {item = {id = product.id, name = product.name}, qty = qty, mats = mat, skill = 'Farming', req = rowReq, xp = xp})
end
end
Line 464: Line 472:
local itemCosts = {}
local itemCosts = {}
for j, itemDef in ipairs(obstacle.itemCosts) do
for j, itemDef in ipairs(obstacle.itemCosts) do
table.insert(itemCosts, {id = itemDef.id, qty = itemDef.quantity})
table.insert(itemCosts, {id = itemDef.id, quantity = itemDef.quantity})
end
end
local req = Agility._getObstacleRequirements(obstacle)
local req = Agility._getObstacleRequirements(obstacle)
Line 483: Line 491:
end
end
-- Non-shard items
-- Non-shard items
for j, nonShardItemID in ipairs(recipe.nonShardItemCosts) do
-- Familiar recipes may also have a currency cost without any non-shard
-- items, so account for this with a dummy ID such that one iteration
-- of the below loop always occurs
local nonShardItemIDs = (Shared.tableIsEmpty(recipe.nonShardItemCosts) and {''} or recipe.nonShardItemCosts)
for j, nonShardItemID in ipairs(nonShardItemIDs) do
if useShards or nonShardItemID == item.id then
if useShards or nonShardItemID == item.id then
-- Item is used in this particular synergy recipe
-- Item is used in this particular synergy recipe
Line 490: Line 502:
end
end
local nonShardItem = Items.getItemByID(nonShardItemID)
local nonShardItem = Items.getItemByID(nonShardItemID)
local itemValue = math.max(nonShardItem.sellsFor, 20)
local nonShardQty = math.max(1, math.floor(recipeGPCost / itemValue))
local recipeCosts = Shared.clone(recipe.itemCosts)
local recipeCosts = Shared.clone(recipe.itemCosts)
local recipeCosts = {}
local recipeCosts = {}
for k, itemCost in ipairs(recipe.itemCosts) do
for k, itemCost in ipairs(recipe.itemCosts) do
table.insert(recipeCosts, {id = itemCost.id, qty = itemCost.quantity})
table.insert(recipeCosts, {id = itemCost.id, quantity = itemCost.quantity})
end
if nonShardItem ~= nil then
-- Item ID can be nil for recipes such as Leprechaun or Cyclops
local itemValue = math.max(nonShardItem.sellsFor, 20)
local nonShardQty = math.max(1, math.floor(recipeGPCost / itemValue))
table.insert(recipeCosts, {id = nonShardItemID, quantity = nonShardQty})
end
end
table.insert(recipeCosts, {id = nonShardItemID, qty = nonShardQty})
table.insert(useArray, {item = {id = recipeItem.id, name = recipeItem.name}, qty = recipe.baseQuantity, mats = recipeCosts, gp = recipe.gpCost, sc = recipe.scCost, skill = 'Summoning', req = recipe.level, xp = recipe.baseExperience})
table.insert(useArray, {item = {id = recipeItem.id, name = recipeItem.name}, qty = recipe.baseQuantity, mats = recipeCosts, gp = recipe.gpCost, sc = recipe.scCost, skill = 'Summoning', req = recipe.level, xp = recipe.baseExperience})
end
end
Line 505: Line 520:
--Handle shop purchases using Module:Shop
--Handle shop purchases using Module:Shop
local shopUses = Shop.getItemCostArray(item.id)
local shopUses = Shop.getItemCostArray(item.id)
for i, purchase in ipairs(shopUses) do
for i, shopUse in ipairs(shopUses) do
local rowReq = Shop.getRequirementString(purchase.unlockRequirements)
local purchase = shopUse.purchase
local rowReq = Shop.getRequirementString(purchase.purchaseRequirements)
local iconType = (purchase.contains.items ~= nil and not Shared.tableIsEmpty(purchase.contains.items) and 'item') or 'upgrade'
local iconType = (purchase.contains.items ~= nil and not Shared.tableIsEmpty(purchase.contains.items) and 'item') or 'upgrade'
local gpCost = Shop.getCurrencyCostString(purchase.cost, 'gp')
local gpCost = Shop.getCurrencyCostString(purchase.cost, 'gp')
Line 571: Line 587:
local matItemID = itemCost.id or itemCost[1] or -1
local matItemID = itemCost.id or itemCost[1] or -1
local matItem = Items.getItemByID(matItemID)
local matItem = Items.getItemByID(matItemID)
local matQty = itemCost.qty or itemCost[2] or 1
local matQty = itemCost.quantity or itemCost[2] or 1
if matItem == nil then
if matItem == nil then
table.insert(matRow, 'ERROR: Failed to find item with ID ' .. itemCost.id .. '[[Category:Pages with script errors]]')
table.insert(matRow, Shared.printError('Failed to find item with ID "' .. itemCost.id .. '"'))
elseif type(matQty) == 'number' then
elseif type(matQty) == 'number' then
table.insert(matRow, Icons.Icon({matItem.name, type='item', qty=matQty}))
table.insert(matRow, Icons.Icon({matItem.name, type='item', qty=matQty}))
Line 593: Line 609:
local scText = nil
local scText = nil
if type(row.sc) == 'number' and row.sc > 0 then
if type(row.sc) == 'number' and row.sc > 0 then
scText = Icons.GP(row.sc)
scText = Icons.SC(row.sc)
elseif type(row.sc) == 'string' then
elseif type(row.sc) == 'string' then
scText = row.sc
scText = row.sc
Line 602: Line 618:
local rcText = nil
local rcText = nil
if type(row.rc) == 'number' and row.rc > 0 then
if type(row.rc) == 'number' and row.rc > 0 then
rcText = Icons.GP(row.rc)
rcText = Icons.RC(row.rc)
elseif type(row.rc) == 'string' then
elseif type(row.rc) == 'string' then
rcText = row.rc
rcText = row.rc
Line 646: Line 662:
local item = Items.getItem(itemName)
local item = Items.getItem(itemName)
if item == nil then
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module"
return Shared.printError('No item named "' .. itemName .. '" exists in the data module')
end
end


Line 657: Line 673:
if Shared.tableIsEmpty(spellList) then
if Shared.tableIsEmpty(spellList) then
return ''
return ''
end
--Adding a check for if the Items column is needed
local hasItems = false
for i, spell in pairs(spellList) do
if Magic._getSpellItems(spell) ~= '' then
hasItems = true
break
end
end
end


Line 664: Line 689:
table.insert(resultPart, '!!Type!!style="width:275px"|Description')
table.insert(resultPart, '!!Type!!style="width:275px"|Description')
table.insert(resultPart, '!!Runes')
table.insert(resultPart, '!!Runes')
if hasItems then
table.insert(resultPart, '!!Item Cost')
end
for i, spell in pairs(spellList) do
for i, spell in pairs(spellList) do
local rowPart = {}
local rowPart = {}
Line 671: Line 701:
table.insert(rowPart, '||'..Icons.Icon({spell.name, type=iconType, noicon=true}))
table.insert(rowPart, '||'..Icons.Icon({spell.name, type=iconType, noicon=true}))
table.insert(rowPart, '||data-sort-value="'..spell.level..'"|'..Magic._getSpellRequirements(spell))
table.insert(rowPart, '||data-sort-value="'..spell.level..'"|'..Magic._getSpellRequirements(spell))
table.insert(rowPart, '||data-sort-value="'..spell.spellbook..'"|')
table.insert(rowPart, '||data-sort-value="'.. spell.spellBook ..'"|')
table.insert(rowPart, Magic.getSpellTypeLink(spell.spellbook))
table.insert(rowPart, Magic.getSpellTypeLink(spell.spellBook))
table.insert(rowPart, '||'..Magic._getSpellStat(spell, 'description'))
table.insert(rowPart, '||'..Magic._getSpellStat(spell, 'description'))
table.insert(rowPart, '||style="text-align:center"|')
table.insert(rowPart, '||style="text-align:center"|')
table.insert(rowPart, Magic._getSpellRunes(spell))
table.insert(rowPart, Magic._getSpellRunes(spell))
if hasItems then
table.insert(rowPart, '||style="text-align:right"|')
table.insert(rowPart, Magic._getSpellItems(spell))
end
table.insert(resultPart, table.concat(rowPart))
table.insert(resultPart, table.concat(rowPart))
end
end
Line 687: Line 721:
local item = Items.getItem(itemName)
local item = Items.getItem(itemName)
if item == nil then
if item == nil then
return "ERROR: No item named "..itemName.." exists in the data module"
return Shared.printError('No item named "' .. itemName .. '" exists in the data module')
end
end


Line 727: Line 761:
'Mastery Token (Cooking)',
'Mastery Token (Cooking)',
'Gem Gloves',
'Gem Gloves',
'Basic Bag'
'Basic Bag',
'Bird Nest'
}
}
local checkFuncs = {
local checkFuncs = {