Documentation for this module may be created at Module:ArmorSet/doc
local p = {}
local cargo = mw.ext.cargo
function p.Bonus(frame)
local inpSet = frame.args['set']
-- prepare query
local args = {
where = 'type="Armor" AND armorset = "' .. inpSet .. '"',
orderBy = 'equipslot',
groupBy = 'id,_pageName',
limit = 10
}
local attr = {["Agility Weapon Damage"] = 0, ["Strength Weapon Damage"] = 0, ["Carrying Capacity"] = 0, ["Follower Damage"] = 0, ["Health"] = 0, ["Stamina"] = 0, ["Concussive Damage"] = 0}
local results = cargo.query( 'Item', 'id, name, _pageName, bonus, equipslot', args )
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
end
-- bonus
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" and k~= "Carrying Capacity" then
bonus = bonus .. "%"
end
end
end
return bonus
end
function p.Main( frame )
local inpSet = frame.args['set']
local inpSource = frame.args['source']
local inpImage = frame.args['image']
-- prepare query
local where = 'armorset = "' .. inpSet .. '"'
tables = 'Item'
fields = 'id, name, _pageName, bonus, heatres, coldres, armor, dlcPackage, equipslot'
local args = {
where = 'type="Armor" AND ' .. where,
orderBy = 'equipslot',
groupBy = 'id,_pageName',
limit = 10
}
-- itemlist
local itemList = ""
local foundHeatres, foundColdres, foundArmor = false
local dlcPackage
local attr = {["Agility Weapon Damage"] = 0, ["Strength Weapon Damage"] = 0, ["Carrying Capacity"] = 0, ["Follower Damage"] = 0, ["Health"] = 0, ["Stamina"] = 0, ["Concussive Damage"] = 0}
local tempResis = {["HeatResi"] = 0, ["ColdResi"] = 0}
local tempArmor = 0
local results = cargo.query( tables, fields, args )
local lastEquipslot = -1
for r = 1, #results do
local result = results[r]
-- item list
itemList = itemList .. "* " .. frame:callParserFunction('#invoke:ItemLink', 'Main', result["_pageName"]) .. "\n"
-- heat/cold res
if tonumber(result["heatres"]) or 0 > 0 then
foundHeatres = true
tempResis["HeatResi"] = tempResis["HeatResi"] + tonumber(result["heatres"])
end
if tonumber(result["coldres"]) or 0 > 0 then
foundColdres = true
tempResis["ColdResi"] = tempResis["ColdResi"] + tonumber(result["coldres"])
end
-- armor
if result["armor"] ~= "" then
foundArmor = true
tempArmor = tempArmor + tonumber(result["armor"])
end
-- 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
-- dlc
if not dlcPackage then
dlcPackage = result["dlcPackage"]
end
end
-- prepare result
-- headline
local headline = '<div style="font-size: 14px; font-weight:bold; color:#a38369">' .. inpSet .. '</div>\n'
-- sub-headline
local subHeadline = ""
-- armor
if foundArmor then
subHeadline = subHeadline .. tempArmor .. " base armor"
end
-- bonus
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" and k ~= "Carrying Capacity" then
bonus = bonus .. "%"
end
end
end
if bonus ~= "" then
subHeadline = subHeadline .. ", " .. bonus
end
-- dlc
if dlcPackage and dlcPackage ~= "" then
subHeadline = subHeadline .. ", [[Downloadable Content|DLC]] [[" .. dlcPackage .. "]]"
end
-- heat/cold res
if foundHeatres then
subHeadline = subHeadline .. "<br>[[File:T_tooltip_warmIcon.png|frameless|32px|link=]]"
local bars = math.floor(tempResis["HeatResi"]/4)
if tempResis["HeatResi"]%4 > 0 then
bars = bars+1
end
if bars > 10 then
bars = 10
end
for i=1, bars do
subHeadline = subHeadline .. "[[File:T_tooltip_warmSlot.png|frameless|link=]]"
end
for i=bars+1, 10 do
subHeadline = subHeadline .. "[[File:T_tooltip_emptySlot.png|frameless|link=]]"
end
subHeadline = subHeadline .. " (" .. tempResis["HeatResi"] .. ")"
end
if foundColdres then
if foundHeatres then
subHeadline = subHeadline .. ", "
else
subHeadline = subHeadline .. "<br>"
end
subHeadline = subHeadline .. " [[File:T_tooltip_coldIcon.png|frameless|32px|link=]]"
local bars = math.floor(tempResis["ColdResi"]/4)
if tempResis["ColdResi"]%4 > 0 then
bars = bars+1
end
if bars > 10 then
bars = 10
end
for i=1, bars do
subHeadline = subHeadline .. "[[File:T_tooltip_coldSlot.png|frameless|link=]]"
end
for i=bars+1, 10 do
subHeadline = subHeadline .. "[[File:T_tooltip_emptySlot.png|frameless|link=]]"
end
subHeadline = subHeadline .. " (" .. tempResis["ColdResi"] .. ")"
end
if not foundHeatres and not foundColdres then
subHeadline = subHeadline .. "<br>No resistances"
end
subHeadline = subHeadline .. "\n"
-- source
local source = ""
if inpSource and inpSource ~= "" then
source = "The prerequisite to craft this is:\n"
source = source .. "* [[" .. inpSource .. "]]\n"
source = source .. " "
end
-- image
if inpImage and inpImage ~= "" then
-- wrap itemList into a tabel and add the image to the second cell
local itemListWrapped = '{|width="750px"\n'
itemListWrapped = itemListWrapped .. '|width="500px"|\n' .. itemList .. '\n'
itemListWrapped = itemListWrapped .. '| style="vertical-align:top;" | ' .. '[[File:' .. inpImage .. '|250px|' .. inpSet .. ']]' .. '\n'
itemListWrapped = itemListWrapped .. '|}'
itemList = itemListWrapped
end
return headline .. subHeadline .. '<div class="mw-collapsible-content">\n' .. itemList .. source .. '</div>\n'
end
function p.Resistance(frame)
local inpHeatres = tonumber(frame.args['heatres']) or 0
local inpColdres = 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
return p