Anonymous

Module:Magic: Difference between revisions

From Melvor Idle
2,544 bytes added ,  12 November 2022
getSpellIconType: Implement for use in Template:SpellIcon
(Added a spell damage column to Archaic & Standard spell books)
(getSpellIconType: Implement for use in Template:SpellIcon)
(6 intermediate revisions by 2 users not shown)
Line 89: Line 89:
         end
         end
     end
     end
end
--Returns the expansion icon for the spell if it has one
function p.getExpansionIcon(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[[Category:Pages with script errors]]"
end
return Icons.getExpansionIcon(spell.id)
end
end


Line 109: Line 120:
         return spellBook.imgType
         return spellBook.imgType
     end
     end
end
function p.getSpellIconType(frame)
local spellName = frame.args ~= nil and frame.args[1] or frame
local spell = p.getSpell(spellName)
if spell == nil then
return 'spell'
else
return p._getSpellIconType(spell)
end
end
end


Line 256: Line 277:
end
end


function p._getSpellDescription(spell)
function p._getSpellDescription(spell, inline)
if inline == nil then inline = false end
local connector = inline and '<br/>' or ' and '
if spell.description ~= nil then
if spell.description ~= nil then
         return Shared.applyTemplateData(spell.description, p._getSpellTemplateData(spell))
         return Shared.applyTemplateData(spell.description, p._getSpellTemplateData(spell))
Line 265: Line 288:
         end
         end
         if spell.targetModifiers ~= nil then
         if spell.targetModifiers ~= nil then
             local targetModText = Constants.getModifiersText(spell.targetModifiers, false)
             local targetModText = Constants.getModifiersText(spell.targetModifiers, false, inline)
             table.insert(resultPart, 'Enemies are inflicted with:<br/>' .. targetModText)
             if inline then
            table.insert(resultPart, targetModText)
            else
            table.insert(resultPart, 'Enemies are inflicted with:<br/>' .. targetModText)
            end
         end
         end
         return table.concat(resultPart, '<br/>')
         return table.concat(resultPart, connector)
     elseif spell.specialAttackID ~= nil or spell.specialAttack ~= nil then
     elseif spell.specialAttackID ~= nil or spell.specialAttack ~= nil then
     local spAtt = Attacks.getAttackByID(spell.specialAttackID or spell.specialAttack)
     local spAtt = Attacks.getAttackByID(spell.specialAttackID or spell.specialAttack)
Line 323: Line 350:
local result = ''
local result = ''


--11/01/22: Added Spell Damage for standard & archaic spells
if spell.spellBook == 'standard' or spell.spellBook == 'archaic' then
result = result.."\r\n|-\r\n|'''Spell Damage:''' "..p._getSpellStat(spell, 'spellDamage')
end
--8/20/21: Changed to using the new getSpellDescription function
--8/20/21: Changed to using the new getSpellDescription function
result = result.."\r\n|-\r\n|'''Description:'''<br/>"..p._getSpellStat(spell, 'description')
result = result.."\r\n|-\r\n|'''Description:'''<br/>"..p._getSpellStat(spell, 'description')
Line 541: Line 572:
end
end


function p._getSpellRow(spell, includeTypeColumn, includeItems, includeDamage)
function p._getSpellHeader(includeTypeColumn, includeItems, includeDamage, includeExperience)
local resultPart = {}
table.insert(resultPart, '{|class="wikitable sortable"\n!colspan="2"| Spell')
if includeTypeColumn then
table.insert(resultPart, 'Spellbook')
end
table.insert(resultPart, 'Requirements')
if includeDamage then
table.insert(resultPart, 'Spell Dmg')
end
table.insert(resultPart, 'style="width:275px"| Description')
if includeExperience then
table.insert(resultPart, 'XP')
end
table.insert(resultPart, 'style="min-width:90px"| Runes')
if includeItems then
table.insert(resultPart, 'Item Cost')
end
return table.concat(resultPart, '\n! ')
end
 
function p._getSpellRow(spell, includeTypeColumn, includeItems, includeDamage, includeExperience)
     local spellBookIdx = p.spellBookIndex[spell.spellBook]
     local spellBookIdx = p.spellBookIndex[spell.spellBook]
     local spellBook = p.spellBooks[spellBookIdx]
     local spellBook = p.spellBooks[spellBookIdx]
     local rowPart = {'\r\n|-\r\n|data-sort-value="' .. spell.name .. '"| '}
     local rowPart = {'\n|-\n|data-sort-value="' .. spell.name .. '"| '}
     table.insert(rowPart, Icons.Icon({spell.name, type=spellBook.imgType, notext=true, size=50}))
     table.insert(rowPart, Icons.Icon({spell.name, type=spellBook.imgType, notext=true, size=50}))
table.insert(rowPart, '|| ' .. Icons.Icon({spell.name, type=spellBook.imgType, noicon=true}))
table.insert(rowPart, '|| ' .. Icons.getExpansionIcon(spell.id) .. Icons.Icon({spell.name, type=spellBook.imgType, noicon=true}))
table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell))
 
if includeTypeColumn then
if includeTypeColumn then
table.insert(rowPart, '||data-sort-value="' .. spellBookIdx .. '"| ' .. p.getSpellTypeLink(spell.spellBook))
table.insert(rowPart, '||data-sort-value="' .. spellBookIdx .. '"| ' .. p.getSpellTypeLink(spell.spellBook))
end
end
table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell))
--11/01/22: Added base damage if requested
--11/01/22: Added base damage if requested
if includeDamage then
if includeDamage then
table.insert(rowPart, '||'..p._getSpellStat(spell, 'spellDamage'))
local dmg = p._getSpellStat(spell, 'spellDamage')
table.insert(rowPart, (dmg > 0 and '||style="text-align:right"| ' .. dmg or '||class="table-na"| N/A'))
end
end
Line 564: Line 617:
local spAtt = Attacks.getAttackByID(spAttID)
local spAtt = Attacks.getAttackByID(spAttID)
local interval = spAtt.attackInterval
local interval = spAtt.attackInterval
if interval ~= nil then
local hits = spAtt.attackCount ~= nil and spAtt.attackCount or 1
local hits = spAtt.attackCount ~= nil and spAtt.attackCount or 1
if interval ~= nil and hits > 1 then
             table.insert(rowPart, '<br/>(' .. Shared.round(interval / 1000, 2, 2) .. 's delay between attacks.')
             table.insert(rowPart, '<br/>(' .. Shared.round(interval / 1000, 2, 2) .. 's delay between attacks.')
if hits > 2 then
if hits > 2 then
Line 573: Line 626:
end
end
end
end
if spell.spellBook == 'altMagic' then
if includeExperience then
table.insert(rowPart, '|| ' .. spell.baseExperience)
local xp = spell.baseExperience
table.insert(rowPart, ((xp == nil or xp == 0) and '||class="table-na"| N/A' or '||style="text-align:right"| ' .. xp))
end
end
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell))
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellRunes(spell))
Line 583: Line 637:
end
end


function p._getSpellBookTable(spellBookID)
function p._getSpellTable(spellList, includeTypeColumn)
    local spells = p.getSpellsBySpellBook(spellBookID)
if type(spellList) == 'table' and not Shared.tableIsEmpty(spellList) then
   
local includeSpellbook, includeItems, includeDamage, includeExperience = false, false, false, false
    if spells ~= nil and not Shared.tableIsEmpty(spells) then
if type(includeTypeColumn) == 'boolean' then
    -- Check to see if we need the items column
includeSpellbook = includeTypeColumn
local hasItems = false
end
for i, spell in ipairs(spells) do
-- Check to see what columns are required
if p._getSpellItems(spell) ~= '' then
for i, spell in ipairs(spellList) do
hasItems = true
if not includeItems and p._getSpellItems(spell) ~= '' then
break
includeItems = true
end
if not includeExperience and spell.spellBook == 'altMagic' then
includeExperience = true
end
if not includeDamage and (spell.spellBook == 'archaic' or spell.spellBook == 'standard') then
includeDamage = true
end
end
end
end
-- Check to see if we want to show damage
local showDamage = spellBookID == 'archaic' or spellBookID == 'standard'
   
        local resultPart = {}
        table.insert(resultPart, '{|class="wikitable sortable"\r\n!colspan="2"| Spell')
        table.insert(resultPart, '\r\n! Requirements')
        if showDamage then
        table.insert(resultPart, '\r\n!Spell Dmg')
        end
        table.insert(resultPart, '\r\n!style="width:275px"| Description')
        if spellBookID == 'altMagic' then
            table.insert(resultPart, '\r\n! Experience')
        end
        table.insert(resultPart, '\r\n! Runes')
        if hasItems then
        table.insert(resultPart, '\r\n! Item Cost')
        end


        for i, spell in ipairs(spells) do
local resultPart = {p._getSpellHeader(includeSpellbook, includeItems, includeDamage, includeExperience)}
            table.insert(resultPart, p._getSpellRow(spell, false, hasItems, showDamage))
for i, spell in ipairs(spellList) do
        end
table.insert(resultPart, p._getSpellRow(spell, includeSpellbook, includeItems, includeDamage, includeExperience))
end


        table.insert(resultPart, '\r\n|}')
table.insert(resultPart, '\n|}')
         return table.concat(resultPart)
         return table.concat(resultPart)
    end
end
end
 
function p.getSpellTableFromList(frame)
local args = frame.args ~= nil and frame.args or frame
local spellListText = args[1]
local includeSpellbook = args.includeSpellbook ~= nil and string.lower(args.includeSpellbook) == 'true'
local spellNames = Shared.splitString(spellListText, ',')
local spellList = {}
for i, spellName in ipairs(spellNames) do
local spell = p.getSpell(spellName)
if spell == nil then
return 'ERROR: Unknown spell "' .. spellName .. '"[[Category:Pages with script errors]]'
else
table.insert(spellList, spell)
end
end
return p._getSpellTable(spellList, includeSpellbook)
end
end


Line 626: Line 686:
local spellBook = frame.args ~= nil and frame.args[1] or frame[1]
local spellBook = frame.args ~= nil and frame.args[1] or frame[1]
spellBook = p.getSpellBookID(spellBook)
spellBook = p.getSpellBookID(spellBook)
return p._getSpellBookTable(spellBook)
return p._getSpellTable(p.getSpellsBySpellBook(spellBook), false)
end
end


-- Included below for backwards compatibility
-- Included below for backwards compatibility
function p.getStandardSpellsTable(frame)
function p.getStandardSpellsTable(frame)
     return p._getSpellBookTable('standard')
     return p._getSpellTable(p.getSpellsBySpellBook('standard'), false)
end
end


function p.getAncientTable(frame)
function p.getAncientTable(frame)
     return p._getSpellBookTable('ancient')
     return p._getSpellTable(p.getSpellsBySpellBook('ancient'), false)
end
end


function p.getCurseTable(frame)
function p.getCurseTable(frame)
     return p._getSpellBookTable('curse')
     return p._getSpellTable(p.getSpellsBySpellBook('curse'), false)
end
end


function p.getAuroraTable(frame)
function p.getAuroraTable(frame)
     return p._getSpellBookTable('aurora')
     return p._getSpellTable(p.getSpellsBySpellBook('aurora'), false)
end
end


function p.getAltSpellsTable(frame)
function p.getAltSpellsTable(frame)
     return p._getSpellBookTable('altMagic')
     return p._getSpellTable(p.getSpellsBySpellBook('altMagic'), false)
end
end


return p
return p