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: Token rarity: If Present then Output Token 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 token = tArgs[2] local size = tArgs[3] or "25"

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

local tOutput = {}

local rType = { ["Common"]   = 1, ["Uncommon"] = 2, ["Rare"]     = 3, ["Epic"]     = 4, ["Legendary"] = 5, }

if token then local tRarity = { "", "", "",				" " }		local tCats = {}

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

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

tCats[rarity] = 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 else -- only stars (rarity first word only) if rarityList ~= "" then local rarity = rarityList:match("^([^%s,]+)") if rType[rarity] then local stars = string.rep(" ",							rType[rarity]) stars = stars:gsub("%s*$", "")

table.insert(tOutput, stars) end end end

return table.concat(tOutput) end

return p --