16,254
edits
(Implement support for spells, familiars & refactor into single combined function for monster & player attacks table) |
(getCombatTriangleTable: Initial creation) |
||
Line 219: | Line 219: | ||
return p._getSpecialAttackTable(effectDefn, tableCategories, sourceHeaderLabel, includeSource) | return p._getSpecialAttackTable(effectDefn, tableCategories, sourceHeaderLabel, includeSource) | ||
end | |||
-- Generates a table showing the damage/DR multipliers for each combat triangle | |||
function p.getCombatTriangleTable() | |||
local triangleAttributes = { | |||
{ | |||
["name"] = 'damageModifier', | |||
["head"] = 'DMG', | |||
["func"] = function(val) | |||
local outVal = 100 * (val - 1) | |||
return { outVal, (outVal < 0 and '' or '+') .. string.format(outVal, '%.0f') .. '%' } | |||
end | |||
}, | |||
{ | |||
["name"] = 'reductionModifier', | |||
["head"] = 'DR', | |||
["func"] = function(val) return { (val - 1), string.format('%.2fx', val) } end | |||
} | |||
} | |||
local combatStyles = { | |||
{ 'melee', Icons.Icon({ 'Attack', 'Melee', type = 'skill' }) }, | |||
{ 'ranged', Icons.Icon({ 'Ranged', type = 'skill' }) }, | |||
{ 'magic', Icons.Icon({ 'Magic', type = 'skill' }) } | |||
} | |||
local gameMode = { | |||
{ 'Standard', 'Standard' }, | |||
{ 'Hardcore', Icons.Icon({ 'Hardcore' }) } | |||
} | |||
local attrCount = Shared.tableCount(triangleAttributes) | |||
local styleCount = Shared.tableCount(combatStyles) | |||
local modeCount = Shared.tableCount(gameMode) | |||
local resultPart = {} | |||
-- Generate header | |||
table.insert(resultPart, '{| class="wikitable"\r\n|-') | |||
table.insert(resultPart, '\r\n!rowspan="2"| Player Style') | |||
table.insert(resultPart, '\r\n!rowspan="2"| Game Mode') | |||
for i, style in ipairs(combatStyles) do | |||
table.insert(resultPart, '\r\n!colspan="' .. attrCount .. '"| VS ' .. style[2]) | |||
end | |||
local attrHeader = '' | |||
for i, attr in ipairs(triangleAttributes) do | |||
attrHeader = attrHeader .. '\r\n! ' .. attr.head | |||
end | |||
table.insert(resultPart, '\r\n|-' .. string.rep(attrHeader, styleCount)) | |||
-- Generate table body | |||
for i, attStyle in ipairs(combatStyles) do | |||
local borderStyle = (i < styleCount and 'style="border-bottom:solid lightgrey"' or '') | |||
for j, mode in ipairs(gameMode) do | |||
table.insert(resultPart, '\r\n|-') | |||
if j == 1 then | |||
table.insert(resultPart, '\r\n|rowspan="' .. modeCount .. '" ' .. borderStyle .. '| ' .. attStyle[2]) | |||
elseif j == modeCount and borderStyle ~= '' then | |||
table.insert(resultPart, ' ' .. borderStyle) | |||
end | |||
table.insert(resultPart, '\r\n| ' .. mode[2]) | |||
for k, targStyle in ipairs(combatStyles) do | |||
for m, attr in ipairs(triangleAttributes) do | |||
local cellStyle = nil | |||
local attValRaw = Constants.getTriangleAttribute(attr.name, attStyle[1], targStyle[1], mode[1]) | |||
local attrVal = attr.func(attValRaw) | |||
if attrVal[1] > 0 then | |||
cellStyle = 'background-color:lightgreen;' | |||
elseif attrVal[1] < 0 then | |||
cellStyle = 'background-color:lightpink;' | |||
end | |||
table.insert(resultPart, '\r\n|' .. (cellStyle ~= nil and 'style="' .. cellStyle .. '"| ' or ' ') .. attrVal[2]) | |||
end | |||
end | |||
end | |||
end | |||
table.insert(resultPart, '\r\n|}') | |||
return table.concat(resultPart) | |||
end | end | ||
return p | return p |