Module:Items/UseTables: Difference between revisions

Update for v1.1
(_getItemUseTable: Support GP & SC in various artisan skills)
(Update for v1.1)
Line 1: Line 1:
local p = {}
local p = {}
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')


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 SkillData = GameData.skillData
local Magic = require('Module:Magic')
local Magic = require('Module:Magic')
local Areas = require('Module:CombatAreas')
local Areas = require('Module:CombatAreas')
Line 12: Line 11:
local Agility = require('Module:Skills/Agility')
local Agility = require('Module:Skills/Agility')
local Shop = require('Module:Shop')
local Shop = require('Module:Shop')
local SkillEnum = mw.loadData('Module:Constants/data').skill


--Brute forcing some item uses to make things easier
--Brute forcing some item uses to make things easier
local itemUseArray = {
local itemUseArray = {
Agility = {},
Agility = {},
Astrology = {'Stardust', 'Golden Stardust'},
Astrology = {'melvorF:Stardust', 'melvorF:Golden_Stardust'},
Attack = {},
Attack = {},
Combat = {'Gold Emerald Ring', 'Obsidian Cape', 'Throwing Power Gloves'},
Combat = {'melvorF:Gold_Emerald_Ring', 'melvorD:Obsidian_Cape', 'melvorF:Throwing_Power_Gloves'},
Cooking = {'Cooking Gloves', 'Crown of Rhaelyx'},
Cooking = {'melvorD:Cooking_Gloves', 'melvorD:Crown_of_Rhaelyx'},
Crafting = {'Crown of Rhaelyx'},
Crafting = {'melvorD:Crown_of_Rhaelyx'},
Defence = {},
Defence = {},
Farming = {'Compost', 'Weird Gloop', 'Bob's Rake'},
Farming = {'melvorD:Compost', 'melvorD:Weird_Gloop', 'melvorD:Bobs_Rake'},
Firemaking = {'Crown of Rhaelyx'},
Firemaking = {'melvorD:Crown_of_Rhaelyx'},
Fishing = {'Amulet of Fishing', 'Message in a Bottle', 'Barbarian Gloves'},
Fishing = {'melvorD:Amulet_of_Fishing', 'melvorD:Message_In_A_Bottle', 'melvorD:Barbarian_Gloves'},
Fletching = {'Crown of Rhaelyx'},
Fletching = {'melvorD:Crown_of_Rhaelyx'},
Herblore = {'Crown of Rhaelyx'},
Herblore = {'melvorD:Crown_of_Rhaelyx'},
Hitpoints = {},
Hitpoints = {},
Magic = {},
Magic = {},
Mining = {'Mining Gloves', 'Gem Gloves'},
Mining = {'melvorD:Mining_Gloves', 'melvorD:Gem_Gloves'},
Prayer = {},
Prayer = {},
Ranged = {},
Ranged = {},
Runecrafting = {'Crown of Rhaelyx'},
Runecrafting = {'melvorD:Crown_of_Rhaelyx'},
Slayer = {},
Slayer = {},
Smithing = {'Smithing Gloves', 'Crown of Rhaelyx'},
Smithing = {'melvorD:Smithing_Gloves', 'melvorD:Crown_of_Rhaelyx'},
Strength = {},
Strength = {},
Summoning = {'Crown of Rhaelyx'},
Summoning = {'melvorD:Crown_of_Rhaelyx'},
Thieving = {'Chapeau Noir', 'Thieving Gloves', 'Gloves of Silence'},
Thieving = {'melvorF:Chapeau_Noir', 'melvorF:Thieving_Gloves', 'melvorF:Gloves_of_Silence'},
Woodcutting = {},
Woodcutting = {},
}
}
local potionUseArray = {
[0] = 'Combat',
[1] = 'Combat',
[2] = 'Combat',
[3] = 'Combat',
[4] = 'Combat',
[5] = 'Combat',
[6] = 'Combat',
[7] = 'Woodcutting',
[8] = 'Fishing',
[9] = 'Firemaking',
[10] = 'Cooking',
[11] = 'Mining',
[12] = 'Smithing',
[13] = 'Thieving',
[14] = 'Farming',
[15] = 'Fletching',
[16] = 'Crafting',
[17] = 'Runecrafting',
[18] = 'Herblore',
[19] = 'Combat',
[20] = 'Combat',
[21] = 'Combat',
[22] = 'Combat',
[23] = 'Combat',
[24] = 'Agility',
[25] = 'Summoning',
[26] = 'Combat',
[27] = 'Combat',
[28] = 'Combat',
[29] = 'Astrology'
}


function p._getItemUses(item, asList, addCategories)
function p._getItemUses(item, asList, addCategories)
Line 93: Line 58:


local addUse = function(useName)
local addUse = function(useName)
local skillID = (type(useName) == 'number' and useName) or SkillEnum[useName]
local skillID = Constants.getSkillID(useName)
if type(skillID) == 'number' then
if skillID == nil then
if skillUses[skillID] == nil then
-- May have been passed a skill ID instead
skillUses[skillID] = Constants.getSkillName(skillID)
local skillName = Constants.getSkillName(useName)
if skillName ~= nil then
skillID = useName
skillUses[skillID] = skillName
end
end
elseif not otherUses[useName] then
else
skillUses[skillID] = useName
end
 
if skillID == nil and  not otherUses[useName] then
otherUses[useName] = true
otherUses[useName] = true
end
end
end
end
local hasUse = function(useName)
local hasUse = function(useName)
local skillID = (type(useName) == 'number' and useName) or SkillEnum[useName]
local skillID = Constants.getSkillID(useName) or (Constants.getSkillName(useName) ~= nil and useName)
if type(skillID) == 'number' then
if skillID ~= nil then
return (skillUses[skillID] ~= nil) or false
return (skillUses[skillID] ~= nil) or false
else
else
Line 113: Line 85:
-- Check for any overrides within itemUseArray
-- Check for any overrides within itemUseArray
for useName, itemList in pairs(itemUseArray) do
for useName, itemList in pairs(itemUseArray) do
if Shared.contains(itemList, item.name) then
if Shared.contains(itemList, item.id) then
addUse(useName)
addUse(useName)
end
end
end
-- If this is a potion add it to the appropriate uses table
if type(item.masteryID) == 'table' and item.masteryID[1] == SkillEnum.Herblore then
-- Default to 'Combat' if unknown
local potionUse = potionUseArray[item.masteryID[2]] or 'Combat'
addUse(potionUseArray[item.masteryID[2]] or 'Combat')
end
end


-- If the item has any modifiers that affect a given skill, add it to those tables
-- If the item has any modifiers that affect a given skill, add it to those tables
-- Added an exception for Mastery Tokens since they were being incorrectly flagged as usable for all skills
-- Added special handling for Mastery Tokens since they were being incorrectly flagged as usable for all skills
if item.modifiers ~= nil and (item.isToken == nil or not item.isToken) then
if item.modifiers ~= nil then
local skillArray = Constants.getModifierSkills(item.modifiers)
if item.modifiers.masteryToken ~= nil then
for i, skillName in ipairs(skillArray) do
-- Mastery tokens
addUse(skillName)
addUse('Mastery')
else
local globalMods = {
'increasedChanceToDoubleItemsGlobal',
'decreasedChanceToDoubleItemsGlobal',
'increasedGlobalSkillIntervalPercent',
'decreasedGlobalSkillIntervalPercent',
'increasedGlobalSkillXP',
'decreasedGlobalSkillXP'
}
for i, globalMod in ipairs(globalMods) do
if item.modifiers[globalMod] ~= nil then
addUse('AllSkills')
break
end
end
if not hasUse('AllSkills') then
local skillArray = Constants.getModifierSkills(item.modifiers)
for i, skillName in ipairs(skillArray) do
addUse(skillName)
end
end
end
end
end
end
Line 140: Line 126:


-- Check if the item is an entry requirement for any Slayer area
-- Check if the item is an entry requirement for any Slayer area
if not hasUse(SkillEnum.Slayer) and item.isEquipment then
if not hasUse('Slayer') and (item.validSlots ~= nil or item.occupiesSlots ~= nil or item.equipmentStats ~= nil) then
local slayerAreas = Areas.getAreas(function(area) return area.type == 'slayer' and type(area.entryRequirements) == 'table' end)
local slayerAreas = Areas.getAreas(function(area) return area.type == 'slayerArea' and type(area.entryRequirements) == 'table' end)
for i, area in pairs(slayerAreas) do
for i, area in ipairs(slayerAreas) do
for j, req in pairs(area.entryRequirements) do
for j, req in ipairs(area.entryRequirements) do
if req.type == "SlayerItem" and req.itemID == item.id then
if req.type == "SlayerItem" and req.itemID == item.id then
addUse(SkillEnum.Slayer)
addUse('Slayer')
break
break
end
end
end
end
if hasUse(SkillEnum.Slayer) then
if hasUse('Slayer') then
break
break
end
end
Line 156: Line 142:


-- Can the item be upgraded, or is it part of an upgrade recipe?
-- Can the item be upgraded, or is it part of an upgrade recipe?
if item.canUpgrade then
for i, upgrade in ipairs(GameData.rawData.itemUpgrades) do
addUse('Upgrade')
if upgrade.upgradedItemID == item.id then
else
addUse('Upgrade')
for i, item2 in pairs(ItemData.Items) do
else
if item2.itemsRequired ~= nil then
for j, itemCost in ipairs(upgrade.itemCosts) do
for j, req in ipairs(item2.itemsRequired) do
if itemCost.id == item.id then
if req[1] == item.id then
addUse('Upgrade')
addUse('Upgrade')
break
end
end
if hasUse('Upgrade') then
break
break
end
end
end
end
end
if hasUse('Upgrade') then
break
end
end
end
end
Line 182: Line 166:
end
end


if item.canOpen then
if item.dropTable ~= nil then
table.insert(categoryArray, '[[Category:Openable Items]]')
table.insert(categoryArray, '[[Category:Openable Items]]')
addUse('Chest')
addUse('Chest')
Line 190: Line 174:
-- All have somewhat consistent recipe data structures
-- All have somewhat consistent recipe data structures
local recipeSkillIDs = {
local recipeSkillIDs = {
SkillEnum.Cooking,
'melvorD:Cooking',
SkillEnum.Smithing,
'melvorD:Smithing',
SkillEnum.Fletching,
'melvorD:Fletching',
SkillEnum.Crafting,
'melvorD:Crafting',
SkillEnum.Runecrafting,
'melvorD:Runecrafting',
SkillEnum.Herblore
'melvorD:Herblore'
}
}
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 recipeKey = (recipeSkillID == SkillEnum.Herblore and 'Potions') or 'Recipes'
local localSkillID = GameData.getLocalID(recipeSkillID)
local skillName = Constants.getSkillName(recipeSkillID)
-- Iterate over all recipes for the current skill
-- Iterate over all recipes for the current skill
for j, recipe in ipairs(SkillData[skillName][recipeKey]) do
for j, recipe in ipairs(SkillData[localSkillID].recipes) do
for k, itemCost in ipairs(recipe.itemCosts) do
for k, itemCost in ipairs(recipe.itemCosts) do
if itemCost.id == item.id then
if itemCost.id == item.id then
Line 231: Line 214:


-- Firemaking
-- Firemaking
if not hasUse(SkillEnum.Firemaking) and type(item.masteryID) == 'table' and item.masteryID[1] == SkillEnum.Firemaking then
if not hasUse('melvorD:Firemaking') then
addUse(SkillEnum.Firemaking)
for i, recipe in ipairs(SkillData.Firemaking.logs) do
if recipe.logID == item.id then
addUse('melvorD:Firemaking')
break
end
end
end
end


-- Farming
-- Farming
if not hasUse(SkillEnum.Farming) and item.grownItemID ~= nil then
if not hasUse('melvorD:Farming') then
addUse(SkillEnum.Farming)
for i, recipe in ipairs(SkillData.Farming.recipes) do
if recipe.seedCost.id == item.id then
addUse('melvorD:Farming')
break
end
end
end
end


-- Agility
-- Agility
if not hasUse(SkillEnum.Agility) and Shared.tableCount(Agility.getObstaclesForItem(item.id)) > 0 then
if not hasUse('melvorD:Agility') and not Shared.tableIsEmpty(Agility.getObstaclesForItem(item.id)) then
addUse(SkillEnum.Agility)
addUse('melvorD:Agility')
end
end


-- Summoning
-- Summoning
if not hasUse(SkillEnum.Summoning) then
if not hasUse('melvorD:Summoning') then
for i, recipe in ipairs(SkillData.Summoning.Marks) do
for i, recipe in ipairs(SkillData.Summoning.recipes) do
-- Tablets & Non-shard items
-- Tablets & Non-shard items
if recipe.itemID == item.id or Shared.contains(recipe.nonShardItemCosts, item.id) then
if recipe.productID == item.id or Shared.contains(recipe.nonShardItemCosts, item.id) then
addUse(SkillEnum.Summoning)
addUse('melvorD:Summoning')
break
break
else
else
Line 256: Line 249:
for j, itemCost in ipairs(recipe.itemCosts) do
for j, itemCost in ipairs(recipe.itemCosts) do
if itemCost.id == item.id then
if itemCost.id == item.id then
addUse(SkillEnum.Summoning)
addUse('melvorD:Summoning')
break
break
end
end
end
if hasUse(SkillEnum.Summoning) then
break
end
end
end
end
Line 270: Line 260:
if item.prayerPoints ~= nil then
if item.prayerPoints ~= nil then
table.insert(categoryArray, '[[Category:Buriable Items]]')
table.insert(categoryArray, '[[Category:Buriable Items]]')
if not hasUse(SkillEnum.Prayer) then
if not hasUse('melvorD:Prayer') then
addUse(SkillEnum.Prayer)
addUse('melvorD:Prayer')
end
end
end
end
Line 278: Line 268:
if not (hasUse('Magic') and hasUse('AltMagic')) then
if not (hasUse('Magic') and hasUse('AltMagic')) then
-- First check if the item its self is used in any spells
-- First check if the item its self is used in any spells
local spellList = Magic.getSpellsForItem(item.id, true)
local spellList = Magic.getSpellsUsingItem(item.id, true)
for i, spell in ipairs(spellList) do
for i, spell in ipairs(spellList) do
local useKey = (spell.type == 'AltMagic' and 'AltMagic' or 'Magic')
local useKey = (spell.type == 'altMagic' and 'AltMagic' or 'Magic')
if not hasUse(useKey) then
if not hasUse(useKey) then
addUse(useKey)
addUse(useKey)
Line 286: Line 276:
end
end
-- Check if the item provides runes, if it does check where they are used also
-- Check if the item provides runes, if it does check where they are used also
if item.providesRune ~= nil then
if item.providedRunes ~= nil then
for i, runeID in ipairs(item.providesRune) do
for i, rune in ipairs(item.providedRunes) do
if hasUse('Magic') and hasUse('AltMagic') then
if hasUse('Magic') and hasUse('AltMagic') then
break
break
else
else
local spellList = Magic.getSpellsForItem(runeID, false)
local spellList = Magic.getSpellsUsingItem(rune.id, false)
for j, spell in ipairs(spellList) do
for j, spell in ipairs(spellList) do
local useKey = (spell.type == 'AltMagic' and 'AltMagic' or 'Magic')
local useKey = (spell.type == 'altMagic' and 'AltMagic' or 'Magic')
if not hasUse(useKey) then
if not hasUse(useKey) then
addUse(useKey)
addUse(useKey)
Line 304: Line 294:


-- Other odds and ends:
-- Other odds and ends:
-- Mastery Tokens are tied to 'Mastery'
if item.isToken and item.skill ~= nil then
addUse('Mastery')
end


-- Skillcapes are tied to the appropriate skill
-- Skillcapes are tied to the appropriate skill
-- Except Maximum Skillcape, which is tied to all skills. (And so is the Signet Ring)
-- Except Maximum Skillcape, which is tied to all skills. (And so is the Signet Ring)
-- And combat skillcapes, since combat skills don't get special treatment
-- And combat skillcapes, since combat skills don't get special treatment
local ignoreCapes = {'Ranged Skillcape', 'Attack Skillcape', 'Strength Skillcape', 'HP Skillcape', 'Defence Skillcape'}
if item.tier == 'Skillcape' then
if Shared.contains({'Maximum Skillcape', "Aorpheat's Signet Ring", 'Ring of Wealth', 'Cape of Completion'}, item.name) then
local ignoreCapes = {
addUse('AllSkills')
'melvorD:Attack_Skillcape',
elseif item.name == 'Magic Skillcape' then
'melvorD:Strength_Skillcape',
addUse(SkillEnum.Magic)
'melvorD:Defence_Skillcape',
addUse('AltMagic')
'melvorD:Hitpoints_Skillcape',
elseif Shared.contains(item.name, 'Skillcape') and not Shared.contains(ignoreCapes, item.name) then
'melvorF:Ranged_Skillcape',
local skillName = Shared.splitString(item.name, ' ')[1]
'melvorTotH:Superior_Attack_Skillcape',
addUse(skillName)
'melvorTotH:Superior_Strength_Skillcape',
end
'melvorTotH:Superior_Defence_Skillcape',
 
'melvorTotH:Superior_Hitpoints_Skillcape',
if Shared.contains(item.name, 'Skillcape') or item.name == 'Cape of Completion' then
'melvorTotH:Superior_Ranged_Skillcape',
}
local allCapes = {
'melvorF:Max_Skillcape',
'melvorF:Cape_of_Completion',
'melvorTotH:Superior_Max_Skillcape',
'melvorTotH:Superior_Cape_Of_Completion'
}
if Shared.contains(allCapes, item.id) then
addUse('AllSkills')
elseif Shared.contains({'melvorF:Magic_Skillcape', 'melvorTotH:Superior_Magic_Skillcape'}, item.id) then
addUse('melvorD:Magic')
addUse('AltMagic')
elseif not Shared.contains(ignoreCapes, item.id) then
local splitName = Shared.splitString(item.name, ' ')
local skillName = (splitName[1] == 'Superior' and splitName[2]) or splitName[1]
addUse(skillName)
end
table.insert(categoryArray, '[[Category:Skillcapes]]')
table.insert(categoryArray, '[[Category:Skillcapes]]')
end
end


--Special note for Charge Stone of Rhaelyx
--Special note for Charge Stone of Rhaelyx
if item.name == 'Charge Stone of Rhaelyx' then
if item.id == 'melvorD:Charge_Stone_of_Rhaelyx' then
addUse('ChargeStone')
addUse('ChargeStone')
end
end
Line 335: Line 337:
--Some items are needed to make shop purchases
--Some items are needed to make shop purchases
local shopArray = Shop.getItemCostArray(item.id)
local shopArray = Shop.getItemCostArray(item.id)
if Shared.tableCount(shopArray) > 0 then
if not Shared.tableIsEmpty(shopArray) then
addUse('Shop')
addUse('Shop')
end
end
Line 371: Line 373:
local useArray = {}
local useArray = {}


-- Loop through all items to find anything that can be upgraded using our source
-- Loop through all upgrades to find anything that can be upgraded using our source
for i, item2 in ipairs(ItemData.Items) do
for i, upgrade in ipairs(GameData.rawData.itemUpgrades) do
if item2.itemsRequired ~= nil then
for j, itemCost in ipairs(upgrade.itemCosts) do
for j, req in pairs(item2.itemsRequired) do
if itemCost.id == item.id then
if req[1] == item.id then
local rowReq = nil
local mat = item2.itemsRequired
-- Potions do have upgrade requirements though
local xp = 'N/A'
local upgradeItem = Items.GetItemByID(upgrade.upgradedItemID)
local rowReq = nil
if upgradeItem ~= nil and upgradeItem.charges ~= nil and upgradeItem.tier ~= nil then
--Potions do have upgrade requirements though
local levelUnlock = GameData.getEntityByProperty(SkillData.Herblore.masteryLevelUnlocks, 'descriptionID', upgradeItem.tier + 1)
if item2.potionTier ~= nil then
if levelUnlock ~= nil then
rowReq = Icons._MasteryReq(item2.name, SkillData.Herblore.TierMasteryLevels[item2.potionTier + 1])
rowReq = Icons._MasteryReq(upgradeItem.name, levelUnlock.level)
end
end
table.insert(useArray, {item = {id = item2.id, name = item2.name}, qty = 1, mats = mat, skill = 'Upgrade', req = rowReq, xp = xp, gp = item2.trimmedGPCost})
break
end
end
table.insert(useArray, {item = {id = upgradeItem.id, name = upgradeItem.name}, qty = 1, mats = upgrade.itemCosts, skill = 'Upgrade', req = rowReq, xp = 'N/A', gp = upgrade.gpCost, sc = upgrade.scCost})
end
end
end
end
Line 393: Line 394:
-- All have somewhat consistent recipe data structures
-- All have somewhat consistent recipe data structures
local recipeSkillIDs = {
local recipeSkillIDs = {
SkillEnum.Cooking,
'melvorD:Cooking',
SkillEnum.Smithing,
'melvorD:Smithing',
SkillEnum.Fletching,
'melvorD:Fletching',
SkillEnum.Crafting,
'melvorD:Crafting',
SkillEnum.Runecrafting,
'melvorD:Runecrafting',
SkillEnum.Herblore
'melvorD:Herblore'
}
}
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 recipeKey = (recipeSkillID == SkillEnum.Herblore and 'Potions') or 'Recipes'
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[skillName][recipeKey]) do
for j, recipe in ipairs(SkillData[localSkillID].recipes) do
local costLists = {recipe.alternativeCosts or {}, {{["itemCosts"] = recipe.itemCosts}}}
local costLists = {recipe.alternativeCosts or {}, {{["itemCosts"] = recipe.itemCosts}}}
for k, costList in pairs(costLists) do
for k, costList in pairs(costLists) do
Line 411: Line 412:
if itemCost.id == item.id then
if itemCost.id == item.id then
local recipeItemIDs = nil
local recipeItemIDs = nil
if recipeSkillID == SkillEnum.Herblore then
if recipeSkillID == 'melvorD:Herblore' then
recipeItemIDs = recipe.potionIDs
recipeItemIDs = recipe.potionIDs
elseif recipeSkillID == SkillEnum.Cooking then
elseif recipeSkillID == 'melvorD:Cooking' then
recipeItemIDs = {recipe.itemID, recipe.perfectCookID}
recipeItemIDs = {recipe.productID, recipe.perfectCookID}
else
else
recipeItemIDs = {recipe.itemID}
recipeItemIDs = {recipe.productID}
end
end
for o, recipeItemID in ipairs(recipeItemIDs) do
for o, recipeItemID in ipairs(recipeItemIDs) do
Line 425: Line 426:
local rowReq = recipe.level
local rowReq = recipe.level
local reqVal = nil
local reqVal = nil
if recipeSkillID == SkillEnum.Herblore then
if recipeSkillID == 'melvorD:Herblore' then
-- Herblore may also have a mastery requirement
-- Herblore may also have a mastery requirement
local masteryLvl = SkillData.Herblore.TierMasteryLevels[o]
local levelUnlock = GameData.getEntityByProperty(SkillData.Herblore.masteryLevelUnlocks, 'descriptionID', recipeItem.tier + 1)
if masteryLvl ~= nil and masteryLvl > 1 then
if levelUnlock ~= nil and levelUnlock.level > 1 then
local masteryReq = Icons._MasteryReq(recipeItem.name, masteryLvl)
local masteryReq = Icons._MasteryReq(recipeItem.name, levelUnlock.level)
reqVal = rowReq + masteryLvl * 0.01
reqVal = rowReq + levelUnlock.level * 0.01
rowReq = Icons._SkillReq(skillName, rowReq) .. '<br/>' .. masteryReq
rowReq = Icons._SkillReq(skillName, rowReq) .. '<br/>' .. masteryReq
end
end
end
end
table.insert(useArray, {item = itemDef, qty = qty, mats = costDef.itemCosts, gp = recipe.gpCost, sc = recipe.scCost, skill = skillName, reqVal = reqVal, req = rowReq, xp = recipe.baseXP})
table.insert(useArray, {item = itemDef, qty = qty, mats = costDef.itemCosts, gp = recipe.gpCost, sc = recipe.scCost, skill = skillName, reqVal = reqVal, req = rowReq, xp = recipe.baseExperience})
end
end
end
end
Line 446: Line 447:


-- Farming
-- Farming
if item.grownItemID ~= nil then
for i, recipe in ipairs(SkillData.Farming.recipes) do
local item2 = Items.getItemByID(item.grownItemID)
if recipe.seedCost.id == item.id then
local mat = {{id = item.id, qty = item.seedsRequired}}
local product = Items.getItemByID(recipe.productID)
local xp = item.farmingXP
local mat = {{id = recipe.seedCost.id, qty = recipe.seedCost.quantity}}
local rowReq = item.farmingLevel
local xp = recipe.baseExperience
local qty = (item.tier ~= nil and item.tier == 'Tree' and 35 or 15)
local rowReq = recipe.level
table.insert(useArray, {item = {id = item2.id, name = item2.name}, qty = qty, mats = mat, skill = 'Farming', req = rowReq, xp = xp})
local category = GameData.getEntityByID(SkillData.Farming.categories, recipe.categoryID)
local qty = 5 * category.harvestMultiplier
table.insert(useArray, {item = {id = product.id, name = product.name}, qty = qty, mats = mat, skill = 'Farming', req = rowReq, xp = xp})
end
end
end


Line 459: Line 463:
for i, obstacle in ipairs(obstacles) do
for i, obstacle in ipairs(obstacles) do
local itemCosts = {}
local itemCosts = {}
for j, itemDef in ipairs(obstacle.cost.items) do
for j, itemDef in ipairs(obstacle.itemCosts) do
table.insert(itemCosts, {id = itemDef[1], qty = itemDef[2]})
table.insert(itemCosts, {id = itemDef.id, qty = itemDef.quantity})
end
end
local req = Agility._getObstacleRequirements(obstacle)
local req = Agility._getObstacleRequirements(obstacle)
--local objType = (obstacle.category == nil and 'Pillar') or 'Obstacle'
--local objType = (obstacle.category == nil and 'Pillar') or 'Obstacle'
table.insert(useArray, {item = {id = obstacle.id, name = obstacle.name}, qty = 1, mats = itemCosts, gp = obstacle.cost.gp, sc = obstacle.cost.slayerCoins, skill = 'Agility', req = req, type = 'skill'})
table.insert(useArray, {item = {id = obstacle.id, name = obstacle.name}, qty = 1, mats = itemCosts, gp = obstacle.gpCost, sc = obstacle.scCost, skill = 'Agility', req = req, type = 'skill'})
end
end


-- Summoning
-- Summoning
for i, recipe in ipairs(SkillData.Summoning.Marks) do
for i, recipe in ipairs(SkillData.Summoning.recipes) do
local recipeGPCost = SkillData.Summoning.RecipeGPCost
local recipeGPCost = SkillData.Summoning.recipeGPCost
local useShards = false
local useShards = false
local recipeItem = nil
local recipeItem = nil
Line 483: Line 487:
-- Item is used in this particular synergy recipe
-- Item is used in this particular synergy recipe
if recipeItem == nil then
if recipeItem == nil then
recipeItem = Items.getItemByID(recipe.itemID)
recipeItem = Items.getItemByID(recipe.productID)
end
end
local nonShardItem = Items.getItemByID(nonShardItemID)
local nonShardItem = Items.getItemByID(nonShardItemID)
Line 489: Line 493:
local nonShardQty = math.max(1, math.floor(recipeGPCost / itemValue))
local nonShardQty = math.max(1, math.floor(recipeGPCost / itemValue))
local recipeCosts = Shared.clone(recipe.itemCosts)
local recipeCosts = Shared.clone(recipe.itemCosts)
local recipeCosts = {}
for k, itemCost in ipairs(recipe.itemCosts) do
table.insert(recipeCosts, {id = itemCost.id, qty = itemCost.quantity})
end
table.insert(recipeCosts, {id = nonShardItemID, qty = nonShardQty})
table.insert(recipeCosts, {id = nonShardItemID, qty = nonShardQty})
table.insert(useArray, {item = {id = recipe.itemID, name = recipeItem.name}, qty = recipe.baseQuantity, mats = recipeCosts, gp = recipe.gpCost, sc = recipe.scCost, skill = 'Summoning', req = recipe.level, xp = recipe.baseXP})
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
end
end
Line 499: Line 507:
for i, purchase in ipairs(shopUses) do
for i, purchase in ipairs(shopUses) do
local rowReq = Shop.getRequirementString(purchase.unlockRequirements)
local rowReq = Shop.getRequirementString(purchase.unlockRequirements)
local iconType = (purchase.contains.items ~= nil and Shared.tableCount(purchase.contains.items) > 0) and 'item' or 'upgrade'
local iconType = (purchase.contains.items ~= nil and not Shared.tableIsEmpty(purchase.contains.items) and 'item') or 'upgrade'
table.insert(useArray, {item = {name = purchase.name}, qty = 1, mats = purchase.cost.items, skill = 'Shop', req = rowReq, xp = 'N/A', gp = purchase.cost.gp, type = iconType})
local gpCost = Shop.getCurrencyCostString(purchase.cost, 'gp')
local scCost = Shop.getCurrencyCostString(purchase.cost, 'slayerCoins')
local rcCost = Shop.getCurrencyCostString(purchase.cost, 'raidCoins')
table.insert(useArray, {item = {name = Shop._getPurchaseName(purchase)}, qty = 1, mats = purchase.cost.items, skill = 'Shop', req = rowReq, xp = 'N/A', gp = gpCost, sc = scCost, rc = rcCost, type = iconType})
end
end


Line 520: Line 531:


local resultPart = {}
local resultPart = {}
if Shared.tableCount(useArray) > 0 then
if not Shared.tableIsEmpty(useArray) then
local typeTextList = {
local typeTextList = {
["Shop"] = Icons.Icon({'Shop'}),
["Shop"] = Icons.Icon({'Shop'}),
Line 570: Line 581:
end
end
end
end
if row.gp ~= nil and row.gp > 0 then
if row.gp ~= nil then
table.insert(matRow, Icons.GP(row.gp))
local gpText = nil
if type(row.gp) == 'number' and row.gp > 0 then
gpText = Icons.GP(row.gp)
elseif type(row.gp) == 'string' then
gpText = row.gp
end
table.insert(matRow, gpText)
end
end
if row.sc ~= nil and row.sc > 0 then
if row.sc ~= nil then
table.insert(matRow, Icons.SC(row.sc))
local scText = nil
if type(row.sc) == 'number' and row.sc > 0 then
scText = Icons.GP(row.sc)
elseif type(row.sc) == 'string' then
scText = row.sc
end
table.insert(matRow, scText)
end
if row.rc ~= nil then
local rcText = nil
if type(row.rc) == 'number' and row.rc > 0 then
rcText = Icons.GP(row.rc)
elseif type(row.rc) == 'string' then
rcText = row.rc
end
table.insert(matRow, rcText)
end
end
-- Item created
-- Item created
Line 603: Line 635:
table.insert(resultPart, '\r\n===' .. Icons.Icon({'Magic', type='skill', size=30}) .. '===\r\n' .. spellUseTable)
table.insert(resultPart, '\r\n===' .. Icons.Icon({'Magic', type='skill', size=30}) .. '===\r\n' .. spellUseTable)
end
end
if Shared.tableCount(resultPart) == 0 then
if Shared.tableIsEmpty(resultPart) then
return ''
return ''
else
else
Line 621: Line 653:


function p._getSpellUseTable(item)
function p._getSpellUseTable(item)
local spellList = Magic.getSpellsForItem(item.id, true)
local spellList = Magic.getSpellsUsingItem(item.id, true)
--Bail immediately if no spells are found
--Bail immediately if no spells are found
if Shared.tableCount(spellList) == 0 then
if Shared.tableIsEmpty(spellList) then
return ''
return ''
end
end
Line 635: Line 667:
local rowPart = {}
local rowPart = {}
table.insert(rowPart, '\r\n|-\r\n|data-sort-value="'..spell.name..'"|')
table.insert(rowPart, '\r\n|-\r\n|data-sort-value="'..spell.name..'"|')
local iconType = (spell.type == 'Auroras' and 'aurora') or (spell.type == 'Curses' and 'curse') or 'spell'
local iconType = Magic._getSpellIconType(spell)
table.insert(rowPart, Icons.Icon({spell.name, type=iconType, notext=true, size=50}))
table.insert(rowPart, Icons.Icon({spell.name, type=iconType, notext=true, size=50}))
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..'"|'..Icons._SkillReq('Magic', spell.level))
table.insert(rowPart, '||data-sort-value="'..spell.level..'"|'..Magic._getSpellRequirements(spell))
--Handle required items/dungeon clears
table.insert(rowPart, '||data-sort-value="'..spell.spellbook..'"|')
if spell.requiredItem ~= nil and spell.requiredItem >= 0 then
table.insert(rowPart, Magic.getSpellTypeLink(spell.spellbook))
local reqItem = Items.getItemByID(spell.requiredItem)
table.insert(rowPart, '<br/>'..Icons.Icon({reqItem.name, type='item', notext=true})..' equipped')
end
if spell.requiredDungeonCompletion ~= nil then
local dung = Areas.getAreaByID('dungeon', spell.requiredDungeonCompletion[1])
table.insert(rowPart, '<br/>'..Icons.Icon({dung.name, type='dungeon', notext=true, qty=spell.requiredDungeonCompletion[2]})..' Clears')
end
table.insert(rowPart, '||data-sort-value="'..Magic.getSpellTypeIndex(spell.type)..'"|')
table.insert(rowPart, Magic.getSpellTypeLink(spell.type))
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"|')