Module:Rarity

--[==[-- - Lua script to display Rarity of items -

rarity: Parameters: 1:	Rarity Format: Rarity,Event Text Event Text is optional Separate multiple entries with dollar sign "$" 2: Type Token: If Present then Output Token Rarity Format ECR: If Present then Output ECR Rarity Format 3: icon size: vertical size of Icon in pixels (Default = 25) --]==]

local p = {}

local util = require('Module:Utility')

function p.rarity(frame) local tArgs = util.getArgs(frame)

local rarityList = tArgs[1] or "" local eType = tArgs[2] local size = tArgs[3] or "25"

rarityList = rarityList:gsub("^%s*(.-)%s*$", "%1") or ''

local tOutput = {}

local rType = { ["common"]   = {1, "Common"}, ["uncommon"] = {2, "Uncommon"}, ["rare"]     = {3, "Rare"}, ["epic"]     = {4, "Epic"}, ["legendary"] = {5, "Legendary"}, }

if eType == "T" then local tRarity = { "", "", "",				" " }		local tCats = {}

for evtRarity in mw.text.gsplit(rarityList, "%s*%$%s*") do			local rarity, eText = string.match(evtRarity, "^([^%s,]+)%s*,?%s*([^,]*)$") rarity = rarity:lower

if rType[rarity] then tRarity[3] = rType[rarity][2] tRarity[5] = rType[rarity][2] tRarity[7] = rType[rarity][1] tRarity[11] = rType[rarity][2] tRarity[13] = rType[rarity][2]

tCats[rType[rarity][2]] = true

table.insert(tOutput, table.concat(tRarity)) else table.insert(tOutput, tRarity[1]) table.insert(tOutput, "Unknown") end if eText and eText ~= "" then table.insert(tOutput, " (")				table.insert(tOutput, eText)				table.insert(tOutput, " Event) ") end

tRarity[1] = " " end table.insert(tOutput, "") for k in pairs(tCats) do			table.insert(tOutput, "") end elseif eType == "ECR" then local tRarity = {"", " ", ""} local tCats = {}

for evtRarity in mw.text.gsplit(rarityList, "%s*%$%s*") do	   	evtRarity = evtRarity:lower if rType[evtRarity] then tRarity[ 3] = evtRarity tRarity[ 5] = rType[evtRarity][2] tRarity[ 7] = string.rep(" ",							rType[evtRarity][1])

tCats[evtRarity] = true

table.insert(tOutput, table.concat(tRarity)) else table.insert(tOutput, tRarity[1]) table.insert(tOutput, '⸺ Unknown Rarity ⸺ ? ? ? ? ?') end

tRarity[1] = " " end else -- only stars (rarity first word only) if rarityList ~= "" then local rarity = rarityList:lower:match("^([^%s,]+)") if rType[rarity] then local stars = string.rep(" ",							rType[rarity][1]) stars = stars:gsub("%s*$", "")

table.insert(tOutput, stars) else table.insert(tOutput, "Unknown") end end end

return table.concat(tOutput) end

return p --