Module:Enemies

local p = {}

function p.enemies(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end type = args.type or "" dlc = args.DLC or ""

local fields = { '_pageName', 'DLC', 'name', 'image', 'class', 'type', 'locations', 'health', 'healthRegen', 'impactResistance', 'protection', 'physResist', 'ethResist', 'decayResist', 'lightResist', 'frostResist', 'fireResist', 'StatusImmunity', 'BaseDamage', 'BaseImpact', 'inflicts' } local cargoWhere = ""

if (type ~= "") then cargoWhere = string.format('type="%s"', type) end if (dlc ~= "") then if (cargoWhere ~= "") then cargoWhere = cargoWhere .. ' AND ' end cargoWhere = cargoWhere .. 'DLC="' .. dlc .. '"' end

local cargoArgs = { limit = 5000, where = cargoWhere }

local result = p.doQuery(table.concat(fields,','), cargoArgs) if not result then return mw.html.create:css('width: 50%'):wikitext('Auto-generated list: No enemies found.'):done else local table = mw.html.create('table'):addClass('wikitable sortable')

-- Headers th = table:tag('tr')

th:tag('th'):wikitext('Image') th:tag('th'):wikitext('Name') th:tag('th'):wikitext('Class') th:tag('th'):wikitext(frame:preprocess(' Health')) th:tag('th'):wikitext(frame:preprocess(' Regen')) th:tag('th'):wikitext(frame:preprocess('')) th:tag('th'):wikitext(frame:preprocess('')) th:tag('th'):wikitext(frame:preprocess('')) th:tag('th'):wikitext(frame:preprocess('')) th:tag('th'):wikitext(frame:preprocess('')) th:tag('th'):wikitext(frame:preprocess('')) th:tag('th'):wikitext('Protection') th:tag('th'):wikitext('Status Immunity') th:tag('th'):wikitext('Base Damage') th:tag('th'):wikitext('Inflicts')

-- Enemy rows styles = { red = { color = "#df756f", align = 'center'}, green = { color = "#aedc99", align = 'center'}, none = { color = "#555555", align = 'center'} }       for k,row in ipairs(result) do            tr = table:tag('tr')

tr:tag('td'):wikitext(frame:preprocess(string.format('',row.image,row._pageName))) local nameCell = string.format('%s',row._pageName) if (row.DLC ~= nil and row.DLC ~= '') then nameCell = nameCell .. ' '	           end tr:tag('td'):wikitext(frame:preprocess(nameCell)) tr:tag('td'):wikitext(frame:preprocess(row.class)) tr:tag('td'):wikitext(row.health):attr('data-sort-row', 0)

p.formatNumberCell(tr, row.healthRegen) p.formatNumberCell(tr, row.physResist) p.formatNumberCell(tr, row.ethResist) p.formatNumberCell(tr, row.decayResist) p.formatNumberCell(tr, row.lightResist) p.formatNumberCell(tr, row.frostResist) p.formatNumberCell(tr, row.fireResist)

if (row.protection ~= nil and row.protection ~= '') then tr:tag('td'):wikitext(frame:preprocess(string.format("%s ",row.protection))):attr('data-sort-row', 0) else tr:tag('td'):wikitext('-') end tr:tag('td'):wikitext(frame:preprocess(row.StatusImmunity)) tr:tag('td'):wikitext(frame:preprocess(row.BaseDamage)):attr('data-sort-row', 0) tr:tag('td'):wikitext(frame:preprocess(row.inflicts)) end

return table end end

function p.formatNumberCell(tr, text) local td = tr:tag('td') local value = tonumber(text) or 0 local style = '' if (value > 0) then style = 'green' elseif (value < 0) then style = 'red' else style = 'none' end td:css(styles[style]):wikitext(value) td:attr('data-sort-row', 0) end

function p.doQuery(fields, args) local result = mw.ext.cargo.query('Enemies', fields, args) if not next(result) then return nil else return result end end

return p