Module:Accessory
Documentation for this module may be created at Module:Accessory/doc
local p = {}
local utils = require("Module:Utils")
local constant = mw.loadJsonData("Module:Data/constant.json")
local accessory = mw.loadJsonData("Module:Data/accessory.json")
local resource = mw.loadJsonData("Module:Data/resource.json")
function p.createInfobox(frame)
local name = frame.args.name
if name == nil or name == "" then name = mw.title.getCurrentTitle().subpageText end
local item = accessory[name]
local description = item.description
local collapse = "f"
if string.len(description) > 350 then collapse = "t" end
local instinct = "—"
local discipline = "—"
local focus = "—"
if item.affinities.Instinct ~= nil then instinct = item.affinities.Instinct[1] end
if item.affinities.Discipline ~= nil then discipline = item.affinities.Discipline[1] end
if item.affinities.Focus ~= nil then focus = item.affinities.Focus[1] end
local itemLevel = frame.args.levelOverride
if itemLevel == nil or itemLevel == "" then itemLevel = 30 end
local stats = p.createStats(item, itemLevel)
local str = ""
if item.tier ~= "Common" then
local setBonus = string.gsub(item.setItem.effect.partial, "+5%% Total ", "")
str = {
AccessoryName = name,
Rarity = item.tier,
Description = description,
DescCollapse = collapse,
SetName = item.setItem.name,
SetBonus = setBonus,
SetAccessory1 = item.setItem.items[1],
SetAccessory2 = item.setItem.items[2],
SetAccessory3 = item.setItem.items[3],
Level = itemLevel,
Instinct = instinct,
InstinctVal = stats[instinct],
Discipline = discipline,
DisciplineVal = stats[discipline],
Focus = focus,
FocusVal = stats[focus]
}
else
str = {
AccessoryName = name,
Rarity = item.tier,
Description = description,
DescCollapse = collapse,
Level = itemLevel,
Instinct = instinct,
InstinctVal = stats[instinct],
Discipline = discipline,
DisciplineVal = stats[discipline],
Focus = focus,
FocusVal = stats[focus]
}
end
return frame:expandTemplate{title = 'Infobox accessory', args = str}
end
function p.getDescription(frame)
local name = frame.args.name
if name == nil or name == "" then name = mw.title.getCurrentTitle().subpageText end
return accessory[name].description
end
function p.createStats(item, itemLevel)
local scaling = (item.attributeAutoScalingData.PerLevelBudgetIncrement * (itemLevel - 1))
local total = 0
for k, v in pairs(item.attributes) do
total = total + v
end
local maxhealth = p.getMaxStats("Max Health", item.attributes["Max Health"] or 0, total, scaling)
local resilience = p.getMaxStats("Resilience", item.attributes["Resilience"] or 0, total, scaling)
local weaponpower = p.getMaxStats("Weapon Power", item.attributes["Weapon Power"] or 0, total, scaling)
local abilitypower = p.getMaxStats("Ability Power", item.attributes["Ability Power"] or 0, total, scaling)
local critrating = p.getMaxStats("Crit Rating", item.attributes["Crit Rating"] or 0, total, scaling)
local critpower = p.getMaxStats("Crit Power", item.attributes["Crit Power"] or 0, total, scaling)
local breakpower = p.getMaxStats("Break Power", item.attributes["Break Power"] or 0, total, scaling)
local physdefense = p.getMaxStats("Phys Defense", item.attributes["Phys Defense"] or 0, total, scaling)
local magdefense = p.getMaxStats("Mag Defense", item.attributes["Mag Defense"] or 0, total, scaling)
local leveledStats = {
["Max Health"] = maxhealth,
["Resilience"] = resilience,
["Weapon Power"] = weaponpower,
["Ability Power"] = abilitypower,
["Crit Rating"] = critrating,
["Crit Power"] = critpower,
["Break Power"] = breakpower,
["Phys Defense"] = physdefense,
["Mag Defense"] = magdefense
}
return leveledStats
end
function p.getMaxStats(stats, single, total, scaling)
local maxstats = math.floor((single/total) * (total + scaling) * constant.Stats[stats].ItemBudgetMultiplier * constant.Stats[stats].DisplayValueMultiplier + 0.5)
if maxstats == 0 then maxstats = "" end
return maxstats
end
function p.createAccessoryList(frame)
local sortBy = frame.args.sortBy
if sortBy == nil or sortBy == "" then sortBy = nil end
local str = ""
local instinct = ""
local discipline = ""
local focus = ""
--local setBonus = ""
sorted = {}
for n in pairs(accessory) do table.insert(sorted, n) end
table.sort(sorted)
for k, v in pairs(sorted) do
instinct = "-"
discipline = "-"
focus = "-"
--setBonus = "-"
if accessory[v].affinities.Instinct ~= nil then instinct = accessory[v].affinities.Instinct[1] end
if accessory[v].affinities.Discipline ~= nil then discipline = accessory[v].affinities.Discipline[1] end
if accessory[v].affinities.Focus ~= nil then focus = accessory[v].affinities.Focus[1] end
--if accessory[v].tier ~= "Common" then setBonus = string.gsub(accessory[v].setItem.effect.partial, "+5%% Total ", "") end
if sortBy == nil or instinct == sortBy or discipline == sortBy or focus == sortBy then
str = str .. "|-" .. "\n" .. "| style=\"background-color:#27253D;\" | '''" .. frame:expandTemplate{title = 'icon', args = {v}} .. "''' || " .. instinct .. " || " .. discipline .. " || " .. focus .. "\n"
end
end
return str
end
function p.createCraftingTable(frame)
local name = frame.args.name
if name == nil or name == "" then name = mw.title.getCurrentTitle().subpageText end
local item = accessory[name]
local material = { "", "", "", "", "", "" }
local amount = { "", "", "", "", "", "" }
for k, v in ipairs(item.craftingRecipes) do
material[k] = v.name
amount[k] = v.amount
end
local str = {
Material1 = material[1],
Amount1 = amount[1],
Material2 = material[2],
Amount2 = amount[2],
Material3 = material[3],
Amount3 = amount[3],
Material4 = material[4],
Amount4 = amount[4],
Material5 = material[5],
Amount5 = amount[5],
Material6 = material[6],
Amount6 = amount[6]
}
return frame:expandTemplate{title = 'Crafting', args = str}
end
function p.createAccessorySetList(frame)
local sortBy = frame.args.sortBy
if sortBy == nil or sortBy == "" then sortBy = nil end
local str = ""
local sets = {}
for n in pairs(accessory) do
if (sortBy == nil and accessory[n].tier ~= "Common") or accessory[n].tier == sortBy then
local setName = accessory[n].setItem.name
local setTier = accessory[n].tier
local setBonus = string.gsub(accessory[n].setItem.effect.partial, "+5%% Total ", "")
local setItems = accessory[n].setItem.items[1] .. ", " .. accessory[n].setItem.items[2] .. ", " .. accessory[n].setItem.items[3]
sets[accessory[n].setItem.name] = {
setName = setName,
setTier = setTier,
setBonus = setBonus,
setItems = setItems
}
end
end
table.sort(sets)
for k, v in pairs(sets) do
local name = v.setName
local tier = v.setTier
local items = string.gsub(v.setItems, ", ", "@")
local stats = string.gsub(v.setBonus, ", ", "@")
local filter = string.gsub(string.gsub(v.setBonus, " ", ""), ",", " "):lower()
local template = {
name = name,
tier = tier,
items = items,
stats = stats,
filter = filter
}
str = str .. frame:expandTemplate{title = 'Accessory set list', args = template}
end
return str
end
return p