Module:Odds

-- --Start Module local p = {} --Required modules local getArgs = require('Module:Arguments').getArgs local yesno = require('Module:Yesno') local string = require('Module:String') local checkType = require('libraryUtil').checkType

--Create aliases for more possible inputs local aliases = { ['g'] = 'guaranteed', ['guaranteed'] = 'guaranteed', ['c'] = 'common', ['common'] = 'common', ['o'] = 'occasional', ['occ'] = 'occasional', ['occasional'] = 'occasional', ['r'] = 'rare', ['rare'] = 'rare', ['e'] = 'extraordinary', ['extraord'] = 'extraordinary', ['extraordinary'] = 'extraordinary', ['eo'] = 'extraordinary', ['p'] = 'pray rngesus', ['pray'] = 'pray rngesus', ['pray rngesus'] = 'pray rngesus', ['rng'] = 'pray rngesus', ['rngesus'] = 'pray rngesus', ['r i'] = 'rng incarnate', ['rng i'] = 'rng incarnate', ['rng incarnate'] = 'rng incarnate', ['rngesus incarnate'] = 'rng incarnate', ['rngesus i'] = 'rng incarnate' } --Store data about all odds local odds_data = { ['guaranteed'] = { name="Guaranteed", color="#00a600", percent="100%", order=1, },   ['common'] = { name="Common", color="#00a600", percent="75%", order=2, },   ['occasional'] = { name="Occasional", color="#3f3fff", percent="20%", order=3, },   ['rare'] = { name="Rare", color="#76d4f2", percent="5%", order=4, },   ['extraordinary'] = { name="Extraordinary", color="#cc1acc", percent="1%", order=5, },   ['pray rngesus'] = { name="Pray RNGesus", color="#ff55ff", percent="<1%", order=6, },   ['rng incarnate'] = { name="RNGesus Incarnate", color="#ff5555", percent="≪1%", order=7, }, }

--hide the order number function hideAlways(data) return string.wrapHtml(data, ' ', {class={"desktop-hide", "hidden"}}) end

local function format(tier, nameonly, approx) local tier = aliases[tier:lower] or error(string.format('Invalid odds name "%s"', tier), 3) local data = odds_data[tier] return table.concat{ ,       string.wrapHtml{            table.concat{                hideAlways(data.order),                data.name,                nameonly and "" or table.concat{                    ' (',                     (approx and tier ~= "pray rngesus") and "~" or "",                     data.percent,                     ') ',                }            },            ' ',            {                style={                    ["font"]="bold 100% monospace";                    ["color"]=data.color;                }            }        },         } end

- -- Template:Odds -- -- Displays Formatted text relating to drop chance - function p.odds(frame) local args = getArgs(frame) local tier = args[1] local big = yesno(args["big"], false) local nameonly = yesno(args["nameonly"] or args["na"] or args["no"], false) local approx = yesno(args["approximate"] or args["approx"] or args["a"], false) local calc = yesno(args["calc"] or args["cal"] or args["c"], false) local success, response = pcall(p._odds, tier, nameonly, approx, big, calc) return success and response or string.error(response) end - -- Template:Odds Module Acess Point - function p._odds(tier, nameonly, approx, big, calc) if type(tier) == "table" then nameonly = tier.nameonly or tier.na or tier.no or tier[2] approx = tier.approx or tier.app or tier.a or tier[3] big = tier.big or tier.b or tier[4] calc = tier.calc or tier.cal or tier.c or tier[5] tier = tier.tier or tier.t or tier[1] end if tier == nil or tier == "" then return "" end if type(tier) ~= "number" and type(tier) ~= "string" then error(string.format('bad argument #1 to \'_odds\' (string/number expected, got %s)', type(tier)), 2) end tier = tostring(tier) if tier:match('([%d%%]+)') and not calc then return table.concat{ big and "" or ' (',            tier:gsub('%%', ''),             '%',             big and "" or ') ' }   end if calc and tier:match('([%d%%]+)') then tier, _ = tier:gsub('%%', '') tier = tonumber(tier) if tier >= 100 then tier = 'g'       elseif tier >= 75 then tier = 'c'       elseif tier >= 20 then tier = 'o'       elseif tier >= 5 then tier = 'r'       elseif tier >= 1 then tier = 'e'       elseif tier < 1 then tier = 'rng' end end return format(tier, nameonly, approx) end

--Finish Module return p