Module:Set infobox
Jump to navigation
Jump to search
Lua module used by Set infobox template.
The above documentation is transcluded from Module:Set infobox/doc. (edit | history)
local p = {}
function p.infobox(frame)
if frame == mw.getCurrentFrame() then
args = require('Module:ProcessArgs').merge(true)
else
frame = mw.getCurrentFrame()
end
-- for some reason this module itself is being stored in the ItemData Cargo table?
-- idk, just gonna do this...
if frame:getTitle() == 'Module:Set_infobox' then return '' 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','manaCostReduction','staminaCostReduction','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)
local result = mw.ext.cargo.query('ItemData', table.concat(fields,','), cargoArgs)
if not next(result) then
return nil
-- else
-- return result
end
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 }
_manaCostReduction = 0
_staminaCostReduction = 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
if (tonumber(v.manaCostReduction) ~= nil) then _manaCostReduction = p.addIfNotNil(_manaCostReduction, v.manaCostReduction) end
if (tonumber(v.staminaCostReduction) ~= nil) then _staminaCostReduction = p.addIfNotNil(_staminaCostReduction, v.staminaCostReduction) end
-- _manaCostReduction = p.addIfNotNil(_manaCostReduction, v.manaCostReduction)
-- _staminaCostReduction = p.addIfNotNil(_staminaCostReduction, v.staminaCostReduction)
_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, "<br>") end
_objectID = string.format("%s%s (%s)", _objectID, v.objectid or '', v.class)
end
end
-- store in cargo table because the {{Item armor}} 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]),
manaCostReduction= p.valueOrEmpty(_manaCostReduction),
staminaCostReduction= p.valueOrEmpty(_staminaCostReduction),
movespeed= p.valueOrEmpty(_movespeed),
pouch= p.valueOrEmpty(_pouch),
corruptresist= p.valueOrEmpty(_corruptresist),
cooldown=p.valueOrEmpty(_cdr),
durability=string.format('%.0f', _durability) or 0,
weight=string.format('%.1f', _weight) or 0,
DLC = dlc,
buy=string.format('%.0f', _buy) or 0,
sell=string.format('%.0f', _sell) or 0,
}
}
local output = ''
if (args.weaponset ~= nil) then
output = frame:preprocess('[[File:' .. image .. '|250x250px|thumb|right|The equipment in the <b>{{PAGENAME}}</b>.]] [[Category:Weapon Sets]]')
else
output = frame:preprocess(string.format([[{{Item armor
|noadd
|name=]] .. set .. [[
|image=]] .. image .. [[
|size=250x350px
|class=Set
|category=Set
|barrier=]] .. p.valueOrEmpty(_barrier) .. [[
|statusResist=]] .. p.valueOrEmpty(_statusResist) .. [[
|protection=]] .. p.valueOrEmpty(_protection) .. [[
|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]) .. [[
|manaCostReduction=]] .. p.valueOrEmpty(_manaCostReduction) .. [[
|staminaCostReduction=]] .. p.valueOrEmpty(_staminaCostReduction) .. [[
|movespeed=]] .. p.valueOrEmpty(_movespeed) .. [[
|pouch=]] .. p.valueOrEmpty(_pouch) .. [[
|corruptresist=]] .. p.valueOrEmpty(_corruptresist) .. [[
|cooldown=]] .. p.valueOrEmpty(_cdr) .. [[
|durability=%.0f
|weight=%.1f
|DLC = ]] .. dlc .. [[
|buy=%.0f
|sell=%.0f
|object id=]] .. ((_objectID ~= "" and _objectID) or "n/a") .. [[
}}]], _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
return p