12,714
edits
Falterfire (talk | contribs) (Added a getSpellItems function) |
(getSpellIconType: Implement for use in Template:SpellIcon) |
||
(8 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, | 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 294: | Line 321: | ||
elseif stat == 'type' then | elseif stat == 'type' then | ||
return p.getTypeString(spell.spellBook) | return p.getTypeString(spell.spellBook) | ||
elseif stat == 'spellDamage' then | |||
if spell.maxHit ~= undefined then | |||
return spell.maxHit * 10 | |||
else | |||
return 0 | |||
end | |||
end | end | ||
return spell[stat] | return spell[stat] | ||
Line 317: | 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 535: | Line 572: | ||
end | end | ||
function p._getSpellRow(spell, includeTypeColumn) | 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 = {' | 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})) | ||
if includeTypeColumn then | |||
table.insert(rowPart, '||data-sort-value="' .. spellBookIdx .. '"| ' .. p.getSpellTypeLink(spell.spellBook)) | |||
end | |||
table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell)) | table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell)) | ||
if | --11/01/22: Added base damage if requested | ||
table.insert(rowPart, '|| | if includeDamage then | ||
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 | ||
--8/20/21: Changed to just getting the spell's description outright | --8/20/21: Changed to just getting the spell's description outright | ||
table.insert(rowPart, '|| ' .. p._getSpellStat(spell, 'description')) | table.insert(rowPart, '|| ' .. p._getSpellStat(spell, 'description')) | ||
Line 553: | Line 617: | ||
local spAtt = Attacks.getAttackByID(spAttID) | local spAtt = Attacks.getAttackByID(spAttID) | ||
local interval = spAtt.attackInterval | local interval = spAtt.attackInterval | ||
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 562: | Line 626: | ||
end | end | ||
end | end | ||
if spell. | if includeExperience then | ||
table.insert(rowPart, '|| ' .. | 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)) | ||
if includeItems then | |||
table.insert(rowPart, '||style="text-align:center"| ' .. p._getSpellItems(spell)) | |||
end | |||
return table.concat(rowPart) | return table.concat(rowPart) | ||
end | end | ||
function p. | function p._getSpellTable(spellList, includeTypeColumn) | ||
if type(spellList) == 'table' and not Shared.tableIsEmpty(spellList) then | |||
local includeSpellbook, includeItems, includeDamage, includeExperience = false, false, false, false | |||
if type(includeTypeColumn) == 'boolean' then | |||
includeSpellbook = includeTypeColumn | |||
end | |||
-- Check to see what columns are required | |||
for i, spell in ipairs(spellList) do | |||
if not includeItems and p._getSpellItems(spell) ~= '' then | |||
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 | |||
local resultPart = {p._getSpellHeader(includeSpellbook, includeItems, includeDamage, includeExperience)} | |||
for i, spell in ipairs(spellList) do | |||
table.insert(resultPart, p._getSpellRow(spell, includeSpellbook, includeItems, includeDamage, includeExperience)) | |||
end | |||
table.insert(resultPart, '\n|}') | |||
return table.concat(resultPart) | return table.concat(resultPart) | ||
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 593: | 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. | 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. | return p._getSpellTable(p.getSpellsBySpellBook('standard'), false) | ||
end | end | ||
function p.getAncientTable(frame) | function p.getAncientTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('ancient'), false) | ||
end | end | ||
function p.getCurseTable(frame) | function p.getCurseTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('curse'), false) | ||
end | end | ||
function p.getAuroraTable(frame) | function p.getAuroraTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('aurora'), false) | ||
end | end | ||
function p.getAltSpellsTable(frame) | function p.getAltSpellsTable(frame) | ||
return p. | return p._getSpellTable(p.getSpellsBySpellBook('altMagic'), false) | ||
end | end | ||
return p | return p |