Anonymous

Module:Magic: Difference between revisions

From Melvor Idle
1,091 bytes added ,  31 October 2022
Added spell item cost to the spellbook table
(Fixed a minor typo that was preventing spell requirements from including equipped items)
(Added spell item cost to the spellbook table)
(One intermediate revision by the same user not shown)
Line 157: Line 157:
     end
     end
     return table.concat(runeList, ', ')  
     return table.concat(runeList, ', ')  
end
function p._getSpellItems(spell)
if type(spell.fixedItemCosts) == 'table' then
local resultPart = {}
for i, req in ipairs(spell.fixedItemCosts) do
local item = Items.getItemByID(req.id)
if item ~= nil then
table.insert(resultPart, Icons.Icon({item.name, type='item', qty = req.quantity}))
end
end
return table.concat(resultPart, '<br/>')
else
return ''
end
end
function p.getSpellItems(frame)
local spellName = frame.args ~= nil and frame.args[1] or frame
local spell = p.getSpell(spellName)
if spell == nil then
return "ERROR: No spell named "..spellName.." exists in the data module"
end
return p._getSpellItems(spell)
end
end


Line 510: Line 535:
end
end


function p._getSpellRow(spell, includeTypeColumn)
function p._getSpellRow(spell, includeTypeColumn, includeItems)
     local spellBookIdx = p.spellBookIndex[spell.spellBook]
     local spellBookIdx = p.spellBookIndex[spell.spellBook]
     local spellBook = p.spellBooks[spellBookIdx]
     local spellBook = p.spellBooks[spellBookIdx]
Line 541: Line 566:
end
end
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell))
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell))
if includeItems then
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellItems(spell))
end
return table.concat(rowPart)
return table.concat(rowPart)
end
end
Line 546: Line 574:
function p._getSpellBookTable(spellBookID)
function p._getSpellBookTable(spellBookID)
     local spells = p.getSpellsBySpellBook(spellBookID)
     local spells = p.getSpellsBySpellBook(spellBookID)
   
     if spells ~= nil and not Shared.tableIsEmpty(spells) then
     if spells ~= nil and not Shared.tableIsEmpty(spells) then
    -- Check to see if we need the items column
local hasItems = false
for i, spell in ipairs(spells) do
if p._getSpellItems(spell) ~= '' then
hasItems = true
break
end
end
   
         local resultPart = {}
         local resultPart = {}
         table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"| Spell')
         table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"| Spell')
Line 555: Line 593:
         end
         end
         table.insert(resultPart, '\r\n! Runes')
         table.insert(resultPart, '\r\n! Runes')
        if hasItems then
        table.insert(resultPart, '\r\n! Item Cost')
        end


         for i, spell in ipairs(spells) do
         for i, spell in ipairs(spells) do
             table.insert(resultPart, p._getSpellRow(spell, false))
             table.insert(resultPart, p._getSpellRow(spell, false, hasItems))
         end
         end