Module:Set infobox

local p = {}

function p.infobox(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end

set = args.set or mw.title.getCurrentTitle.text image = args.image or string.format("%s.png",mw.title.getCurrentTitle.text) dlc = args.DLC or ''

local fields = { '_pageName', 'name', 'image', 'effects', 'weight', 'buy', 'sell', 'durability', 'class', 'protection','barrier','statusResist','physical','ethereal','decay','lightning','frost','fire','impact','physicalBonus','etherealBonus','decayBonus','lightningBonus','frostBonus','fireBonus','manacost','staminacost','durability','movespeed','coldresist','heatresist','pouch','corruptresist','cooldown','itemset','objectid' } local cargoArgs = { where = string.format('itemset="%s"', set) } local result = p.doQuery(table.concat(fields,','), cargoArgs)

if result then _weight = 0 _durability = 0 _protection = 0 _barrier = 0 _statusResist = 0 _resistances = { 0, 0, 0, 0, 0, 0 } _impact = 0 _bonuses = { 0, 0, 0, 0, 0, 0 } _manacost = 0 _staminacost =0 _movespeed = 0 _coldresist = 0 _heatresist = 0 _corruptresist = 0 _cdr = 0 _pouch = 0 _buy = 0 _sell = 0 _objectID = ""

body = args.body or "" helm = args.head or "" boots = args.boots or ""

foundBody = false foundHelm = false foundBoots = false

for k,v in ipairs(result) do           local add = false

if v.class == "Chest" then if foundBody == false then if body == "" or body == v.name then foundBody = true add = true end end elseif (v.class == "Legs") then if foundBoots == false then if boots == "" or boots == v.name then foundBoots = true add = true end end elseif (v.class == "Head") then if foundHelm == false then if helm == "" or helm == v.name then foundHelm = true add = true end end end

if (add == true) then if (tonumber(v.weight) ~= nil) then _weight = _weight + tonumber(v.weight) end if (tonumber(v.durability) ~= nil) then _durability = _durability + tonumber(v.durability) end

_protection = p.addIfNotNil(_protection, v.protection) if (tonumber(v.barrier) ~= nil) then _barrier = p.addIfNotNil(_barrier, v.barrier) end if (tonumber(v.statusResist) ~= nil) then _statusResist = p.addIfNotNil(_statusResist, v.statusResist) end

_resistances[1] = p.addIfNotNil(_resistances[1], v.physical) _resistances[2] = p.addIfNotNil(_resistances[2], v.ethereal) _resistances[3] = p.addIfNotNil(_resistances[3], v.decay) _resistances[4] = p.addIfNotNil(_resistances[4], v.lightning) _resistances[5] = p.addIfNotNil(_resistances[5], v.frost) _resistances[6] = p.addIfNotNil(_resistances[6], v.fire) _impact = p.addIfNotNil(_impact, v.impact) _bonuses[1] = p.addIfNotNil(_bonuses[1], v.physicalBonus) _bonuses[2] = p.addIfNotNil(_bonuses[2], v.etherealBonus) _bonuses[3] = p.addIfNotNil(_bonuses[3], v.decayBonus) _bonuses[4] = p.addIfNotNil(_bonuses[4], v.lightningBonus) _bonuses[5] = p.addIfNotNil(_bonuses[5], v.frostBonus) _bonuses[6] = p.addIfNotNil(_bonuses[6], v.fireBonus)

if (tonumber(v.corruptresist) ~= nil) then _corruptresist = p.addIfNotNil(_corruptresist, v.corruptresist) end if (tonumber(v.cooldown) ~= nil) then _cdr = p.addIfNotNil(_cdr, v.cooldown) end _manacost = p.addIfNotNil(_manacost, v.manacost) _staminacost = p.addIfNotNil(_staminacost, v.staminacost) _movespeed = p.addIfNotNil(_movespeed, v.movespeed) _coldresist = p.addIfNotNil(_coldresist, v.coldresist) _heatresist = p.addIfNotNil(_heatresist, v.heatresist) _pouch = p.addIfNotNil(_pouch, v.pouch) _buy = p.addIfNotNil(_buy, v.buy) _sell = p.addIfNotNil(_sell, v.sell)

if (_objectID ~= "") then _objectID = string.format("%s%s", _objectID, " ") end _objectID = string.format("%s%s (%s)", _objectID, v.objectid, v.class) end end -- store in cargo table because the template is not storing it for some reason frame:callParserFunction{ name='#cargo_store', args = {				'_table=ItemData', name = set, image = image, size = '250x350px', category = 'Set', class = 'Set', protection= p.valueOrEmpty(_protection), barrier = p.valueOrEmpty(_barrier), statusResist = p.valueOrEmpty(_statusResist), physical= p.valueOrEmpty(_resistances[1]), ethereal= p.valueOrEmpty(_resistances[2]), decay= p.valueOrEmpty(_resistances[3]), lightning= p.valueOrEmpty(_resistances[4]), frost= p.valueOrEmpty(_resistances[5]), fire= p.valueOrEmpty(_resistances[6]), impact= p.valueOrEmpty(_impact, ""), coldresist= p.valueOrEmpty(_coldresist), heatresist= p.valueOrEmpty(_heatresist), physicalBonus= p.valueOrEmpty(_bonuses[1]), etherealBonus= p.valueOrEmpty(_bonuses[2]), decayBonus= p.valueOrEmpty(_bonuses[3]), lightningBonus= p.valueOrEmpty(_bonuses[4]), frostBonus= p.valueOrEmpty(_bonuses[5]), fireBonus= p.valueOrEmpty(_bonuses[6]), manacost= p.valueOrEmpty(_manacost), staminacost= p.valueOrEmpty(_staminacost), movespeed= p.valueOrEmpty(_movespeed), pouch= p.valueOrEmpty(_pouch), corruptresist= p.valueOrEmpty(_corruptresist), cooldown=p.valueOrEmpty(_cdr), durability=string.format('%.0f', _durability), weight=string.format('%.1f', _weight), DLC = dlc, buy=string.format('%.0f', _buy), sell=string.format('%.0f', _sell), }		}       local output = '' if (args.weaponset ~= nil) then output = frame:preprocess(' ') else output = frame:preprocess(string.format(, _durability, _weight, _buy, _sell)) end

return output else return mw.html.create:css('width: 50%'):wikitext('[Infobox] No set pieces found!'):done end end

function p.addIfNotNil(obj,valueToAdd) if (valueToAdd ~= nil and valueToAdd ~= "") then obj = obj + tonumber(valueToAdd) end return obj end

function p.valueOrEmpty(val,emptyVal) if (val == nil) then return "" else return (val ~= 0 and string.format("%.0f",val) or (emptyVal ~= nil and emptyVal or "")) end end

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

return p