Anonymous

Module:Magic: Difference between revisions

From Melvor Idle
Okay for real this should be a fix for standard magic spell linking
(Added delay/duration information to spell tables (should only affect ancient magicks))
(Okay for real this should be a fix for standard magic spell linking)
(7 intermediate revisions by 2 users not shown)
Line 2: Line 2:


local MagicData = mw.loadData('Module:Magic/data')
local MagicData = mw.loadData('Module:Magic/data')
local SkillData = mw.loadData('Module:Skills/data')


local Areas = require('Module:CombatAreas')
local Areas = require('Module:CombatAreas')
Line 25: Line 26:
section = 'Auroras'
section = 'Auroras'
elseif type == 'Alt Magic' or type == 'Alternative Magic' then
elseif type == 'Alt Magic' or type == 'Alternative Magic' then
section='AltMagic'
section = 'AltMagic'
end
end
 
name = Shared.fixPagename(name)
name = Shared.fixPagename(name)
if section == nil then
if section == nil then
Line 57: Line 58:
section = 'Auroras'
section = 'Auroras'
elseif type == 'Alt Magic' or type == 'Alternative Magic' then
elseif type == 'Alt Magic' or type == 'Alternative Magic' then
section='AltMagic'
section = 'AltMagic'
end
end
 
if MagicData[section] ~= nil then
if MagicData[section] ~= nil then
return processSpell(section, id + 1)
return processSpell(section, id + 1)
Line 77: Line 78:
return "Combat Spell"
return "Combat Spell"
elseif type == 'Ancient' then
elseif type == 'Ancient' then
return 'Ancient Magick'
return 'Ancient Magick'
end
end
end
end
Line 107: Line 108:


function p._getSpellRunes(spell)
function p._getSpellRunes(spell)
local result = ''
local formatRuneList = function(runes)
for i, req in Shared.skpairs(spell.runesRequired) do
local runeList = {}
local rune = Items.getItemByID(req.id)
for i, req in ipairs(runes) do
if i > 1 then result = result..', ' end
local rune = Items.getItemByID(req.id)
result = result..Icons.Icon({rune.name, type='item', notext=true, qty=req.qty})
if rune ~= nil then
end
table.insert(runeList, Icons.Icon({rune.name, type='item', notext=true, qty=req.qty}))
if spell.runesRequiredAlt ~= nil and not Shared.tablesEqual(spell.runesRequired, spell.runesRequiredAlt) then
end
result = result.."<br/>'''OR'''<br/>"
end
for i, req in pairs(spell.runesRequiredAlt) do
return table.concat(runeList, ', ')
local rune = Items.getItemByID(req.id)
end
if i > 1 then result = result..', ' end
if type(spell.runesRequired) == 'table' then
result = result..Icons.Icon({rune.name, type='item', notext=true, qty=req.qty})
local resultPart  = {}
table.insert(resultPart, formatRuneList(spell.runesRequired))
if spell.runesRequiredAlt ~= nil and not Shared.tablesEqual(spell.runesRequired, spell.runesRequiredAlt) then
table.insert(resultPart, "<br/>'''OR'''<br/>" .. formatRuneList(spell.runesRequiredAlt))
end
end
return table.concat(resultPart)
else
return ''
end
end
return result
end
end


Line 214: Line 220:
end
end


function p.getSpellsForRune(runeID)
-- 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 Shared.skpairs(MagicData) do
for secName, secArray in pairs(MagicData) do
for i, spell in pairs(secArray) do
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 == runeID then
if req.id == itemID then
table.insert(spellList, processSpell(secName, i))
foundSpell = true
foundSpell = true
break
break
end
end
end
end
if spell.runesRequiredAlt ~= nil and not foundSpell then
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 == runeID then
if req.id == itemID then
table.insert(spellList, processSpell(secName, i))
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
end
end
table.sort(spellList, function(a, b)  
table.sort(spellList, function(a, b)
if a.type ~= b.type then
if a.type ~= b.type then
return p.getSpellTypeIndex(a.type) < p.getSpellTypeIndex(b.type)
return p.getSpellTypeIndex(a.type) < p.getSpellTypeIndex(b.type)
else
else
return a.level < b.level
return a.level < b.level
end
end
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


Line 263: Line 325:
function p.getSpellTypeLink(type)
function p.getSpellTypeLink(type)
if type == 'Spells' then
if type == 'Spells' then
return Icons.Icon({'Magic', 'Standard', img='Standard', type='spellType'})
return Icons.Icon({'Standard Magic', 'Standard', img='Standard', type='spellType'})
elseif type == 'Curses' then
elseif type == 'Curses' then
return Icons.Icon({'Curses', 'Curse', img='Curse', type='spellType'})
return Icons.Icon({'Curses', 'Curse', img='Curse', type='spellType'})
Line 312: Line 374:
rowTxt = rowTxt..Shared.round(interval / 1000, 2, 2)..'s delay between attacks.'
rowTxt = rowTxt..Shared.round(interval / 1000, 2, 2)..'s delay between attacks.'
if hits > 2 then
if hits > 2 then
rowTxt = rowTxt..' '..Shared.round(interval * hits / 1000, 2, 2)..'s total duration.'
rowTxt = rowTxt..' '..Shared.round(interval * (hits - 1) / 1000, 2, 2)..'s total duration.'
end
end
rowTxt = rowTxt..')'
rowTxt = rowTxt..')'
Line 318: Line 380:
end
end
if p.getSpellTypeIndex(spell.type) == 4 then
if p.getSpellTypeIndex(spell.type) == 4 then
rowTxt = rowTxt..'||'..spell.magicXP
rowTxt = rowTxt..'||'..spell.baseExperience
end
end
rowTxt = rowTxt..'||style="text-align:center"|'
rowTxt = rowTxt..'||style="text-align:center"|'