Anonymous

Module:Magic/Sandbox: Difference between revisions

From Melvor Idle
no edit summary
(Created page with "local p = {} local Shared = require('Module:Shared') local GameData = require('Module:GameData') local SkillData = GameData.skillData local Common = require('Module:Common') local Modifiers = require('Module:Modifiers') local Attacks = require('Module:Attacks') local Icons = require('Module:Icons') local Items = require('Module:Items') p.spellBooks = { { id = 'standard', dataID = 'attackSpells', name = 'Standard Magic', imgType = 'spell', bookID = 'melvorD:Standard' }...")
 
No edit summary
Line 598: Line 598:


function p._getSpellHeader(includeTypeColumn, includeItems, includeDamage, includeExperience)
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
end


function p._getSpellRow(spell, includeTypeColumn, includeItems, includeDamage, includeExperience)
function p._getSpellRow(spell, includeTypeColumn, includeItems, includeDamage, includeExperience)
local spellBook = p.getSpellBookFromSpell(spell)
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.getExpansionIcon(spell.id) .. Icons.Icon({spell.name, type=spellBook.imgType, noicon=true}))
if includeTypeColumn then
table.insert(rowPart, '||data-sort-value="' .. spellBook.id .. '"| ' .. p.getSpellTypeLink(spellBook.id))
end
table.insert(rowPart, '||data-sort-value="' .. spell.level .. '"| ' .. p._getSpellRequirements(spell))


--11/01/22: Added base damage if requested
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
--8/20/21: Changed to just getting the spell's description outright
table.insert(rowPart, '|| ' .. p._getSpellStat(spell, 'description'))
--1/4/22: haha just kidding. Now we're also getting delay between attacks for spells with special attacks
local spAttID = spell.specialAttackID or spell.specialAttack
if spAttID ~= nil then
local spAtt = Attacks.getAttackByID(spAttID)
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.')
if hits > 2 then
table.insert(rowPart, ' ' .. Shared.round(interval * (hits - 1) / 1000, 2, 2) .. 's total duration.')
end
table.insert(rowPart, ')')
end
end
if includeExperience then
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
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)
end
end


Line 683: Line 627:
local spellListSorted = Shared.shallowClone(spellList)
local spellListSorted = Shared.shallowClone(spellList)
table.sort(spellListSorted, function(a, b) return a.level < b.level end)
table.sort(spellListSorted, function(a, b) return a.level < b.level end)
local resultPart = {p._getSpellHeader(includeSpellbook, includeItems, includeDamage, includeExperience)}
---- Header stuff ----
local html = mw.html.create('table')
:addClass('wikitable, sortable, stickyHeader')
local header = html.tag('tr')
header.tag('th'):wikitext('Spell')
:attr('colspan', 2)
 
if includeTypeColumn then
header.tag('th'):wikitext('Spellbook')
end
header.tag('th'):wikitext('Requirements')
header.tag('th'):wikitext('[[DLC]]')
 
if includeDamage then
header.tag('th'):wikitext('Spell Dmg')
end
header.tag('th'):wikitext('Description')
--table.insert(resultPart, 'style="width:275px"| Description')
if includeExperience then
header.tag('th'):wikitext('XP')
end
header.tag('th'):wikitext('Runes')
:css('min-width', '90px')
 
if includeItems then
header.tag('th'):wikitext('Item Cost')
end
 
---- row stuff ----
for i, spell in ipairs(spellListSorted) do
for i, spell in ipairs(spellListSorted) do
table.insert(resultPart, p._getSpellRow(spell, includeSpellbook, includeItems, includeDamage, includeExperience))
local spellBook = p.getSpellBookFromSpell(spell)
local row = html.tag('tr')
row.tag('td'):wikitext(Icons.Icon({spell.name, type=spellBook.imgType, notext=true}))
:css('text-align', 'center')
:attr('data-sort-value', spell.name)
row.tag('td'):wikitext(Icons.Icon({spell.name, type=spellBook.imgType, noicon=true}))
 
if includeTypeColumn then
row.tag('td'):wikitext(p.getSpellTypeLink(spellBook.id))
:attr('data-sort-value', spellBook.id)
end
row.tag('td'):wikitext(Icons.getDLCColumnIcon(spell.id))
:attr('data-sort-value', Icons.getExpansionID(spell.id))
:css('text-align', 'center')
row.tag('td'):wikitext(p._getSpellRequirements(spell))
    :attr('data-sort-value', spell.level)
 
--11/01/22: Added base damage if requested
if includeDamage then
local dmg = p._getSpellStat(spell, 'spellDamage')
if dmg > 0 then
row.tag('td'):wikitext(dmg)
:css('text-align', 'right')
else
row.tag('td'):wikitext('N/A')
:addClass('table-na')
end
end
--8/20/21: Changed to just getting the spell's description outright
row.tag('td'):wikitext(p._getSpellStat(spell, 'description'))
 
--1/4/22: haha just kidding. Now we're also getting delay between attacks for spells with special attacks
local spAttID = spell.specialAttackID or spell.specialAttack
if spAttID ~= nil then
local spAtt = Attacks.getAttackByID(spAttID)
local interval = spAtt.attackInterval
local hits = spAtt.attackCount ~= nil and spAtt.attackCount or 1
if interval ~= nil and hits > 1 then
local intervalTable = {}
table.insert(intervalTable, '<br/>(' .. Shared.round(interval / 1000, 2, 2) .. 's delay between attacks.')
if hits > 2 then
table.insert(intervalTable, ' ' .. Shared.round(interval * (hits - 1) / 1000, 2, 2) .. 's total duration.')
end
table.insert(intervalTable, ')')
row.tag('td'):wikitext(table.concat(intervalTable))
end
end
if includeExperience then
local xp = spell.baseExperience
if xp == nil or xp == 0 then
row.tag('td'):wikitext('N/A')
:addClass('table-na')
else
row.tag('td'):wikitext(xp)
:addClass('text-align', 'right')
end
end
row.tag('td'):wikitext(p._getSpellRunes(spell))
:css('text-align', 'center')
if includeItems then
row.tag('td'):wikitext(p._getSpellItems(spell))
        :css('text-align', 'center')
end
end
end


table.insert(resultPart, '\n|}')
return tostring(html)
return table.concat(resultPart)
end
end
end
end
2,875

edits