Module:Items

-- local p = {}

local logbook = require("Module:Items/LogbookData") local data = require("Module:Items/Data") local data_e = require("Module:Equipment/Data") local all_items = data.items local all_equipment = data_e.equipment

Count function p.ItemCount local c, e = 0, 0 for i, item in pairs(all_items) do   if item.Rarity ~= "NoTier" then c = c + 1 end end for i in pairs(all_equipment) do   e = e + 1 end return c .. " items and " .. e .. " equipment" end

Item Infobox local infobox_template_item = [=[ ]=]

function p.InfoboxItem(frame) local item_name = frame.args[1] ~= "" and frame.args[1] or mw.title.getCurrentTitle.text local item = all_items[item_name] return frame:preprocess(infobox_template_item:format( item_name, item_name, item.Quote, item.Desc:gsub("\r\n", " "), item.Rarity, item.Boss or "", item.Category and Category(item.Category) or "", item.Unlock and "" .. item.Unlock .. "" or "", item.ID, item.Stats and Stats(item.Stats) or "" )) end

Equipment Infobox local infobox_template_equipment = [=[ ]=]

function p.InfoboxEquipment(frame) local equipment_name = frame.args[1] ~= "" and frame.args[1] or mw.title.getCurrentTitle.text local equipment = all_equipment[equipment_name] return frame:preprocess(infobox_template_equipment:format( equipment_name, equipment_name, equipment.Quote, equipment.Desc:gsub("\r\n", " "), equipment.Rarity, equipment.Cooldown and equipment.Cooldown .. "s" or "", equipment.Duration and math.ceil(math.log(equipment.Duration / (equipment.Cooldown * 0.5)) / math.log(0.85) - 0.05) + 1 or "", equipment.Duration and math.ceil(math.log(equipment.Duration / equipment.Cooldown) / math.log(0.85) - 0.05) or "", equipment.Unlock and "" .. equipment.Unlock .. "" or "", equipment.ID )) end

Category function Category(list) local cats = {} for i, v in ipairs(list) do   table.insert(cats, "" .. v .. "") end return table.concat(cats, " ") end

Stats local stats_row = [=[ ]=]
 * stat%s = %s
 * value%s = %s
 * stack%s = %s
 * add%s = %s

function Stats(stats) local rows = "" for i, v in ipairs(stats) do   rows = rows .. stats_row:format(     i, v.Stat,      i, v.Value,      i, Stack(v.Stack),      i, v.Add    ) end return rows end

Stack local colors = {} colors["Linear"] = "#CCCCCC" colors["Hyperbolic"] = "#33CC33" colors["Exponential"] = "#CC6666" colors["Special"] = "#8888FF" colors["None"] = "#888888"

function Stack(stack) if stack == "None" then return "None " end for k, v in pairs(colors) do   if stack == k then stack = stack:gsub(k, "" .. k .. " ") break end end return stack end

Item Table local table_head_item = [=[ {| class="article-table sortable firstcolumn-center-nowrap floatheader" style="width:100%;max-width:1350px" ! style="width:20%" | Item ! class="unsortable" | Description ! style="width:10%" | Stack Type ]=]

local table_row_item = [=[ ]=]
 * data-sort-value="%s" | %s.png%s
 * %s
 * %s
 * %s

function p.Table(frame) local rarity = frame.args[1] local wikitable = table_head_item for i, item in ipairs(Sort(all_items)) do   if item.Rarity == rarity then wikitable = wikitable .. table_row_item:format(       item.Name, item.Name, item.Name, item.Name,        Description(item.Desc),        StackTypes(item.Stats)      ) end end return frame:preprocess(wikitable .. "|}") end

Boss Table local table_head_boss = [=[ {| class="article-table sortable firstcolumn-center-nowrap floatheader" style="width:100%;max-width:1350px" ! style="width:20%" | Item ! class="unsortable" | Description ! style="width:20%" | Boss / Acquired From ! style="width:10%" | Stack Type ]=]

local table_row_boss = [=[ ]=]
 * data-sort-value="%s" | %s.png%s
 * %s
 * style="text-align:center;white-space:nowrap" data-sort-value="%s" | %s
 * %s
 * %s

function p.BossTable(frame) local wikitable = table_head_boss for i, item in ipairs(Sort(all_items)) do   if item.Rarity == "Boss" then wikitable = wikitable .. table_row_boss:format(       item.Name, item.Name, item.Name, item.Name,        Description(item.Desc),        item.Boss or "-", item.Boss and ("%s"):format(item.Boss, item.Boss, item.Boss) or "-",        StackTypes(item.Stats)      ) end end return frame:preprocess(wikitable .. "|}") end

Equipment Table local table_head_equipment = [=[ {| class="article-table sortable firstcolumn-center-nowrap floatheader" style="width:100%%;max-width:1350px" ! style="width:20%%" | Item ! class="unsortable" | Description ! style="white-space:nowrap;width:10%%" data-sort-type="number" | %s ]=]

local table_row_equipment = [=[ ]=]
 * data-sort-value="%s" | %s.png%s
 * %s
 * style="text-align:center" | %s
 * style="text-align:center" | %s

function p.EquipmentTable(frame) local rarity = frame.args[1] local wikitable = table_head_equipment:format(rarity == "Elite Equipment" and "Elite" or "Cooldown") for i, equipment in ipairs(Sort(all_equipment)) do   if equipment.Rarity == rarity then wikitable = wikitable .. table_row_equipment:format(       equipment.Name, equipment.Name, equipment.Name, equipment.Name,        Description(equipment.Desc),        rarity == "Elite Equipment" and equipment.Elite or (equipment.Cooldown and equipment.Cooldown .. "s" or "-")     ) end end return frame:preprocess(wikitable .. "|}") end

Description local link_patterns = {} link_patterns["Damage"] = { "[Dd]amage", "[Aa]ttack [Ss]peed" } link_patterns["Health"] = { "[Hh]ealth" } link_patterns["Shield"] = { "[Ss]hields?" } link_patterns["Barrier"] = { "[Bb]arrier" } link_patterns["Armor"] = { "[Aa]rmor" } link_patterns["Movement Speed"] = { "[Mm]ovement [Ss]peed", "[Ss]print [Ss]peed", "[Mm]ovespeed" } link_patterns["Chests#Rusty Lockbox"] = { "[Hh]idden [Cc]ache" } link_patterns[":Category:OnKillEffect Items"] = { "On%-Kill" } link_patterns["Interactibles#Shrines"] = { "Shrine" } link_patterns["3D Printers"] = { "3D Printers" } link_patterns["57 Leaf Clover"] = { "[Ll]uck" } link_patterns["Monsters#Bosses"] = { "[Bb]osses" } link_patterns["Monsters#Elites"] = { "[Ee]lites?" }

function Description(desc) for link, patterns in pairs(link_patterns) do   for i, v in ipairs(patterns) do      local a, b = desc:find(v) if a then desc = desc:sub(1, a - 1) .. "" .. desc:sub(a, b) .. " " .. desc:sub(b + 1, desc:len) break end end end return desc end

StackTypes function StackTypes(stats) if not stats then return "-" end local stack = {} for i, v in ipairs(stats) do   if v.Stack ~= stack[#stack] then table.insert(stack, v.Stack) end end return table.concat(stack, " ") end

Nav Items local nav_head_items = [=[ {| class="navbox" ! Items ]=]

local nav_row_items = [=[ ]=]
 * %s
 * %s
 * %s
 * %s

function p.NavItems(frame) local nav = nav_head_items local items = { Common = {}, Uncommon = {}, Legendary = {}, Boss = {}, Lunar = {}, NoTier = {} } for name, item in pairs(all_items) do   table.insert(items[item.Rarity], "" .. name .. "") end for rarity in pairs(items) do   table.sort(items[rarity]) end for i, rarity in ipairs({ "Common", "Uncommon", "Legendary", "Boss", "Lunar" }) do   nav = nav .. nav_row_items:format(     rarity,      rarity,      table.concat(items[rarity], " • ")    ) end return nav .. "|}" end

Nav Equipment local nav_head_equipment = [=[ {| class="navbox" ! Equipment ]=]

local nav_row_equipment = [=[ ]=]
 * %s
 * %s
 * %s
 * %s

function p.NavEquipment(frame) local nav = nav_head_equipment local equipment = { Equipment = {}, ["Lunar Equipment"] = {}, ["Elite Equipment"] = {} } for name, e in pairs(all_equipment) do   table.insert(equipment[e.Rarity], "" .. name .. "") end for rarity in pairs(equipment) do   table.sort(equipment[rarity]) end for i, rarity in ipairs({ "Equipment", "Lunar Equipment", "Elite Equipment" }) do   nav = nav .. nav_row_equipment:format(     rarity,      rarity:gsub(" Equipment", ""):gsub("Equipment", "Normal"),      table.concat(equipment[rarity], " • ")    ) end return nav .. "|}" end

Sort function Sort(list) local items = {} for name, item in pairs(list) do   item.Name = name table.insert(items, item) end table.sort(items, function(a, b) return a.Name < b.Name end) return items end

GetItemOrEquipment -- returns item object (table) or string with error function GetItemOrEquipment(item_name) if item_name == nil then return ' Error: Name missing. 1st parameter is required. ' end local item = all_items[item_name] or all_equipment[item_name] if item == nil then return ' Error: Incorrect name. Check capitalization. ' else return item end end

GetRarity function p.GetRarity(frame) local item_name = frame.args[1] local simple_form = frame.args[2] or false local item = GetItemOrEquipment(item_name) if type(item) == 'string' then return item end local rarity = item.Rarity if simple_form and rarity == 'Elite Equipment' then rarity = 'Equipment' elseif simple_form and rarity == 'Lunar Equipment' then rarity = 'Lunar' end return rarity end

local GetItemBox local itembox_template = ' ' ..  ..                           ' ' ..                               ..                            ' ' ..                          ' ' local function GetItemBox(frame, name, size) frame.args[1] = name frame.args[2] = 'simple' local rarity = p.GetRarity(frame) local itemSize = math.floor(size * 0.9375) local offset = (size - itemSize) / 2 return string.format(itembox_template,     rarity,      size,      name,      offset,      offset,      name,      itemSize,      name  ) end

Logbook local logbook_template = [=[

function p.Logbook(frame) local size = frame.args.size or frame.args[1] or 64 local spacing = math.max(0, size / 16 - 2) local rows = {} for i, item in ipairs(logbook.order) do   rows[#rows+1] = '| ' .. GetItemBox(frame, item, size) if i % logbook.width == 0 and i ~= count then rows[#rows+1] = '|-' end end return string.format(logbook_template, spacing, table.concat(rows, '\n')) end

return p --