Module:TestArmorSet
Appearance
Documentation for this module may be created at Module:TestArmorSet/doc
local util_args = require("Module:ArgsUtil")
local util_cache = require("Module:CacheUtil")
local util_vars = require("Module:VarsUtil")
local cache = require('mw.ext.LuaCache')
local PREFIX = 'ITEMLINK_04'
local lang = mw.getLanguage('en')
local p = {}
local h = {}
local cargo = mw.ext.cargo
function p.Main(frame)
local args = util_args.mergeKeepEmpty()
local text = ""
local inpArmorType = args[1]
-- query all armor sets of a given type (light, medium or heavy)
local cargoArgs = {
where = 'armorset IS NOT NULL AND armortype = "' .. inpArmorType .. '"',
orderBy = 'armortype,armorset',
groupBy = 'armorset',
limit = 5000
}
local resultsArmorSets = cargo.query( 'Item', 'armorset, armortype', cargoArgs )
for r = 1, #resultsArmorSets do
local resultArmorSet = resultsArmorSets[r]
local inpSet = resultArmorSet["armorset"]
-- query the armor set
local cargoArgs2 = {
where = 'type = "Armor" AND armorset = "' .. inpSet .. '"',
orderBy = 'equipslot',
groupBy = 'id,_pageName',
limit = 10
}
local results = cargo.query( 'Item', 'id, name, _pageName, bonus, heatres, coldres, armor, dlcPackage, equipslot', cargoArgs2 )
-- process result and prepare data
local attr = {["Agility Weapon Damage"] = 0, ["Strength Weapon Damage"] = 0, ["Carrying Capacity"] = 0, ["Follower Damage"] = 0, ["Health"] = 0, ["Stamina"] = 0}
local dlcPackage
local sumArmor = 0
local sumHeatRes = 0
local sumColdRes = 0
local sumWeight = 0
local lastEquipslot = -1
for r = 1, #results do
local result = results[r]
-- bonus
if result["bonus"] ~= "" then
-- only add bonus of it is a differnet equipslot than the last one
if result["equipslot"] ~= lastEquipslot then
lastEquipslot = result["equipslot"]
for x in string.gmatch(result["bonus"], "([^,]+)") do
x = (x:gsub("^%s*(.-)%s*$", "%1"))
local key, value = string.match(x,'(.*) %+(%d+)%%?')
if attr[key] then
value = value + attr[key]
attr[key] = value
end
end
end
end
-- heat/cold res
local heatres = tonumber(result["heatres"]) or 0
if heatres > 0 then
foundHeatres = true
sumHeatRes = sumHeatRes + heatres
end
local coldres = tonumber(result["coldres"]) or 0
if coldres > 0 then
foundColdres = true
sumColdRes = sumColdRes + coldres
end
-- dlc (currently without a consistency check)
if not dlcPackage then
dlcPackage = result["dlcPackage"]
end
-- armor
local armor = tonumber(result["armor"]) or 0
if armor > 0 then
sumArmor = sumArmor + armor
end
-- weight
local weight = tonumber(result["weight"]) or 0
if weight > 0 then
sumWeight = sumWeight + weight
end
end
-- prepare output
-- start:table
text = text .. "{|class=\"wikitable mw-collapsible mw-collapsed\" style=\"text-align:center; width:100%\"\n"
-- table header
text = text .. "!Pieces!!Armor!!Bonus!!Resist!!Durability!!Weight!!Image\n" -- TODO image
-- start:caption
text = text .. "|-\n"
text = text .. "|+ style=\"text-align: left;\"|<span style=\"color:#a38369\">" .. inpSet .. "</span> - <small>"
local firstAddition = true
-- caption: feat (TODO)
-- caption:dlc
if dlcPackage and dlcPackage ~= "" then
if not firstAddition then text = text .. ", " end
text = text .. "[[" .. dlcPackage .. "]]"
firstAddition = false
end
-- caption:new line
text = text .. "<br>"
firstAddition = true -- new line => reset first addition flag
-- caption:sum armor
if sumArmor > 0 then
text = text .. sumArmor .. " Armor"
firstAddition = false
end
-- caption:bonus
local bonus = h.prepBonusText(attr)
if bonus ~= "" then
if not firstAddition then text = text .. ", " end
text = text .. bonus
firstAddition = false
end
-- caption: heat/cold resistance
if not firstAddition then text = text .. ", " end
text = text .. p.Resistance(frame, sumHeatRes, sumColdRes)
-- caption: weight
if not firstAddition then text = text .. ", " end
text = text .. sumWeight .. " Weight"
-- end:caption
text = text .. "</small>\n"
-- start:items
for r = 1, #results do
local result = results[r]
local pageName = result["_pageName"]
text = text .."|-\n"
text = text .. "|rowspan=1|" .. frame:expandTemplate({title = "ItemLink", args = {[1] = result["_pageName"]}})
text = text .. "||rowspan=1|" .. result["armor"]
text = text .. "||rowspan=1|" .. result["bonus"]
text = text .. "||rowspan=1|" .. frame:preprocess(p.Resistance(frame, tonumber(result["heatres"]) or 0, tonumber(result["coldres"]) or 0))
text = text .. "||rowspan=1|" .. "-"
text = text .. "||rowspan=1|" .. "-"
text = text .. "||rowspan=1|" .. "-" .. "\n"
end
-- end:table
text = text .. "|}\n"
end
return text
end
function p.Resistance(frame, heat, cold)
local inpHeatres = heat or tonumber(frame.args['heatres']) or 0
local inpColdres = cold or tonumber(frame.args['coldres']) or 0
if inpHeatres == 0 and inpColdres == 0 then
return "No resistances"
end
-- heat/cold res
local text = ""
if inpHeatres > 0 then
text = text .. "<span style=\"white-space: nowrap;\">[[File:T_tooltip_warmIcon.png|frameless|32px|link=]]"
local bars = math.floor(inpHeatres/4)
if inpHeatres%4 > 0 then
bars = bars+1
end
if bars > 10 then
bars = 10
end
for i=1, bars do
text = text .. "[[File:T_tooltip_warmSlot.png|frameless|link=]]"
end
for i=bars+1, 10 do
text = text .. "[[File:T_tooltip_emptySlot.png|frameless|link=]]"
end
text = text .. " (" .. inpHeatres .. ")</span>"
end
if inpColdres > 0 then
if inpHeatres then
text = text .. " "
end
text = text .. "<span style=\"white-space: nowrap;\">[[File:T_tooltip_coldIcon.png|frameless|32px|link=]]"
local bars = math.floor(inpColdres/4)
if inpColdres%4 > 0 then
bars = bars+1
end
if bars > 10 then
bars = 10
end
for i=1, bars do
text = text .. "[[File:T_tooltip_coldSlot.png|frameless|link=]]"
end
for i=bars+1, 10 do
text = text .. "[[File:T_tooltip_emptySlot.png|frameless|link=]]"
end
text = text .. " (" .. inpColdres .. ")</span>"
end
return text
end
function h.prepBonusText(attr)
local bonus = ""
for k, v in pairs(attr) do
if v > 0 then
if bonus ~= "" then bonus = bonus .. ", " end
bonus = bonus .. k .. " +" .. v
if k ~= "Stamina" and k ~= "Health" then
bonus = bonus .. "%"
end
end
end
return bonus
end
return p