Module:Odds

-- --Start Module local p = {}

--Required modules local getArgs = require('Module:Arguments').getArgs local loader = require('Module:Loader')

local string, table, yesno, libUtil = loader.require('String', 'Table', 'Yesno', 'LibraryUtil') local odds_data, aliases = loader.loadData('Odds/Data', 'Odds/Aliases')

local checkType = libUtil.checkType

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

local function makeLink(tier, nameonly, approx, alt) local tier = aliases[tier:lower] or error(string.format('Invalid odds name %q', 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,					') ',				}			},			' ', {				class = 'hsw-gamefont',				style = {					['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 alt = args[2] or nil 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, alt) return success and response or string.error(response) end - -- Template:Odds Module Acess Point - function p._odds(tier, nameonly, approx, big, calc, alt) if type(tier) == 'table' then tier = tier.tier or tier.t or tier[1] 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] alt = tier.alt or tier[6] 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%%]+)') or not aliases[tier:lower]) and not calc then return table.concat{ big and  or ' (',			tier:match('^~?-?[%d%.]+%%?$') and (alt or tier):gsub('%%', ) or (alt or tier),			tier:match('^~?-?[%d%.]+%%?$') and '%' or ,			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 makeLink(tier, nameonly, approx, alt) end

--Finish Module return p