17,101
edits
(Update for v1.0.2) |
(getSpellsForItem: Implement) |
||
Line 2: | Line 2: | ||
local MagicData = mw.loadData('Module:Magic/data') | local MagicData = mw.loadData('Module:Magic/data') | ||
local SkillData = mw.loadData('Module:Sandbox/Skills/data') | |||
local Areas = require('Module:CombatAreas') | local Areas = require('Module:CombatAreas') | ||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local Items = require('Module:Items') | local Items = require('Module:Sandbox/Items') | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
Line 219: | Line 220: | ||
end | end | ||
function p. | -- If includeConsumes = true, then checks for Alt Magic spell resource consumptions as well as | ||
-- the rune cost of spells | |||
function p.getSpellsForItem(itemID, includeConsumes) | |||
if type(includeConsumes) ~= 'boolean' then | |||
includeConsumes = false | |||
end | |||
-- The superheat table is built later as & when needed | |||
local superheatCosts, coalID = nil, nil | |||
local spellList = {} | local spellList = {} | ||
for secName, secArray in | for secName, secArray in pairs(MagicData) do | ||
for i, spell in | for i, spell in ipairs(secArray) do | ||
local foundSpell = false | local foundSpell = false | ||
for j, req in pairs(spell.runesRequired) do | for j, req in pairs(spell.runesRequired) do | ||
if req.id == | if req.id == itemID then | ||
foundSpell = true | foundSpell = true | ||
break | break | ||
end | end | ||
end | end | ||
if spell.runesRequiredAlt ~= nil | if not foundSpell and spell.runesRequiredAlt ~= nil then | ||
for j, req in pairs(spell.runesRequiredAlt) do | for j, req in pairs(spell.runesRequiredAlt) do | ||
if req.id == | if req.id == itemID then | ||
foundSpell = true | |||
break | break | ||
end | end | ||
end | end | ||
end | |||
if includeConsumes and not foundSpell and spell.consumes ~= nil and spell.consumes > 0 then | |||
-- The consumes property of Alt Magic spells is as follows: | |||
-- 0 = Any item | |||
-- 1 = Junk item | |||
-- 2 = Superheat/ores with Coal | |||
-- 3 = Superheat/ores without Coal | |||
-- 4 = Nothing | |||
-- 5 = Coal ore | |||
-- We ignore 4 (no resource consumption) and 0 (as this would flag every item unhelpfully) | |||
-- Determine the coal ID for the first time if we need it | |||
if coalID == nil and Shared.contains({2, 3, 5}, spell.consumes) then | |||
local coalItem = Items.getItem('Coal Ore') | |||
if coalItem ~= nil then | |||
coalID = coalItem.id | |||
end | |||
end | |||
if spell.consumes == 1 and Shared.contains(SkillData.Fishing.JunkItems, itemID) then | |||
foundSpell = true | |||
elseif spell.consumes == 2 or spell.consumes == 3 then | |||
if superheatCosts == nil then | |||
-- Initialize the superheatItems table | |||
superheatCosts = {} | |||
for j, recipe in ipairs(SkillData.Smithing.Recipes) do | |||
if recipe.category == 0 then | |||
-- Bar recipe | |||
for k, itemCost in ipairs(recipe.itemCosts) do | |||
if itemCost.id ~= coalID then | |||
superheatCosts[itemCost.id] = true | |||
end | |||
end | |||
end | |||
end | |||
end | |||
local ignoreCoal = (spell.consumes == 3) | |||
if superheatCosts[itemID] or (not ignoreCoal and itemID == coalID) then | |||
foundSpell = true | |||
end | |||
elseif spell.consumes == 5 and itemID == coalID then | |||
foundSpell = true | |||
end | |||
end | |||
if foundSpell then | |||
table.insert(spellList, processSpell(secName, i)) | |||
end | end | ||
end | end | ||
Line 249: | Line 301: | ||
end) | end) | ||
return spellList | return spellList | ||
end | |||
-- The below function is included for backwards compatibility | |||
function p.getSpellsForRune(runeID) | |||
return p.getSpellsForItem(runeID, false) | |||
end | end | ||