17,105
edits
(Substitute links with Icons.Icon() where possible to benefit from ambiguous link handling) |
(getSpecialAttackTable: Initial implementation) |
||
Line 1,112: | Line 1,112: | ||
return table.concat(tableParts) | return table.concat(tableParts) | ||
end | end | ||
function p.getSpecialAttackTable(frame) | |||
local spAttTable = {} | |||
for i, monster in ipairs(MonsterData.Monsters) do | |||
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then | |||
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0) | |||
for j, spAtt in ipairs(monster.specialAttacks) do | |||
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance) | |||
if spAttTable[spAtt.id] == nil then | |||
spAttTable[spAtt.id] = { ['defn'] = spAtt, ['icons'] = {} } | |||
end | |||
if spAttTable[spAtt.id]['icons'][attChance] == nil then | |||
spAttTable[spAtt.id]['icons'][attChance] = {} | |||
end | |||
table.insert(spAttTable[spAtt.id]['icons'][attChance], Icons.Icon({ monster.name, type = 'monster' })) | |||
end | |||
end | |||
end | |||
local resultPart = {} | |||
table.insert(resultPart, '{|class="wikitable sortable stickyHeader"') | |||
table.insert(resultPart, '\r\n|- class="headerRow-0"') | |||
table.insert(resultPart, '\r\n!Name!!style="min-width:180px"|Monsters!!Chance!!Effect') | |||
for i, spAttData in Shared.skpairs(spAttTable) do | |||
local spAtt = spAttData.defn | |||
local firstRow = true | |||
local rowsSpanned = Shared.tableCount(spAttData.icons) | |||
local rowSuffix = '' | |||
if rowsSpanned > 1 then | |||
rowSuffix = '|rowspan="' .. rowsSpanned .. '"' | |||
end | |||
for chance, iconList in Shared.skpairs(spAttData.icons) do | |||
table.insert(resultPart, '\r\n|-') | |||
if firstRow then | |||
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.name) | |||
end | |||
table.insert(resultPart, '\r\n|data-sort-value="' .. spAtt.name .. '"| ' .. table.concat(iconList, '<br/>')) | |||
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%') | |||
if firstRow then | |||
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description) | |||
firstRow = false | |||
end | |||
end | |||
end | |||
table.insert(resultPart, '\r\n|}') | |||
return table.concat(resultPart) | |||
end | |||
return p | return p |