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 "" if rarityList == "" then return "" end local eType = tArgs[2] local size = tArgs[3] or "20"

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

local tOutput = {}

local rType = { ["common"]   = {1, "Common", "245f8d"}, ["uncommon"] = {2, "Uncommon", "f8bb2a"}, ["rare"]     = {3, "Rare", "53c4fe"}, ["epic"]     = {4, "Epic", "af15fd"}, ["legendary"] = {5, "Legendary", "fb3d05"}, }

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

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

tCats[evtRarity] = true end

table.insert(tOutput, table.concat(tRarity))

tRarity[1] = " " end

table.insert(tOutput, "")

for k in pairs(tCats) do			table.insert(tOutput, "") end elseif eType == "ECR" then local tRarity = { "", '⸺⸺ ', 'Unknown', '  ⸺⸺ ', 'At that time, there were no rarity' }

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

table.insert(tOutput, table.concat(tRarity))

tRarity[1] = " " end elseif eType == "S" then -- 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 else local tRarity = { "", '', "", 'Unknown', "", ' ', '' }

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

table.insert(tOutput, table.concat(tRarity))

tRarity[1] = " " end end

return table.concat(tOutput) end

return p